Tue, 08 Oct 2024 22:19:24 +0200
add tabview value/varname parameter
306
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2024 Olaf Wintermann. All rights reserved. |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include "headerbar.h" |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
307
diff
changeset
|
31 | #include "button.h" |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
32 | #include "menu.h" |
306
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #if GTK_MAJOR_VERSION >= 3 |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #ifdef UI_LIBADWAITA |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #define UI_HEADERBAR AdwHeaderBar* |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | #define UI_HEADERBAR_CAST(h) ADW_HEADER_BAR(h) |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | #define UI_HEADERBAR_PACK_START(h, w) adw_header_bar_pack_start(ADW_HEADER_BAR(h), w) |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #define UI_HEADERBAR_PACK_END(h, w) adw_header_bar_pack_end(ADW_HEADER_BAR(h), w) |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | #define UI_HEADERBAR_SET_TITLE_WIDGET(h, w) adw_header_bar_set_title_widget(ADW_HEADER_BAR(h), w) |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | #else |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | #define UI_HEADERBAR GtkHeaderBar* |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | #define UI_HEADERBAR_CAST(h) GTK_HEADER_BAR(h) |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | #define UI_HEADERBAR_PACK_START(h, w) gtk_header_bar_pack_start(GTK_HEADER_BAR(h), w) |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | #define UI_HEADERBAR_PACK_END(h, w) gtk_header_bar_pack_end(GTK_HEADER_BAR(h), w) |
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
47 | #if GTK_MAJOR_VERSION >= 4 |
306
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | #define UI_HEADERBAR_SET_TITLE_WIDGET(h, w) gtk_header_bar_set_title_widget(GTK_HEADER_BAR(h), w) |
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
49 | #else |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
50 | #define UI_HEADERBAR_SET_TITLE_WIDGET(h, w) gtk_header_bar_set_custom_title(GTK_HEADER_BAR(h), w) |
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
51 | #endif |
306
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | #endif |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | void ui_fill_headerbar(UiObject *obj, GtkWidget *headerbar) { |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | CxList *left_defaults = uic_get_toolbar_defaults(UI_TOOLBAR_LEFT); |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | CxList *center_defaults = uic_get_toolbar_defaults(UI_TOOLBAR_CENTER); |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | CxList *right_defaults = uic_get_toolbar_defaults(UI_TOOLBAR_RIGHT); |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | ui_headerbar_add_items(obj, headerbar, left_defaults, UI_TOOLBAR_LEFT); |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | ui_headerbar_add_items(obj, headerbar, center_defaults, UI_TOOLBAR_CENTER); |
322
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
61 | |
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
62 | UiToolbarMenuItem *appmenu = uic_get_appmenu(); |
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
63 | if(appmenu) { |
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
64 | ui_add_headerbar_menu(headerbar, NULL, appmenu, obj, UI_TOOLBAR_RIGHT); |
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
65 | } |
306
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | ui_headerbar_add_items(obj, headerbar, right_defaults, UI_TOOLBAR_RIGHT); |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | } |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | static void create_item(UiObject *obj, GtkWidget *headerbar, GtkWidget *box, UiToolbarItemI *i, enum UiToolbarPos pos) { |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | switch(i->type) { |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | case UI_TOOLBAR_ITEM: { |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | ui_add_headerbar_item(headerbar, box, (UiToolbarItem*)i, obj, pos); |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | break; |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | } |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | case UI_TOOLBAR_TOGGLEITEM: { |
309
02c95df91de1
add headerbar toggle button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
308
diff
changeset
|
76 | ui_add_headerbar_toggleitem(headerbar, box, (UiToolbarToggleItem*)i, obj, pos); |
306
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | break; |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | } |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | case UI_TOOLBAR_MENU: { |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
80 | ui_add_headerbar_menu(headerbar, box, (UiToolbarMenuItem*)i, obj, pos); |
306
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | break; |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | } |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | default: fprintf(stderr, "toolbar item type unimplemented: %d\n", (int)i->type); |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | } |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | } |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | static void headerbar_add(GtkWidget *headerbar, GtkWidget *box, GtkWidget *item, enum UiToolbarPos pos) { |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | switch(pos) { |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | case UI_TOOLBAR_LEFT: { |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | UI_HEADERBAR_PACK_START(headerbar, item); |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | break; |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | } |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | case UI_TOOLBAR_CENTER: { |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | #if GTK_MAJOR_VERSION >= 4 |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | gtk_box_append(GTK_BOX(box), item); |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | #else |
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
98 | gtk_box_pack_start(GTK_BOX(box), item, 0, 0, 0); |
306
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | #endif |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | break; |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | } |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | case UI_TOOLBAR_RIGHT: { |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | UI_HEADERBAR_PACK_END(headerbar, item); |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | break; |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | } |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | } |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | } |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | void ui_headerbar_add_items(UiObject *obj, GtkWidget *headerbar, CxList *items, enum UiToolbarPos pos) { |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | GtkWidget *box = NULL; |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | if(pos == UI_TOOLBAR_CENTER && cxListSize(items) > 0) { |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6); |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | UI_HEADERBAR_SET_TITLE_WIDGET(headerbar, box); |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | } |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | CxIterator i = pos == UI_TOOLBAR_RIGHT ? cxListBackwardsIterator(items) : cxListIterator(items); |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | cx_foreach(char*, def, i) { |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | UiToolbarItemI* item = uic_toolbar_get_item(def); |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | if (!item) { |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | fprintf(stderr, "unknown toolbar item: %s\n", def); |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | continue; |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | } |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | create_item(obj, headerbar, box, item, pos); |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | } |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | } |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
128 | void ui_add_headerbar_item( |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
129 | GtkWidget *headerbar, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
130 | GtkWidget *box, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
131 | UiToolbarItem *item, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
132 | UiObject *obj, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
133 | enum UiToolbarPos pos) |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
134 | { |
308
4efc7c19e31d
simplify gtk button code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
307
diff
changeset
|
135 | GtkWidget *button = ui_create_button(obj, item->args.label, item->args.icon, item->args.onclick, item->args.onclickdata); |
307
301d6c73087a
make headerbar buttons flat (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
136 | WIDGET_ADD_CSS_CLASS(button, "flat"); |
306
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | headerbar_add(headerbar, box, button, pos); |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | } |
309
02c95df91de1
add headerbar toggle button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
308
diff
changeset
|
139 | |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
140 | void ui_add_headerbar_toggleitem( |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
141 | GtkWidget *headerbar, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
142 | GtkWidget *box, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
143 | UiToolbarToggleItem *item, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
144 | UiObject *obj, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
145 | enum UiToolbarPos pos) |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
146 | { |
309
02c95df91de1
add headerbar toggle button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
308
diff
changeset
|
147 | GtkWidget *button = gtk_toggle_button_new(); |
02c95df91de1
add headerbar toggle button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
308
diff
changeset
|
148 | WIDGET_ADD_CSS_CLASS(button, "flat"); |
02c95df91de1
add headerbar toggle button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
308
diff
changeset
|
149 | ui_setup_togglebutton(obj, button, item->args.label, item->args.icon, item->args.varname, NULL, item->args.onchange, item->args.onchangedata); |
02c95df91de1
add headerbar toggle button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
308
diff
changeset
|
150 | headerbar_add(headerbar, box, button, pos); |
02c95df91de1
add headerbar toggle button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
308
diff
changeset
|
151 | } |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
152 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
153 | void ui_add_headerbar_menu( |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
154 | GtkWidget *headerbar, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
155 | GtkWidget *box, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
156 | UiToolbarMenuItem *item, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
157 | UiObject *obj, |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
158 | enum UiToolbarPos pos) |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
159 | { |
314
d96ba820083a
implement file dialog for gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
160 | |
d96ba820083a
implement file dialog for gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
161 | |
d96ba820083a
implement file dialog for gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
162 | #if GTK_MAJOR_VERSION >= 4 |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
163 | GtkWidget *menubutton = gtk_menu_button_new(); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
164 | if(item->args.label) { |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
165 | gtk_menu_button_set_label(GTK_MENU_BUTTON(menubutton), item->args.label); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
166 | } |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
167 | if(item->args.icon) { |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
168 | gtk_menu_button_set_icon_name(GTK_MENU_BUTTON(menubutton), item->args.icon); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
169 | } |
314
d96ba820083a
implement file dialog for gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
170 | |
322
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
171 | if(!item->args.label && !item->args.icon) { |
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
172 | gtk_menu_button_set_icon_name(GTK_MENU_BUTTON(menubutton), "open-menu-symbolic"); |
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
173 | } |
22f6dadd9f46
implement ui_menuseparator (GTK4)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
174 | |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
175 | GMenu *menu = g_menu_new(); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
176 | ui_gmenu_add_menu_items(menu, 0, &item->menu, obj); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
177 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
178 | gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(menubutton), G_MENU_MODEL(menu)); |
314
d96ba820083a
implement file dialog for gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
179 | #else |
d96ba820083a
implement file dialog for gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
180 | GtkWidget *menubutton = gtk_menu_button_new(); |
d96ba820083a
implement file dialog for gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
181 | |
d96ba820083a
implement file dialog for gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
182 | // TODO |
d96ba820083a
implement file dialog for gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
183 | |
d96ba820083a
implement file dialog for gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
184 | |
d96ba820083a
implement file dialog for gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
185 | #endif |
311
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
186 | |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
187 | headerbar_add(headerbar, box, menubutton, pos); |
450a813dc2a5
implement GTK4 gmenu item and item list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
310
diff
changeset
|
188 | } |
306
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | |
d02e1149cdb9
add headerbar (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | #endif |