ui/gtk/headerbar.c

Sun, 29 Sep 2024 20:25:41 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 29 Sep 2024 20:25:41 +0200
changeset 45
ab71409644b0
parent 44
473954dc6b74
child 46
31bc86844659
permissions
-rw-r--r--

update toolkit, fix download/upload progressbar

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

mercurial