172 gtk_widget_show (widg);
174 gtk_widget_show_all (widg);
190 if (GTK_IS_WIDGET(widg))
192 gtk_widget_set_sensitive (widg, sensitive);
209 gtk_container_add (GTK_CONTAINER(widg), child);
215 gtk_window_set_child ((GtkWindow *)widg, child);
223 gtk_scrolled_window_set_child ((GtkScrolledWindow *)widg, NULL);
224 gtk_scrolled_window_set_child ((GtkScrolledWindow *)widg, child);
228 gtk_viewport_set_child ((GtkViewport *)widg, child);
232 gtk_button_set_child ((GtkButton *)widg, child);
236 gtk_frame_set_child ((GtkFrame *)widg, child);
240 gtk_expander_set_child ((GtkExpander *)widg, child);
257void add_box_child_end (GtkWidget * widg, GtkWidget * child, gboolean expand, gboolean fill,
int padding)
261 gtk_box_append (GTK_BOX(widg), child);
263 gtk_box_pack_end (GTK_BOX(widg), child, expand, fill, padding);
279void add_box_child_start (
int orientation, GtkWidget * widg, GtkWidget * child, gboolean expand, gboolean fill,
int padding)
282 if (orientation == GTK_ORIENTATION_HORIZONTAL && padding)
284 gtk_box_append (GTK_BOX(widg),
markup_label (
" ", padding, -1, 0.0, 0.0));
286 else if (orientation == GTK_ORIENTATION_VERTICAL && padding > 10)
288 gtk_box_append (GTK_BOX(widg),
markup_label (
" ", -1, padding/2, 0.0, 0.0));
290 gtk_box_append (GTK_BOX(widg), child);
291 if (orientation == GTK_ORIENTATION_HORIZONTAL && padding)
293 gtk_box_append (GTK_BOX(widg),
markup_label (
" ", padding, -1, 0.0, 0.0));
295 else if (orientation == GTK_ORIENTATION_VERTICAL && padding > 10)
297 gtk_box_append (GTK_BOX(widg),
markup_label (
" ", -1, padding/2, 0.0, 0.0));
300 gtk_box_pack_start (GTK_BOX(widg), child, expand, fill, padding);
317 gtk_menu_item_set_submenu ((GtkMenuItem *)item, sub_menu);
331 return gtk_window_new ();
333 return gtk_window_new (GTK_WINDOW_TOPLEVEL);
365void add_widget_gesture_and_key_action (GtkWidget * widget,
366 gchar * cp_name, GCallback cp_handler, gpointer cp_data,
367 gchar * cr_name, GCallback cr_handler, gpointer cr_data,
368 gchar * kp_name, GCallback kp_handler, gpointer kp_data,
369 gchar * mo_name, GCallback mo_handler, gpointer mo_data,
370 gchar * sc_name, GCallback sc_handler, gpointer sc_data)
372 GtkGesture * gesture;
373 GtkEventController * key;
374 GtkEventController *
motion;
377 gesture = gtk_gesture_click_new ();
378 gtk_event_controller_set_name (GTK_EVENT_CONTROLLER (gesture), cp_name);
379 gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0);
380 if (cp_handler) g_signal_connect (gesture,
"pressed", cp_handler, cp_data);
381 gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (gesture));
385 gesture = gtk_gesture_click_new ();
386 gtk_event_controller_set_name (GTK_EVENT_CONTROLLER (gesture), cr_name);
387 gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0);
388 if (cr_handler) g_signal_connect (gesture,
"released", cr_handler, cr_data);
389 gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (gesture));
393 key = gtk_event_controller_key_new ();
394 gtk_event_controller_set_name (key, kp_name);
395 if (kp_handler) g_signal_connect (key,
"key-pressed", kp_handler, kp_data);
396 gtk_widget_add_controller (widget, key);
400 motion = gtk_event_controller_motion_new ();
401 gtk_event_controller_set_name (
motion, mo_name);
402 if (mo_handler) g_signal_connect (
motion,
"motion", mo_handler, mo_data);
403 gtk_widget_add_controller (widget,
motion);
407 motion = gtk_event_controller_scroll_new (GTK_EVENT_CONTROLLER_SCROLL_VERTICAL);
408 gtk_event_controller_set_name (
motion, sc_name);
409 if (sc_handler) g_signal_connect (
motion,
"scroll", sc_handler, sc_data);
410 gtk_widget_add_controller (widget,
motion);
425GtkWidget *
create_win (gchar * str, GtkWidget * parent, gboolean modal, gboolean resiz)
430 gtk_window_set_resizable (GTK_WINDOW (win), TRUE);
432 gtk_window_set_attached_to (GTK_WINDOW (win), parent);
433 gtk_window_set_icon (GTK_WINDOW (win),
THETD);
436 gtk_window_set_modal (GTK_WINDOW(win), modal);
437 gtk_window_set_resizable (GTK_WINDOW(win), resiz);
438 gtk_window_set_destroy_with_parent (GTK_WINDOW (win), TRUE);
452void run_this_gtk_native_dialog (GtkNativeDialog * dial, GCallback handler, gpointer data)
454 gtk_native_dialog_set_modal (dial, TRUE);
455 if (handler) g_signal_connect (G_OBJECT(dial),
"response", handler, data);
456 gtk_native_dialog_show (dial);
474 gtk_window_set_modal (GTK_WINDOW(dial), TRUE);
475 if (handler) g_signal_connect (G_OBJECT(dial),
"response", handler, data);
492 GtkWidget * win = gtk_dialog_new_with_buttons (str, parent, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, _(
"_Close"), GTK_RESPONSE_CLOSE, NULL);
493 gtk_window_set_resizable (GTK_WINDOW (win), FALSE);
495 gtk_window_set_icon (GTK_WINDOW (win),
THETD);
511GtkWidget *
message_dialogmodal (gchar * message, gchar * title, GtkMessageType mtype, GtkButtonsType buttons, GtkWidget * parent)
516 win = gtk_message_dialog_new (GTK_WINDOW(parent), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, mtype, buttons, NULL);
520 win = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, mtype, buttons, NULL);
522 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (win), message);
523 gtk_window_set_title (GTK_WINDOW(win), title);
524 gtk_window_set_resizable (GTK_WINDOW (win), FALSE);
526 gtk_window_set_icon (GTK_WINDOW (win),
THETD);
543 GtkWidget * dca = gtk_dialog_new_with_buttons (title, GTK_WINDOW(parent), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
544 "Cancel", GTK_RESPONSE_CANCEL,
"Apply", GTK_RESPONSE_APPLY, NULL);
545 gtk_window_set_resizable (GTK_WINDOW(dca), resiz);
547 gtk_window_set_icon (GTK_WINDOW (dca),
THETD);
564 gtk_window_resize (GTK_WINDOW(window),
x,
y);
566 gtk_window_set_default_size (GTK_WINDOW(window),
x,
y);
580 return gtk_editable_get_text (GTK_EDITABLE(entry));
582 return gtk_entry_get_text (entry);
596 gchar * value = g_strdup_printf(
"%d", intval);
598 gtk_editable_set_text (GTK_EDITABLE(entry), (
const gchar *)value);
600 gtk_entry_set_text (entry, (
const gchar *)value);
615 gchar * value = g_strdup_printf(
"%f", doubleval);
617 gtk_editable_set_text (GTK_EDITABLE(entry), (
const gchar *)value);
619 gtk_entry_set_text (entry, (
const gchar *)value);
634 gchar * value = g_strdup_printf(
"%15.10lf", doubleval);
636 gtk_editable_set_text (GTK_EDITABLE(entry), (
const gchar *)value);
638 gtk_entry_set_text (entry, (
const gchar *)value);
654 gtk_editable_set_text (GTK_EDITABLE(entry), (
const gchar *)
text);
656 gtk_entry_set_text (entry, (
const gchar *)
text);
669 gtk_text_view_set_monospace (GTK_TEXT_VIEW(view), TRUE);
683 gtk_label_set_xalign (GTK_LABEL (
lab),
ax);
684 gtk_label_set_yalign (GTK_LABEL (
lab),
ay);
696 if (GTK_IS_WIDGET(widg))
698 return gtk_widget_is_visible (widg);
725 float val,
int pos,
int round,
int size,
726 GCallback handler, GCallback scroll_handler, gpointer data)
729 hscale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
min,
max, delta);
730 gtk_scale_set_draw_value (GTK_SCALE(hscale), TRUE);
731 gtk_widget_set_size_request (hscale, size, -1);
732 gtk_scale_set_value_pos (GTK_SCALE(hscale), pos);
733 gtk_range_set_value (GTK_RANGE(hscale),
val);
734 gtk_range_set_round_digits (GTK_RANGE(hscale), round);
735 if (handler != NULL) g_signal_connect (G_OBJECT(hscale),
"value-changed", handler, data);
736 if (scroll_handler != NULL) g_signal_connect (G_OBJECT(hscale),
"change-value", scroll_handler, data);
759 float val,
int pos,
int round,
int size,
760 GCallback handler, GCallback scroll_handler, gpointer data)
763 vscale = gtk_scale_new_with_range (GTK_ORIENTATION_VERTICAL,
min,
max, delta);
764 gtk_scale_set_draw_value (GTK_SCALE(vscale), TRUE);
765 gtk_scale_set_value_pos (GTK_SCALE(vscale), pos);
766 gtk_widget_set_size_request (vscale, size, size);
767 gtk_range_set_value (GTK_RANGE(vscale),
val);
768 gtk_range_set_round_digits (GTK_RANGE(vscale), round);
769 if (handler != NULL) g_signal_connect (G_OBJECT(vscale),
"value-changed", handler, data);
770 if (scroll_handler != NULL) g_signal_connect (G_OBJECT(vscale),
"change-value", scroll_handler, data);
783 return gtk_box_new (GTK_ORIENTATION_VERTICAL, spacing);
795 return gtk_box_new (GTK_ORIENTATION_HORIZONTAL, spacing);
808 return gtk_dialog_get_content_area (GTK_DIALOG(widg));
811 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, gtk_dialog_get_content_area (GTK_DIALOG(widg)),
vbox, TRUE, TRUE, 0);
829 gtk_layout_put (GTK_LAYOUT(
layout), child, x_pos, y_pos);
831 gtk_fixed_put (GTK_FIXED(
layout), child, x_pos, y_pos);
847 gtk_widget_set_size_request (
vbox, size_x, size_y);
864 layout = gtk_layout_new (NULL, NULL);
866 layout = gtk_fixed_new ();
868 gtk_widget_set_size_request (
layout,
x,
y);
882 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(combo),
text);
895 gtk_combo_box_text_prepend_text (GTK_COMBO_BOX_TEXT(combo),
text);
905 return gtk_combo_box_text_new ();
917 GtkTextTagTable * textags = gtk_text_buffer_get_tag_table(buffer);
920 tag = gtk_text_tag_new (
"sans");
922 gtk_text_tag_table_add (textags,
tag);
923 g_object_unref (
tag);
926 tag = gtk_text_tag_new (
"monospace");
928 gtk_text_tag_table_add (textags,
tag);
929 g_object_unref (
tag);
932 tag = gtk_text_tag_new (
"default-size");
934 gtk_text_tag_table_add (textags,
tag);
935 g_object_unref (
tag);
938 tag = gtk_text_tag_new (
"underline");
939 g_object_set (
tag,
"size",
DEFAULT_FONT_SIZE * PANGO_SCALE,
"underline", PANGO_UNDERLINE_SINGLE, NULL);
940 gtk_text_tag_table_add (textags,
tag);
941 g_object_unref (
tag);
944 tag = gtk_text_tag_new (
"underline_double");
945 g_object_set (
tag,
"size",
DEFAULT_FONT_SIZE * PANGO_SCALE,
"underline", PANGO_UNDERLINE_DOUBLE, NULL);
946 gtk_text_tag_table_add (textags,
tag);
947 g_object_unref (
tag);
950 tag = gtk_text_tag_new (
"italic");
952 gtk_text_tag_table_add (textags,
tag);
953 g_object_unref (
tag);
956 tag = gtk_text_tag_new (
"bold");
958 gtk_text_tag_table_add (textags,
tag);
959 g_object_unref (
tag);
962 tag = gtk_text_tag_new (
"bold_italic");
964 "style", PANGO_STYLE_ITALIC,
965 "weight", PANGO_WEIGHT_BOLD, NULL);
966 gtk_text_tag_table_add (textags,
tag);
967 g_object_unref (
tag);
970 tag = gtk_text_tag_new (
"sup");
972 gtk_text_tag_table_add (textags,
tag);
973 g_object_unref (
tag);
976 tag = gtk_text_tag_new (
"sub");
978 gtk_text_tag_table_add (textags,
tag);
979 g_object_unref (
tag);
982 tag = gtk_text_tag_new(
"justify-left");
983 g_object_set(
tag,
"size",
DEFAULT_FONT_SIZE * PANGO_SCALE,
"justification", GTK_JUSTIFY_LEFT, NULL);
984 gtk_text_tag_table_add(textags,
tag);
988 tag = gtk_text_tag_new(
"justify-center");
989 g_object_set(
tag,
"size",
DEFAULT_FONT_SIZE * PANGO_SCALE,
"justification", GTK_JUSTIFY_CENTER, NULL);
990 gtk_text_tag_table_add(textags,
tag);
994 tag = gtk_text_tag_new(
"justify-right");
995 g_object_set(
tag,
"justification", GTK_JUSTIFY_RIGHT, NULL);
996 gtk_text_tag_table_add(textags,
tag);
997 g_object_unref (
tag);
1000 tag = gtk_text_tag_new(
"heading");
1002 "weight", PANGO_WEIGHT_BOLD,
1004 "justification", GTK_JUSTIFY_CENTER,
1005 "underline", PANGO_UNDERLINE_DOUBLE, NULL);
1006 gtk_text_tag_table_add(textags,
tag);
1007 g_object_unref (
tag);
1010 tag = gtk_text_tag_new(
"red");
1012 gtk_text_tag_table_add(textags,
tag);
1013 g_object_unref (
tag);
1016 tag = gtk_text_tag_new(
"orange");
1018 gtk_text_tag_table_add(textags,
tag);
1019 g_object_unref (
tag);
1022 tag = gtk_text_tag_new(
"yellow");
1024 gtk_text_tag_table_add(textags,
tag);
1025 g_object_unref (
tag);
1028 tag = gtk_text_tag_new(
"green");
1030 gtk_text_tag_table_add(textags,
tag);
1031 g_object_unref (
tag);
1034 tag = gtk_text_tag_new(
"light_green");
1036 gtk_text_tag_table_add(textags,
tag);
1037 g_object_unref (
tag);
1040 tag = gtk_text_tag_new(
"cyan");
1042 gtk_text_tag_table_add(textags,
tag);
1043 g_object_unref (
tag);
1046 tag = gtk_text_tag_new(
"blue");
1048 gtk_text_tag_table_add(textags,
tag);
1049 g_object_unref (
tag);
1052 tag = gtk_text_tag_new(
"pink");
1054 gtk_text_tag_table_add(textags,
tag);
1055 g_object_unref (
tag);
1058 tag = gtk_text_tag_new(
"violet");
1060 gtk_text_tag_table_add(textags,
tag);
1061 g_object_unref (
tag);
1064 tag = gtk_text_tag_new(
"grey_back");
1066 gtk_text_tag_table_add(textags,
tag);
1067 g_object_unref (
tag);
1070 tag = gtk_text_tag_new(
"bold_grey_back");
1072 "background",
"lightgrey",
1073 "weight", PANGO_WEIGHT_BOLD, NULL);
1074 gtk_text_tag_table_add(textags,
tag);
1075 g_object_unref (
tag);
1078 tag = gtk_text_tag_new (
"bold_red");
1080 "foreground",
"red",
1081 "weight", PANGO_WEIGHT_BOLD, NULL);
1082 gtk_text_tag_table_add (textags,
tag);
1083 g_object_unref (
tag);
1086 tag = gtk_text_tag_new (
"bold_blue");
1088 "foreground",
"blue",
1089 "weight", PANGO_WEIGHT_BOLD, NULL);
1090 gtk_text_tag_table_add (textags,
tag);
1091 g_object_unref (
tag);
1094 tag = gtk_text_tag_new (
"bold_green");
1096 "foreground",
"green",
1097 "weight", PANGO_WEIGHT_BOLD, NULL);
1098 gtk_text_tag_table_add (textags,
tag);
1099 g_object_unref (
tag);
1102 tag = gtk_text_tag_new (
"bold_orange");
1104 "foreground",
"orange",
1105 "weight", PANGO_WEIGHT_BOLD, NULL);
1106 gtk_text_tag_table_add (textags,
tag);
1107 g_object_unref (
tag);
1110 tag = gtk_text_tag_new (
"bold_pink");
1112 "foreground",
"pink",
1113 "weight", PANGO_WEIGHT_BOLD, NULL);
1114 gtk_text_tag_table_add (textags,
tag);
1115 g_object_unref (
tag);
1118 tag = gtk_text_tag_new (
"sub_italic");
1120 "style", PANGO_STYLE_ITALIC,
1121 "scale", .6,
"rise", -6000, NULL);
1122 gtk_text_tag_table_add (textags,
tag);
1123 g_object_unref (
tag);
1126 tag = gtk_text_tag_new (
"sub_bold");
1128 "weight", PANGO_WEIGHT_BOLD,
1129 "scale", .6,
"rise", -6000, NULL);
1130 gtk_text_tag_table_add (textags,
tag);
1131 g_object_unref (
tag);
1134 tag = gtk_text_tag_new (
"sup_bold");
1136 "weight", PANGO_WEIGHT_BOLD,
1137 "scale", .6,
"rise", 6000, NULL);
1138 gtk_text_tag_table_add (textags,
tag);
1139 g_object_unref (
tag);
1153 GtkTextBuffer * buffer;
1156 buffer = gtk_text_buffer_new (NULL);
1158 gtk_text_buffer_get_start_iter (buffer, &bStart);
1159 gtk_text_buffer_get_end_iter (buffer, &bEnd);
1160 gtk_text_buffer_delete (buffer, &bStart, &bEnd);
1161 if (
text != NULL) gtk_text_buffer_set_text (buffer,
text, -1);
1162 if (handler != NULL) g_signal_connect (G_OBJECT (buffer),
"changed", handler, data);
1179GtkWidget *
create_text_view (
int dimx,
int dimy,
int edit,
int mono, GCallback handler, gpointer data, gchar *
text)
1181 GtkWidget * tview = gtk_text_view_new ();
1182 gtk_text_view_set_buffer (GTK_TEXT_VIEW(tview),
add_buffer(handler, data,
text));
1183 gtk_widget_set_size_request (tview, dimx, dimy);
1184 gtk_text_view_set_editable (GTK_TEXT_VIEW(tview), edit);
1201static void convert_alpha (cairo_surface_t * surf, GdkPixbuf *
pix,
int src_x,
int src_y,
int width,
int height)
1204 guchar * src_data = cairo_image_surface_get_data (surf);
1205 int src_stride = cairo_image_surface_get_stride (surf);
1206 guchar * dest_data = gdk_pixbuf_get_pixels (
pix);
1207 int dest_stride = gdk_pixbuf_get_rowstride (
pix);
1209 src_data += src_stride * src_y + src_x * 4;
1211 for (
y = 0;
y < height;
y++) {
1212 guint32 *src = (guint32 *) src_data;
1214 for (
x = 0;
x < width;
x++) {
1215 guint alpha = src[
x] >> 24;
1219 dest_data[
x * 4 + 0] = 0;
1220 dest_data[
x * 4 + 1] = 0;
1221 dest_data[
x * 4 + 2] = 0;
1225 dest_data[
x * 4 + 0] = (((src[
x] & 0xff0000) >> 16) * 255 + alpha / 2) / alpha;
1226 dest_data[
x * 4 + 1] = (((src[
x] & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha;
1227 dest_data[
x * 4 + 2] = (((src[
x] & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha;
1229 dest_data[
x * 4 + 3] = alpha;
1232 src_data += src_stride;
1233 dest_data += dest_stride;
1246 int width = cairo_image_surface_get_width (surf);
1247 int height = cairo_image_surface_get_height (surf);
1248 GdkPixbuf *
pix = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width , height);
1249 convert_alpha (surf,
pix, 0, 0, width, height);
1263G_MODULE_EXPORT gboolean
to_activate_entry (GtkWidget * widg, GdkEventFocus * event, gpointer data)
1265 g_signal_emit_by_name (G_OBJECT(widg),
"activate", data);
1279 g_signal_emit_by_name (G_OBJECT(gtk_event_controller_get_widget((GtkEventController *)focus)),
"activate", data);
1294GtkWidget *
create_entry (GCallback handler,
int dim,
int cdim, gboolean key_release, gpointer data)
1296 GtkWidget * entry = gtk_entry_new ();
1297 gtk_widget_set_size_request (entry, dim, -1);
1299 gtk_editable_set_width_chars (GTK_EDITABLE(entry), 0);
1300 gtk_editable_set_max_width_chars (GTK_EDITABLE(entry), cdim);
1302 gtk_entry_set_width_chars (GTK_ENTRY(entry), 0);
1303 gtk_entry_set_max_width_chars (GTK_ENTRY(entry), cdim);
1305 gtk_entry_set_alignment (GTK_ENTRY(entry), 1.0);
1307 if (handler != NULL)
1309 g_signal_connect (G_OBJECT (entry),
"activate", handler, data);
1311 g_signal_connect (G_OBJECT (entry),
"focus-out-event", G_CALLBACK(
to_activate_entry), data);
1320 GtkEventController * focus = gtk_event_controller_focus_new ();
1321 gtk_event_controller_set_name (focus,
"focus-out");
1322 g_signal_connect (G_OBJECT(focus),
"leave", G_CALLBACK(
to_activate_entry), data);
1323 gtk_widget_add_controller (entry, focus);
1329 g_signal_connect (G_OBJECT (entry),
"key-release-event", G_CALLBACK(
to_activate_entry), data);
1347 return gtk_image_new_from_icon_name (stock_id);
1349 return gtk_image_new_from_icon_name (stock_id, GTK_ICON_SIZE_MENU);
1364 return (add_mnemo) ? gtk_menu_item_new_with_mnemonic (name) : gtk_menu_item_new_with_label (name);
1382 item = gtk_check_menu_item_new ();
1383 if (radio) gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM(item), TRUE);
1384 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(item),
status);
1388 item = gtk_menu_item_new ();
1390 gtk_container_add (GTK_CONTAINER(item), widg);
1425 GtkWidget * icon = NULL;
1429 icon = gtk_image_new_from_pixbuf ((GdkPixbuf*)item_image);
1433 icon = gtk_image_new_from_pixbuf (
convert_to_pixbuf ((cairo_surface_t *)item_image));
1435 icon = gtk_image_new_from_surface ((cairo_surface_t *)item_image);
1439 icon = gtk_image_new_from_file ((
const gchar *)item_image);
1472 int icon_format, gpointer item_icon,
1473 GCallback handler, gpointer data,
1474 gboolean accel, guint key, GdkModifierType mod,
1475 gboolean check, gboolean radio, gboolean
status)
1478 GtkWidget * icon = NULL;
1479 GtkWidget *
lab = NULL;
1485 lab = gtk_accel_label_new (name);
1487 gtk_widget_set_size_request (
lab, -1, -1);
1488 gtk_label_set_use_markup (GTK_LABEL(
lab), TRUE);
1489 gtk_accel_label_set_accel ((GtkAccelLabel *)
lab, key, mod);
1519 if (handler != NULL) g_signal_connect (G_OBJECT(item),
"activate", handler, data);
1520 if (menu != NULL) gtk_menu_shell_append ((GtkMenuShell *)menu, item);
1536GtkWidget *
add_advanced_item (GtkWidget * menu, GCallback handler, gpointer data, gboolean accel, guint key, GdkModifierType mod)
1538 return gtk3_menu_item (menu,
"Advanced",
IMG_STOCK, (gpointer)
DPROPERTIES, handler, data, accel, key, mod, FALSE, FALSE, FALSE);
1550 gtk_menu_shell_append ((GtkMenuShell *)menu, gtk_separator_menu_item_new ());
1567 GtkWidget *
lab = gtk_label_new (
text);
1569 gtk_widget_set_size_request (
lab, dimx, dimy);
1570 gtk_label_set_use_markup (GTK_LABEL(
lab), TRUE);
1584 ColRGBA * new_col = g_malloc0 (num*
sizeof*new_col);
1586 for (i=0; i<num; i++) new_col[i] =
col[i];
1638 g_object_set (renderer,
"foreground-rgba", & colo,
"foreground-set", TRUE, NULL);
1639 g_object_set(renderer,
"weight", PANGO_WEIGHT_BOLD,
"weight-set", TRUE, NULL);
1643 g_object_set(renderer,
"foreground-set", FALSE,
"weight", FALSE, NULL);
1666 gtk_button_set_child (but,
hbox);
1670 gtk_button_set_child (but,
img);
1690 gtk_label_set_xalign (GTK_LABEL(
lab),
ax);
1691 gtk_label_set_yalign (GTK_LABEL(
lab),
ay);
1692 gtk_widget_set_size_request (
lab, dimx, dimy);
1693 gtk_label_set_use_markup (GTK_LABEL(
lab), TRUE);
1712 colorb = gtk_color_button_new_with_rgba (& colo);
1713 gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER(colorb), alpha);
1714 if (handler != NULL) g_signal_connect (G_OBJECT(colorb),
"color-set", handler, data);
1715 gtk_widget_set_size_request (colorb, dimx, dimy);
1730GtkWidget *
font_button (gchar * font,
int dimx,
int dimy, GCallback handler, gpointer data)
1732 GtkWidget * fontb = gtk_font_button_new_with_font (font);
1733 g_signal_connect (G_OBJECT(fontb),
"font-set", handler, data);
1734 gtk_widget_set_size_request (fontb, dimx, dimy);
1752GtkWidget *
spin_button (GCallback handler,
double value,
double start,
double end,
double step,
int digits,
int dim, gpointer data)
1754 GtkWidget *
spin = gtk_spin_button_new_with_range (start, end,
step);
1755 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(
spin), digits);
1757 gtk_editable_set_alignment (GTK_EDITABLE(
spin), 1.0);
1759 gtk_entry_set_alignment (GTK_ENTRY(
spin), 1.0);
1761 gtk_spin_button_set_value (GTK_SPIN_BUTTON(
spin), value);
1762 gtk_widget_set_size_request (
spin, dim, -1);
1763 if (handler != NULL) g_signal_connect (G_OBJECT (
spin),
"value-changed", handler, data);
1779GtkWidget *
check_button (gchar *
text,
int dimx,
int dimy, gboolean state, GCallback handler, gpointer data)
1781 GtkWidget * but = gtk_check_button_new ();
1785 gtk_check_button_set_label (GTK_CHECK_BUTTON(but),
text);
1786 GtkWidget *
lab = gtk_widget_get_last_child (but);
1792 gtk_widget_set_size_request (but, dimx, dimy);
1794 gtk_check_button_set_active (GTK_CHECK_BUTTON(but), state);
1796 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(but), state);
1798 if (handler != NULL) g_signal_connect (G_OBJECT(but),
"toggled", handler, data);
1814GtkWidget *
radio_button (gchar *
text,
int dimx,
int dimy, gboolean state, GCallback handler, gpointer data)
1818 but = gtk_toggle_button_new ();
1820 but = gtk_radio_button_new (NULL);
1823 gtk_widget_set_size_request (but, dimx, dimy);
1824 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(but), state);
1825 if (handler != NULL) g_signal_connect (G_OBJECT(but),
"toggled", handler, data);
1843GtkWidget *
create_button (gchar *
text,
int image_format, gchar *
image,
int dimx,
int dimy,
int relief, GCallback handler, gpointer data)
1847 but = (
text) ? gtk_button_new_with_label (
text) : gtk_button_new ();
1849 but = (
text && image_format ==
IMG_NONE) ? gtk_button_new_with_label (
text) : gtk_button_new ();
1852 gtk_widget_set_size_request (but, dimx, dimy);
1854 gtk_button_set_relief (GTK_BUTTON(but), relief);
1857 if (relief == GTK_RELIEF_NONE) gtk_button_set_has_frame (GTK_BUTTON(but), FALSE);
1859 if (handler != NULL)
1861 g_signal_connect (G_OBJECT (but),
"clicked", handler, data);
1877 gtk_image_set_from_icon_name (GTK_IMAGE(widg), icon);
1879 gtk_image_set_from_icon_name (GTK_IMAGE(widg), icon, GTK_ICON_SIZE_BUTTON);
1892GtkWidget *
abox (GtkWidget * box,
char *
lab,
int vspace)
1944 scroll = gtk_scrolled_window_new ();
1946 scroll = gtk_scrolled_window_new (NULL, NULL);
1947 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(scroll), shadow);
1949 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1950 gtk_widget_set_size_request (scroll, dimx, dimy);
1952 if (box != NULL)
add_box_child_start (GTK_ORIENTATION_VERTICAL, box, scroll, TRUE, TRUE, 0);
1966 GtkWidget * expand = gtk_expander_new (name);
1968 if (file_img != NULL)
1970 GtkWidget *
img = gtk_image_new_from_file (file_img);
1971 gtk_widget_set_size_request (
img, 20, 20);
1975 gtk_expander_set_label_widget (GTK_EXPANDER(expand),
hbox);
1988 GtkCssProvider * provider = gtk_css_provider_new ();
1990 gtk_css_provider_load_from_data (provider, css, -1);
1991 gtk_style_context_add_provider_for_display (gdk_display_get_default (),
1992 GTK_STYLE_PROVIDER(provider),
1993 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
1995 gtk_css_provider_load_from_data (provider, css, -1, NULL);
1996 gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
1997 GTK_STYLE_PROVIDER(provider),
1998 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
2000 g_object_unref (provider);
2014 if (GTK_IS_WIDGET(widg))
2018 gtk_widget_destroy (widg);
2020 GtkWidget * wid = gtk_widget_get_parent (widg);
2023 if (GTK_IS_WIDGET(wid))
2025 gtk_widget_unparent (widg);
2044 gtk_window_destroy (GTK_WINDOW(dialog));
2062 gtk_native_dialog_destroy (dialog);
2063 g_object_unref (dialog);
2091 return gtk_file_chooser_get_files (chooser);
2101 return gtk_file_chooser_get_filenames (chooser);
2115 return g_file_get_parse_name (gtk_file_chooser_get_file (chooser));
2117 return gtk_file_chooser_get_filename (chooser);
2131 return g_file_get_parse_name (gtk_file_chooser_get_current_folder (chooser));
2133 return gtk_file_chooser_get_current_folder (chooser);
2147 GFile * default_file_for_saving = g_file_new_for_path (filename);
2148 gboolean
res = gtk_file_chooser_set_file (chooser, default_file_for_saving, NULL);
2151 gchar * str = g_strdup_printf (
"Impossible to locate file: %s", filename);
2167 gtk_file_chooser_set_current_folder (chooser, g_file_new_for_path (
"./"), NULL);
2169 gtk_file_chooser_set_current_folder (chooser,
"");
2184GtkFileChooserNative *
create_file_chooser (
const gchar * title, GtkWindow * parent, GtkFileChooserAction act,
const gchar * act_name)
2186 return gtk_file_chooser_native_new (title, parent, act, act_name,
"Cancel");
2199GtkWidget *
create_file_chooser (
const gchar * title, GtkWindow * parent, GtkFileChooserAction act,
const gchar * act_name)
2201 return gtk_file_chooser_dialog_new (title, parent, act,
"Cancel", GTK_RESPONSE_CANCEL, act_name, GTK_RESPONSE_ACCEPT, NULL);
2215 gtk_color_chooser_get_rgba (colob, &
col);
2229 gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER(color_win), &
col);
2244 gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER(color_win), & colo);
2264 gtk_popover_set_has_arrow (GTK_POPOVER(
pop), FALSE);
2265 gtk_popover_set_pointing_to (GTK_POPOVER(
pop), & rect);
2266 gtk_popover_popup (GTK_POPOVER(
pop));
2280 gtk_menu_popup_at_pointer (GTK_MENU (widg), event);
2294 return (GtkWidget *)gtk_widget_get_root (widg);
2296 return gtk_widget_get_toplevel (widg);
2350 gtk_widget_hide (GTK_WIDGET(win));
2366 g_signal_connect (G_OBJECT (widg),
"close-request", handler, data);
2368 g_signal_connect (G_OBJECT (widg),
"delete-event", handler, data);
GMainLoop * Event_loop[5]
Global variable declarations Global convenience function declarations Global data structure defin...
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)
GtkWidget * add_advanced_item(GtkWidget *menu, GCallback handler, gpointer data, gboolean accel, guint key, GdkModifierType mod)
GtkWidget * create_menu_item(gboolean add_mnemo, gchar *action)
#define DEFAULT_FONT_SIZE
gchar * prepare_for_title(gchar *init)
prepare a string for a window title, getting rid of all markup
void add_menu_separator(GtkWidget *menu)
GtkWidget * menu_item_new_with_submenu(gchar *name, gboolean active, GtkWidget *sub_menu)
void motion(glwin *view, gint x, gint y, GdkModifierType state)
mouse motion in the OpenGL window
gboolean spin(gpointer data)
spin
GtkWidget * dialog_cancel_apply(gchar *title, GtkWidget *parent, gboolean resiz)
create a dialog modal offering a choice to apply something or not
GdkPixbuf * convert_to_pixbuf(cairo_surface_t *surf)
convert cairo surface to GdkPixbuf
void run_this_gtk_dialog(GtkWidget *dial, GCallback handler, gpointer data)
run a GTK (3 and 4) basic GtkDialog
void file_chooser_set_current_folder(GtkFileChooser *chooser)
set current folder in a GtkFilechooser
GtkWidget * create_entry(GCallback handler, int dim, int cdim, gboolean key_release, gpointer data)
Create a GtkEntry.
void update_entry_double(GtkEntry *entry, double doubleval)
update the content of a GtkEntry as double
void set_renderer_color(int tocol, GtkCellRenderer *renderer, ColRGBA col)
set the color of a GtkCellRenderer
void adjust_label(GtkWidget *lab, int dimx, int dimy, float ax, float ay)
adjust the text position, and widget size of a GtkLabel
ColRGBA gdkrgba_to_rgba(GdkRGBA colgdk)
convert GdkRGBA color to ColRGBA color
GtkWidget * font_button(gchar *font, int dimx, int dimy, GCallback handler, gpointer data)
create a font selection button
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
GtkTextBuffer * add_buffer(GCallback handler, gpointer data, gchar *text)
create a GtkTextBuffer
GtkWidget * create_scroll(GtkWidget *box, int dimx, int dimy, int shadow)
create a scroll window
GtkWidget * dialogmodal(gchar *str, GtkWindow *parent)
Create a new dialog modal window.
void set_color_chooser_color(GtkWidget *color_win, ColRGBA col)
set the color of a color selection window
gboolean is_the_widget_visible(GtkWidget *widg)
test if a GtkWidget exist, then return if it is visible or not
void resize_this_window(GtkWidget *window, int x, int y)
resize this GtkWindow
GtkWidget * create_win(gchar *str, GtkWidget *parent, gboolean modal, gboolean resiz)
create a new GtkWindow
ColRGBA get_window_color(GtkWidget *color_win)
get the ColRGBA color from a color selection window
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.
gchar * file_chooser_get_file_name(GtkFileChooser *chooser)
get a file name from a GtkFileChooser (single file selected)
const gchar * entry_get_text(GtkEntry *entry)
get the text in a GtkEntry
GdkRGBA colrgba_togtkrgba(ColRGBA col)
convert ColRGBA color to GdkRGBA color
void update_entry_int(GtkEntry *entry, int intval)
update the content of a GtkEntry as int
G_MODULE_EXPORT gboolean hide_this_window(GtkWidget *win, GdkEvent *event, gpointer data)
hide a GtkWindow
void pop_menu_at_pointer(GtkWidget *widg, GdkEvent *event)
popup a menu at pointer location
gboolean file_chooser_set_file_name(GtkFileChooser *chooser, gchar *filename)
set file name in a GtkFilechooser
G_MODULE_EXPORT gboolean destroy_this_window(GtkWidget *win, GdkEvent *event, gpointer data)
destroy a GtkWindow
GtkWidget * stock_image(const gchar *stock_id)
create a GtkImage for the Gtk database
void add_gtk_close_event(GtkWidget *widg, GCallback handler, gpointer data)
add a close event signal and callback to a GtkWidget
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
void layout_add_widget(GtkWidget *layout, GtkWidget *child, int x_pos, int y_pos)
Add a GtkWidget in a GtkLayout.
GtkWidget * fbox(GtkWidget *box, char *lab)
gchar * file_chooser_get_current_folder(GtkFileChooser *chooser)
get the current folder for a GtkFileChooser
GtkWidget * radio_button(gchar *text, int dimx, int dimy, gboolean state, GCallback handler, gpointer data)
create a radio button
GtkWidget * spin_button(GCallback handler, double value, double start, double end, double step, int digits, int dim, gpointer data)
create a spin button
GtkWidget * check_button(gchar *text, int dimx, int dimy, gboolean state, GCallback handler, gpointer data)
create a check button
G_MODULE_EXPORT void to_activate_entry(GtkEventControllerFocus *focus, gpointer data)
GtkEntry activate signal managment.
GtkWidget * create_button(gchar *text, int image_format, gchar *image, int dimx, int dimy, int relief, GCallback handler, gpointer data)
create a simple button
GtkWidget * get_top_level(GtkWidget *widg)
get the top level container, window, of a widget
GtkWidget * create_combo()
create a GtkCombox widget, note deprecated in GTK4
GtkWidget * dialog_get_content_area(GtkWidget *widg)
prepare GtkWidget to insert content in a GtkDialog window
void button_set_image(GtkButton *but, gchar *text, int format, gpointer image)
Add an image to a GtkButton.
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
GtkWidget * cbox(GtkWidget *box, char *lab)
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.
ColRGBA get_button_color(GtkColorChooser *colob)
get the ColRGBA color from a GtkColorChooser button
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
void text_view_set_monospace(GtkWidget *view)
set the font of a GtkTextView as monospace
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
GtkWidget * new_gtk_window()
create a new GtkWindow
GtkWidget * create_image_from_data(int format, gpointer item_image)
create Gtk image for data
void gtk_label_align(GtkWidget *lab, float ax, float ay)
set text alignment in a GtkLabel
void combo_text_append(GtkWidget *combo, gchar *text)
append text in GtkComboBox widget
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
GtkWidget * create_layout(int x, int y)
create a GtkLayout / GtkFixed widget
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
GtkWidget * color_button(ColRGBA col, gboolean alpha, int dimx, int dimy, GCallback handler, gpointer data)
create a color selection button
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
GtkWidget * bbox(GtkWidget *box, char *lab)
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.
void update_entry_text(GtkEntry *entry, gchar *text)
update the content of a GtkEntry as string
void provide_gtk_css(gchar *css)
create a css provider based on the css data
GSList * file_chooser_get_file_names(GtkFileChooser *chooser)
create a file list from files selected using a GtkFileChooser
void setup_text_tags(GtkTextBuffer *buffer)
prepare the avialable text tags for the GtkTextBuffer
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
void set_image_from_icon_name(GtkWidget *widg, gchar *icon)
set a image from a stock icon name
GtkWidget * message_dialogmodal(gchar *message, gchar *title, GtkMessageType mtype, GtkButtonsType buttons, GtkWidget *parent)
create a modal (cannot be ignored) message window
void combo_text_prepend(GtkWidget *combo, gchar *text)
prepend text in GtkComboBox widget
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
ColRGBA * duplicate_color(int num, ColRGBA *col)
duplicate a ColRGBA pointer
GtkWidget * abox(GtkWidget *box, char *lab, int vspace)
box creating routine, to help design faster elements for the GUI
GtkWidget * create_expander(gchar *name, gchar *file_img)
create GtkExpander
GtkWidget * create_file_chooser(const gchar *title, GtkWindow *parent, GtkFileChooserAction act, const gchar *act_name)
create a GtkFileChooser, utility to select file(s)
void destroy_this_native_dialog(GtkNativeDialog *dialog)
destroy a GtkNativeDialog
void show_the_widgets(GtkWidget *widg)
show GtkWidget
void update_entry_long_double(GtkEntry *entry, double doubleval)
update the content of a GtkEntry as long double
void show_error(char *error, int val, GtkWidget *win)
show error message
Messaging function declarations.