forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgtk2drawing.c
3418 lines (2908 loc) · 119 KB
/
gtk2drawing.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* This file contains painting functions for each of the gtk2 widgets.
* Adapted from the gtkdrawing.c, and gtk+2.0 source.
*/
#include <gtk/gtk.h>
#include <gdk/gdkprivate.h>
#include <string.h>
#include "gtkdrawing.h"
#include "nsDebug.h"
#include "prinrval.h"
#include <math.h>
#define XTHICKNESS(style) (style->xthickness)
#define YTHICKNESS(style) (style->ythickness)
#define WINDOW_IS_MAPPED(window) ((window) && GDK_IS_WINDOW(window) && gdk_window_is_visible(window))
static GtkWidget* gProtoWindow;
static GtkWidget* gProtoLayout;
static GtkWidget* gButtonWidget;
static GtkWidget* gToggleButtonWidget;
static GtkWidget* gButtonArrowWidget;
static GtkWidget* gCheckboxWidget;
static GtkWidget* gRadiobuttonWidget;
static GtkWidget* gHorizScrollbarWidget;
static GtkWidget* gVertScrollbarWidget;
static GtkWidget* gSpinWidget;
static GtkWidget* gHScaleWidget;
static GtkWidget* gVScaleWidget;
static GtkWidget* gEntryWidget;
static GtkWidget* gComboBoxWidget;
static GtkWidget* gComboBoxButtonWidget;
static GtkWidget* gComboBoxArrowWidget;
static GtkWidget* gComboBoxSeparatorWidget;
static GtkWidget* gComboBoxEntryWidget;
static GtkWidget* gComboBoxEntryTextareaWidget;
static GtkWidget* gComboBoxEntryButtonWidget;
static GtkWidget* gComboBoxEntryArrowWidget;
static GtkWidget* gHandleBoxWidget;
static GtkWidget* gToolbarWidget;
static GtkWidget* gFrameWidget;
static GtkWidget* gStatusbarWidget;
static GtkWidget* gProgressWidget;
static GtkWidget* gTabWidget;
static GtkWidget* gTooltipWidget;
static GtkWidget* gMenuBarWidget;
static GtkWidget* gMenuBarItemWidget;
static GtkWidget* gMenuPopupWidget;
static GtkWidget* gMenuItemWidget;
static GtkWidget* gImageMenuItemWidget;
static GtkWidget* gCheckMenuItemWidget;
static GtkWidget* gTreeViewWidget;
static GtkTreeViewColumn* gMiddleTreeViewColumn;
static GtkWidget* gTreeHeaderCellWidget;
static GtkWidget* gTreeHeaderSortArrowWidget;
static GtkWidget* gExpanderWidget;
static GtkWidget* gToolbarSeparatorWidget;
static GtkWidget* gMenuSeparatorWidget;
static GtkWidget* gHPanedWidget;
static GtkWidget* gVPanedWidget;
static GtkWidget* gScrolledWindowWidget;
static style_prop_t style_prop_func;
static gboolean have_arrow_scaling;
static gboolean is_initialized;
/* Because we have such an unconventional way of drawing widgets, signal to the GTK theme engine
that they are drawing for Mozilla instead of a conventional GTK app so they can do any specific
things they may want to do. */
static void
moz_gtk_set_widget_name(GtkWidget* widget)
{
gtk_widget_set_name(widget, "MozillaGtkWidget");
}
gint
moz_gtk_enable_style_props(style_prop_t styleGetProp)
{
style_prop_func = styleGetProp;
return MOZ_GTK_SUCCESS;
}
static gint
ensure_window_widget()
{
if (!gProtoWindow) {
gProtoWindow = gtk_window_new(GTK_WINDOW_POPUP);
gtk_widget_realize(gProtoWindow);
moz_gtk_set_widget_name(gProtoWindow);
}
return MOZ_GTK_SUCCESS;
}
static gint
setup_widget_prototype(GtkWidget* widget)
{
ensure_window_widget();
if (!gProtoLayout) {
gProtoLayout = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(gProtoWindow), gProtoLayout);
}
gtk_container_add(GTK_CONTAINER(gProtoLayout), widget);
gtk_widget_realize(widget);
g_object_set_data(G_OBJECT(widget), "transparent-bg-hint", GINT_TO_POINTER(TRUE));
return MOZ_GTK_SUCCESS;
}
static gint
ensure_button_widget()
{
if (!gButtonWidget) {
gButtonWidget = gtk_button_new_with_label("M");
setup_widget_prototype(gButtonWidget);
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_hpaned_widget()
{
if (!gHPanedWidget) {
gHPanedWidget = gtk_hpaned_new();
setup_widget_prototype(gHPanedWidget);
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_vpaned_widget()
{
if (!gVPanedWidget) {
gVPanedWidget = gtk_vpaned_new();
setup_widget_prototype(gVPanedWidget);
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_toggle_button_widget()
{
if (!gToggleButtonWidget) {
gToggleButtonWidget = gtk_toggle_button_new();
setup_widget_prototype(gToggleButtonWidget);
/* toggle button must be set active to get the right style on hover. */
GTK_TOGGLE_BUTTON(gToggleButtonWidget)->active = TRUE;
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_button_arrow_widget()
{
if (!gButtonArrowWidget) {
ensure_toggle_button_widget();
gButtonArrowWidget = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
gtk_container_add(GTK_CONTAINER(gToggleButtonWidget), gButtonArrowWidget);
gtk_widget_realize(gButtonArrowWidget);
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_checkbox_widget()
{
if (!gCheckboxWidget) {
gCheckboxWidget = gtk_check_button_new_with_label("M");
setup_widget_prototype(gCheckboxWidget);
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_radiobutton_widget()
{
if (!gRadiobuttonWidget) {
gRadiobuttonWidget = gtk_radio_button_new_with_label(NULL, "M");
setup_widget_prototype(gRadiobuttonWidget);
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_scrollbar_widget()
{
if (!gVertScrollbarWidget) {
gVertScrollbarWidget = gtk_vscrollbar_new(NULL);
setup_widget_prototype(gVertScrollbarWidget);
}
if (!gHorizScrollbarWidget) {
gHorizScrollbarWidget = gtk_hscrollbar_new(NULL);
setup_widget_prototype(gHorizScrollbarWidget);
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_spin_widget()
{
if (!gSpinWidget) {
gSpinWidget = gtk_spin_button_new(NULL, 1, 0);
setup_widget_prototype(gSpinWidget);
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_scale_widget()
{
if (!gHScaleWidget) {
gHScaleWidget = gtk_hscale_new(NULL);
setup_widget_prototype(gHScaleWidget);
}
if (!gVScaleWidget) {
gVScaleWidget = gtk_vscale_new(NULL);
setup_widget_prototype(gVScaleWidget);
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_entry_widget()
{
if (!gEntryWidget) {
gEntryWidget = gtk_entry_new();
setup_widget_prototype(gEntryWidget);
}
return MOZ_GTK_SUCCESS;
}
/* We need to have pointers to the inner widgets (button, separator, arrow)
* of the ComboBox to get the correct rendering from theme engines which
* special cases their look. Since the inner layout can change, we ask GTK
* to NULL our pointers when they are about to become invalid because the
* corresponding widgets don't exist anymore. It's the role of
* g_object_add_weak_pointer().
* Note that if we don't find the inner widgets (which shouldn't happen), we
* fallback to use generic "non-inner" widgets, and they don't need that kind
* of weak pointer since they are explicit children of gProtoWindow and as
* such GTK holds a strong reference to them. */
static void
moz_gtk_get_combo_box_inner_button(GtkWidget *widget, gpointer client_data)
{
if (GTK_IS_TOGGLE_BUTTON(widget)) {
gComboBoxButtonWidget = widget;
g_object_add_weak_pointer(G_OBJECT(widget),
(gpointer) &gComboBoxButtonWidget);
gtk_widget_realize(widget);
g_object_set_data(G_OBJECT(widget), "transparent-bg-hint", GINT_TO_POINTER(TRUE));
}
}
static void
moz_gtk_get_combo_box_button_inner_widgets(GtkWidget *widget,
gpointer client_data)
{
if (GTK_IS_SEPARATOR(widget)) {
gComboBoxSeparatorWidget = widget;
g_object_add_weak_pointer(G_OBJECT(widget),
(gpointer) &gComboBoxSeparatorWidget);
} else if (GTK_IS_ARROW(widget)) {
gComboBoxArrowWidget = widget;
g_object_add_weak_pointer(G_OBJECT(widget),
(gpointer) &gComboBoxArrowWidget);
} else
return;
gtk_widget_realize(widget);
g_object_set_data(G_OBJECT(widget), "transparent-bg-hint", GINT_TO_POINTER(TRUE));
}
static gint
ensure_combo_box_widgets()
{
GtkWidget* buttonChild;
if (gComboBoxButtonWidget && gComboBoxArrowWidget)
return MOZ_GTK_SUCCESS;
/* Create a ComboBox if needed */
if (!gComboBoxWidget) {
gComboBoxWidget = gtk_combo_box_new();
setup_widget_prototype(gComboBoxWidget);
}
/* Get its inner Button */
gtk_container_forall(GTK_CONTAINER(gComboBoxWidget),
moz_gtk_get_combo_box_inner_button,
NULL);
if (gComboBoxButtonWidget) {
/* Get the widgets inside the Button */
buttonChild = GTK_BIN(gComboBoxButtonWidget)->child;
if (GTK_IS_HBOX(buttonChild)) {
/* appears-as-list = FALSE, cell-view = TRUE; the button
* contains an hbox. This hbox is there because the ComboBox
* needs to place a cell renderer, a separator, and an arrow in
* the button when appears-as-list is FALSE. */
gtk_container_forall(GTK_CONTAINER(buttonChild),
moz_gtk_get_combo_box_button_inner_widgets,
NULL);
} else if(GTK_IS_ARROW(buttonChild)) {
/* appears-as-list = TRUE, or cell-view = FALSE;
* the button only contains an arrow */
gComboBoxArrowWidget = buttonChild;
g_object_add_weak_pointer(G_OBJECT(buttonChild), (gpointer)
&gComboBoxArrowWidget);
gtk_widget_realize(gComboBoxArrowWidget);
g_object_set_data(G_OBJECT(gComboBoxArrowWidget),
"transparent-bg-hint", GINT_TO_POINTER(TRUE));
}
} else {
/* Shouldn't be reached with current internal gtk implementation; we
* use a generic toggle button as last resort fallback to avoid
* crashing. */
ensure_toggle_button_widget();
gComboBoxButtonWidget = gToggleButtonWidget;
}
if (!gComboBoxArrowWidget) {
/* Shouldn't be reached with current internal gtk implementation;
* we gButtonArrowWidget as last resort fallback to avoid
* crashing. */
ensure_button_arrow_widget();
gComboBoxArrowWidget = gButtonArrowWidget;
}
/* We don't test the validity of gComboBoxSeparatorWidget since there
* is none when "appears-as-list" = TRUE or "cell-view" = FALSE; if it
* is invalid we just won't paint it. */
return MOZ_GTK_SUCCESS;
}
/* We need to have pointers to the inner widgets (entry, button, arrow) of
* the ComboBoxEntry to get the correct rendering from theme engines which
* special cases their look. Since the inner layout can change, we ask GTK
* to NULL our pointers when they are about to become invalid because the
* corresponding widgets don't exist anymore. It's the role of
* g_object_add_weak_pointer().
* Note that if we don't find the inner widgets (which shouldn't happen), we
* fallback to use generic "non-inner" widgets, and they don't need that kind
* of weak pointer since they are explicit children of gProtoWindow and as
* such GTK holds a strong reference to them. */
static void
moz_gtk_get_combo_box_entry_inner_widgets(GtkWidget *widget,
gpointer client_data)
{
if (GTK_IS_TOGGLE_BUTTON(widget)) {
gComboBoxEntryButtonWidget = widget;
g_object_add_weak_pointer(G_OBJECT(widget),
(gpointer) &gComboBoxEntryButtonWidget);
} else if (GTK_IS_ENTRY(widget)) {
gComboBoxEntryTextareaWidget = widget;
g_object_add_weak_pointer(G_OBJECT(widget),
(gpointer) &gComboBoxEntryTextareaWidget);
} else
return;
gtk_widget_realize(widget);
g_object_set_data(G_OBJECT(widget), "transparent-bg-hint", GINT_TO_POINTER(TRUE));
}
static void
moz_gtk_get_combo_box_entry_arrow(GtkWidget *widget, gpointer client_data)
{
if (GTK_IS_ARROW(widget)) {
gComboBoxEntryArrowWidget = widget;
g_object_add_weak_pointer(G_OBJECT(widget),
(gpointer) &gComboBoxEntryArrowWidget);
gtk_widget_realize(widget);
g_object_set_data(G_OBJECT(widget), "transparent-bg-hint", GINT_TO_POINTER(TRUE));
}
}
static gint
ensure_combo_box_entry_widgets()
{
GtkWidget* buttonChild;
if (gComboBoxEntryTextareaWidget &&
gComboBoxEntryButtonWidget &&
gComboBoxEntryArrowWidget)
return MOZ_GTK_SUCCESS;
/* Create a ComboBoxEntry if needed */
if (!gComboBoxEntryWidget) {
gComboBoxEntryWidget = gtk_combo_box_entry_new();
setup_widget_prototype(gComboBoxEntryWidget);
}
/* Get its inner Entry and Button */
gtk_container_forall(GTK_CONTAINER(gComboBoxEntryWidget),
moz_gtk_get_combo_box_entry_inner_widgets,
NULL);
if (!gComboBoxEntryTextareaWidget) {
ensure_entry_widget();
gComboBoxEntryTextareaWidget = gEntryWidget;
}
if (gComboBoxEntryButtonWidget) {
/* Get the Arrow inside the Button */
buttonChild = GTK_BIN(gComboBoxEntryButtonWidget)->child;
if (GTK_IS_HBOX(buttonChild)) {
/* appears-as-list = FALSE, cell-view = TRUE; the button
* contains an hbox. This hbox is there because ComboBoxEntry
* inherits from ComboBox which needs to place a cell renderer,
* a separator, and an arrow in the button when appears-as-list
* is FALSE. Here the hbox should only contain an arrow, since
* a ComboBoxEntry doesn't need all those widgets in the
* button. */
gtk_container_forall(GTK_CONTAINER(buttonChild),
moz_gtk_get_combo_box_entry_arrow,
NULL);
} else if(GTK_IS_ARROW(buttonChild)) {
/* appears-as-list = TRUE, or cell-view = FALSE;
* the button only contains an arrow */
gComboBoxEntryArrowWidget = buttonChild;
g_object_add_weak_pointer(G_OBJECT(buttonChild), (gpointer)
&gComboBoxEntryArrowWidget);
gtk_widget_realize(gComboBoxEntryArrowWidget);
g_object_set_data(G_OBJECT(gComboBoxEntryArrowWidget),
"transparent-bg-hint", GINT_TO_POINTER(TRUE));
}
} else {
/* Shouldn't be reached with current internal gtk implementation;
* we use a generic toggle button as last resort fallback to avoid
* crashing. */
ensure_toggle_button_widget();
gComboBoxEntryButtonWidget = gToggleButtonWidget;
}
if (!gComboBoxEntryArrowWidget) {
/* Shouldn't be reached with current internal gtk implementation;
* we gButtonArrowWidget as last resort fallback to avoid
* crashing. */
ensure_button_arrow_widget();
gComboBoxEntryArrowWidget = gButtonArrowWidget;
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_handlebox_widget()
{
if (!gHandleBoxWidget) {
gHandleBoxWidget = gtk_handle_box_new();
setup_widget_prototype(gHandleBoxWidget);
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_toolbar_widget()
{
if (!gToolbarWidget) {
ensure_handlebox_widget();
gToolbarWidget = gtk_toolbar_new();
gtk_container_add(GTK_CONTAINER(gHandleBoxWidget), gToolbarWidget);
gtk_widget_realize(gToolbarWidget);
g_object_set_data(G_OBJECT(gToolbarWidget), "transparent-bg-hint", GINT_TO_POINTER(TRUE));
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_toolbar_separator_widget()
{
if (!gToolbarSeparatorWidget) {
ensure_toolbar_widget();
gToolbarSeparatorWidget = GTK_WIDGET(gtk_separator_tool_item_new());
setup_widget_prototype(gToolbarSeparatorWidget);
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_tooltip_widget()
{
if (!gTooltipWidget) {
gTooltipWidget = gtk_window_new(GTK_WINDOW_POPUP);
gtk_widget_realize(gTooltipWidget);
moz_gtk_set_widget_name(gTooltipWidget);
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_tab_widget()
{
if (!gTabWidget) {
gTabWidget = gtk_notebook_new();
setup_widget_prototype(gTabWidget);
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_progress_widget()
{
if (!gProgressWidget) {
gProgressWidget = gtk_progress_bar_new();
setup_widget_prototype(gProgressWidget);
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_statusbar_widget()
{
if (!gStatusbarWidget) {
gStatusbarWidget = gtk_statusbar_new();
setup_widget_prototype(gStatusbarWidget);
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_frame_widget()
{
if (!gFrameWidget) {
ensure_statusbar_widget();
gFrameWidget = gtk_frame_new(NULL);
gtk_container_add(GTK_CONTAINER(gStatusbarWidget), gFrameWidget);
gtk_widget_realize(gFrameWidget);
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_menu_bar_widget()
{
if (!gMenuBarWidget) {
gMenuBarWidget = gtk_menu_bar_new();
setup_widget_prototype(gMenuBarWidget);
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_menu_bar_item_widget()
{
if (!gMenuBarItemWidget) {
ensure_menu_bar_widget();
gMenuBarItemWidget = gtk_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(gMenuBarWidget),
gMenuBarItemWidget);
gtk_widget_realize(gMenuBarItemWidget);
g_object_set_data(G_OBJECT(gMenuBarItemWidget),
"transparent-bg-hint", GINT_TO_POINTER(TRUE));
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_menu_popup_widget()
{
if (!gMenuPopupWidget) {
ensure_menu_bar_item_widget();
gMenuPopupWidget = gtk_menu_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(gMenuBarItemWidget),
gMenuPopupWidget);
gtk_widget_realize(gMenuPopupWidget);
g_object_set_data(G_OBJECT(gMenuPopupWidget),
"transparent-bg-hint", GINT_TO_POINTER(TRUE));
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_menu_item_widget()
{
if (!gMenuItemWidget) {
ensure_menu_popup_widget();
gMenuItemWidget = gtk_menu_item_new_with_label("M");
gtk_menu_shell_append(GTK_MENU_SHELL(gMenuPopupWidget),
gMenuItemWidget);
gtk_widget_realize(gMenuItemWidget);
g_object_set_data(G_OBJECT(gMenuItemWidget),
"transparent-bg-hint", GINT_TO_POINTER(TRUE));
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_image_menu_item_widget()
{
if (!gImageMenuItemWidget) {
ensure_menu_popup_widget();
gImageMenuItemWidget = gtk_image_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(gMenuPopupWidget),
gImageMenuItemWidget);
gtk_widget_realize(gImageMenuItemWidget);
g_object_set_data(G_OBJECT(gImageMenuItemWidget),
"transparent-bg-hint", GINT_TO_POINTER(TRUE));
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_menu_separator_widget()
{
if (!gMenuSeparatorWidget) {
ensure_menu_popup_widget();
gMenuSeparatorWidget = gtk_separator_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(gMenuPopupWidget),
gMenuSeparatorWidget);
gtk_widget_realize(gMenuSeparatorWidget);
g_object_set_data(G_OBJECT(gMenuSeparatorWidget),
"transparent-bg-hint", GINT_TO_POINTER(TRUE));
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_check_menu_item_widget()
{
if (!gCheckMenuItemWidget) {
ensure_menu_popup_widget();
gCheckMenuItemWidget = gtk_check_menu_item_new_with_label("M");
gtk_menu_shell_append(GTK_MENU_SHELL(gMenuPopupWidget),
gCheckMenuItemWidget);
gtk_widget_realize(gCheckMenuItemWidget);
g_object_set_data(G_OBJECT(gCheckMenuItemWidget),
"transparent-bg-hint", GINT_TO_POINTER(TRUE));
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_tree_view_widget()
{
if (!gTreeViewWidget) {
gTreeViewWidget = gtk_tree_view_new();
setup_widget_prototype(gTreeViewWidget);
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_tree_header_cell_widget()
{
if(!gTreeHeaderCellWidget) {
/*
* Some GTK engines paint the first and last cell
* of a TreeView header with a highlight.
* Since we do not know where our widget will be relative
* to the other buttons in the TreeView header, we must
* paint it as a button that is between two others,
* thus ensuring it is neither the first or last button
* in the header.
* GTK doesn't give us a way to do this explicitly,
* so we must paint with a button that is between two
* others.
*/
GtkTreeViewColumn* firstTreeViewColumn;
GtkTreeViewColumn* lastTreeViewColumn;
ensure_tree_view_widget();
/* Create and append our three columns */
firstTreeViewColumn = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(firstTreeViewColumn, "M");
gtk_tree_view_append_column(GTK_TREE_VIEW(gTreeViewWidget), firstTreeViewColumn);
gMiddleTreeViewColumn = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(gMiddleTreeViewColumn, "M");
gtk_tree_view_append_column(GTK_TREE_VIEW(gTreeViewWidget),
gMiddleTreeViewColumn);
lastTreeViewColumn = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(lastTreeViewColumn, "M");
gtk_tree_view_append_column(GTK_TREE_VIEW(gTreeViewWidget), lastTreeViewColumn);
/* Use the middle column's header for our button */
gTreeHeaderCellWidget = gMiddleTreeViewColumn->button;
gTreeHeaderSortArrowWidget = gMiddleTreeViewColumn->arrow;
g_object_set_data(G_OBJECT(gTreeHeaderCellWidget),
"transparent-bg-hint", GINT_TO_POINTER(TRUE));
g_object_set_data(G_OBJECT(gTreeHeaderSortArrowWidget),
"transparent-bg-hint", GINT_TO_POINTER(TRUE));
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_expander_widget()
{
if (!gExpanderWidget) {
gExpanderWidget = gtk_expander_new("M");
setup_widget_prototype(gExpanderWidget);
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_scrolled_window_widget()
{
if (!gScrolledWindowWidget) {
gScrolledWindowWidget = gtk_scrolled_window_new(NULL, NULL);
setup_widget_prototype(gScrolledWindowWidget);
}
return MOZ_GTK_SUCCESS;
}
static GtkStateType
ConvertGtkState(GtkWidgetState* state)
{
if (state->disabled)
return GTK_STATE_INSENSITIVE;
else if (state->depressed)
return (state->inHover ? GTK_STATE_PRELIGHT : GTK_STATE_ACTIVE);
else if (state->inHover)
return (state->active ? GTK_STATE_ACTIVE : GTK_STATE_PRELIGHT);
else
return GTK_STATE_NORMAL;
}
static gint
TSOffsetStyleGCArray(GdkGC** gcs, gint xorigin, gint yorigin)
{
int i;
/* there are 5 gc's in each array, for each of the widget states */
for (i = 0; i < 5; ++i)
gdk_gc_set_ts_origin(gcs[i], xorigin, yorigin);
return MOZ_GTK_SUCCESS;
}
static gint
TSOffsetStyleGCs(GtkStyle* style, gint xorigin, gint yorigin)
{
TSOffsetStyleGCArray(style->fg_gc, xorigin, yorigin);
TSOffsetStyleGCArray(style->bg_gc, xorigin, yorigin);
TSOffsetStyleGCArray(style->light_gc, xorigin, yorigin);
TSOffsetStyleGCArray(style->dark_gc, xorigin, yorigin);
TSOffsetStyleGCArray(style->mid_gc, xorigin, yorigin);
TSOffsetStyleGCArray(style->text_gc, xorigin, yorigin);
TSOffsetStyleGCArray(style->base_gc, xorigin, yorigin);
gdk_gc_set_ts_origin(style->black_gc, xorigin, yorigin);
gdk_gc_set_ts_origin(style->white_gc, xorigin, yorigin);
return MOZ_GTK_SUCCESS;
}
gint
moz_gtk_init()
{
GtkWidgetClass *entry_class;
if (is_initialized)
return MOZ_GTK_SUCCESS;
is_initialized = TRUE;
have_arrow_scaling = (gtk_major_version > 2 ||
(gtk_major_version == 2 && gtk_minor_version >= 12));
/* Add style property to GtkEntry.
* Adding the style property to the normal GtkEntry class means that it
* will work without issues inside GtkComboBox and for Spinbuttons. */
entry_class = g_type_class_ref(GTK_TYPE_ENTRY);
gtk_widget_class_install_style_property(entry_class,
g_param_spec_boolean("honors-transparent-bg-hint",
"Transparent BG enabling flag",
"If TRUE, the theme is able to draw the GtkEntry on non-prefilled background.",
FALSE,
G_PARAM_READWRITE));
return MOZ_GTK_SUCCESS;
}
GdkColormap*
moz_gtk_widget_get_colormap()
{
/* Child widgets inherit the colormap from the GtkWindow. */
ensure_window_widget();
return gtk_widget_get_colormap(gProtoWindow);
}
gint
moz_gtk_checkbox_get_metrics(gint* indicator_size, gint* indicator_spacing)
{
ensure_checkbox_widget();
gtk_widget_style_get (gCheckboxWidget,
"indicator_size", indicator_size,
"indicator_spacing", indicator_spacing,
NULL);
return MOZ_GTK_SUCCESS;
}
gint
moz_gtk_radio_get_metrics(gint* indicator_size, gint* indicator_spacing)
{
ensure_radiobutton_widget();
gtk_widget_style_get (gRadiobuttonWidget,
"indicator_size", indicator_size,
"indicator_spacing", indicator_spacing,
NULL);
return MOZ_GTK_SUCCESS;
}
gint
moz_gtk_widget_get_focus(GtkWidget* widget, gboolean* interior_focus,
gint* focus_width, gint* focus_pad)
{
gtk_widget_style_get (widget,
"interior-focus", interior_focus,
"focus-line-width", focus_width,
"focus-padding", focus_pad,
NULL);
return MOZ_GTK_SUCCESS;
}
gint
moz_gtk_menuitem_get_horizontal_padding(gint* horizontal_padding)
{
ensure_menu_item_widget();
gtk_widget_style_get (gMenuItemWidget,
"horizontal-padding", horizontal_padding,
NULL);
return MOZ_GTK_SUCCESS;
}
gint
moz_gtk_checkmenuitem_get_horizontal_padding(gint* horizontal_padding)
{
ensure_check_menu_item_widget();
gtk_widget_style_get (gCheckMenuItemWidget,
"horizontal-padding", horizontal_padding,
NULL);
return MOZ_GTK_SUCCESS;
}
gint
moz_gtk_button_get_default_overflow(gint* border_top, gint* border_left,
gint* border_bottom, gint* border_right)
{
GtkBorder* default_outside_border;
ensure_button_widget();
gtk_widget_style_get(gButtonWidget,
"default-outside-border", &default_outside_border,
NULL);
if (default_outside_border) {
*border_top = default_outside_border->top;
*border_left = default_outside_border->left;
*border_bottom = default_outside_border->bottom;
*border_right = default_outside_border->right;
gtk_border_free(default_outside_border);
} else {
*border_top = *border_left = *border_bottom = *border_right = 0;
}
return MOZ_GTK_SUCCESS;
}
static gint
moz_gtk_button_get_default_border(gint* border_top, gint* border_left,
gint* border_bottom, gint* border_right)
{
GtkBorder* default_border;
ensure_button_widget();
gtk_widget_style_get(gButtonWidget,
"default-border", &default_border,
NULL);
if (default_border) {
*border_top = default_border->top;
*border_left = default_border->left;
*border_bottom = default_border->bottom;
*border_right = default_border->right;
gtk_border_free(default_border);
} else {
/* see gtkbutton.c */
*border_top = *border_left = *border_bottom = *border_right = 1;
}
return MOZ_GTK_SUCCESS;
}
gint
moz_gtk_splitter_get_metrics(gint orientation, gint* size)
{
if (orientation == GTK_ORIENTATION_HORIZONTAL) {
ensure_hpaned_widget();
gtk_widget_style_get(gHPanedWidget, "handle_size", size, NULL);
} else {
ensure_vpaned_widget();
gtk_widget_style_get(gVPanedWidget, "handle_size", size, NULL);
}
return MOZ_GTK_SUCCESS;
}
gint
moz_gtk_button_get_inner_border(GtkWidget* widget, GtkBorder* inner_border)
{
static const GtkBorder default_inner_border = { 1, 1, 1, 1 };
GtkBorder *tmp_border;
gtk_widget_style_get (widget, "inner-border", &tmp_border, NULL);
if (tmp_border) {
*inner_border = *tmp_border;
gtk_border_free(tmp_border);
}
else
*inner_border = default_inner_border;
return MOZ_GTK_SUCCESS;
}
static gint
moz_gtk_button_paint(GdkDrawable* drawable, GdkRectangle* rect,
GdkRectangle* cliprect, GtkWidgetState* state,
GtkReliefStyle relief, GtkWidget* widget,
GtkTextDirection direction)
{
GtkShadowType shadow_type;
GtkStyle* style = widget->style;
GtkStateType button_state = ConvertGtkState(state);
gint x = rect->x, y=rect->y, width=rect->width, height=rect->height;
gboolean interior_focus;
gint focus_width, focus_pad;
moz_gtk_widget_get_focus(widget, &interior_focus, &focus_width, &focus_pad);
if (WINDOW_IS_MAPPED(drawable)) {
gdk_window_set_back_pixmap(drawable, NULL, TRUE);
gdk_window_clear_area(drawable, cliprect->x, cliprect->y,
cliprect->width, cliprect->height);
}
gtk_widget_set_state(widget, button_state);
gtk_widget_set_direction(widget, direction);
if (state->isDefault)
GTK_WIDGET_SET_FLAGS(widget, GTK_HAS_DEFAULT);
GTK_BUTTON(widget)->relief = relief;
/* Some theme engines love to cause us pain in that gtk_paint_focus is a
no-op on buttons and button-like widgets. They only listen to this flag. */
if (state->focused && !state->disabled)
GTK_WIDGET_SET_FLAGS(widget, GTK_HAS_FOCUS);
if (!interior_focus && state->focused) {
x += focus_width + focus_pad;
y += focus_width + focus_pad;
width -= 2 * (focus_width + focus_pad);
height -= 2 * (focus_width + focus_pad);
}
shadow_type = button_state == GTK_STATE_ACTIVE ||
state->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
if (state->isDefault && relief == GTK_RELIEF_NORMAL) {
/* handle default borders both outside and inside the button */
gint default_top, default_left, default_bottom, default_right;
moz_gtk_button_get_default_overflow(&default_top, &default_left,
&default_bottom, &default_right);
x -= default_left;
y -= default_top;
width += default_left + default_right;
height += default_top + default_bottom;
gtk_paint_box(style, drawable, GTK_STATE_NORMAL, GTK_SHADOW_IN, cliprect,
widget, "buttondefault", x, y, width, height);
moz_gtk_button_get_default_border(&default_top, &default_left,
&default_bottom, &default_right);
x += default_left;
y += default_top;
width -= (default_left + default_right);
height -= (default_top + default_bottom);
}
if (relief != GTK_RELIEF_NONE || state->depressed ||
(button_state != GTK_STATE_NORMAL &&
button_state != GTK_STATE_INSENSITIVE)) {
TSOffsetStyleGCs(style, x, y);
/* the following line can trigger an assertion (Crux theme)
file ../../gdk/gdkwindow.c: line 1846 (gdk_window_clear_area):
assertion `GDK_IS_WINDOW (window)' failed */
gtk_paint_box(style, drawable, button_state, shadow_type, cliprect,