ChGtk.cpp

Small Qt fix - Zbigniew Rebacz, 01/21/2014 02:42 AM

Download (21.2 KB)

 
1
#include "CtrlLib.h"
2
#include "ChGtk.h"
3

    
4
#ifdef PLATFORM_X11
5
#ifndef flagNOGTK
6

    
7
#define LLOG(x)  // DLOG(x)
8
#define LDUMP(x) // DDUMP(x)
9

    
10
NAMESPACE_UPP
11

    
12
extern int    gtk_antialias;
13
extern int    gtk_hinting;
14
extern String gtk_hintstyle;
15
extern String gtk_rgba;
16

    
17
extern void ClearFtFaceCache();
18

    
19
void SetDefTrough(ScrollBar::Style& s)
20
{
21
        for(int i = 0; i < 4; i++) {
22
                Image m = CtrlsImg::Get(CtrlsImg::I_SBVU + i);
23
                ImageBuffer ib(m);
24
                Size sz = ib.GetSize();
25
                ib[0][sz.cx - 1] = ib[0][0] = SColorShadow();
26
                ib.SetHotSpot(Point(0, 0));
27
                ib.Set2ndSpot(Point(sz.cx - 1, 0));
28
                m = ib;
29
                s.vlower[i] = s.vupper[i] = m;
30
                m = CtrlsImg::Get(CtrlsImg::I_SBHU + i);
31
                ib = m;
32
                sz = ib.GetSize();
33
                ib[sz.cy - 1][0] = ib[0][0] = SColorShadow();
34
                ib.SetHotSpot(Point(0, 0));
35
                ib.Set2ndSpot(Point(0, sz.cy - 1));
36
                m = ib;
37
                s.hupper[i] = s.hlower[i] = m;
38
        }
39
}
40

    
41
extern void (*chgtkspy__)(const char *name, int state, int shadow, const char *detail, int type, int cx, int cy, const Value& look);
42

    
43
void ChHostSkin()
44
{
45
        MemoryIgnoreLeaksBlock __;
46
        static struct { void (*set)(Color); int ii; } col[] = {
47
                { SColorPaper_Write, 6*5 + 0 },
48
                { SColorFace_Write, 1*5 + 0 },
49
                { SColorText_Write, 5*5 + 0 },
50
                { SColorHighlight_Write, 6*5 + 3 },
51
                { SColorHighlightText_Write, 5*5 + 3 },
52
                { SColorMenu_Write, 6*5 + 0 },
53
                { SColorMenuText_Write, 5*5 + 0 },
54
                { SColorDisabled_Write, 5*5 + 4 },
55
                { SColorLight_Write, 2*5 + 0 },
56
                { SColorShadow_Write, 3*5 + 0 },
57
        };
58
        for(int i = 0; i < __countof(col); i++)
59
                (*col[i].set)(ChGtkColor(col[i].ii, gtk__parent()));
60

    
61
        ////////
62
                GtkWidget *label = gtk_label_new("Ch");
63
                Setup(label);
64
                Color ch_ink = ChGtkColor(0, label);
65
                gtk_widget_destroy(label);
66
                SColorLabel_Write(ch_ink);
67
                
68
        ///////
69
        CtrlsImg::Reset();
70
        ColoredOverride(CtrlsImg::Iml(), ClassicCtrlsImg::Iml());
71

    
72
        ChLookFn(GtkLookFn);
73
        
74
        bool KDE = Environment().Get("KDE_FULL_SESSION", String()) == "true";
75

    
76
        String engine = GtkStyleString("gtk-theme-name");
77
        
78
        LDUMP(engine);
79
        
80
        bool Qt = engine == "Qt" || KDE;
81
        
82
        if(chgtkspy__)
83
                engine.Clear();
84

    
85
        int fontname = Font::ARIAL;
86
        int fontheight = 13;
87
        bool bold = false;
88
        bool italic = false;
89

    
90
        String font_name = GtkStyleString("gtk-font-name");
91
        int xdpi = Nvl(GtkStyleInt("gtk-xft-dpi"), 72 * 1024);
92
        gtk_antialias = Nvl(GtkStyleInt("gtk-xft-antialias"), -1);
93
        if(GetDesktopManager() != "gnome")
94
                gtk_antialias = -1;
95
        gtk_hinting = Nvl(GtkStyleInt("gtk-xft-hinting"), -1);
96
//        gtk_hintstyle = GtkStyleString("gtk-xft-hintstyle");
97
        gtk_hintstyle = gtk_hinting? "hintfull" : "hintnone"; // Gtk does not seem to follow its own rules...
98
        gtk_rgba = GtkStyleString("gtk-xft-rgba");
99

    
100
        const char *q = strrchr(font_name, ' ');
101
        if(q) {
102
                int h = atoi(q);
103
                if(h)
104
                        fontheight = h;
105
                String face(font_name, q);
106
                fontname = Font::FindFaceNameIndex(face);
107

    
108
                if(fontname == 0) {
109
                        for(;;) {
110
                                const char *q = strrchr(face, ' ');
111
                                if(!q) break;
112
                                const char *s = q + 1;
113
                                if(stricmp(s, "Bold") == 0 || stricmp(s, "Heavy") == 0)
114
                                        bold = true;
115
                                else
116
                                if(stricmp(s, "Italic") == 0 || stricmp(s, "Oblique") == 0)
117
                                        italic = true;
118
                                else
119
                                if(stricmp(s, "Regular") == 0 || stricmp(s, "Light") || stricmp(s, "Medium"))
120
                                        ;
121
                                else
122
                                        continue;
123
                                face = String(~face, q);
124
                        }
125
                        fontname = Font::FindFaceNameIndex(face);
126
                        if(fontname == 0)
127
                                if(ToUpper(face[0]) == 'M')
128
                                        fontname = Font::COURIER;
129
                                else
130
                                if(ToUpper(face[0]) == 'S' && ToUpper(face[1]) == 'e')
131
                                        fontname = Font::ROMAN;
132
                                else
133
                                        fontname = Font::ARIAL;
134
                }
135
        }
136

    
137
        Font::SetDefaultFont(Font(fontname, (fontheight * xdpi + 512*72) / (1024*72))
138
                             .Bold(bold).Italic(italic));
139

    
140
        ClearFtFaceCache();
141

    
142
        ColoredOverride(CtrlsImg::Iml(), CtrlsImg::Iml());
143

    
144
        Color fc = Blend(SColorHighlight, SColorShadow);
145

    
146
        ChGtkIs().Clear();
147
        GtkWidget *w = Setup(gtk_radio_button_new(NULL));
148
        int is = GtkInt(w, "indicator-size") + 2;
149
        GTK_TOGGLE_BUTTON(w)->active = false;
150
        GTK_TOGGLE_BUTTON(w)->inconsistent = false;
151
        GtkIml(CtrlsImg::I_S0, w, 2, "radiobutton", GTK_OPTION|GTK_MARGIN1, is, is);
152
        GTK_TOGGLE_BUTTON(w)->active = true;
153
        GtkIml(CtrlsImg::I_S1, w, 1, "radiobutton", GTK_OPTION|GTK_MARGIN1, is, is);
154
        gtk_widget_destroy(w);
155

    
156
        w = Setup(gtk_check_button_new());
157
        GTK_TOGGLE_BUTTON(w)->active = false;
158
        GTK_TOGGLE_BUTTON(w)->inconsistent = false;
159
        GtkIml(CtrlsImg::I_O0, w, 2, "checkbutton", GTK_CHECK|GTK_MARGIN1, is, is);
160
        GTK_TOGGLE_BUTTON(w)->active = true;
161
        GtkIml(CtrlsImg::I_O1, w, 1, "checkbutton", GTK_CHECK|GTK_MARGIN1, is, is);
162
        GTK_TOGGLE_BUTTON(w)->active = false;
163
        GTK_TOGGLE_BUTTON(w)->inconsistent = true;
164
        GtkIml(CtrlsImg::I_O2, w, 3, "checkbutton", GTK_CHECK|GTK_MARGIN1, is, is);
165
        gtk_widget_destroy(w);
166

    
167
        if(Qt) {
168
                for(int i = 0; i < 4; i++) {
169
                        Image m = CtrlsImg::Get(CtrlsImg::I_O2 + i);
170
                        ImageBuffer ib(m);
171
                        Size sz = ib.GetSize();
172
                        if(sz.cx > 6)
173
                                for(int q = -2; q <= 2; q++)
174
                                        ib[sz.cy / 2 - 1][sz.cx / 2 - q - 1] = i == CTRL_DISABLED ? SColorDisabled() : SColorText();
175
                        m = ib;
176
                        CtrlsImg::Set(CtrlsImg::I_O2 + i, m);
177
                }
178
        }
179

    
180
        Point po(0, 0);
181

    
182
        int classiq = engine == "Redmond" || engine == "Raleigh" || engine == "Glider" || engine == "Simple";
183

    
184
        {
185
                Button::Style& s = Button::StyleNormal().Write();
186
                s.overpaint = 3;
187
                static GtkWidget *button = gtk_button_new();
188
                ChGtkNew(button, "button", GTK_BOX|GTK_MARGIN3);
189
                GtkChButton(s.look);
190

    
191
                po.x = GtkInt("child-displacement-x");
192
                po.y = GtkInt("child-displacement-y");
193

    
194
                s.ok = GtkImage("gtk-ok", 4, 16);
195
                s.cancel = GtkImage("gtk-cancel", 4, 16);
196
                s.exit = GtkImage("gtk-quit", 4, 16);
197

    
198
                ChGtkColor(s.textcolor, 0 * 5);
199
                s.pressoffset = po;
200

    
201
                Color c = SColorFace();
202
                for(int i = 0; i < 4; i++)
203
                        s.monocolor[i] = c.GetR() + c.GetG() + c.GetB() < 3 * 128 ? White() : Black();
204
                s.monocolor[3] = Gray();
205

    
206
                ToolBar::Style& ts = ToolBar::StyleDefault().Write();
207
                GtkChButton(ts.buttonstyle.look);
208
                ts.buttonstyle.look[CTRL_NORMAL] = Null;
209
                ts.buttonstyle.look[CTRL_DISABLED] = Null;
210
                GtkCh(ts.buttonstyle.look[CTRL_CHECKED], 1, 1);
211
                GtkCh(ts.buttonstyle.look[CTRL_HOTCHECKED], 1, 1);
212

    
213
                {
214
                        HeaderCtrl::Style& hs = HeaderCtrl::StyleDefault().Write();
215
                        if(classiq)
216
                                for(int i = 0; i < 4; i++)
217
                                        hs.look[i] = s.look[i];
218
                        else {
219
                                ChGtkNew(button, "button", GTK_BOX);
220
                                hs.look[0] = GtkMakeCh(2|GTKELEMENT_TABFLAG, 4, Rect(6, 3, 6, 0));
221
                                hs.look[1] = GtkMakeCh(2|GTKELEMENT_TABFLAG, 2, Rect(6, 3, 6, 0));
222
                                hs.look[2] = GtkMakeCh(1|GTKELEMENT_TABFLAG, 1, Rect(6, 3, 6, 0));
223
                                hs.look[3] = GtkMakeCh(2|GTKELEMENT_TABFLAG, 4, Rect(6, 3, 6, 0));
224
                                hs.pressoffset = po.x || po.y;
225
                        }
226
                }
227
        }
228

    
229
        {
230
                Button::Style& s = Button::StyleOk().Write();
231
                static GtkWidget *def_button;
232
                if(!def_button) {
233
                        def_button = gtk_button_new();
234
                        Setup(def_button);
235
                        gtk_widget_set(def_button, "can-default", true, NULL);
236
                        gtk_window_set_default(GTK_WINDOW(gtk__parent()), def_button);
237
                        ChGtkNew(def_button, "button", GTK_BOX|GTK_MARGIN3);
238
                }
239
                GtkChButton(s.look);
240
        }
241

    
242
        {
243
                ScrollBar::Style& s = ScrollBar::StyleDefault().Write();
244
                SetDefTrough(s);
245
                s.through = true;
246
                GtkObject *adj = gtk_adjustment_new(250, 0, 1000, 1, 1, 500);
247
                static GtkWidget *vscrollbar = gtk_vscrollbar_new(GTK_ADJUSTMENT(adj));
248
                ChGtkNew(vscrollbar, "slider", GTK_SLIDER|GTK_VAL1);
249

    
250
                s.thumbmin = GTK_RANGE(vscrollbar)->min_slider_size;
251
                s.barsize = max(14, GtkInt("slider_width")); // 'max' - ugly fix for ThinIce theme
252
                s.arrowsize = max(s.barsize, GtkInt("stepper_size")); // 'max' - ugly fix for ThinIce theme
253

    
254
                /* The only theme with 3 buttons is Amaranth and it does not look good...
255
                s.isright2 = s.isdown2 = GtkInt("has-secondary-forward-stepper");
256
                s.isleft2 = s.isup2 = GtkInt("has-secondary-backward-stepper");
257
                */
258

    
259
                for(int i = 0; i < 6; i++)
260
                        CtrlsImg::Set(CtrlsImg::I_DA + i, CtrlsImg::Get(CtrlsImg::I_kDA + i));
261

    
262
                if(Qt) {
263
                        LLOG("Qt path");
264
                        int r = Null;
265
                        for(int i = 0; i < 4; i++) {
266
                                ImageDraw iw(64, 64);
267
                                iw.DrawRect(0, 0, 64, 64, SColorFace());
268
                                ChPaint(iw, Size(64, 64), Button::StyleNormal().look[i == CTRL_HOT ? CTRL_NORMAL : i]);
269
                                Image m = iw;
270
                                if(IsNull(r))
271
                                        r = minmax(ImageMargin(m, 4, 50), 0, 2);
272
                                m = Rescale(Crop(m, 4, 4, 56, 56), 16, 16);
273
                                ChPartMaker pm(m);
274
                                pm.tr = pm.tl = r;
275
                                pm.bl = pm.br = 0;
276
                                s.up.look[i] = ChLookWith(pm.Make(), CtrlsImg::UA(), ButtonMonoColor(i));
277
                                pm.tr = pm.tl = 0;
278
                                pm.t = false;
279
                                s.down2.look[i] = ChLookWith(pm.Make(), CtrlsImg::DA(), ButtonMonoColor(i));
280
                                pm.t = true;
281
                                pm.bl = pm.br = r;
282
                                s.down.look[i] = ChLookWith(pm.Make(), CtrlsImg::DA(), ButtonMonoColor(i));
283
                                pm.br = pm.bl = 0;
284
                                pm.b = false;
285
                                s.up2.look[i] = ChLookWith(pm.Make(), CtrlsImg::UA(), ButtonMonoColor(i));
286
                                pm.br = pm.bl = pm.tl = pm.tr = r;
287
                                pm.b = true;
288
                                Image bm = pm.Make();
289
                                Button::StyleScroll().Write().look[i] = bm;
290
                                pm.ResetShape();
291
                                pm.t = pm.b = pm.l = false;
292
                                Image lm = pm.Make();
293
                                Button::StyleLeftEdge().Write().look[i] = lm;
294
                                pm.r = false;
295
                                pm.l = true;
296
                                Image rm = pm.Make();
297
                                Button::StyleEdge().Write().look[i] = rm;
298
                                {
299
                                        DropList::Style& s = DropList::StyleFrame().Write();
300
                                        s.look[i] = s.trivial[i] = s.right[i] = ChLookWith(rm, CtrlsImg::DA());
301
                                        s.left[i] = ChLookWith(lm, CtrlsImg::DA());
302
                                        s.pressoffset = po;
303
                                }
304
                                {
305
                                        SpinButtons::Style& s = SpinButtons::StyleDefault().Write();
306
                                        s.dec.look[i] = ChLookWith(rm, CtrlImg::spindown2());
307
                                        pm.b = true;
308
                                        s.inc.look[i] = ChLookWith(pm.Make(), CtrlImg::spinup2());
309
                                }
310
                                pm.ResetShape();
311
                                pm.tl = pm.bl = r;
312
                                pm.tr = pm.br = 0;
313
                                s.left.look[i] = ChLookWith(pm.Make(), CtrlsImg::LA(), ButtonMonoColor(i));
314
                                pm.tl = pm.bl = 0;
315
                                pm.l = false;
316
                                s.right2.look[i] = ChLookWith(pm.Make(), CtrlsImg::RA(), ButtonMonoColor(i));
317
                                pm.l = true;
318
                                pm.tl = pm.bl = 0;
319
                                pm.tr = pm.br = r;
320
                                s.right.look[i] = ChLookWith(pm.Make(), CtrlsImg::RA(), ButtonMonoColor(i));
321
                                pm.tr = pm.br = 0;
322
                                pm.r = false;
323
                                s.left2.look[i] = ChLookWith(pm.Make(), CtrlsImg::LA(), ButtonMonoColor(i));
324
                        }
325
                        ChGtkNew(vscrollbar, "slider", GTK_SLIDER|GTK_VAL1|GTK_MARGIN1|GTK_XMARGIN);
326
                        GtkChSlider(s.vthumb);
327
                        s.barsize += 2;
328
                        s.arrowsize++;
329
                        SetDefTrough(s);
330
                        static GtkWidget *hscrollbar = gtk_hscrollbar_new(GTK_ADJUSTMENT(adj));
331
                        ChGtkNew(hscrollbar, "slider", GTK_SLIDER|GTK_MARGIN1|GTK_XMARGIN);
332
                        GtkChSlider(s.hthumb);
333
                        s.overthumb = false;
334
                }
335
                else {
336
                        GtkChScrollBar(s.up.look, s.up2.look, s.vlower, s.vthumb, s.vupper, s.down2.look, s.down.look,
337
                                       CtrlsImg::I_UA, CtrlsImg::I_DA, false);
338

    
339
                        if(IsEmptyImage(GetGTK(ChGtkLast(), 2, 2, "vscrollbar", GTK_BOX|GTK_TOP|GTK_RANGEA, 16, 16))) {
340
                                static GtkWidget *btn = gtk_button_new();
341
                                ChGtkNew(btn, "button", GTK_BOX);
342

    
343
                                GtkChButton(Button::StyleScroll().Write().look);
344
                                GtkChButton(Button::StyleEdge().Write().look);
345
                                GtkChButton(Button::StyleLeftEdge().Write().look);
346

    
347
                                {
348
                                        DropList::Style& s = DropList::StyleFrame().Write();
349
                                        GtkChButtonWith(s.look, CtrlsImg::DA());
350
                                        GtkChButtonWith(s.trivial, CtrlsImg::DA());
351
                                }
352
                                {
353
                                        SpinButtons::Style& s = SpinButtons::StyleDefault().Write();
354
                                        GtkChButtonWith(s.inc.look, CtrlImg::spinup2());
355
                                        GtkChButtonWith(s.dec.look, CtrlImg::spindown2());
356
                                }
357
                        }
358
                        else {
359
                                ChGtkNew("vscrollbar", GTK_BOX|GTK_VCENTER|GTK_RANGEB);
360
                                GtkCh(Button::StyleScroll().Write().look, "02142222");
361

    
362
                                int q = !classiq;
363

    
364
                                GtkChImgWith(Button::StyleEdge().Write().look, Null, 1 * q);
365
                                GtkChImgWith(Button::StyleLeftEdge().Write().look, Null, 2 * q);
366

    
367
                                {
368
                                        DropList::Style& s = DropList::StyleFrame().Write();
369
                                        GtkChImgWith(s.look, CtrlsImg::DA(), 1 * q, po);
370
                                        GtkChImgWith(s.trivial, CtrlsImg::DA(), 1 * q, po);
371
                                        GtkChImgWith(s.left, CtrlsImg::DA(), 2 * q, po);
372
                                        GtkChImgWith(s.right, CtrlsImg::DA(), 1 * q, po);
373
                                        s.pressoffset = po;
374
                                }
375
                                {
376
                                        SpinButtons::Style& s = SpinButtons::StyleDefault().Write();
377
                                        GtkChImgWith(s.inc.look, q ? CtrlImg::spinup2() : CtrlImg::spinup3(), (1|GTK_BOTTOMLINE) * q, po);
378
                                        GtkChImgWith(s.dec.look, q ? CtrlImg::spindown2() : CtrlImg::spindown3(), 1 * q, po);
379
                                }
380
                        }
381

    
382
                        static GtkWidget *hscrollbar = gtk_hscrollbar_new(GTK_ADJUSTMENT(adj));
383
                        ChGtkNew(hscrollbar, "slider", GTK_SLIDER);
384
                        GtkChScrollBar(s.left.look, s.left2.look, s.hlower, s.hthumb, s.hupper, s.right2.look, s.right.look,
385
                                       CtrlsImg::I_LA, CtrlsImg::I_RA, true);
386
                        
387
                        int d = Diff(fc, SColorPaper());
388
                        Image m = GtkGetLastImage();
389
                        for(int x = 0; x < 4; x++)
390
                                for(int y = 0; y < 4; y++) {
391
                                        RGBA c = m[x][y];
392
                                        if(c.a == 255) {
393
                                                int dd = Diff(c, SColorPaper());
394
                                                if(dd > d) {
395
                                                        fc = c;
396
                                                        d = dd;
397
                                                }
398
                                        }
399
                                }
400
                        FieldFrameColor_Write(fc);
401

    
402
                        gtk_object_sink(adj);
403

    
404
                        adj = gtk_adjustment_new(0, 0, 1000, 1, 1, 500);
405
                        w = gtk_vscrollbar_new(NULL);
406
                        Setup(w);
407
                        s.overthumb = m != GetGTK(w, 0, 0, "slider", GTK_SLIDER|GTK_VAL1, 16, 32) && !Qt;
408
                        gtk_widget_destroy(w);
409
                        gtk_object_sink(adj);
410
                        
411
                        w = gtk_hscale_new_with_range(0.0, 100.0, 1.0);
412
                        Setup(w);
413
                        int cx = GtkInt(w, "slider-length");
414
                        int cy = 15;
415
                        if(engine == "Glider")
416
                                cy += cx-3;
417
                        if(engine == "Human" || engine == "DarkRoom" || engine == "Crux")
418
                                cy = 13;
419
                        CtrlImg::Set("hthumb",GetGTK(w, 0, 0, "hscale", GTK_SLIDER, cx, cy));
420
                        CtrlImg::Set("hthumb1",GetGTK(w, 2, 0, "hscale", GTK_SLIDER, cx, cy));
421
                        gtk_widget_destroy(w);
422
                        w = gtk_hscale_new_with_range(0.0, 100.0, 1.0);
423
                        Setup(w);
424
                        CtrlImg::Set("vthumb",GetGTK(w, 0, 0, "vscale", GTK_SLIDER|GTK_VAL1, cy, cx));
425
                        CtrlImg::Set("vthumb1",GetGTK(w, 2, 0, "vscale", GTK_SLIDER|GTK_VAL1, cy, cx));
426
                        gtk_widget_destroy(w);
427
                }
428

    
429
        }
430

    
431
        if(!Qt)
432
        {
433
                TabCtrl::Style& s = TabCtrl::StyleDefault().Write();
434
                static GtkWidget *tabctrl = gtk_notebook_new();
435
                ChGtkNew(tabctrl, "tab", GTK_EXT|GTK_VAL3|GTK_MARGIN3);
436
                ImageBuffer ib(9, 9);
437
                ImageBuffer ib1(9, 9);
438
                Image m = GetGTK(tabctrl, 0, 2, "tab", GTK_EXT|GTK_VAL3, 12, 24);
439
                for(int i = 0; i < 5; i++) {
440
                        RGBA *t = ~ib + i * 9 + i;
441
                        RGBA *t1 = ~ib1 + i * 9 + i;
442
                        for(int n = 9 - 2 * i; n--; t += 9, t1 += 9) {
443
                                Fill(t, m[21][i], 9 - 2 * i);
444
                                Fill(t1, m[21][11 - i], 9 - 2 * i);
445
                        }
446
                }
447
                {
448
                        RGBA *t = ~ib + 9 + 8;
449
                        RGBA *t1 = ~ib1 + 9 + 8;
450
                        for(int i = 1; i < 9; i++) {
451
                                memcpy(t, t1, i * sizeof(RGBA));
452
                                t += 9 - 1;
453
                                t1 += 9 - 1;
454
                        }
455
                }
456
                ib.SetHotSpot(Point(4, 4));
457
                s.body = Image(ib);
458
                GtkCh(s.normal[0], 2, 1);
459
                GtkCh(s.normal[1], 2, 1);
460
                GtkCh(s.normal[2], 0x82, 0);
461
                GtkCh(s.normal[3], 2, 1);
462
                for(int i = 0; i < 4; i++)
463
                        s.first[i] = s.last[i] = s.both[i] = s.normal[i];
464
                s.margin = 0;
465

    
466
                s.sel = Rect(0, 2, 0, 4);
467
                s.extendleft = 2;
468
                ChGtkColor(s.text_color, 0);
469
        }
470

    
471
        int efm = 0;
472
        {
473
                EditField::Style& s = EditField::StyleDefault().Write();
474
                Image img;
475
                for(int i = 0; i < 4; i++) {
476
                        GtkWidget *w = Setup(gtk_entry_new());
477
                        if(i == CTRL_PRESSED)
478
                                GTK_WIDGET_FLAGS (w) |= GTK_HAS_FOCUS;
479
                        if(i == CTRL_DISABLED)
480
                                GTK_WIDGET_FLAGS (w) &= GTK_SENSITIVE;
481
                        if(i == 0) {
482
                                img = GetGTK(w, GTK_STATE_NORMAL, GTK_SHADOW_IN, "entry", GTK_SHADOW, 20, 20);
483
                                efm = max(ImageMargin(img, 4, 0), 1);
484
                        }
485
                        img = GetGTK(w, GTK_STATE_NORMAL, GTK_SHADOW_IN,
486
                                     "entry", GTK_SHADOW, 2 * efm + 3, 2 * efm + 3);
487
                        ImageBuffer eb(img);
488
                        eb.SetHotSpot(Point(efm, efm));
489
                        s.edge[i] = Image(eb);
490
                        s.activeedge = true;
491
                        gtk_widget_destroy(w);
492
                }
493
        }
494

    
495
        {
496
                MultiButton::Style& s = MultiButton::StyleDefault().Write();
497
                s.usetrivial = true;
498
                s.trivialsep = true;
499
                s.edge[0] = Null;
500
                s.overpaint = Button::StyleNormal().overpaint;
501
                s.margin.left = 3;
502
                for(int i = 0; i < 4; i++)
503
                        s.left[i] = s.right[i] = s.lmiddle[i] = s.look[i] = Button::StyleNormal().look[i];
504
                s.loff = 1;
505
                s.roff = -1;
506
                s.trivialborder = s.border = 0;
507
                s.sep2 = SColorShadow();
508
                s.sep1 = SColorLight();
509
                s.sepm = 4;
510
                {
511
                        MultiButton::Style& s = MultiButton::StyleFrame().Write();
512
                        for(int i = 0; i < 4; i++)
513
                                s.edge[i] = EditField::StyleDefault().edge[i];
514
                        s.activeedge = true;
515
                        s.sep1 = Null;
516
                        s.trivialborder = s.border = efm;
517
                        s.usetrivial = true;
518
                        s.sepm = 0;
519
                        s.margin = Rect(efm, efm, efm, efm);
520
                }
521
        }
522

    
523
        ImageBuffer ib;
524
        ib.Create(3, 3);
525
        Fill(~ib, fc, ib.GetLength());
526
        ib[1][1] = Color(Null);
527
        ib.SetHotSpot(Point(1, 1));
528
        CtrlsImg::Set(CtrlsImg::I_EFE, ib);
529
        ib.Create(5, 5);
530
        Fill(~ib, fc, ib.GetLength());
531
        for(int x = 1; x < 4; x++)
532
                Fill(ib[x] + 1, SColorPaper(), 3);
533
        ib[2][2] = Color(Null);
534
        ib.SetHotSpot(Point(2, 2));
535
        CtrlsImg::Set(CtrlsImg::I_VE, ib);
536

    
537
        static GtkWidget *popup;
538
        static GtkWidget *bar = Setup(gtk_menu_bar_new());
539
        static int shadowtype;
540
        static GtkWidget *top_item;
541
        static GtkWidget *menu_item;
542
        if(!popup) {
543
                gtk_widget_style_get(bar, "shadow_type", &shadowtype, NULL);
544
                top_item = gtk_menu_item_new_with_label("M");
545
                gtk_menu_shell_append(GTK_MENU_SHELL(bar), top_item);
546
                gtk_widget_realize(top_item);
547
                gtk_widget_show(top_item);
548
                popup = gtk_menu_new();
549
                gtk_menu_item_set_submenu(GTK_MENU_ITEM(top_item), popup);
550
                gtk_widget_realize(popup);
551
                gtk_widget_show(popup);
552
                GTK_MENU_SHELL(bar)->active = true;
553
                menu_item = gtk_menu_item_new_with_label("M");
554
                
555
                gtk_menu_shell_append(GTK_MENU_SHELL(popup), menu_item);
556
                gtk_widget_realize(menu_item);
557
                gtk_widget_show(menu_item);
558
//                gtk_widget_show(GTK_MENU(GTK_MENU_ITEM(top_item)->submenu)->toplevel);
559
        }
560
        Image mimg = GetGTK(popup, 0, 2, "menu", GTK_BGBOX, 32, 32);
561
        Color c = mimg[16][16];
562
        Value rlook;
563
        if(!IsNull(c))
564
                SColorMenu_Write(c);
565
        {
566
                MenuBar::Style& s = MenuBar::StyleDefault().Write();
567
                s.pullshift.y = 0;
568
                int m = ImageMargin(mimg, 4, 5);
569
                s.popupframe = WithHotSpot(mimg, m, m);
570
                s.popupbody = Crop(mimg, m, m, 32 - 2 * m, 32 - 2 * m);
571
                s.leftgap = 26;
572
                ChGtkNew(menu_item, "menuitem", GTK_BOX);
573
                int sw = GTK_SHADOW_OUT;
574
                if(gtk_check_version(2, 1, 0))
575
                        sw = GtkInt("selected_shadow_type");
576
                GtkCh(s.item, sw, GTK_STATE_PRELIGHT);
577
                s.itemtext = ChGtkColor(2, menu_item);
578
                s.menutext = SColorMenuText();
579
                if(Diff(c, s.menutext) < 200) // menutext color too close to background color, fix it
580
                        s.menutext = IsDark(c) ? White() : Black();
581

    
582
                ChGtkNew(top_item, "menuitem", GTK_BOX);
583
                if(gtk_check_version(2, 1, 0))
584
                        sw = GtkInt("selected_shadow_type");
585
                
586
                s.topitemtext[0] = ChGtkColor(0, top_item);
587
                if(Qt)
588
                        s.topitemtext[1] = ChGtkColor(2, top_item);
589
                else
590
                        s.topitemtext[1] = ChGtkColor(0, top_item);
591
                s.topitemtext[2] = ChGtkColor(2, top_item);
592
                SColorMenuText_Write(s.topitemtext[1]);
593
                if(Qt)
594
                        GtkCh(s.topitem[1], sw, GTK_STATE_PRELIGHT);
595
                else
596
                        s.topitem[1] = s.topitem[2];
597
                GtkCh(s.topitem[2], sw, GTK_STATE_PRELIGHT);
598
                s.topitemtext[2] = ChGtkColor(2, top_item);
599
                if(engine == "Redmond") {
600
                        s.topitem[1] = ChBorder(ThinOutsetBorder(), SColorFace());
601
                        s.topitem[2] = ChBorder(ThinInsetBorder(), SColorFace());
602
                }
603
                if(engine == "Geramik" || engine == "ThinGeramik")
604
                        s.topitemtext[2] = SColorText();
605
                ChGtkNew(bar, "menubar", GTK_BGBOX);
606
                sw = GtkInt("shadow_type");
607
                s.look = GtkMakeCh(sw, GTK_STATE_NORMAL, Rect(0, 0, 0, 1));
608
                rlook = GtkMakeCh(sw, GTK_STATE_NORMAL, Rect(0, 1, 0, 1));
609
                Image img = GetGTK(bar, GTK_STATE_NORMAL, sw, "menubar", GTK_BGBOX, 32, 32);
610
                s.breaksep.l1 = Color(img[31][15]);
611
                TopSeparator1_Write(s.breaksep.l1);
612
                s.breaksep.l2 = Null;
613
        }
614

    
615
        {
616
                ToolBar::Style& s = ToolBar::StyleDefault().Write();
617
                static GtkWidget *toolbar;
618
                if(!toolbar) {
619
                        GtkWidget *handle = Setup(gtk_handle_box_new());
620
                        toolbar = gtk_toolbar_new();
621
                        gtk_container_add(GTK_CONTAINER(handle), toolbar);
622
                }
623
                ChGtkNew(toolbar, "toolbar", GTK_BGBOX);
624
                int sw = GtkInt("shadow_type");
625
                s.arealook = Null;
626
                s.look = GtkMakeCh(sw, GTK_STATE_NORMAL, Rect(0, 1, 0, 1));
627
                if(engine == "Redmond")
628
                        s.look = rlook;
629
                s.breaksep.l1 = MenuBar::StyleDefault().breaksep.l1;
630
                Image img = GetGTK(toolbar, GTK_STATE_NORMAL, sw, "toolbar", GTK_BGBOX, 32, 32);
631
                MenuBar::StyleDefault().Write().breaksep.l2 = s.breaksep.l2 = Color(img[0][15]);
632
                TopSeparator2_Write(s.breaksep.l2);
633
        }
634

    
635
        if(engine != "Qt")
636
        {
637
                ProgressIndicator::Style& s = ProgressIndicator::StyleDefault().Write();
638
                static GtkWidget *pg = gtk_progress_bar_new();
639
                ChGtkNew(pg, "trough", GTK_BOX);
640
                int mx = pg->style->xthickness;
641
                int my = pg->style->ythickness;
642
                s.hlook = GtkMakeCh(GTK_SHADOW_IN, GTK_STATE_NORMAL, Rect(0, 0, 0, 0), Rect(mx, my, mx, my));
643
                ChGtkNew(pg, "bar", GTK_BOX);
644
                GtkCh(s.hchunk, GTK_SHADOW_OUT, GTK_STATE_PRELIGHT);
645
                s.bound = true;
646
        }
647

    
648
        static GtkWidget *ve = Setup(gtk_text_view_new());
649
        if(engine == "Redmond")
650
                ViewEdge_Write(EditFieldEdge());
651
        else
652
                ViewEdge_Write(WithHotSpot(GetGTK(ve, GTK_STATE_NORMAL, GTK_SHADOW_IN, "frame", GTK_BOX, 32, 32), 2, 2));
653

    
654
        ChCtrlImg(CtrlImg::I_information, "gtk-dialog-info", 6);
655
        ChCtrlImg(CtrlImg::I_question, "gtk-dialog-question", 6);
656
        ChCtrlImg(CtrlImg::I_exclamation, "gtk-dialog-warning", 6);
657
        ChCtrlImg(CtrlImg::I_error, "gtk-dialog-error", 6);
658

    
659
        static struct {
660
                void  (*set)(Image);
661
                const char *gtk;
662
        } bimg[] = {
663
                { YesButtonImage_Write, "gtk-yes" },
664
                { NoButtonImage_Write, "gtk-no" },
665
                { AbortButtonImage_Write, "gtk-stop" },
666
                { RetryButtonImage_Write, "gtk-refresh" },
667
        };
668

    
669
        for(int i = 0; i < __countof(bimg); i++)
670
                (*bimg[i].set)(GtkImage(bimg[i].gtk, 4, 16));
671

    
672
        if(engine != "Redmond")
673
                DropEdge_Write(ViewEdge());
674

    
675
        SwapOKCancel_Write(true);
676

    
677
        GUI_GlobalStyle_Write(GUISTYLE_XP);
678
        GUI_DragFullWindow_Write(1);
679
        GUI_PopUpEffect_Write(Ctrl::IsCompositedGui() ? GUIEFFECT_NONE : GUIEFFECT_SLIDE);
680
        GUI_DropShadows_Write(1);
681
        GUI_AltAccessKeys_Write(1);
682
        GUI_AKD_Conservative_Write(0);
683
        
684
        ClearFtFaceCache();
685
}
686

    
687
END_UPP_NAMESPACE
688

    
689
#endif
690
#endif