1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
|
/* The TdeGtk Theming Engine for Gtk+.
* Copyright (C) 2012 Timothy Pearson <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
// NOTE
// GTK contains a number of bugs that will interfere with your overall visual experience
// Those that I have reported can be accessed with this link:
// https://bugzilla.gnome.org/buglist.cgi?type0-0-4=substring&emailcc1=1&emailreporter1=1&emaillongdesc1=1&field0-0-0=product&type0-0-1=substring&field0-0-1=component&field0-0-4=longdesc&emailtype1=substring&type0-0-3=substring&query_format=advanced&emailassigned_to1=1&field0-0-3=status_whiteboard&emailqa_contact1=1&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&bug_status=NEEDINFO&bug_status=RESOLVED&bug_status=VERIFIED&field0-0-2=short_desc&email1=kb9vqf%40pearsoncomputing.net&type0-0-0=substring&value0-0-0=gtk%2B&type0-0-2=substring
// FIXME
// This style should use the TDE open/save dialogs instead of the stock Gnome GtkFileChooserDialog
// This is not currently possible in GTK
// See upstream GTK bug #687173
#define TDEGTK_THEME_THEME_DIRECTORY_NAME "tdegtk"
#define TDEGTK_THEME_CONTROL_FILE_NAME "gtk.css"
#define RC_CACHE_VERSION TQString("1")
#define DEBUG_PRINT(x) if (gtk3TQtDebug) printf(x"\n\r");
#define DEBUG_PRINT_ARGS(x,y) if (gtk3TQtDebug) printf(x"\n\r",y);
bool gtk3TQtEnable = false;
int gtk3TQtDebug = false;
bool tde_showIconsOnPushButtons = false;
void initTDESettings();
void writeGtkThemeControlFile(int forceRecreate);
extern "C" {
#include <gmodule.h>
#include <gtk/gtk.h>
#include "tdegtk-engine.h"
G_MODULE_EXPORT void theme_init(GTypeModule *module);
G_MODULE_EXPORT void theme_exit(void);
G_MODULE_EXPORT GtkThemingEngine* create_engine(void);
G_MODULE_EXPORT void theme_init(GTypeModule *module) {
tdegtk_engine_register_types(module);
}
G_MODULE_EXPORT void theme_exit(void) {
//
}
}
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <utility>
#include <vector>
#include <fstream>
#include <sstream>
#include <tqpainter.h>
#include <tqapplication.h>
#include <tqdir.h>
#include <tqfile.h>
#include <tqstyle.h>
#include <tqslider.h>
#include <tqscrollbar.h>
#include <tqregexp.h>
#include <tqfont.h>
#include <kapplication.h>
#include <kcmdlineargs.h>
#include <kiconloader.h>
#include <kaboutdata.h>
#include <kicontheme.h>
#include <klocale.h>
#include <kconfig.h>
#include <kglobal.h>
#include <kglobalsettings.h>
#include <gdk/gdkx.h>
#include "tdegtk-widgetlookup.h"
extern WidgetLookup m_widgetLookup;
typedef std::pair<std::string, unsigned int> SizePair;
typedef std::vector<SizePair> SizeMap;
SizeMap icon_sizes;
G_MODULE_EXPORT GtkThemingEngine* create_engine(void) {
gtk3TQtEnable = true;
gtk3TQtDebug = (getenv("GTK3_TQT_ENGINE_DEBUG") != NULL) ? 1 : 0;
DEBUG_PRINT("Creating KApplication")
int argc = 1;
char** argv;
// Supply it with fake data to keep KApplication happy
argv = (char**) malloc(sizeof(char*));
argv[0] = (char*) malloc(sizeof(char) * 21);
strncpy(argv[0], "gtk3-tqt-application", 21);
KAboutData aboutData("gtk3-tqt-engine", I18N_NOOP("gtk3-tqt-engine"), "v0.1",
"GTK3 TQt theme engine", KAboutData::License_GPL,
"(c) 2012, Timothy Pearson",
"", 0 /* TODO: Website */, "[email protected]");
KCmdLineArgs::init(argc, const_cast<char**>(argv), &aboutData);
KApplication::disableAutoDcopRegistration();
new KApplication(gdk_x11_get_default_xdisplay(), true, 0, 0, true);
initTDESettings();
// initialize icon sizes
icon_sizes.push_back(std::make_pair("panel-menu", 16));
icon_sizes.push_back(std::make_pair("panel", 32));
icon_sizes.push_back(std::make_pair("gtk-small-toolbar", IconSize(KIcon::Toolbar)));
icon_sizes.push_back(std::make_pair("gtk-large-toolbar", IconSize(KIcon::MainToolbar)));
icon_sizes.push_back(std::make_pair("gtk-dnd", IconSize(KIcon::Small)));
icon_sizes.push_back(std::make_pair("gtk-button", IconSize(KIcon::Small)));
icon_sizes.push_back(std::make_pair("gtk-menu", IconSize(KIcon::Small)));
icon_sizes.push_back(std::make_pair("gtk-dialog", IconSize(KIcon::Small)));
icon_sizes.push_back(std::make_pair("", IconSize(KIcon::Small)));
writeGtkThemeControlFile(false);
// Initialize hooks
m_widgetLookup.initializeHooks();
return GTK_THEMING_ENGINE (g_object_new (TDEGTK_TYPE_ENGINE, "name", "tdegtk", NULL));
}
// =========================================================================================================
//
// TQt3/GTK Theme Control Functions
//
// =========================================================================================================
TQStringList tdeSearchPaths;
TQString iconTheme;
TQStringList iconThemeDirs;
TQColor alternateBackgroundColour;
int showIconsOnButtons;
int toolbarStyle;
TQString tdeConfigValue(const TQString& section, const TQString& name, const TQString& def) {
KConfig currentConfig;
currentConfig.setGroup(section);
return currentConfig.readEntry(name, def);
}
bool tdeBoolConfigValue(const TQString& section, const TQString& name, bool def) {
KConfig currentConfig;
currentConfig.setGroup(section);
return currentConfig.readBoolEntry(name, def);
}
TQString tdeFindDir(const TQString& suffix, const TQString& file1, const TQString& file2) {
for ( TQStringList::Iterator it = tdeSearchPaths.begin(); it != tdeSearchPaths.end(); ++it )
{
if ((TQFile::exists((*it) + suffix + file1)) || (TQFile::exists((*it) + suffix + file2)))
return (*it) + suffix;
}
return TQString();
}
TQString runCommand(const TQString& command) {
FILE* p = popen(command.latin1(), "r");
if ((p == NULL) || (p < 0))
return TQString();
TQString ret;
while (!feof(p))
{
char buffer[256];
int n = fread(buffer, 1, 255, p);
buffer[n] = '\0';
ret += buffer;
}
pclose(p);
return ret.stripWhiteSpace();
}
void initTDESettings() {
tdeSearchPaths.clear();
TQString tdeHome = getenv("TDEHOME");
TQString tdeDirs = getenv("TDEDIRS");
TQString tdeDir = getenv("TDEDIR");
if (!tdeHome.isEmpty()) {
tdeSearchPaths.append(tdeHome);
}
tdeSearchPaths.append(runCommand("tde-config --localprefix"));
if (!tdeDirs.isEmpty()) {
tdeSearchPaths += TQStringList::split(':', tdeDirs);
}
if (!tdeDir.isEmpty()) {
tdeSearchPaths.append(tdeDir);
}
tdeSearchPaths.append(runCommand("tde-config --prefix"));
iconTheme = tdeConfigValue("Icons", "Theme", "crystalsvg");
tde_showIconsOnPushButtons = tdeBoolConfigValue("KDE", "ShowIconsOnPushButtons", false);
TQStringList back = TQStringList::split(',', tdeConfigValue("General", "alternateBackground", "238,246,255"));
alternateBackgroundColour.setRgb(back[0].toInt(), back[1].toInt(), back[2].toInt());
showIconsOnButtons = (tdeConfigValue("KDE", "ShowIconsOnPushButtons", "true").lower() == "true");
TQString tmp = tdeConfigValue("Toolbar style", "IconText", "true").lower();
if (tmp == "icononly") {
toolbarStyle = 0;
}
else if (tmp == "icontextright") {
toolbarStyle = 3;
}
else if (tmp == "textonly") {
toolbarStyle = 1;
}
else if (tmp == "icontextbottom") {
toolbarStyle = 2;
}
else {
// Should never happen, but just in case we fallback to TDE's default "icononly"
toolbarStyle = 0;
}
}
void gtk3_tqt_load_resource_string(const char* css_string) {
GtkCssProvider *provider;
provider = gtk_css_provider_new();
gtk_css_provider_load_from_data(provider, css_string, -1, NULL);
GdkDisplay *display = gdk_display_get_default();
GdkScreen *screen = gdk_display_get_default_screen(display);
gtk_style_context_add_provider_for_screen(screen, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref(provider);
DEBUG_PRINT_ARGS("gtk3_tqt_load_resource_string(%s)", css_string)
}
void gtk3_tqt_reload_theme_definition_file(const char* filename) {
GtkCssProvider *provider;
GError *error;
provider = gtk_css_provider_new();
GdkDisplay *display = gdk_display_get_default();
GdkScreen *screen = gdk_display_get_default_screen(display);
gtk_style_context_add_provider_for_screen(screen, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref(provider);
if (!gtk_css_provider_load_from_path(provider, filename, &error)) {
g_printerr("%s: error parsing %s: %s\n", G_STRFUNC, filename, error->message);
g_clear_error(&error);
}
}
TQString tdeFontToGTKFontString(TQFont font) {
TQString fontDescriptor = "font: ";
fontDescriptor.append(font.family());
if (font.bold()) {
fontDescriptor.append(" bold");
}
if (font.italic()) {
fontDescriptor.append(" italic");
}
if (font.pointSizeFloat() != -1) {
fontDescriptor.append(TQString(" %1").arg(font.pointSizeFloat()));
}
else {
fontDescriptor.append(TQString(" %1px").arg(font.pixelSize()));
}
return fontDescriptor;
}
// Thanks Martin Dvorak of metatheme
TQString parse_rc_string(const TQString& defs, const TQString& pattern, bool widgetClass = true) {
static int dynamic_counter = 0;
++dynamic_counter;
return pattern + " {\n\t" + defs + ";\n}\n\n";
}
GtkIconSet* generateIconSet(const std::string& gtkIconName, const std::string& tdeIconName, TQStringList pathList) {
if (tdeIconName == "NONE") {
return 0L;
}
bool empty = true;
// create iconSet
GtkIconSet* iconSet = gtk_icon_set_new();
// loop over iconSizes
for (SizeMap::const_iterator sizeIter = icon_sizes.begin(); sizeIter != icon_sizes.end(); ++sizeIter) {
// generate full icon name
std::ostringstream iconFileStream;
iconFileStream << sizeIter->second << "x" << sizeIter->second << "/" << tdeIconName;
// loop over provided path to see if at least one icon is found
for (TQStringList::const_iterator pathIter = pathList.begin(); pathIter != pathList.end(); ++pathIter) {
std::string filename((*pathIter + '/' + iconFileStream.str()).latin1());
if (!std::ifstream(filename.c_str())) {
continue;
}
empty = false;
GtkIconSource* iconSource(gtk_icon_source_new());
// set name
gtk_icon_source_set_filename(iconSource, filename.c_str());
// set direction and state wildcarded
gtk_icon_source_set_direction_wildcarded(iconSource, TRUE);
gtk_icon_source_set_state_wildcarded(iconSource, TRUE);
// set size
if (sizeIter->first.empty()) {
gtk_icon_source_set_size_wildcarded(iconSource, TRUE);
}
else {
GtkIconSize size = gtk_icon_size_from_name(sizeIter->first.c_str());
if (size != GTK_ICON_SIZE_INVALID) {
gtk_icon_source_set_size_wildcarded(iconSource, FALSE);
gtk_icon_source_set_size(iconSource, size);
}
}
// add source to iconSet
gtk_icon_set_add_source(iconSet, iconSource);
break;
}
}
// if nothing found, return;
if (empty) {
gtk_icon_set_unref(iconSet);
return 0L;
}
else {
return iconSet;
}
}
void doIconMapping(const char* gtkName, const char * tdeName, GtkIconFactory* factory, TQStringList tdeIconThemeDirs) {
GtkIconSet* iconSet = generateIconSet(gtkName, tdeName, tdeIconThemeDirs);
if (iconSet) {
gtk_icon_factory_add(factory, gtkName, iconSet);
gtk_icon_set_unref(iconSet);
}
}
TQString colorString(TQColor color) {
TQString ret = "rgb(";
ret += TQString::number(color.red()) + ", ";
ret += TQString::number(color.green()) + ", ";
ret += TQString::number(color.blue()) + ")";
return ret;
}
void setColour(TQString name, TQString state, TQColor color) {
state = ":" + state;
if (state == ":normal") {
state = "";
}
gtk3_tqt_load_resource_string(parse_rc_string(name + ": " + colorString(color), "*" + state).latin1());
}
static TQStringList iconInheritsDirs(const TQString& icondir) {
TQFile index;
index.setName(icondir + "index.theme");
if( !index.open( IO_ReadOnly )) {
index.setName(icondir + "index.desktop");
if( !index.open( IO_ReadOnly ))
return TQStringList();
}
char buf[1024];
TQRegExp reg( "^\\s*Inherits=([^\\n]*)" );
for(;;) {
if( index.readLine(buf, 1023) <= 0 ) {
break;
}
if( reg.search(buf, 0) >= 0 ) {
return TQStringList::split(",", reg.cap(1));
}
}
return TQStringList();
}
void addIconThemeDir(const TQString& theme) {
// Try to find this theme's directory
TQString icondir = tdeFindDir("/share/icons/" + theme + "/", "index.theme", "index.desktop");
if(icondir.isEmpty()) {
return;
}
if (iconThemeDirs.contains(icondir)) {
return;
}
// Add this theme to the list
iconThemeDirs.append(icondir);
// Do it again for any parent themes
TQStringList parents = iconInheritsDirs(icondir);
for ( TQStringList::Iterator it=parents.begin() ; it!=parents.end(); ++it) {
addIconThemeDir((*it).stripWhiteSpace());
}
}
void writeGtkThemeControlFile(int forceRecreate) {
if (!gtk3TQtEnable) {
return;
}
DEBUG_PRINT("writeGtkThemeControlFile()")
// Set colors
// Normal
setColour("color", "normal", tqApp->palette().active().text());
setColour("background-color", "normal", tqApp->palette().active().background());
// setColour("text", "normal", tqApp->palette().active().text());
// setColour("base", "normal", tqApp->palette().active().base());
// Active (on)
setColour("color", "active", tqApp->palette().active().text());
setColour("background-color", "active", tqApp->palette().active().background());
// setColour("text", "active", tqApp->palette().active().text());
// setColour("base", "active", tqApp->palette().active().base());
// Mouseover
setColour("color", "prelight", tqApp->palette().active().text()); // menu items - change?
setColour("background-color", "prelight", tqApp->palette().active().highlight());
// setColour("text", "prelight", tqApp->palette().active().text());
// setColour("base", "prelight", tqApp->palette().active().base());
// Selected
setColour("color", "selected", tqApp->palette().active().highlightedText());
setColour("background-color", "selected", tqApp->palette().active().highlight());
// setColour("text", "selected", tqApp->palette().active().highlightedText());
// setColour("base", "selected", tqApp->palette().active().highlight());
// Disabled
setColour("color", "insensitive", tqApp->palette().disabled().text());
setColour("background-color", "insensitive", tqApp->palette().disabled().background());
// setColour("text", "insensitive", tqApp->palette().disabled().text());
// setColour("base", "insensitive", tqApp->palette().disabled().background());
TQString iconSettingsString;
iconSettingsString.append(TQString("gtk-menu=%1,%2").arg(IconSize(KIcon::Small)).arg(IconSize(KIcon::Small)));
iconSettingsString.append(TQString(":gtk-button=%1,%2").arg(IconSize(KIcon::Small)).arg(IconSize(KIcon::Small)));
iconSettingsString.append(TQString(":gtk-small-toolbar=%1,%2").arg(IconSize(KIcon::Toolbar)).arg(IconSize(KIcon::Toolbar)));
iconSettingsString.append(TQString(":gtk-large-toolbar=%1,%2").arg(IconSize(KIcon::MainToolbar)).arg(IconSize(KIcon::MainToolbar)));
iconSettingsString.append(TQString(":gtk-dnd=%1,%2").arg(IconSize(KIcon::Small)).arg(IconSize(KIcon::Small)));
iconSettingsString.append(TQString(":gtk-dialog=%1,%2").arg(IconSize(KIcon::Small)).arg(IconSize(KIcon::Small)));
// Set up global application settings
GtkSettings* gtksettings = gtk_settings_get_default();
GtkSettingsValue svalue;
if (gtksettings) {
g_object_set(gtksettings, "gtk-alternative-button-order", TRUE, NULL);
g_object_set(gtksettings, "gtk-button-images", tde_showIconsOnPushButtons, NULL);
g_object_set(gtksettings, "gtk-menu-popup-delay", tqApp->style().styleHint(TQStyle::SH_PopupMenu_SubMenuPopupDelay), NULL);
g_object_set(gtksettings, "gtk-icon-sizes", iconSettingsString.ascii(), NULL);
// Handle toolbar text display
if (toolbarStyle == 3) {
// This is broken by GTK bug #68700
g_object_set(gtksettings, "gtk-toolbar-style", GTK_TOOLBAR_BOTH_HORIZ, NULL);
}
else if (toolbarStyle == 2) {
g_object_set(gtksettings, "gtk-toolbar-style", GTK_TOOLBAR_BOTH, NULL);
}
else if (toolbarStyle == 1) {
g_object_set(gtksettings, "gtk-toolbar-style", GTK_TOOLBAR_TEXT, NULL);
}
else {
g_object_set(gtksettings, "gtk-toolbar-style", GTK_TOOLBAR_ICONS, NULL);
}
}
// This function takes quite a long time to execute, and is run at the start of every app.
// In order to speed it up, we can store the results in a file, along with the name of icon
// theme and style. This file can then be regenerated when the icon theme or style change.
TQDir curDir;
TQString themeFilePath = TQDir::homeDirPath();
curDir.setPath(themeFilePath);
if (!curDir.exists()) {
curDir.mkdir(themeFilePath);
}
themeFilePath = themeFilePath + "/.themes/";
curDir.setPath(themeFilePath);
if (!curDir.exists()) {
curDir.mkdir(themeFilePath);
}
themeFilePath = themeFilePath + TQString(TDEGTK_THEME_THEME_DIRECTORY_NAME) + "/";
curDir.setPath(themeFilePath);
if (!curDir.exists()) {
curDir.mkdir(themeFilePath);
}
themeFilePath = themeFilePath + "gtk-3.0/";
curDir.setPath(themeFilePath);
if (!curDir.exists()) {
curDir.mkdir(themeFilePath);
}
themeFilePath = themeFilePath + TDEGTK_THEME_CONTROL_FILE_NAME;
TQFile themeFile(themeFilePath);
TQTextStream stream;
if (!forceRecreate && themeFile.exists())
{
themeFile.open(IO_ReadOnly);
stream.setDevice(TQT_TQIODEVICE(&themeFile));
if (stream.readLine() == "/* " + iconTheme + ", " + tqApp->style().name() + ", " + RC_CACHE_VERSION + " */")
{
// This cache matches the current icon theme and style
gtk3_tqt_reload_theme_definition_file(themeFilePath.latin1());
return;
}
stream.unsetDevice();
themeFile.close();
}
themeFile.open(IO_WriteOnly | IO_Truncate);
stream.setDevice(TQT_TQIODEVICE(&themeFile));
stream << "/* " << iconTheme << ", " << tqApp->style().name() << ", " << RC_CACHE_VERSION << " */\n\n";
stream << "/* This file was generated by the Gtk TQt Theme Engine */\n";
stream << "/* It will be recreated when you change your TDE icon theme or widget style */\n\n";
stream << "\n";
stream << "* {\n\tengine:tdegtk;\n}\n";
stream << "\n";
TQScrollBar sbar(NULL);
sbar.setOrientation(TQt::Horizontal);
sbar.setValue(1);
sbar.resize(200,25);
// The following code determines how many buttons are on a scrollbar
// It works by looking at each pixel of the scrollbar's area not taken up by the groove,
// and asking the style which subcontrol is at that location.
TQRect rect = tqApp->style().querySubControlMetrics(TQStyle::CC_ScrollBar, &sbar, TQStyle::SC_ScrollBarGroove);
bool back1 = false;
bool forward1 = false;
bool back2 = false;
bool forward2 = false;
TQStyle::SubControl sc = TQStyle::SC_None;
for (TQPoint pos(0,7) ; pos.x()<rect.x() ; pos.setX(pos.x()+1))
{
TQStyle::SubControl sc2 = tqApp->style().querySubControl(TQStyle::CC_ScrollBar, &sbar, pos);
if (sc != sc2)
{
if (sc2 == TQStyle::SC_ScrollBarAddLine) forward1 = true;
if (sc2 == TQStyle::SC_ScrollBarSubLine) back1 = true;
sc = sc2;
}
}
sc = TQStyle::SC_None;
for (TQPoint pos(rect.x()+rect.width(),7) ; pos.x()<200 ; pos.setX(pos.x()+1))
{
TQStyle::SubControl sc2 = tqApp->style().querySubControl(TQStyle::CC_ScrollBar, &sbar, pos);
if (sc != sc2)
{
if (sc2 == TQStyle::SC_ScrollBarAddLine) forward2 = true;
if (sc2 == TQStyle::SC_ScrollBarSubLine) back2 = true;
sc = sc2;
}
}
bool combobox_appears_as_list = (!(tqApp->style().styleHint(TQStyle::SH_ComboBox_Popup) || tqApp->style().styleHint(TQStyle::SH_GUIStyle) == TQt::MotifStyle));
stream << parse_rc_string(TQString("-GtkComboBox-appears-as-list: %1px").arg(combobox_appears_as_list), "*");
stream << parse_rc_string("-GtkComboBox-arrow-size: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_ArrowSize)), "*");
stream << parse_rc_string("-GtkComboBox-arrow-scaling: 0", "*");
stream << parse_rc_string(TQString("-GtkScrollbar-has-backward-stepper: ") + (back1 ? "1" : "0"), "*");
stream << parse_rc_string(TQString("-GtkScrollbar-has-forward-stepper: ") + (forward2 ? "1" : "0"), "*");
stream << parse_rc_string(TQString("-GtkScrollbar-has-secondary-forward-stepper: ") + (forward1 ? "1" : "0"), "*");
stream << parse_rc_string(TQString("-GtkScrollbar-has-secondary-backward-stepper: ") + (back2 ? "1" : "0"), "*");
stream << parse_rc_string("-GtkScrollbar-stepper-size: " + TQString::number(tqApp->style().querySubControlMetrics(TQStyle::CC_ScrollBar, &sbar, TQStyle::SC_ScrollBarSubLine).width() - 1), "*");
stream << parse_rc_string("-GtkScrollbar-min-slider-length: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_ScrollBarSliderMin)), "*");
stream << parse_rc_string("-GtkRange-slider-width: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_ScrollBarExtent)), "GtkScrollbar");
stream << parse_rc_string("-GtkRange-stepper-size: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_ScrollBarExtent)), "GtkScrollbar");
stream << parse_rc_string("-GtkRange-trough-border: 0", "GtkScrollbar");
stream << parse_rc_string("-GtkButton-child-displacement-x: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_ButtonShiftHorizontal)), "*");
stream << parse_rc_string("-GtkButton-child-displacement-y: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_ButtonShiftVertical)), "*");
stream << parse_rc_string("-GtkButton-default-border: 0 0 0 0", "*");
stream << parse_rc_string("-GtkButton-default-outside-border: 0 0 0 0", "*");
#ifdef USE_NATIVE_GTK_BUTTON_DRAWING
stream << parse_rc_string("-GtkButton-inner-border: 2 2 2 2", "*");
#else
if (tde_showIconsOnPushButtons) {
stream << parse_rc_string("-GtkButton-inner-border: 10 10 2 2", "*"); // Allow space for the icon on either side of the text
}
else {
stream << parse_rc_string("-GtkButton-inner-border: 2 2 2 2", "*");
}
#endif
stream << parse_rc_string("-GtkButtonBox-child_min_height: 0", "*");
stream << parse_rc_string("-GtkButtonBox-child_internal_pad_x: 0", "*");
stream << parse_rc_string("-GtkButtonBox-child_internal_pad_y: 0", "*");
TQSlider slider(NULL); // To keep BlueCurve happy
stream << parse_rc_string("-GtkScale-slider-length: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_SliderLength, &slider)), "*");
stream << parse_rc_string("-GtkRange-arrow-scaling: 1.0", "GtkScrollbar");
stream << parse_rc_string("-xthickness: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_DefaultFrameWidth)), "*.GtkMenu");
stream << parse_rc_string("-ythickness: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_DefaultFrameWidth)), "*.GtkMenu");
stream << parse_rc_string("-xthickness: 5", "*.GtkMenu.Gtk*MenuItem");
stream << parse_rc_string("-xthickness: 3", "*.GtkNotebook");
stream << parse_rc_string("-ythickness: 3", "*.GtkNotebook");
stream << parse_rc_string("-ythickness: 1", "*.GtkButton");
stream << parse_rc_string("-color: " + colorString(TQColor(0,0,0)), "gtk-tooltips.GtkLabel", false);
stream << parse_rc_string("-xthickness: 1", "*.GtkButton.*");
stream << parse_rc_string("-ythickness: 1", "*.GtkButton.*");
// stream << parse_rc_string("GtkTreeView::allow-rules = 0", "*");
// stream << parse_rc_string("GtkTreeView::tree-line-width = 1", "*");
// stream << parse_rc_string("GtkTreeView::vertical-separator = 30", "*");
// //stream << parse_rc_string("GtkTreeView::odd-row-color = { 0.0, 0.0, 0.0 }", "*");
stream << parse_rc_string("-GtkButton-inner-border: 0 0 0 0", "*GtkToolbar*GtkButton*");
stream << parse_rc_string("-GtkButton-inner-border: 0 0 0 0", "*GtkToolbar*GtkToggleButton*");
stream << parse_rc_string("-GtkButton-inner-border: 0 0 0 0", "*GtkNotebook*GtkButton*");
stream << parse_rc_string("-GtkButton-inner-border: 0 0 0 0", "*GtkNotebook*GtkToggleButton*");
// TQt calls them tab boxes, GTK calls them notebooks (!??!?) Either way they are a pain...
//stream << parse_rc_string("-GtkNotebook-tab-overlap: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_TabBarTabOverlap)), "*");
stream << parse_rc_string("-GtkNotebook-tab-overlap: 0", "*"); // Overlap is handled in the style engine itself
stream << parse_rc_string("-GtkNotebook-tab-curvature: 0", "*");
stream << parse_rc_string("-GtkNotebook-initial-gap: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_TabBarTabOverlap)), "*");
// This sets both the radio button and check box sizes
stream << parse_rc_string("-GtkCheckButton-indicator-size: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_IndicatorHeight)), "*");
stream << parse_rc_string("-GtkCheckMenuItem-indicator-size: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_IndicatorHeight)), "*");
// FIXME
// GtkCellRendererToggle indicator-size must be set as follows, however GTK3 does not provide any means to change the default size!
// See upstream GTK bug #687076
//stream << parse_rc_string("-GtkCellRendererToggle-indicator-size: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_IndicatorHeight)), "*");
// FIXME
// GtkSpinButton widgets use ugly unthemed horizontal buttons
// When GTK provides an option to switch to vertical buttons, implement theming support for them
// See upstream GTK bug #687172
// FIXME
// There must be a way to set the selected tab offset (shift)
// If not, it may be neccessary to override the GTK text drawing routines for notebooks to insert the proper shift
//stream << parse_rc_string("-????: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_TabBarTabShiftHorizontal)), "*");
stream << parse_rc_string("-GtkButton-child-displacement-x: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_ButtonShiftHorizontal)), "*");
stream << parse_rc_string("-GtkButton-child-displacement-y: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_ButtonShiftVertical)), "*");
// Set up fonts
TQFont generalFont = KGlobalSettings::generalFont();
TQFont toolBarFont = KGlobalSettings::toolBarFont();
TQFont menuFont = KGlobalSettings::menuFont();
// TQFont windowTitleFont = KGlobalSettings::windowTitleFont();
// TQFont taskbarFont = KGlobalSettings::taskbarFont();
stream << parse_rc_string(tdeFontToGTKFontString(generalFont), "*");
stream << parse_rc_string(tdeFontToGTKFontString(toolBarFont), "*GtkToolbar*GtkButton*");
stream << parse_rc_string(tdeFontToGTKFontString(menuFont), "*.GtkMenu");
// Set up icons
// Build the list of icon theme directories.
// This function is recursive - it gets the directories of all the inherited themes as well
addIconThemeDir(iconTheme);
if (iconThemeDirs.isEmpty()) {
themeFile.close();
if (!forceRecreate) {
gtk3_tqt_reload_theme_definition_file(themeFilePath.latin1());
}
return;
}
GtkIconFactory* factory;
factory = gtk_icon_factory_new();
doIconMapping("gtk-about", "actions/about_kde.png", factory, iconThemeDirs);
doIconMapping("gtk-add", "actions/add.png", factory, iconThemeDirs);
doIconMapping("gtk-apply", "actions/apply.png", factory, iconThemeDirs);
doIconMapping("gtk-bold", "actions/text_bold.png", factory, iconThemeDirs);
doIconMapping("gtk-cancel", "actions/button_cancel.png", factory, iconThemeDirs);
doIconMapping("gtk-cdrom", "devices/cdrom_unmount.png", factory, iconThemeDirs);
doIconMapping("gtk-clear", "actions/editclear.png", factory, iconThemeDirs);
doIconMapping("gtk-close", "actions/fileclose.png", factory, iconThemeDirs);
doIconMapping("gtk-color-picker", "actions/colorpicker.png", factory, iconThemeDirs);
doIconMapping("gtk-copy", "actions/editcopy.png", factory, iconThemeDirs);
doIconMapping("gtk-convert", "actions/gtk-convert.png", factory, iconThemeDirs);
doIconMapping("gtk-connect", "actions/connect_creating.png", factory, iconThemeDirs);
doIconMapping("gtk-cut", "actions/editcut.png", factory, iconThemeDirs);
doIconMapping("gtk-delete", "actions/editdelete.png", factory, iconThemeDirs);
doIconMapping("gtk-dialog-authentication", "status/gtk-dialog-authentication", factory, iconThemeDirs);
doIconMapping("gtk-dialog-error", "actions/messagebox_critical.png", factory, iconThemeDirs);
doIconMapping("gtk-dialog-info", "actions/messagebox_info.png", factory, iconThemeDirs);
doIconMapping("gtk-dialog-question", "actions/help.png", factory, iconThemeDirs);
doIconMapping("gtk-dialog-warning", "actions/messagebox_warning.png", factory, iconThemeDirs);
doIconMapping("gtk-directory", "filesystems/folder.png", factory, iconThemeDirs);
doIconMapping("gtk-disconnect", "actions/connect_no.png", factory, iconThemeDirs);
doIconMapping("gtk-dnd", "mimetypes/empty.png", factory, iconThemeDirs);
doIconMapping("gtk-dnd-multiple", "mimetypes/kmultiple.png", factory, iconThemeDirs);
doIconMapping("gtk-edit", "actions/edit.png", factory, iconThemeDirs); //2.6
doIconMapping("gtk-execute", "actions/exec.png", factory, iconThemeDirs);
doIconMapping("gtk-file", "mimetypes/empty.png", factory, iconThemeDirs);
doIconMapping("gtk-find", "actions/find.png", factory, iconThemeDirs);
doIconMapping("gtk-find-and-replace", "actions/find.png", factory, iconThemeDirs); // Is there a TDE "find and replace" icon? FIXME
doIconMapping("gtk-floppy", "devices/3floppy_unmount.png", factory, iconThemeDirs);
doIconMapping("gtk-fullscreen", "actions/window-fullscreen.png", factory, iconThemeDirs);
doIconMapping("gtk-goto-bottom", "actions/bottom.png", factory, iconThemeDirs);
doIconMapping("gtk-goto-first", "actions/start.png", factory, iconThemeDirs);
doIconMapping("gtk-goto-last", "actions/finish.png", factory, iconThemeDirs);
doIconMapping("gtk-goto-top", "actions/top.png", factory, iconThemeDirs);
doIconMapping("gtk-go-back", "actions/back.png", factory, iconThemeDirs);
doIconMapping("gtk-go-down", "actions/down.png", factory, iconThemeDirs);
doIconMapping("gtk-go-forward", "actions/forward.png", factory, iconThemeDirs);
doIconMapping("gtk-go-up", "actions/up.png", factory, iconThemeDirs);
doIconMapping("gtk-harddisk", "devices/hdd_unmount.png", factory, iconThemeDirs);
doIconMapping("gtk-help", "apps/khelpcenter.png", factory, iconThemeDirs);
doIconMapping("gtk-home", "filesystems/folder_home.png", factory, iconThemeDirs);
doIconMapping("gtk-indent", "actions/indent.png", factory, iconThemeDirs);
doIconMapping("gtk-index", "actions/contents.png", factory, iconThemeDirs);
doIconMapping("gtk-info", "actions/messagebox_info.png", factory, iconThemeDirs);
doIconMapping("gtk-italic", "actions/text_italic.png", factory, iconThemeDirs);
doIconMapping("gtk-jump-to", "actions/goto.png", factory, iconThemeDirs);
doIconMapping("gtk-justify-center", "actions/text_center.png", factory, iconThemeDirs);
doIconMapping("gtk-justify-fill", "actions/text_block.png", factory, iconThemeDirs);
doIconMapping("gtk-justify-left", "actions/text_left.png", factory, iconThemeDirs);
doIconMapping("gtk-justify-right", "actions/text_right.png", factory, iconThemeDirs);
doIconMapping("gtk-leave-fullscreen", "actions/window-nofullscreen.png", factory, iconThemeDirs);
doIconMapping("gtk-media-forward", "player-fwd.png", factory, iconThemeDirs);
doIconMapping("gtk-media-next", "actions/player-end.png", factory, iconThemeDirs);
doIconMapping("gtk-media-pause", "actions/player-pause.png", factory, iconThemeDirs);
doIconMapping("gtk-media-previous", "actions/player-start.png", factory, iconThemeDirs);
doIconMapping("gtk-media-record", "actions/gtk-media-record.png", factory, iconThemeDirs); // FIXME
doIconMapping("gtk-media-rewind", "actions/player-rew.png", factory, iconThemeDirs);
doIconMapping("gtk-media-stop", "actions/player-stop.png", factory, iconThemeDirs);
doIconMapping("gtk-missing-image", "mimetypes/unknown.png", factory, iconThemeDirs);
doIconMapping("gtk-network", "filesystems/network.png", factory, iconThemeDirs);
doIconMapping("gtk-new", "actions/filenew.png", factory, iconThemeDirs);
doIconMapping("gtk-no", "actions/gtk-no.png", factory, iconThemeDirs);
doIconMapping("gtk-ok", "actions/button_ok.png", factory, iconThemeDirs);
doIconMapping("gtk-open", "actions/fileopen.png", factory, iconThemeDirs);
//doIconMapping("gtk-orientation-landscape", factory, iconThemeDirs); // FIXME
//doIconMapping("gtk-orientation-portrait", factory, iconThemeDirs); // FIXME
//doIconMapping("gtk-orientation-reverse-landscape", factory, iconThemeDirs); // FIXME
//doIconMapping("gtk-orientation-reverse-portrait"", factory, iconThemeDirs); // FIXME
doIconMapping("gtk-paste", "actions/editpaste.png", factory, iconThemeDirs);
doIconMapping("gtk-preferences", "actions/configure.png", factory, iconThemeDirs);
doIconMapping("gtk-print", "actions/fileprint.png", factory, iconThemeDirs);
doIconMapping("gtk-print-preview", "actions/filequickprint.png", factory, iconThemeDirs);
doIconMapping("gtk-properties", "actions/configure.png", factory, iconThemeDirs);
doIconMapping("gtk-quit", "actions/exit.png", factory, iconThemeDirs);
doIconMapping("gtk-redo", "actions/redo.png", factory, iconThemeDirs);
doIconMapping("gtk-refresh", "actions/reload.png", factory, iconThemeDirs);
doIconMapping("gtk-remove", "actions/remove.png", factory, iconThemeDirs);
doIconMapping("gtk-revert-to-saved", "actions/revert.png", factory, iconThemeDirs);
doIconMapping("gtk-save", "actions/filesave.png", factory, iconThemeDirs);
doIconMapping("gtk-save-as", "actions/filesaveas.png", factory, iconThemeDirs);
doIconMapping("gtk-select-all", "actions/gtk-select-all.png", factory, iconThemeDirs); // FIXME
doIconMapping("gtk-select-color", "actions/colorize.png", factory, iconThemeDirs);
doIconMapping("gtk-select-font", "mimetypes/font.png", factory, iconThemeDirs);
//doIconMapping("gtk-sort-ascending", "??", factory, iconThemeDirs); // FIXME
//doIconMapping("gtk-sort-descending", "??", factory, iconThemeDirs); // FIXME
doIconMapping("gtk-spell-check", "actions/spellcheck.png", factory, iconThemeDirs);
doIconMapping("gtk-stop", "actions/stop.png", factory, iconThemeDirs);
doIconMapping("gtk-strikethrough", "actions/text_strike.png", factory, iconThemeDirs);
doIconMapping("gtk-undelete", "actions/gtk-undelete.png", factory, iconThemeDirs); // FIXME
doIconMapping("gtk-underline", "actions/text_under.png", factory, iconThemeDirs);
doIconMapping("gtk-undo", "actions/undo.png", factory, iconThemeDirs);
doIconMapping("gtk-unindent", "actions/unindent.png", factory, iconThemeDirs);
doIconMapping("gtk-yes", "actions/button_ok.png", factory, iconThemeDirs); // Verify mapping here
doIconMapping("gtk-zoom-100", "actions/viewmag1.png", factory, iconThemeDirs);
doIconMapping("gtk-zoom-fit", "actions/viewmagfit.png", factory, iconThemeDirs);
doIconMapping("gtk-zoom-in", "actions/viewmag+.png", factory, iconThemeDirs);
doIconMapping("gtk-zoom-out", "actions/viewmag-.png", factory, iconThemeDirs);
// Other icons that really should have Trinity equivalents in tdelibs
doIconMapping("list-add", "actions/add.png", factory, iconThemeDirs);
doIconMapping("list-remove", "actions/remove.png", factory, iconThemeDirs);
doIconMapping("list-add-symbolic", "actions/add.png", factory, iconThemeDirs);
doIconMapping("list-remove-symbolic", "actions/remove.png", factory, iconThemeDirs);
gtk_icon_factory_add_default(factory);
themeFile.close();
if (!forceRecreate) {
gtk3_tqt_reload_theme_definition_file(themeFilePath.latin1());
}
}
// =========================================================================================================
|