atomes 1.1.16
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
gtk-misc.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2024 by CNRS and University of Strasbourg */
15
24/*
25* This file: 'gtk-misc.c'
26*
27* Contains:
28*
29
30 - GTK3/GTK4 utility subroutines, instead of having pre-processor flags everywhere in the code
31 Whenever I need to use a GTK function that changed between v3 and v4,
32 I created an home made function declared in this file, and deal then here with the potential GTK versions issues.
33
34*
35* List of functions:
36
37 gboolean is_the_widget_visible (GtkWidget * widg);
38 gboolean file_chooser_set_file_name (GtkFileChooser * chooser, gchar * filename);
39
40 G_MODULE_EXPORT gboolean to_activate_entry (GtkWidget * widg, GdkEventFocus * event, gpointer data);
41 G_MODULE_EXPORT gboolean destroy_this_window (GtkWindow * win, gpointer data);
42 G_MODULE_EXPORT gboolean destroy_this_window (GtkWidget * win, GdkEvent * event, gpointer data);
43 G_MODULE_EXPORT gboolean hide_this_window (GtkWindow * win, gpointer data);
44 G_MODULE_EXPORT gboolean hide_this_window (GtkWidget * win, GdkEvent * event, gpointer data);
45
46 gchar * file_chooser_get_file_name (GtkFileChooser * chooser);
47 gchar * file_chooser_get_current_folder (GtkFileChooser * chooser);
48
49 const gchar * entry_get_text (GtkEntry * entry);
50
51 void show_the_widgets (GtkWidget * widg);
52 void hide_the_widgets (GtkWidget * widg);
53 void widget_set_sensitive (GtkWidget * widg, gboolean sensitive);
54 void add_container_child (int type, GtkWidget * widg, GtkWidget * child);
55 void add_box_child_end (GtkWidget * widg, GtkWidget * child, gboolean expand, gboolean fill, int padding);
56 void add_box_child_start (int orientation, GtkWidget * widg, GtkWidget * child, gboolean expand, gboolean fill, int padding);
57 void add_widget_gesture_and_key_action (GtkWidget * widget,
58 gchar * cp_name, GCallback cp_handler, gpointer cp_data,
59 gchar * cr_name, GCallback cr_handler, gpointer cr_data,
60 gchar * kp_name, GCallback kp_handler, gpointer kp_data,
61 gchar * mo_name, GCallback mo_handler, gpointer mo_data,
62 gchar * sc_name, GCallback sc_handler, gpointer sc_data);
63 void run_this_gtk_native_dialog (GtkNativeDialog * dial, GCallback handler, gpointer data);
64 void run_this_gtk_dialog (GtkWidget * dial, GCallback handler, gpointer data);
65 void resize_this_window (GtkWidget * window, int x, int y);
66 void update_entry_int (GtkEntry * entry, int intval);
67 void update_entry_double (GtkEntry * entry, double doubleval);
68 void update_entry_long_double (GtkEntry * entry, double doubleval);
69 void update_entry_text (GtkEntry * entry, gchar * text);
70 void text_view_set_monospace (GtkWidget * view);
71 void gtk_label_align (GtkWidget * lab, float ax, float ay);
72 void layout_add_widget (GtkWidget * layout, GtkWidget * child, int x_pos, int y_pos);
73 void combo_text_append (GtkWidget * combo, gchar * text);
74 void combo_text_prepend (GtkWidget * combo, gchar * text);
75 void setup_text_tags (GtkTextBuffer * buffer);
76 void add_menu_separator (GtkWidget * menu);
77 void set_renderer_color (int tocol, GtkCellRenderer * renderer, ColRGBA col);
78 void button_set_image (GtkButton * but, gchar * text, int format, gpointer image);
79 void adjust_label (GtkWidget * lab, int dimx, int dimy, float ax, float ay);
80 void set_image_from_icon_name (GtkWidget * widg, gchar * icon);
81 void provide_gtk_css (gchar * css);
82 void destroy_this_dialog (GtkDialog * dialog);
83 void destroy_this_native_dialog (GtkNativeDialog * dialog);
84 void file_chooser_set_current_folder (GtkFileChooser * chooser);
85 void set_color_chooser_color (GtkWidget * color_win, ColRGBA col);
86 void pop_menu_at_pointer (GtkWidget * pop, double x, double y);
87 void pop_menu_at_pointer (GtkWidget * widg, GdkEvent * event);
88 void add_gtk_close_event (GtkWidget * widg, GCallback handler, gpointer data);
89 static void convert_alpha (cairo_surface_t * surf, GdkPixbuf * pix, int src_x, int src_y, int width, int height);
90
91 G_MODULE_EXPORT void to_activate_entry (GtkEventControllerFocus * focus, gpointer data);
92 G_MODULE_EXPORT void run_destroy_dialog (GtkDialog * dialog, gint response_id, gpointer data);
93
94 GtkWidget * menu_item_new_with_submenu (gchar * name, gboolean active, GtkWidget * sub_menu);
95 GtkWidget * new_gtk_window ();
96 GtkWidget * create_win (gchar * str, GtkWidget * parent, gboolean modal, gboolean resiz);
97 GtkWidget * dialogmodal (gchar * str, GtkWindow * parent);
98 GtkWidget * message_dialogmodal (gchar * message, gchar * title, GtkMessageType mtype, GtkButtonsType buttons, GtkWidget * parent);
99 GtkWidget * dialog_cancel_apply (gchar * title, GtkWidget * parent, gboolean resiz);
100 GtkWidget * create_hscale (float min, float max, float delta,
101 float val, int pos, int round, int size,
102 GCallback handler, GCallback scroll_handler, gpointer data);
103 GtkWidget * create_vscale (float min, float max, float delta,
104 float val, int pos, int round, int size,
105 GCallback handler, GCallback scroll_handler, gpointer data);
106 GtkWidget * create_vbox (int spacing);
107 GtkWidget * create_hbox (int spacing);
108 GtkWidget * dialog_get_content_area (GtkWidget * widg);
109 GtkWidget * add_vbox_to_layout (GtkWidget * layout, int size_x, int size_y);
110 GtkWidget * create_layout (int x, int y);
111 GtkWidget * create_combo ();
112 GtkWidget * create_text_view (int dimx, int dimy, int edit, int mono, GCallback handler, gpointer data, gchar * text);
113 GtkWidget * create_entry (GCallback handler, int dim, int cdim, gboolean key_release, gpointer data);
114 GtkWidget * stock_image (const gchar * stock_id);
115 GtkWidget * create_menu_item (gboolean add_mnemo, gchar * name);
116 GtkWidget * create_menu_item_from_widget (GtkWidget * widg, gboolean check, gboolean radio, gboolean status);
117 GtkWidget * create_image_from_data (int format, gpointer item_image);
118 GtkWidget * gtk3_menu_item (GtkWidget * menu, gchar * name,
119 int icon_format, gpointer item_icon,
120 GCallback handler, gpointer data,
121 gboolean accel, guint key, GdkModifierType mod,
122 gboolean check, gboolean radio, gboolean status);
123 GtkWidget * add_advanced_item (GtkWidget * menu, GCallback handler, gpointer data, gboolean accel, guint key, GdkModifierType mod);
124 GtkWidget * markup_label (gchar * text, int dimx, int dimy, float ax, float ay);
125 GtkWidget * color_button (ColRGBA col, gboolean alpha, int dimx, int dimy, GCallback handler, gpointer data);
126 GtkWidget * font_button (gchar * font, int dimx, int dimy, GCallback handler, gpointer data);
127 GtkWidget * spin_button (GCallback handler, double value, double start, double end, double step, int digits, int dim, gpointer data);
128 GtkWidget * check_button (gchar * text, int dimx, int dimy, gboolean state, GCallback handler, gpointer data);
129 GtkWidget * radio_button (gchar * text, int dimx, int dimy, gboolean state, GCallback handler, gpointer data);
130 GtkWidget * create_button (gchar * text, int image_format, gchar * image, int dimx, int dimy, int relief, GCallback handler, gpointer data);
131 GtkWidget * abox (GtkWidget * box, char * lab, int vspace);
132 GtkWidget * bbox (GtkWidget * box, char * lab);
133 GtkWidget * cbox (GtkWidget * box, char * lab);
134 GtkWidget * fbox (GtkWidget * box, char * lab);
135 GtkWidget * create_scroll (GtkWidget * box, int dimx, int dimy, int shadow);
136 GtkWidget * create_expander (gchar * name, gchar * file_img);
137 GtkWidget * destroy_this_widget (GtkWidget * widg);
138 GtkWidget * create_file_chooser (const gchar * title, GtkWindow * parent, GtkFileChooserAction act, const gchar * act_name);
139 GtkWidget * get_top_level (GtkWidget * widg);
140
141 GtkTextBuffer * add_buffer (GCallback handler, gpointer data, gchar * text);
142
143 GtkFileChooserNative * create_file_chooser (const gchar * title, GtkWindow * parent, GtkFileChooserAction act, const gchar * act_name);
144
145 GdkPixbuf * convert_to_pixbuf (cairo_surface_t * surf);
146
147 GMenuItem * create_menu_item (gboolean add_mnemo, gchar * name, gchar * action);
148
149 GListModel * file_chooser_get_file_names (GtkFileChooser * chooser);
150
151 ColRGBA * duplicate_color (int num, ColRGBA * col);
152 ColRGBA gdkrgba_to_rgba (GdkRGBA colgdk);
153 ColRGBA get_button_color (GtkColorChooser * colob);
154 ColRGBA get_window_color (GtkWidget * color_win);
155
156 GdkRGBA colrgba_togtkrgba (ColRGBA col);
157
158 int get_widget_width (GtkWidget * widg);
159 int get_widget_height (GtkWidget * widg);
160
161*/
162
163#include "global.h"
164#include "interface.h"
165
173void show_the_widgets (GtkWidget * widg)
174{
175#ifdef GTK4
176 gtk_widget_set_visible (widg, TRUE);
177#else
178 gtk_widget_show_all (widg);
179#endif
180}
181
189void hide_the_widgets (GtkWidget * widg)
190{
191#ifdef GTK4
192 gtk_widget_set_visible (widg, FALSE);
193#else
194 gtk_widget_hide (widg);
195#endif
196}
197
206void widget_set_sensitive (GtkWidget * widg, gboolean sensitive)
207{
208 if (widg != NULL)
209 {
210 if (GTK_IS_WIDGET(widg))
211 {
212 gtk_widget_set_sensitive (widg, sensitive);
213 }
214 }
215}
216
226void add_container_child (int type, GtkWidget * widg, GtkWidget * child)
227{
228#ifdef GTK3
229 gtk_container_add (GTK_CONTAINER(widg), child);
230#else
231 switch (type)
232 {
233 case CONTAINER_WIN:
234 // gtk_window_set_child ((GtkWindow *)widg, NULL);
235 gtk_window_set_child ((GtkWindow *)widg, child);
236 break;
237 case CONTAINER_SCR:
238 // Bug in the management of scrolled window child
239/* Frequently getting warning messages at this point with GTK4
240(atomes:?????): GLib-GObject-CRITICAL **: ??:??:??.???: g_object_set: assertion 'G_IS_OBJECT (object)' failed
241(atomes:?????): Gtk-CRITICAL **: ??:??:??.???: gtk_widget_unparent: assertion 'GTK_IS_WIDGET (widget)' failed
242*/
243 gtk_scrolled_window_set_child ((GtkScrolledWindow *)widg, NULL);
244 gtk_scrolled_window_set_child ((GtkScrolledWindow *)widg, child);
245 break;
246 case CONTAINER_VIE:
247 // gtk_viewport_set_child ((GtkViewport *)widg, NULL);
248 gtk_viewport_set_child ((GtkViewport *)widg, child);
249 break;
250 case CONTAINER_BUT:
251 // gtk_button_set_child ((GtkButton *)widg, NULL);
252 gtk_button_set_child ((GtkButton *)widg, child);
253 break;
254 case CONTAINER_FRA:
255 // gtk_frame_set_child ((GtkFrame *)widg, NULL);
256 gtk_frame_set_child ((GtkFrame *)widg, child);
257 break;
258 case CONTAINER_EXP:
259 // gtk_expander_set_child ((GtkExpander *)widg, NULL);
260 gtk_expander_set_child ((GtkExpander *)widg, child);
261 break;
262 }
263#endif
264}
265
277void add_box_child_end (GtkWidget * widg, GtkWidget * child, gboolean expand, gboolean fill, int padding)
278{
279#ifdef GTK4
280 // gtk_widget_set_hexpand (child, TRUE);
281 gtk_box_append (GTK_BOX(widg), child);
282#else
283 gtk_box_pack_end (GTK_BOX(widg), child, expand, fill, padding);
284#endif
285}
286
299void add_box_child_start (int orientation, GtkWidget * widg, GtkWidget * child, gboolean expand, gboolean fill, int padding)
300{
301#ifdef GTK4
302 if (orientation == GTK_ORIENTATION_HORIZONTAL && padding)
303 {
304 gtk_box_append (GTK_BOX(widg), markup_label (" ", padding, -1, 0.0, 0.0));
305 }
306 else if (orientation == GTK_ORIENTATION_VERTICAL && padding > 10)
307 {
308 gtk_box_append (GTK_BOX(widg), markup_label (" ", -1, padding/2, 0.0, 0.0));
309 }
310 gtk_box_append (GTK_BOX(widg), child);
311 if (orientation == GTK_ORIENTATION_HORIZONTAL && padding)
312 {
313 gtk_box_append (GTK_BOX(widg), markup_label (" ", padding, -1, 0.0, 0.0));
314 }
315 else if (orientation == GTK_ORIENTATION_VERTICAL && padding > 10)
316 {
317 gtk_box_append (GTK_BOX(widg), markup_label (" ", -1, padding/2, 0.0, 0.0));
318 }
319#else
320 gtk_box_pack_start (GTK_BOX(widg), child, expand, fill, padding);
321#endif
322}
323
324#ifdef GTK3
334GtkWidget * menu_item_new_with_submenu (gchar * name, gboolean active, GtkWidget * sub_menu)
335{
336 GtkWidget * item = create_menu_item (FALSE, name);
337 gtk_menu_item_set_submenu ((GtkMenuItem *)item, sub_menu);
338 widget_set_sensitive (item, active);
339 return item;
340}
341#endif
342
348GtkWidget * new_gtk_window ()
349{
350#ifdef GTK4
351 return gtk_window_new ();
352#else
353 return gtk_window_new (GTK_WINDOW_TOPLEVEL);
354#endif
355}
356
357#ifdef GTK4
385void add_widget_gesture_and_key_action (GtkWidget * widget,
386 gchar * cp_name, GCallback cp_handler, gpointer cp_data,
387 gchar * cr_name, GCallback cr_handler, gpointer cr_data,
388 gchar * kp_name, GCallback kp_handler, gpointer kp_data,
389 gchar * mo_name, GCallback mo_handler, gpointer mo_data,
390 gchar * sc_name, GCallback sc_handler, gpointer sc_data)
391{
392 GtkGesture * gesture;
393 GtkEventController * key;
394 GtkEventController * motion;
395 if (cp_name)
396 {
397 gesture = gtk_gesture_click_new ();
398 gtk_event_controller_set_name (GTK_EVENT_CONTROLLER (gesture), cp_name);
399 gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0);
400 if (cp_handler) g_signal_connect (gesture, "pressed", cp_handler, cp_data);
401 gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (gesture));
402 }
403 if (cr_name)
404 {
405 gesture = gtk_gesture_click_new ();
406 gtk_event_controller_set_name (GTK_EVENT_CONTROLLER (gesture), cr_name);
407 gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0);
408 if (cr_handler) g_signal_connect (gesture, "released", cr_handler, cr_data);
409 gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (gesture));
410 }
411 if (kp_name)
412 {
413 key = gtk_event_controller_key_new ();
414 gtk_event_controller_set_name (key, kp_name);
415 if (kp_handler) g_signal_connect (key, "key-pressed", kp_handler, kp_data);
416 gtk_widget_add_controller (widget, key);
417 }
418 if (mo_name)
419 {
420 motion = gtk_event_controller_motion_new ();
421 gtk_event_controller_set_name (motion, mo_name);
422 if (mo_handler) g_signal_connect (motion, "motion", mo_handler, mo_data);
423 gtk_widget_add_controller (widget, motion);
424 }
425 if (sc_name)
426 {
427 motion = gtk_event_controller_scroll_new (GTK_EVENT_CONTROLLER_SCROLL_VERTICAL);
428 gtk_event_controller_set_name (motion, sc_name);
429 if (sc_handler) g_signal_connect (motion, "scroll", sc_handler, sc_data);
430 gtk_widget_add_controller (widget, motion);
431 }
432}
433#endif
434
445GtkWidget * create_win (gchar * str, GtkWidget * parent, gboolean modal, gboolean resiz)
446{
447 GtkWidget * win;
448 win = new_gtk_window ();
449 if (str) gtk_window_set_title (GTK_WINDOW(win), prepare_for_title(str));
450 gtk_window_set_resizable (GTK_WINDOW (win), TRUE);
451#ifdef GTK3
452 gtk_window_set_attached_to (GTK_WINDOW (win), parent);
453 gtk_window_set_icon (GTK_WINDOW (win), THETD);
454#endif
455 // gtk_window_set_transient_for (GTK_WINDOW (win), GTK_WINDOW (parent));
456 gtk_window_set_modal (GTK_WINDOW(win), modal);
457 gtk_window_set_resizable (GTK_WINDOW(win), resiz);
458 gtk_window_set_destroy_with_parent (GTK_WINDOW (win), TRUE);
459 return win;
460}
461
462#ifdef GTK4
472void run_this_gtk_native_dialog (GtkNativeDialog * dial, GCallback handler, gpointer data)
473{
474 gtk_native_dialog_set_modal (dial, TRUE);
475 if (handler) g_signal_connect (G_OBJECT(dial), "response", handler, data);
476 gtk_native_dialog_show (dial);
477 dialog_id ++;
478 Event_loop[dialog_id] = g_main_loop_new (NULL, FALSE);
479 g_main_loop_run (Event_loop[dialog_id]);
480}
481#endif
482
492void run_this_gtk_dialog (GtkWidget * dial, GCallback handler, gpointer data)
493{
494 gtk_window_set_modal (GTK_WINDOW(dial), TRUE);
495 if (handler) g_signal_connect (G_OBJECT(dial), "response", handler, data);
496 show_the_widgets (dial);
497 dialog_id ++;
498 Event_loop[dialog_id] = g_main_loop_new (NULL, FALSE);
499 g_main_loop_run (Event_loop[dialog_id]);
500}
501
510GtkWidget * dialogmodal (gchar * str, GtkWindow * parent)
511{
512 GtkWidget * win = gtk_dialog_new_with_buttons (str, parent, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, _("_Close"), GTK_RESPONSE_CLOSE, NULL);
513 gtk_window_set_resizable (GTK_WINDOW (win), FALSE);
514#ifdef GTK3
515 gtk_window_set_icon (GTK_WINDOW (win), THETD);
516#endif
517 return win;
518}
519
531GtkWidget * message_dialogmodal (gchar * message, gchar * title, GtkMessageType mtype, GtkButtonsType buttons, GtkWidget * parent)
532{
533 GtkWidget * win;
534 if (parent)
535 {
536 win = gtk_message_dialog_new (GTK_WINDOW(parent), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, mtype, buttons, NULL);
537 }
538 else
539 {
540 win = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, mtype, buttons, NULL);
541 }
542 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (win), message);
543 gtk_window_set_title (GTK_WINDOW(win), title);
544 gtk_window_set_resizable (GTK_WINDOW (win), FALSE);
545#ifdef GTK3
546 gtk_window_set_icon (GTK_WINDOW (win), THETD);
547#endif
548 show_the_widgets (win);
549 return win;
550}
551
561GtkWidget * dialog_cancel_apply (gchar * title, GtkWidget * parent, gboolean resiz)
562{
563 GtkWidget * dca = gtk_dialog_new_with_buttons (title, GTK_WINDOW(parent), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
564 "Cancel", GTK_RESPONSE_CANCEL, "Apply", GTK_RESPONSE_APPLY, NULL);
565 gtk_window_set_resizable (GTK_WINDOW(dca), resiz);
566#ifdef GTK3
567 gtk_window_set_icon (GTK_WINDOW (dca), THETD);
568#endif
569 return dca;
570}
571
581void resize_this_window (GtkWidget * window, int x, int y)
582{
583#ifdef GTK3
584 gtk_window_resize (GTK_WINDOW(window), x, y);
585#else
586 gtk_window_set_default_size (GTK_WINDOW(window), x, y);
587#endif
588}
589
597const gchar * entry_get_text (GtkEntry * entry)
598{
599#ifdef GTK4
600 return gtk_editable_get_text (GTK_EDITABLE(entry));
601#else
602 return gtk_entry_get_text (entry);
603#endif
604}
605
614void update_entry_int (GtkEntry * entry, int intval)
615{
616 gchar * value = g_strdup_printf("%d", intval);
617#ifdef GTK4
618 gtk_editable_set_text (GTK_EDITABLE(entry), (const gchar *)value);
619#else
620 gtk_entry_set_text (entry, (const gchar *)value);
621#endif
622 g_free (value);
623}
624
633void update_entry_double (GtkEntry * entry, double doubleval)
634{
635 gchar * value = g_strdup_printf("%f", doubleval);
636#ifdef GTK4
637 gtk_editable_set_text (GTK_EDITABLE(entry), (const gchar *)value);
638#else
639 gtk_entry_set_text (entry, (const gchar *)value);
640#endif
641 g_free (value);
642}
643
652void update_entry_long_double (GtkEntry * entry, double doubleval)
653{
654 gchar * value = g_strdup_printf("%15.10lf", doubleval);
655#ifdef GTK4
656 gtk_editable_set_text (GTK_EDITABLE(entry), (const gchar *)value);
657#else
658 gtk_entry_set_text (entry, (const gchar *)value);
659 g_free (value);
660#endif
661}
662
671void update_entry_text (GtkEntry * entry, gchar * text)
672{
673#ifdef GTK4
674 gtk_editable_set_text (GTK_EDITABLE(entry), (const gchar *)text);
675#else
676 gtk_entry_set_text (entry, (const gchar *)text);
677#endif
678}
679
687void text_view_set_monospace (GtkWidget * view)
688{
689 gtk_text_view_set_monospace (GTK_TEXT_VIEW(view), TRUE);
690}
691
701void gtk_label_align (GtkWidget * lab, float ax, float ay)
702{
703 gtk_label_set_xalign (GTK_LABEL (lab), ax);
704 gtk_label_set_yalign (GTK_LABEL (lab), ay);
705}
706
714gboolean is_the_widget_visible (GtkWidget * widg)
715{
716 if (GTK_IS_WIDGET(widg))
717 {
718 return gtk_widget_is_visible (widg);
719 }
720 else
721 {
722 return FALSE;
723 }
724}
725
744GtkWidget * create_hscale (float min, float max, float delta,
745 float val, int pos, int round, int size,
746 GCallback handler, GCallback scroll_handler, gpointer data)
747{
748 GtkWidget * hscale;
749 hscale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, min, max, delta);
750 gtk_scale_set_draw_value (GTK_SCALE(hscale), TRUE);
751 gtk_widget_set_size_request (hscale, size, -1);
752 gtk_scale_set_value_pos (GTK_SCALE(hscale), pos);
753 gtk_range_set_value (GTK_RANGE(hscale), val);
754 gtk_range_set_round_digits (GTK_RANGE(hscale), round);
755 if (handler != NULL) g_signal_connect (G_OBJECT(hscale), "value-changed", handler, data);
756 if (scroll_handler != NULL) g_signal_connect (G_OBJECT(hscale), "change-value", scroll_handler, data);
757 return hscale;
758}
759
778GtkWidget * create_vscale (float min, float max, float delta,
779 float val, int pos, int round, int size,
780 GCallback handler, GCallback scroll_handler, gpointer data)
781{
782 GtkWidget * vscale;
783 vscale = gtk_scale_new_with_range (GTK_ORIENTATION_VERTICAL, min, max, delta);
784 gtk_scale_set_draw_value (GTK_SCALE(vscale), TRUE);
785 gtk_scale_set_value_pos (GTK_SCALE(vscale), pos);
786 gtk_widget_set_size_request (vscale, size, size);
787 gtk_range_set_value (GTK_RANGE(vscale), val);
788 gtk_range_set_round_digits (GTK_RANGE(vscale), round);
789 if (handler != NULL) g_signal_connect (G_OBJECT(vscale), "value-changed", handler, data);
790 if (scroll_handler != NULL) g_signal_connect (G_OBJECT(vscale), "change-value", scroll_handler, data);
791 return vscale;
792}
793
801GtkWidget * create_vbox (int spacing)
802{
803 return gtk_box_new (GTK_ORIENTATION_VERTICAL, spacing);
804}
805
813GtkWidget * create_hbox (int spacing)
814{
815 return gtk_box_new (GTK_ORIENTATION_HORIZONTAL, spacing);
816}
817
825GtkWidget * dialog_get_content_area (GtkWidget * widg)
826{
827#ifdef GTK3
828 return gtk_dialog_get_content_area (GTK_DIALOG(widg));
829#else
830 GtkWidget * vbox = create_vbox (BSEP);
831 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, gtk_dialog_get_content_area (GTK_DIALOG(widg)), vbox, TRUE, TRUE, 0);
832 return vbox;
833#endif
834}
835
846void layout_add_widget (GtkWidget * layout, GtkWidget * child, int x_pos, int y_pos)
847{
848#ifdef GTK3
849 gtk_layout_put (GTK_LAYOUT(layout), child, x_pos, y_pos);
850#else
851 gtk_fixed_put (GTK_FIXED(layout), child, x_pos, y_pos);
852#endif
853}
854
864GtkWidget * add_vbox_to_layout (GtkWidget * layout, int size_x, int size_y)
865{
866 GtkWidget * vbox = create_vbox (BSEP);
867 gtk_widget_set_size_request (vbox, size_x, size_y);
869 return vbox;
870}
871
880GtkWidget * create_layout (int x, int y)
881{
882 GtkWidget * layout;
883#ifdef GTK3
884 layout = gtk_layout_new (NULL, NULL);
885#else
886 layout = gtk_fixed_new ();
887#endif
888 gtk_widget_set_size_request (layout, x, y);
889 return layout;
890}
891
900void combo_text_append (GtkWidget * combo, gchar * text)
901{
902 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(combo), text);
903}
904
913void combo_text_prepend (GtkWidget * combo, gchar * text)
914{
915 gtk_combo_box_text_prepend_text (GTK_COMBO_BOX_TEXT(combo), text);
916}
917
923GtkWidget * create_combo ()
924{
925 return gtk_combo_box_text_new ();
926}
927
935void setup_text_tags (GtkTextBuffer * buffer)
936{
937 GtkTextTagTable * textags = gtk_text_buffer_get_tag_table(buffer);
938
939 /* Sans font */
940 tag = gtk_text_tag_new ("sans");
941 g_object_set (tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE, "family", "sans", NULL);
942 gtk_text_tag_table_add (textags, tag);
943 g_object_unref (tag);
944
945 /* Monospace font */
946 tag = gtk_text_tag_new ("monospace");
947 g_object_set (tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE, "family", "monospace", NULL);
948 gtk_text_tag_table_add (textags, tag);
949 g_object_unref (tag);
950
951 /* Default Font size */
952 tag = gtk_text_tag_new ("default-size");
953 g_object_set (tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE, NULL);
954 gtk_text_tag_table_add (textags, tag);
955 g_object_unref (tag);
956
957 /* <u> */
958 tag = gtk_text_tag_new ("underline");
959 g_object_set (tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE, "underline", PANGO_UNDERLINE_SINGLE, NULL);
960 gtk_text_tag_table_add (textags, tag);
961 g_object_unref (tag);
962
963 /* <uu> */
964 tag = gtk_text_tag_new ("underline_double");
965 g_object_set (tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE, "underline", PANGO_UNDERLINE_DOUBLE, NULL);
966 gtk_text_tag_table_add (textags, tag);
967 g_object_unref (tag);
968
969 /* <i> italic */
970 tag = gtk_text_tag_new ("italic");
971 g_object_set (tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE, "style", PANGO_STYLE_ITALIC, NULL);
972 gtk_text_tag_table_add (textags, tag);
973 g_object_unref (tag);
974
975 /* <b> bold */
976 tag = gtk_text_tag_new ("bold");
977 g_object_set (tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE, "weight", PANGO_WEIGHT_BOLD, NULL);
978 gtk_text_tag_table_add (textags, tag);
979 g_object_unref (tag);
980
981 /* <b> bold italic */
982 tag = gtk_text_tag_new ("bold_italic");
983 g_object_set (tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE,
984 "style", PANGO_STYLE_ITALIC,
985 "weight", PANGO_WEIGHT_BOLD, NULL);
986 gtk_text_tag_table_add (textags, tag);
987 g_object_unref (tag);
988
989 /* <sup> superscript */
990 tag = gtk_text_tag_new ("sup");
991 g_object_set (tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE, "scale", .6, "rise", 6000, NULL);
992 gtk_text_tag_table_add (textags, tag);
993 g_object_unref (tag);
994
995 /* <sub> subscript */
996 tag = gtk_text_tag_new ("sub");
997 g_object_set (tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE, "scale", .6, "rise", -6000, NULL);
998 gtk_text_tag_table_add (textags, tag);
999 g_object_unref (tag);
1000
1001 /* justify-left */
1002 tag = gtk_text_tag_new("justify-left");
1003 g_object_set(tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE, "justification", GTK_JUSTIFY_LEFT, NULL);
1004 gtk_text_tag_table_add(textags, tag);
1005 g_object_unref(tag);
1006
1007 /* justify-center */
1008 tag = gtk_text_tag_new("justify-center");
1009 g_object_set(tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE, "justification", GTK_JUSTIFY_CENTER, NULL);
1010 gtk_text_tag_table_add(textags, tag);
1011 g_object_unref(tag);
1012
1013 /* justify-right */
1014 tag = gtk_text_tag_new("justify-right");
1015 g_object_set(tag, "justification", GTK_JUSTIFY_RIGHT, NULL);
1016 gtk_text_tag_table_add(textags, tag);
1017 g_object_unref (tag);
1018
1019 /* heading */
1020 tag = gtk_text_tag_new("heading");
1021 g_object_set(tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE,
1022 "weight", PANGO_WEIGHT_BOLD,
1023 "scale", 1.5,
1024 "justification", GTK_JUSTIFY_CENTER,
1025 "underline", PANGO_UNDERLINE_DOUBLE, NULL);
1026 gtk_text_tag_table_add(textags, tag);
1027 g_object_unref (tag);
1028
1029 /* red font */
1030 tag = gtk_text_tag_new("red");
1031 g_object_set(tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE, "foreground", "red", NULL);
1032 gtk_text_tag_table_add(textags, tag);
1033 g_object_unref (tag);
1034
1035 /* orange font */
1036 tag = gtk_text_tag_new("orange");
1037 g_object_set(tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE, "foreground", "orange", NULL);
1038 gtk_text_tag_table_add(textags, tag);
1039 g_object_unref (tag);
1040
1041 /* yellow font */
1042 tag = gtk_text_tag_new("yellow");
1043 g_object_set(tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE, "foreground", "yellow2", NULL);
1044 gtk_text_tag_table_add(textags, tag);
1045 g_object_unref (tag);
1046
1047 /* green font */
1048 tag = gtk_text_tag_new("green");
1049 g_object_set(tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE, "foreground", "green", NULL);
1050 gtk_text_tag_table_add(textags, tag);
1051 g_object_unref (tag);
1052
1053 /* light green font */
1054 tag = gtk_text_tag_new("light_green");
1055 g_object_set(tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE, "foreground", "light green", NULL);
1056 gtk_text_tag_table_add(textags, tag);
1057 g_object_unref (tag);
1058
1059 /* cyan font */
1060 tag = gtk_text_tag_new("cyan");
1061 g_object_set(tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE, "foreground", "cyan", NULL);
1062 gtk_text_tag_table_add(textags, tag);
1063 g_object_unref (tag);
1064
1065 /* blue font */
1066 tag = gtk_text_tag_new("blue");
1067 g_object_set(tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE, "foreground", "blue", NULL);
1068 gtk_text_tag_table_add(textags, tag);
1069 g_object_unref (tag);
1070
1071 /* pink font */
1072 tag = gtk_text_tag_new("pink");
1073 g_object_set(tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE, "foreground", "pink", NULL);
1074 gtk_text_tag_table_add(textags, tag);
1075 g_object_unref (tag);
1076
1077 /* violet font */
1078 tag = gtk_text_tag_new("violet");
1079 g_object_set(tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE, "foreground", "dark violet", NULL);
1080 gtk_text_tag_table_add(textags, tag);
1081 g_object_unref (tag);
1082
1083 /* grey background */
1084 tag = gtk_text_tag_new("grey_back");
1085 g_object_set(tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE, "background", "lightgrey", NULL);
1086 gtk_text_tag_table_add(textags, tag);
1087 g_object_unref (tag);
1088
1089 /* bold grey background */
1090 tag = gtk_text_tag_new("bold_grey_back");
1091 g_object_set(tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE,
1092 "background", "lightgrey",
1093 "weight", PANGO_WEIGHT_BOLD, NULL);
1094 gtk_text_tag_table_add(textags, tag);
1095 g_object_unref (tag);
1096
1097 /* bold red font */
1098 tag = gtk_text_tag_new ("bold_red");
1099 g_object_set (tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE,
1100 "foreground", "red",
1101 "weight", PANGO_WEIGHT_BOLD, NULL);
1102 gtk_text_tag_table_add (textags, tag);
1103 g_object_unref (tag);
1104
1105 /* bold blue font */
1106 tag = gtk_text_tag_new ("bold_blue");
1107 g_object_set (tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE,
1108 "foreground", "blue",
1109 "weight", PANGO_WEIGHT_BOLD, NULL);
1110 gtk_text_tag_table_add (textags, tag);
1111 g_object_unref (tag);
1112
1113 /* bold green font */
1114 tag = gtk_text_tag_new ("bold_green");
1115 g_object_set (tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE,
1116 "foreground", "green",
1117 "weight", PANGO_WEIGHT_BOLD, NULL);
1118 gtk_text_tag_table_add (textags, tag);
1119 g_object_unref (tag);
1120
1121 /* bold orange font */
1122 tag = gtk_text_tag_new ("bold_orange");
1123 g_object_set (tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE,
1124 "foreground", "orange",
1125 "weight", PANGO_WEIGHT_BOLD, NULL);
1126 gtk_text_tag_table_add (textags, tag);
1127 g_object_unref (tag);
1128
1129 /* bold pink font */
1130 tag = gtk_text_tag_new ("bold_pink");
1131 g_object_set (tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE,
1132 "foreground", "pink",
1133 "weight", PANGO_WEIGHT_BOLD, NULL);
1134 gtk_text_tag_table_add (textags, tag);
1135 g_object_unref (tag);
1136
1137 /* subscript italic*/
1138 tag = gtk_text_tag_new ("sub_italic");
1139 g_object_set (tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE,
1140 "style", PANGO_STYLE_ITALIC,
1141 "scale", .6, "rise", -6000, NULL);
1142 gtk_text_tag_table_add (textags, tag);
1143 g_object_unref (tag);
1144
1145 /* subscript bold */
1146 tag = gtk_text_tag_new ("sub_bold");
1147 g_object_set (tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE,
1148 "weight", PANGO_WEIGHT_BOLD,
1149 "scale", .6, "rise", -6000, NULL);
1150 gtk_text_tag_table_add (textags, tag);
1151 g_object_unref (tag);
1152
1153 /* superscript bold */
1154 tag = gtk_text_tag_new ("sup_bold");
1155 g_object_set (tag, "size", DEFAULT_FONT_SIZE * PANGO_SCALE,
1156 "weight", PANGO_WEIGHT_BOLD,
1157 "scale", .6, "rise", 6000, NULL);
1158 gtk_text_tag_table_add (textags, tag);
1159 g_object_unref (tag);
1160}
1161
1171GtkTextBuffer * add_buffer (GCallback handler, gpointer data, gchar * text)
1172{
1173 GtkTextBuffer * buffer;
1174 GtkTextIter bStart;
1175 GtkTextIter bEnd;
1176 buffer = gtk_text_buffer_new (NULL);
1177 setup_text_tags (buffer);
1178 gtk_text_buffer_get_start_iter (buffer, &bStart);
1179 gtk_text_buffer_get_end_iter (buffer, &bEnd);
1180 gtk_text_buffer_delete (buffer, &bStart, &bEnd);
1181 if (text != NULL) gtk_text_buffer_set_text (buffer, text, -1);
1182 if (handler != NULL) g_signal_connect (G_OBJECT (buffer), "changed", handler, data);
1183 return buffer;
1184}
1185
1199GtkWidget * create_text_view (int dimx, int dimy, int edit, int mono, GCallback handler, gpointer data, gchar * text)
1200{
1201 GtkWidget * tview = gtk_text_view_new ();
1202 gtk_text_view_set_buffer (GTK_TEXT_VIEW(tview), add_buffer(handler, data, text));
1203 gtk_widget_set_size_request (tview, dimx, dimy);
1204 gtk_text_view_set_editable (GTK_TEXT_VIEW(tview), edit);
1205 if (mono) text_view_set_monospace (tview);
1206 return tview;
1207}
1208
1221static void convert_alpha (cairo_surface_t * surf, GdkPixbuf * pix, int src_x, int src_y, int width, int height)
1222{
1223 int x, y;
1224 guchar * src_data = cairo_image_surface_get_data (surf);
1225 int src_stride = cairo_image_surface_get_stride (surf);
1226 guchar * dest_data = gdk_pixbuf_get_pixels (pix);
1227 int dest_stride = gdk_pixbuf_get_rowstride (pix);
1228
1229 src_data += src_stride * src_y + src_x * 4;
1230
1231 for (y = 0; y < height; y++) {
1232 guint32 *src = (guint32 *) src_data;
1233
1234 for (x = 0; x < width; x++) {
1235 guint alpha = src[x] >> 24;
1236
1237 if (alpha == 0)
1238 {
1239 dest_data[x * 4 + 0] = 0;
1240 dest_data[x * 4 + 1] = 0;
1241 dest_data[x * 4 + 2] = 0;
1242 }
1243 else
1244 {
1245 dest_data[x * 4 + 0] = (((src[x] & 0xff0000) >> 16) * 255 + alpha / 2) / alpha;
1246 dest_data[x * 4 + 1] = (((src[x] & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha;
1247 dest_data[x * 4 + 2] = (((src[x] & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha;
1248 }
1249 dest_data[x * 4 + 3] = alpha;
1250 }
1251
1252 src_data += src_stride;
1253 dest_data += dest_stride;
1254 }
1255}
1256
1264GdkPixbuf * convert_to_pixbuf (cairo_surface_t * surf)
1265{
1266 int width = cairo_image_surface_get_width (surf);
1267 int height = cairo_image_surface_get_height (surf);
1268 GdkPixbuf * pix = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width , height);
1269 convert_alpha (surf, pix, 0, 0, width, height);
1270 return pix;
1271}
1272
1273#ifdef GTK3
1283G_MODULE_EXPORT gboolean to_activate_entry (GtkWidget * widg, GdkEventFocus * event, gpointer data)
1284{
1285 g_signal_emit_by_name (G_OBJECT(widg), "activate", data);
1286 return FALSE;
1287}
1288#else
1297G_MODULE_EXPORT void to_activate_entry (GtkEventControllerFocus * focus, gpointer data)
1298{
1299 g_signal_emit_by_name (G_OBJECT(gtk_event_controller_get_widget((GtkEventController *)focus)), "activate", data);
1300}
1301#endif
1302
1314GtkWidget * create_entry (GCallback handler, int dim, int cdim, gboolean key_release, gpointer data)
1315{
1316 GtkWidget * entry = gtk_entry_new ();
1317 gtk_widget_set_size_request (entry, dim, -1);
1318#ifdef GTK4
1319 gtk_editable_set_width_chars (GTK_EDITABLE(entry), 0);
1320 gtk_editable_set_max_width_chars (GTK_EDITABLE(entry), cdim);
1321#else
1322 gtk_entry_set_width_chars (GTK_ENTRY(entry), 0);
1323 gtk_entry_set_max_width_chars (GTK_ENTRY(entry), cdim);
1324#endif
1325 gtk_entry_set_alignment (GTK_ENTRY(entry), 1.0);
1326
1327 if (handler != NULL)
1328 {
1329 g_signal_connect (G_OBJECT (entry), "activate", handler, data);
1330#ifdef GTK3
1331 g_signal_connect (G_OBJECT (entry), "focus-out-event", G_CALLBACK(to_activate_entry), data);
1332#else
1333 /* Pour ajouter une icone dans l'entry:
1334 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, "edit-find-symbolic");
1335 // Set up the search icon
1336 gtk_entry_set_icon_activatable (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, TRUE);
1337 gtk_entry_set_icon_sensitive (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, TRUE);
1338 // Then the press can have action see gtk4 demo
1339 g_signal_connect (entry, "icon-press", G_CALLBACK(icon_press_cb), NULL); */
1340 GtkEventController * focus = gtk_event_controller_focus_new ();
1341 gtk_event_controller_set_name (focus, "focus-out");
1342 g_signal_connect (G_OBJECT(focus), "leave", G_CALLBACK(to_activate_entry), data);
1343 gtk_widget_add_controller (entry, focus);
1344#endif
1345 }
1346 if (key_release)
1347 {
1348#ifdef GTK3
1349 g_signal_connect (G_OBJECT (entry), "key-release-event", G_CALLBACK(to_activate_entry), data);
1350#else
1351 // Key press controler
1352#endif
1353 }
1354 return entry;
1355}
1356
1364GtkWidget * stock_image (const gchar * stock_id)
1365{
1366#ifdef GTK4
1367 return gtk_image_new_from_icon_name (stock_id);
1368#else
1369 return gtk_image_new_from_icon_name (stock_id, GTK_ICON_SIZE_MENU);
1370#endif
1371}
1372
1373#ifdef GTK3
1382GtkWidget * create_menu_item (gboolean add_mnemo, gchar * name)
1383{
1384 return (add_mnemo) ? gtk_menu_item_new_with_mnemonic (name) : gtk_menu_item_new_with_label (name);
1385}
1386
1397GtkWidget * create_menu_item_from_widget (GtkWidget * widg, gboolean check, gboolean radio, gboolean status)
1398{
1399 GtkWidget * item;
1400 if (check)
1401 {
1402 item = gtk_check_menu_item_new ();
1403 if (radio) gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM(item), TRUE);
1404 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(item), status);
1405 }
1406 else
1407 {
1408 item = gtk_menu_item_new ();
1409 }
1410 gtk_container_add (GTK_CONTAINER(item), widg);
1411 return item;
1412}
1413#endif
1414
1415/* GIcon*
1416g_icon_new_for_string (
1417 const gchar* str,
1418 GError** error
1419)
1420
1421void
1422g_menu_item_set_icon (
1423 GMenuItem* menu_item,
1424 GIcon* icon
1425)
1426
1427void
1428g_menu_item_set_attribute (
1429 GMenuItem* menu_item,
1430 const gchar* attribute,
1431 const gchar* format_string,
1432 ...
1433) */
1434
1443GtkWidget * create_image_from_data (int format, gpointer item_image)
1444{
1445 GtkWidget * icon = NULL;
1446 switch (format)
1447 {
1448 case IMG_PIXBUF:
1449 icon = gtk_image_new_from_pixbuf ((GdkPixbuf*)item_image);
1450 break;
1451 case IMG_SURFACE:
1452#ifdef GTK4
1453 icon = gtk_image_new_from_pixbuf (convert_to_pixbuf ((cairo_surface_t *)item_image));
1454#else
1455 icon = gtk_image_new_from_surface ((cairo_surface_t *)item_image);
1456#endif
1457 break;
1458 case IMG_FILE:
1459 icon = gtk_image_new_from_file ((const gchar *)item_image);
1460 break;
1461 case IMG_STOCK:
1462 icon = stock_image ((const gchar *)item_image);
1463 break;
1464 }
1465 return icon;
1466}
1467
1468#ifdef GTK3
1491GtkWidget * gtk3_menu_item (GtkWidget * menu, gchar * name,
1492 int icon_format, gpointer item_icon,
1493 GCallback handler, gpointer data,
1494 gboolean accel, guint key, GdkModifierType mod,
1495 gboolean check, gboolean radio, gboolean status)
1496{
1497 GtkWidget * item = NULL;
1498 GtkWidget * icon = NULL;
1499 GtkWidget * lab = NULL;
1500
1501 if (name)
1502 {
1503 if (accel)
1504 {
1505 lab = gtk_accel_label_new (name);
1506 gtk_label_align (lab, 0.0, 0.5);
1507 gtk_widget_set_size_request (lab, -1, -1);
1508 gtk_label_set_use_markup (GTK_LABEL(lab), TRUE);
1509 gtk_accel_label_set_accel ((GtkAccelLabel *)lab, key, mod);
1510 }
1511 else
1512 {
1513 lab = markup_label(name, -1, -1, 0.0, 0.5);
1514 }
1515 }
1516 if (icon_format != IMG_NONE) icon = create_image_from_data (icon_format, item_icon);
1517 if (name)
1518 {
1519#ifdef MENU_ICONS
1520 if (icon)
1521 {
1522 GtkWidget * box = create_hbox (0);
1523 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, icon, FALSE, FALSE, 0);
1524 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, lab, FALSE, FALSE, (icon_format == IMG_SURFACE) ? 0 : 6);
1525 item = create_menu_item_from_widget (box, check, radio, status);
1526 }
1527 else
1528 {
1529 item = create_menu_item_from_widget (lab, check, radio, status);
1530 }
1531#else
1532 item = create_menu_item_from_widget (lab, check, radio, status);
1533#endif
1534 }
1535 else if (icon)
1536 {
1537 item = create_menu_item_from_widget (icon, check, radio, status);
1538 }
1539 if (handler != NULL) g_signal_connect (G_OBJECT(item), "activate", handler, data);
1540 if (menu != NULL) gtk_menu_shell_append ((GtkMenuShell *)menu, item);
1541 return item;
1542}
1543
1556GtkWidget * add_advanced_item (GtkWidget * menu, GCallback handler, gpointer data, gboolean accel, guint key, GdkModifierType mod)
1557{
1558 return gtk3_menu_item (menu, "Advanced", IMG_STOCK, (gpointer)DPROPERTIES, handler, data, accel, key, mod, FALSE, FALSE, FALSE);
1559}
1560
1568void add_menu_separator (GtkWidget * menu)
1569{
1570 gtk_menu_shell_append ((GtkMenuShell *)menu, gtk_separator_menu_item_new ());
1571}
1572#endif
1573
1574/*
1575* GtkWidget * markup_label (gchar * text, int dimx, int dimy, float ax, float ay)
1576
1577 \brief create a GtkLabel with pango markup
1578
1579 \param text Message to display
1580 \param dimx y size for the widget
1581 \param dimy y size for the widget
1582 \param ax x alignment
1583 \param ay y alignment
1584*/
1585GtkWidget * markup_label (gchar * text, int dimx, int dimy, float ax, float ay)
1586{
1587 GtkWidget * lab = gtk_label_new (text);
1589 gtk_widget_set_size_request (lab, dimx, dimy);
1590 gtk_label_set_use_markup (GTK_LABEL(lab), TRUE);
1591 return lab;
1592}
1593
1603{
1604 ColRGBA * new_col = g_malloc0 (num*sizeof*new_col);
1605 int i;
1606 for (i=0; i<num; i++) new_col[i] = col[i];
1607 return new_col;
1608}
1609
1617ColRGBA gdkrgba_to_rgba (GdkRGBA colgdk)
1618{
1619 ColRGBA col;
1620 col.red = colgdk.red;
1621 col.green = colgdk.green;
1622 col.blue = colgdk.blue;
1623 col.alpha = colgdk.alpha;
1624 return col;
1625}
1626
1635{
1636 GdkRGBA colo;
1637 colo.red = col.red;
1638 colo.green = col.green;
1639 colo.blue = col.blue;
1640 colo.alpha = col.alpha;
1641 return colo;
1642}
1643
1653void set_renderer_color (int tocol, GtkCellRenderer * renderer, ColRGBA col)
1654{
1655 if (tocol)
1656 {
1657 GdkRGBA colo = colrgba_togtkrgba (col);
1658 g_object_set (renderer, "foreground-rgba", & colo, "foreground-set", TRUE, NULL);
1659 g_object_set(renderer, "weight", PANGO_WEIGHT_BOLD, "weight-set", TRUE, NULL);
1660 }
1661 else
1662 {
1663 g_object_set(renderer, "foreground-set", FALSE, "weight", FALSE, NULL);
1664 }
1665}
1666
1677void button_set_image (GtkButton * but, gchar * text, int format, gpointer image)
1678{
1679#ifdef GTK4
1680 GtkWidget * img = create_image_from_data (format, image);
1681 if (text)
1682 {
1683 GtkWidget * hbox = create_hbox (5);
1684 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, img, FALSE, FALSE, 0);
1685 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label (text, -1, -1, 0.0, 0.5), FALSE, FALSE, 0);
1686 gtk_button_set_child (but, hbox);
1687 }
1688 else
1689 {
1690 gtk_button_set_child (but, img);
1691 }
1692#else
1693 gtk_button_set_image (but, create_image_from_data (format, image));
1694#endif
1695}
1696
1708void adjust_label (GtkWidget * lab, int dimx, int dimy, float ax, float ay)
1709{
1710 gtk_label_set_xalign (GTK_LABEL(lab), ax);
1711 gtk_label_set_yalign (GTK_LABEL(lab), ay);
1712 gtk_widget_set_size_request (lab, dimx, dimy);
1713 gtk_label_set_use_markup (GTK_LABEL(lab), TRUE);
1714}
1715
1728GtkWidget * color_button (ColRGBA col, gboolean alpha, int dimx, int dimy, GCallback handler, gpointer data)
1729{
1730 GtkWidget * colorb;
1731 GdkRGBA colo = colrgba_togtkrgba (col);
1732 colorb = gtk_color_button_new_with_rgba (& colo);
1733 gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER(colorb), alpha);
1734 if (handler != NULL) g_signal_connect (G_OBJECT(colorb), "color-set", handler, data);
1735 gtk_widget_set_size_request (colorb, dimx, dimy);
1736 return colorb;
1737}
1738
1750GtkWidget * font_button (gchar * font, int dimx, int dimy, GCallback handler, gpointer data)
1751{
1752 GtkWidget * fontb = gtk_font_button_new_with_font (font);
1753 g_signal_connect (G_OBJECT(fontb), "font-set", handler, data);
1754 gtk_widget_set_size_request (fontb, dimx, dimy);
1755 return fontb;
1756}
1757
1772GtkWidget * spin_button (GCallback handler, double value, double start, double end, double step, int digits, int dim, gpointer data)
1773{
1774 GtkWidget * spin = gtk_spin_button_new_with_range (start, end, step);
1775 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(spin), digits);
1776#ifdef GTK4
1777 gtk_editable_set_alignment (GTK_EDITABLE(spin), 1.0);
1778#else
1779 gtk_entry_set_alignment (GTK_ENTRY(spin), 1.0);
1780#endif
1781 gtk_spin_button_set_value (GTK_SPIN_BUTTON(spin), value);
1782 gtk_widget_set_size_request (spin, dim, -1);
1783 if (handler != NULL) g_signal_connect (G_OBJECT (spin), "value-changed", handler, data);
1784 return spin;
1785}
1786
1799GtkWidget * check_button (gchar * text, int dimx, int dimy, gboolean state, GCallback handler, gpointer data)
1800{
1801 GtkWidget * but = gtk_check_button_new ();
1802 if (text != NULL)
1803 {
1804#ifdef GTK4
1805 gtk_check_button_set_label (GTK_CHECK_BUTTON(but), text);
1806 GtkWidget * lab = gtk_widget_get_last_child (but);
1807 adjust_label (lab, -1, -1, 0.0, 0.5);
1808#else
1809 add_container_child (CONTAINER_BUT, but, markup_label(text, -1, -1, 0.0, 0.5));
1810#endif
1811 }
1812 gtk_widget_set_size_request (but, dimx, dimy);
1813#ifdef GTK4
1814 gtk_check_button_set_active (GTK_CHECK_BUTTON(but), state);
1815#else
1816 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(but), state);
1817#endif
1818 if (handler != NULL) g_signal_connect (G_OBJECT(but), "toggled", handler, data);
1819 return but;
1820}
1821
1834GtkWidget * radio_button (gchar * text, int dimx, int dimy, gboolean state, GCallback handler, gpointer data)
1835{
1836 GtkWidget * but;
1837#ifdef GTK4
1838 but = gtk_toggle_button_new ();
1839#else
1840 but = gtk_radio_button_new (NULL);
1841#endif
1842 if (text != NULL) add_container_child (CONTAINER_BUT, but, markup_label(text, -1, -1, 0.0, 0.5));
1843 gtk_widget_set_size_request (but, dimx, dimy);
1844 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(but), state);
1845 if (handler != NULL) g_signal_connect (G_OBJECT(but), "toggled", handler, data);
1846 return but;
1847}
1848
1863GtkWidget * create_button (gchar * text, int image_format, gchar * image, int dimx, int dimy, int relief, GCallback handler, gpointer data)
1864{
1865 GtkWidget * but;
1866#ifdef GTK3
1867 but = (text) ? gtk_button_new_with_label (text) : gtk_button_new ();
1868#else
1869 but = (text && image_format == IMG_NONE) ? gtk_button_new_with_label (text) : gtk_button_new ();
1870#endif
1871 if (image_format != IMG_NONE) button_set_image (GTK_BUTTON(but), text, image_format, (gpointer)image);
1872 gtk_widget_set_size_request (but, dimx, dimy);
1873#ifdef GTK3
1874 gtk_button_set_relief (GTK_BUTTON(but), relief);
1875#endif
1876#ifdef GTK4
1877 if (relief == GTK_RELIEF_NONE) gtk_button_set_has_frame (GTK_BUTTON(but), FALSE);
1878#endif
1879 if (handler != NULL)
1880 {
1881 g_signal_connect (G_OBJECT (but), "clicked", handler, data);
1882 }
1883 return but;
1884}
1885
1894void set_image_from_icon_name (GtkWidget * widg, gchar * icon)
1895{
1896#ifdef GTK4
1897 gtk_image_set_from_icon_name (GTK_IMAGE(widg), icon);
1898#else
1899 gtk_image_set_from_icon_name (GTK_IMAGE(widg), icon, GTK_ICON_SIZE_BUTTON);
1900#endif
1901}
1902
1912GtkWidget * abox (GtkWidget * box, char * lab, int vspace)
1913{
1914 GtkWidget * hbox = create_hbox (0);
1915 add_box_child_start (GTK_ORIENTATION_VERTICAL, box, hbox, FALSE, FALSE, vspace);
1916 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label("<b>.</b>", 5, -1, 0.0, 0.5), FALSE, FALSE, 10);
1917 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(lab, 150, 30, 0.0, 0.5), FALSE, FALSE, 0);
1918 return hbox;
1919}
1920
1921GtkWidget * bbox (GtkWidget * box, char * lab)
1922{
1923 GtkWidget * hbox = create_hbox (0);
1924 add_box_child_start (GTK_ORIENTATION_VERTICAL, box, hbox, FALSE, FALSE, 2);
1925 GtkWidget * hhbox = create_hbox (0);
1926 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, hhbox, FALSE, FALSE, 40);
1927 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hhbox, markup_label(lab, 150, 30, 0.0, 0.5), FALSE, FALSE, 0);
1928 return hhbox;
1929}
1930
1931GtkWidget * cbox (GtkWidget * box, char * lab)
1932{
1933 GtkWidget * hbox = create_hbox (0);
1934 add_box_child_start (GTK_ORIENTATION_VERTICAL, box, hbox, TRUE, TRUE, 2);
1935 GtkWidget * hhbox = create_hbox (0);
1936 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, hhbox, TRUE, TRUE, 40);
1937 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hhbox, markup_label(lab, -1, 30, 0.0, 0.5), TRUE, TRUE, 40);
1938 return hhbox;
1939}
1940
1941GtkWidget * fbox (GtkWidget * box, char * lab)
1942{
1943 GtkWidget * hbox = create_hbox (0);
1944 add_box_child_start (GTK_ORIENTATION_VERTICAL, box, hbox, FALSE, FALSE, 0);
1945 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label("<b>.</b>", 5, -1, 0.0, 0.5), FALSE, FALSE, 10);
1946 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(lab, 350, 30, 0.0, 0.5), FALSE, FALSE, 0);
1947 return hbox;
1948}
1949
1960GtkWidget * create_scroll (GtkWidget * box, int dimx, int dimy, int shadow)
1961{
1962 GtkWidget * scroll;
1963#ifdef GTK4
1964 scroll = gtk_scrolled_window_new ();
1965#else
1966 scroll = gtk_scrolled_window_new (NULL, NULL);
1967 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(scroll), shadow);
1968#endif
1969 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1970 gtk_widget_set_size_request (scroll, dimx, dimy);
1971 // To check all create_scroll !
1972 if (box != NULL) add_box_child_start (GTK_ORIENTATION_VERTICAL, box, scroll, TRUE, TRUE, 0);
1973 return scroll;
1974}
1975
1984GtkWidget * create_expander (gchar * name, gchar * file_img)
1985{
1986 GtkWidget * expand = gtk_expander_new (name);
1987 GtkWidget * hbox = create_hbox (0);
1988 if (file_img != NULL)
1989 {
1990 GtkWidget * img = gtk_image_new_from_file (file_img);
1991 gtk_widget_set_size_request (img, 20, 20);
1992 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, img, TRUE, TRUE, 10);
1993 }
1994 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(name, 200, 20, 0.0, 0.5), FALSE, TRUE, 0);
1995 gtk_expander_set_label_widget (GTK_EXPANDER(expand), hbox);
1996 return expand;
1997}
1998
2006void provide_gtk_css (gchar * css)
2007{
2008 GtkCssProvider * provider = gtk_css_provider_new ();
2009#ifdef GTK4
2010#if GTK_MINOR_VERSION < 12
2011 gtk_css_provider_load_from_data (provider, css, -1);
2012#else
2013 gtk_css_provider_load_from_string (provider, css);
2014#endif
2015 gtk_style_context_add_provider_for_display (gdk_display_get_default (),
2016 GTK_STYLE_PROVIDER(provider),
2017 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
2018#else
2019 gtk_css_provider_load_from_data (provider, css, -1, NULL);
2020 gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
2021 GTK_STYLE_PROVIDER(provider),
2022 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
2023#endif
2024 g_object_unref (provider);
2025}
2026
2034GtkWidget * destroy_this_widget (GtkWidget * widg)
2035{
2036 if (widg != NULL)
2037 {
2038 if (GTK_IS_WIDGET(widg))
2039 {
2040 if (is_the_widget_visible(widg)) hide_the_widgets (widg);
2041#ifdef GTK3
2042 gtk_widget_destroy (widg);
2043#else
2044 /* GtkWidget * wid = gtk_widget_get_parent (widg);
2045 if (wid != NULL)
2046 {
2047 if (GTK_IS_WIDGET(wid))
2048 {
2049 gtk_widget_unparent (widg);
2050 }
2051 } */
2052#endif
2053 }
2054 }
2055 return NULL;
2056}
2057
2065void destroy_this_dialog (GtkDialog * dialog)
2066{
2067#ifdef GTK4
2068 gtk_window_destroy (GTK_WINDOW(dialog));
2069#else
2070 destroy_this_widget (GTK_WIDGET(dialog));
2071#endif
2072 g_main_loop_quit (Event_loop[dialog_id]);
2073 g_main_loop_unref (Event_loop[dialog_id]);
2074 dialog_id --;
2075}
2076
2084void destroy_this_native_dialog (GtkNativeDialog * dialog)
2085{
2086 gtk_native_dialog_destroy (dialog);
2087 g_object_unref (dialog);
2088 g_main_loop_quit (Event_loop[dialog_id]);
2089 g_main_loop_unref (Event_loop[dialog_id]);
2090 dialog_id --;
2091}
2092
2102G_MODULE_EXPORT void run_destroy_dialog (GtkDialog * dialog, gint response_id, gpointer data)
2103{
2104 destroy_this_dialog (dialog);
2105}
2106
2107#ifdef GTK4
2113GListModel * file_chooser_get_file_names (GtkFileChooser * chooser)
2114{
2115 return gtk_file_chooser_get_files (chooser);
2116}
2117#else
2123GSList * file_chooser_get_file_names (GtkFileChooser * chooser)
2124{
2125 return gtk_file_chooser_get_filenames (chooser);
2126}
2127#endif
2128
2136gchar * file_chooser_get_file_name (GtkFileChooser * chooser)
2137{
2138#ifdef GTK4
2139 return g_file_get_parse_name (gtk_file_chooser_get_file (chooser));
2140#else
2141 return gtk_file_chooser_get_filename (chooser);
2142#endif
2143}
2144
2152gchar * file_chooser_get_current_folder (GtkFileChooser * chooser)
2153{
2154#ifdef GTK4
2155 return g_file_get_parse_name (gtk_file_chooser_get_current_folder (chooser));
2156#else
2157 return gtk_file_chooser_get_current_folder (chooser);
2158#endif
2159}
2160
2169gboolean file_chooser_set_file_name (GtkFileChooser * chooser, gchar * filename)
2170{
2171 GFile * default_file_for_saving = g_file_new_for_path (filename);
2172 gboolean res = gtk_file_chooser_set_file (chooser, default_file_for_saving, NULL);
2173 if (! res)
2174 {
2175 gchar * str = g_strdup_printf ("Impossible to locate file: %s", filename);
2176 show_error (str, 0, (GtkWidget *)chooser);
2177 }
2178 return res;
2179}
2180
2188void file_chooser_set_current_folder (GtkFileChooser * chooser)
2189{
2190#ifdef GTK4
2191 gtk_file_chooser_set_current_folder (chooser, g_file_new_for_path ("./"), NULL);
2192#else
2193 gtk_file_chooser_set_current_folder (chooser, "");
2194#endif
2195}
2196
2197#ifdef GTK4
2208GtkFileChooserNative * create_file_chooser (const gchar * title, GtkWindow * parent, GtkFileChooserAction act, const gchar * act_name)
2209{
2210 return gtk_file_chooser_native_new (title, parent, act, act_name, "Cancel");
2211}
2212#else
2223GtkWidget * create_file_chooser (const gchar * title, GtkWindow * parent, GtkFileChooserAction act, const gchar * act_name)
2224{
2225 return gtk_file_chooser_dialog_new (title, parent, act, "Cancel", GTK_RESPONSE_CANCEL, act_name, GTK_RESPONSE_ACCEPT, NULL);
2226}
2227#endif
2228
2236ColRGBA get_button_color (GtkColorChooser * colob)
2237{
2238 GdkRGBA col;
2239 gtk_color_chooser_get_rgba (colob, & col);
2240 return gdkrgba_to_rgba (col);
2241}
2242
2250ColRGBA get_window_color (GtkWidget * color_win)
2251{
2252 GdkRGBA col;
2253 gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER(color_win), & col);
2254 return gdkrgba_to_rgba (col);
2255}
2256
2265void set_color_chooser_color (GtkWidget * color_win, ColRGBA col)
2266{
2267 GdkRGBA colo = colrgba_togtkrgba(col);
2268 gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER(color_win), & colo);
2269}
2270
2271#ifdef GTK4
2281void pop_menu_at_pointer (GtkWidget * pop, double x, double y)
2282{
2283 GdkRectangle rect;
2284 rect.x = x;
2285 rect.y = y;
2286 rect.width = 1;
2287 rect.height = 1;
2288 gtk_popover_set_has_arrow (GTK_POPOVER(pop), FALSE);
2289 gtk_popover_set_pointing_to (GTK_POPOVER(pop), & rect);
2290 gtk_popover_popup (GTK_POPOVER(pop));
2291}
2292#else
2301void pop_menu_at_pointer (GtkWidget * widg, GdkEvent * event)
2302{
2303 show_the_widgets (widg);
2304 gtk_menu_popup_at_pointer (GTK_MENU (widg), event);
2305}
2306#endif
2307
2315GtkWidget * get_top_level (GtkWidget * widg)
2316{
2317#ifdef GTK4
2318 return (GtkWidget *)gtk_widget_get_root (widg);
2319#else
2320 return gtk_widget_get_toplevel (widg);
2321#endif
2322}
2323
2324#ifdef GTK4
2333G_MODULE_EXPORT gboolean destroy_this_window (GtkWindow * win, gpointer data)
2334#else
2344G_MODULE_EXPORT gboolean destroy_this_window (GtkWidget * win, GdkEvent * event, gpointer data)
2345#endif
2346{
2347 destroy_this_widget (GTK_WIDGET(win));
2348 return TRUE;
2349}
2350
2351#ifdef GTK4
2360G_MODULE_EXPORT gboolean hide_this_window (GtkWindow * win, gpointer data)
2361#else
2371G_MODULE_EXPORT gboolean hide_this_window (GtkWidget * win, GdkEvent * event, gpointer data)
2372#endif
2373{
2374 hide_the_widgets (GTK_WIDGET(win));
2375 return TRUE;
2376}
2377
2387void add_gtk_close_event (GtkWidget * widg, GCallback handler, gpointer data)
2388{
2389#ifdef GTK4
2390 g_signal_connect (G_OBJECT (widg), "close-request", handler, data);
2391#else
2392 g_signal_connect (G_OBJECT (widg), "delete-event", handler, data);
2393#endif
2394}
2395
2403int get_widget_width (GtkWidget * widg)
2404{
2405#ifdef GTK3
2406 return gtk_widget_get_allocated_width (widg);
2407#else
2408 return gtk_widget_get_width (widg);
2409#endif
2410}
2411
2419int get_widget_height (GtkWidget * widg)
2420{
2421#ifdef GTK3
2422 return gtk_widget_get_allocated_height (widg);
2423#else
2424 return gtk_widget_get_height (widg);
2425#endif
2426}
double ay
Definition curve.c:70
double ax
Definition curve.c:70
PangoLayout * layout
Definition curve.c:79
ColRGBA col
Definition d_measures.c:77
gchar * text
Definition datab.c:105
float val
Definition dlp_init.c:117
int dialog_id
Definition global.c:167
GtkTextTag * tag
Definition global.c:213
GMainLoop * Event_loop[5]
Definition global.c:178
GdkPixbuf * THETD
Definition global.c:216
GtkWidget * pop
Definition global.c:204
Global variable declarations Global convenience function declarations Global data structure defin...
@ IMG_PIXBUF
Definition global.h:261
@ IMG_NONE
Definition global.h:260
@ IMG_STOCK
Definition global.h:264
@ IMG_SURFACE
Definition global.h:262
@ IMG_FILE
Definition global.h:263
GtkWidget * create_menu_item_from_widget(GtkWidget *widg, gboolean check, gboolean radio, gboolean status)
GtkWidget * gtk3_menu_item(GtkWidget *menu, gchar *name, int icon_format, gpointer item_icon, GCallback handler, gpointer data, gboolean accel, guint key, GdkModifierType mod, gboolean check, gboolean radio, gboolean status)
#define BSEP
Definition global.h:245
GtkWidget * add_advanced_item(GtkWidget *menu, GCallback handler, gpointer data, gboolean accel, guint key, GdkModifierType mod)
@ CONTAINER_EXP
Definition global.h:255
@ CONTAINER_WIN
Definition global.h:250
@ CONTAINER_FRA
Definition global.h:254
@ CONTAINER_BUT
Definition global.h:253
@ CONTAINER_SCR
Definition global.h:251
@ CONTAINER_VIE
Definition global.h:252
#define DPROPERTIES
Definition global.h:206
GtkWidget * create_menu_item(gboolean add_mnemo, gchar *action)
#define min(a, b)
Definition global.h:81
#define DEFAULT_FONT_SIZE
Definition global.h:335
gchar * prepare_for_title(gchar *init)
prepare a string for a window title, getting rid of all markup
Definition tools.c:71
void add_menu_separator(GtkWidget *menu)
GtkWidget * menu_item_new_with_submenu(gchar *name, gboolean active, GtkWidget *sub_menu)
#define max(a, b)
Definition global.h:80
void motion(glwin *view, gint x, gint y, GdkModifierType state)
mouse motion in the OpenGL window
Definition glview.c:626
int step
Definition ogl_draw.c:70
gboolean spin(gpointer data)
spin
Definition w_spiner.c:56
GtkWidget * dialog_cancel_apply(gchar *title, GtkWidget *parent, gboolean resiz)
create a dialog modal offering a choice to apply something or not
Definition gtk-misc.c:561
GdkPixbuf * convert_to_pixbuf(cairo_surface_t *surf)
convert cairo surface to GdkPixbuf
Definition gtk-misc.c:1264
void run_this_gtk_dialog(GtkWidget *dial, GCallback handler, gpointer data)
run a GTK (3 and 4) basic GtkDialog
Definition gtk-misc.c:492
void file_chooser_set_current_folder(GtkFileChooser *chooser)
set current folder in a GtkFilechooser
Definition gtk-misc.c:2188
GtkWidget * create_entry(GCallback handler, int dim, int cdim, gboolean key_release, gpointer data)
Create a GtkEntry.
Definition gtk-misc.c:1314
void update_entry_double(GtkEntry *entry, double doubleval)
update the content of a GtkEntry as double
Definition gtk-misc.c:633
void set_renderer_color(int tocol, GtkCellRenderer *renderer, ColRGBA col)
set the color of a GtkCellRenderer
Definition gtk-misc.c:1653
void adjust_label(GtkWidget *lab, int dimx, int dimy, float ax, float ay)
adjust the text position, and widget size of a GtkLabel
Definition gtk-misc.c:1708
ColRGBA gdkrgba_to_rgba(GdkRGBA colgdk)
convert GdkRGBA color to ColRGBA color
Definition gtk-misc.c:1617
GtkWidget * font_button(gchar *font, int dimx, int dimy, GCallback handler, gpointer data)
create a font selection button
Definition gtk-misc.c:1750
GtkWidget * create_text_view(int dimx, int dimy, int edit, int mono, GCallback handler, gpointer data, gchar *text)
create a GtkTextView and display some text
Definition gtk-misc.c:1199
GtkTextBuffer * add_buffer(GCallback handler, gpointer data, gchar *text)
create a GtkTextBuffer
Definition gtk-misc.c:1171
GtkWidget * create_scroll(GtkWidget *box, int dimx, int dimy, int shadow)
create a scroll window
Definition gtk-misc.c:1960
GtkWidget * dialogmodal(gchar *str, GtkWindow *parent)
Create a new dialog modal window.
Definition gtk-misc.c:510
void set_color_chooser_color(GtkWidget *color_win, ColRGBA col)
set the color of a color selection window
Definition gtk-misc.c:2265
gboolean is_the_widget_visible(GtkWidget *widg)
test if a GtkWidget exist, then return if it is visible or not
Definition gtk-misc.c:714
void resize_this_window(GtkWidget *window, int x, int y)
resize this GtkWindow
Definition gtk-misc.c:581
GtkWidget * create_win(gchar *str, GtkWidget *parent, gboolean modal, gboolean resiz)
create a new GtkWindow
Definition gtk-misc.c:445
ColRGBA get_window_color(GtkWidget *color_win)
get the ColRGBA color from a color selection window
Definition gtk-misc.c:2250
GtkWidget * add_vbox_to_layout(GtkWidget *layout, int size_x, int size_y)
Insert a vertical GtkBox in a GtkLatout then send back the GtkBox.
Definition gtk-misc.c:864
int get_widget_height(GtkWidget *widg)
retrive GtkWidget height
Definition gtk-misc.c:2419
gchar * file_chooser_get_file_name(GtkFileChooser *chooser)
get a file name from a GtkFileChooser (single file selected)
Definition gtk-misc.c:2136
const gchar * entry_get_text(GtkEntry *entry)
get the text in a GtkEntry
Definition gtk-misc.c:597
GdkRGBA colrgba_togtkrgba(ColRGBA col)
convert ColRGBA color to GdkRGBA color
Definition gtk-misc.c:1634
void update_entry_int(GtkEntry *entry, int intval)
update the content of a GtkEntry as int
Definition gtk-misc.c:614
G_MODULE_EXPORT gboolean hide_this_window(GtkWidget *win, GdkEvent *event, gpointer data)
hide a GtkWindow
Definition gtk-misc.c:2371
void pop_menu_at_pointer(GtkWidget *widg, GdkEvent *event)
popup a menu at pointer location
Definition gtk-misc.c:2301
gboolean file_chooser_set_file_name(GtkFileChooser *chooser, gchar *filename)
set file name in a GtkFilechooser
Definition gtk-misc.c:2169
G_MODULE_EXPORT gboolean destroy_this_window(GtkWidget *win, GdkEvent *event, gpointer data)
destroy a GtkWindow
Definition gtk-misc.c:2344
GtkWidget * stock_image(const gchar *stock_id)
create a GtkImage for the Gtk database
Definition gtk-misc.c:1364
int get_widget_width(GtkWidget *widg)
retrive GtkWidget width
Definition gtk-misc.c:2403
void add_gtk_close_event(GtkWidget *widg, GCallback handler, gpointer data)
add a close event signal and callback to a GtkWidget
Definition gtk-misc.c:2387
GtkWidget * create_vscale(float min, float max, float delta, float val, int pos, int round, int size, GCallback handler, GCallback scroll_handler, gpointer data)
create an vertical scale GtkWidget
Definition gtk-misc.c:778
void layout_add_widget(GtkWidget *layout, GtkWidget *child, int x_pos, int y_pos)
Add a GtkWidget in a GtkLayout.
Definition gtk-misc.c:846
GtkWidget * fbox(GtkWidget *box, char *lab)
Definition gtk-misc.c:1941
gchar * file_chooser_get_current_folder(GtkFileChooser *chooser)
get the current folder for a GtkFileChooser
Definition gtk-misc.c:2152
GtkWidget * radio_button(gchar *text, int dimx, int dimy, gboolean state, GCallback handler, gpointer data)
create a radio button
Definition gtk-misc.c:1834
GtkWidget * spin_button(GCallback handler, double value, double start, double end, double step, int digits, int dim, gpointer data)
create a spin button
Definition gtk-misc.c:1772
GtkWidget * check_button(gchar *text, int dimx, int dimy, gboolean state, GCallback handler, gpointer data)
create a check button
Definition gtk-misc.c:1799
G_MODULE_EXPORT void to_activate_entry(GtkEventControllerFocus *focus, gpointer data)
GtkEntry activate signal managment.
Definition gtk-misc.c:1297
GtkWidget * create_button(gchar *text, int image_format, gchar *image, int dimx, int dimy, int relief, GCallback handler, gpointer data)
create a simple button
Definition gtk-misc.c:1863
GtkWidget * get_top_level(GtkWidget *widg)
get the top level container, window, of a widget
Definition gtk-misc.c:2315
GtkWidget * create_combo()
create a GtkCombox widget, note deprecated in GTK4
Definition gtk-misc.c:923
GtkWidget * dialog_get_content_area(GtkWidget *widg)
prepare GtkWidget to insert content in a GtkDialog window
Definition gtk-misc.c:825
void button_set_image(GtkButton *but, gchar *text, int format, gpointer image)
Add an image to a GtkButton.
Definition gtk-misc.c:1677
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
Definition gtk-misc.c:1585
GtkWidget * cbox(GtkWidget *box, char *lab)
Definition gtk-misc.c:1931
void add_box_child_start(int orientation, GtkWidget *widg, GtkWidget *child, gboolean expand, gboolean fill, int padding)
Add a GtkWidget in a GtkBox at the initial position.
Definition gtk-misc.c:299
ColRGBA get_button_color(GtkColorChooser *colob)
get the ColRGBA color from a GtkColorChooser button
Definition gtk-misc.c:2236
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:206
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2065
void text_view_set_monospace(GtkWidget *view)
set the font of a GtkTextView as monospace
Definition gtk-misc.c:687
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:813
GtkWidget * new_gtk_window()
create a new GtkWindow
Definition gtk-misc.c:348
GtkWidget * create_image_from_data(int format, gpointer item_image)
create Gtk image for data
Definition gtk-misc.c:1443
void gtk_label_align(GtkWidget *lab, float ax, float ay)
set text alignment in a GtkLabel
Definition gtk-misc.c:701
void combo_text_append(GtkWidget *combo, gchar *text)
append text in GtkComboBox widget
Definition gtk-misc.c:900
G_MODULE_EXPORT void run_destroy_dialog(GtkDialog *dialog, gint response_id, gpointer data)
to destroy a GtkDialog when the dialog emit the closing signal
Definition gtk-misc.c:2102
GtkWidget * create_layout(int x, int y)
create a GtkLayout / GtkFixed widget
Definition gtk-misc.c:880
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2034
GtkWidget * color_button(ColRGBA col, gboolean alpha, int dimx, int dimy, GCallback handler, gpointer data)
create a color selection button
Definition gtk-misc.c:1728
GtkWidget * create_hscale(float min, float max, float delta, float val, int pos, int round, int size, GCallback handler, GCallback scroll_handler, gpointer data)
create an horizontal scale GtkWidget
Definition gtk-misc.c:744
GtkWidget * bbox(GtkWidget *box, char *lab)
Definition gtk-misc.c:1921
void add_box_child_end(GtkWidget *widg, GtkWidget *child, gboolean expand, gboolean fill, int padding)
Add a GtkWidget in a GtkBox at the end position.
Definition gtk-misc.c:277
void update_entry_text(GtkEntry *entry, gchar *text)
update the content of a GtkEntry as string
Definition gtk-misc.c:671
void provide_gtk_css(gchar *css)
create a css provider based on the css data
Definition gtk-misc.c:2006
GSList * file_chooser_get_file_names(GtkFileChooser *chooser)
create a file list from files selected using a GtkFileChooser
Definition gtk-misc.c:2123
void setup_text_tags(GtkTextBuffer *buffer)
prepare the avialable text tags for the GtkTextBuffer
Definition gtk-misc.c:935
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:226
void set_image_from_icon_name(GtkWidget *widg, gchar *icon)
set a image from a stock icon name
Definition gtk-misc.c:1894
GtkWidget * message_dialogmodal(gchar *message, gchar *title, GtkMessageType mtype, GtkButtonsType buttons, GtkWidget *parent)
create a modal (cannot be ignored) message window
Definition gtk-misc.c:531
void combo_text_prepend(GtkWidget *combo, gchar *text)
prepend text in GtkComboBox widget
Definition gtk-misc.c:913
void hide_the_widgets(GtkWidget *widg)
hide GtkWidget
Definition gtk-misc.c:189
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:801
ColRGBA * duplicate_color(int num, ColRGBA *col)
duplicate a ColRGBA pointer
Definition gtk-misc.c:1602
GtkWidget * abox(GtkWidget *box, char *lab, int vspace)
box creating routine, to help design faster elements for the GUI
Definition gtk-misc.c:1912
GtkWidget * create_expander(gchar *name, gchar *file_img)
create GtkExpander
Definition gtk-misc.c:1984
GtkWidget * create_file_chooser(const gchar *title, GtkWindow *parent, GtkFileChooserAction act, const gchar *act_name)
create a GtkFileChooser, utility to select file(s)
Definition gtk-misc.c:2223
void destroy_this_native_dialog(GtkNativeDialog *dialog)
destroy a GtkNativeDialog
Definition gtk-misc.c:2084
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:173
void update_entry_long_double(GtkEntry *entry, double doubleval)
update the content of a GtkEntry as long double
Definition gtk-misc.c:652
void show_error(char *error, int val, GtkWidget *win)
show error message
Definition interface.c:293
Messaging function declarations.
double y
Definition ogl_draw.c:57
double x
Definition ogl_draw.c:57
float blue
Definition global.h:124
float alpha
Definition global.h:125
float red
Definition global.h:122
float green
Definition global.h:123
Definition glwin.h:277
int status
Definition w_advance.c:160
GtkWidget * res[2]
Definition w_encode.c:212
GdkPixbuf * pix
Definition workspace.c:69
GtkWidget * hbox
Definition workspace.c:71
GtkWidget * img
Definition workspace.c:70
GtkWidget * vbox
Definition workspace.c:72
GtkWidget * lab
Definition workspace.c:73