2007-06-06 00:30:13 +00:00
|
|
|
/*
|
2014-01-19 01:09:44 +00:00
|
|
|
* This file Copyright (C) 2007-2014 Mnemosyne LLC
|
2007-06-06 00:30:13 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2008-09-23 19:11:04 +00:00
|
|
|
*
|
2007-06-06 00:30:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
2021-08-15 09:41:48 +00:00
|
|
|
|
|
|
|
#include <libtransmission/tr-macros.h>
|
|
|
|
|
2007-06-06 00:30:13 +00:00
|
|
|
#include "hig.h"
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWidget* hig_workarea_create(void)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWidget* grid = gtk_grid_new();
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(grid), GUI_PAD_BIG);
|
|
|
|
gtk_grid_set_row_spacing(GTK_GRID(grid), GUI_PAD);
|
|
|
|
gtk_grid_set_column_spacing(GTK_GRID(grid), GUI_PAD_BIG);
|
2012-07-14 19:26:55 +00:00
|
|
|
|
|
|
|
return grid;
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void hig_workarea_add_section_divider(GtkWidget* t, guint* row)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2019-11-06 19:09:27 +00:00
|
|
|
GtkWidget* w = gtk_fixed_new();
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2019-03-17 04:07:48 +00:00
|
|
|
gtk_widget_set_size_request(w, 0U, 6U);
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_grid_attach(GTK_GRID(t), w, 0, *row, 2, 1);
|
|
|
|
++*row;
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void hig_workarea_add_section_title_widget(GtkWidget* t, guint* row, GtkWidget* w)
|
2008-06-02 04:41:55 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_widget_set_hexpand(w, TRUE);
|
|
|
|
gtk_grid_attach(GTK_GRID(t), w, 0, *row, 2, 1);
|
|
|
|
++*row;
|
2008-06-02 04:41:55 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void hig_workarea_add_section_title(GtkWidget* t, guint* row, char const* section_title)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2011-08-13 21:08:53 +00:00
|
|
|
char buf[512];
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWidget* l;
|
2008-02-12 16:56:44 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_snprintf(buf, sizeof(buf), "<b>%s</b>", section_title);
|
|
|
|
l = gtk_label_new(buf);
|
2019-11-06 19:09:27 +00:00
|
|
|
g_object_set(l, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, NULL);
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_label_set_use_markup(GTK_LABEL(l), TRUE);
|
|
|
|
hig_workarea_add_section_title_widget(t, row, l);
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void hig_workarea_add_wide_control(GtkWidget* t, guint* row, GtkWidget* w)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_widget_set_hexpand(w, TRUE);
|
2019-11-06 19:09:27 +00:00
|
|
|
#if GTK_CHECK_VERSION(3, 12, 0)
|
|
|
|
gtk_widget_set_margin_start(w, 18);
|
|
|
|
#else
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_widget_set_margin_left(w, 18);
|
2019-11-06 19:09:27 +00:00
|
|
|
#endif
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_grid_attach(GTK_GRID(t), w, 0, *row, 2, 1);
|
|
|
|
++*row;
|
2007-12-13 19:54:24 +00:00
|
|
|
}
|
2019-07-14 21:30:14 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void hig_workarea_add_wide_tall_control(GtkWidget* t, guint* row, GtkWidget* w)
|
2009-10-28 03:54:36 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_widget_set_hexpand(w, TRUE);
|
|
|
|
gtk_widget_set_vexpand(w, TRUE);
|
|
|
|
hig_workarea_add_wide_control(t, row, w);
|
2009-10-28 03:54:36 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
GtkWidget* hig_workarea_add_wide_checkbutton(GtkWidget* t, guint* row, char const* mnemonic_string, gboolean is_active)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWidget* w = gtk_check_button_new_with_mnemonic(mnemonic_string);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), is_active);
|
|
|
|
hig_workarea_add_wide_control(t, row, w);
|
2008-02-12 16:56:44 +00:00
|
|
|
return w;
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void hig_workarea_add_label_w(GtkWidget* t, guint row, GtkWidget* w)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2019-11-06 19:09:27 +00:00
|
|
|
#if GTK_CHECK_VERSION(3, 12, 0)
|
|
|
|
gtk_widget_set_margin_start(w, 18);
|
|
|
|
#else
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_widget_set_margin_left(w, 18);
|
2019-11-06 19:09:27 +00:00
|
|
|
#endif
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (GTK_IS_LABEL(w))
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
g_object_set(
|
|
|
|
w,
|
|
|
|
TR_ARG_TUPLE("halign", GTK_ALIGN_START),
|
|
|
|
TR_ARG_TUPLE("valign", GTK_ALIGN_CENTER),
|
|
|
|
TR_ARG_TUPLE("use-markup", TRUE),
|
2020-08-27 23:41:26 +00:00
|
|
|
NULL);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_grid_attach(GTK_GRID(t), w, 0, row, 1, 1);
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void hig_workarea_add_tall_control(GtkWidget* t, guint row, GtkWidget* control)
|
2009-09-17 01:21:49 +00:00
|
|
|
{
|
2020-08-27 23:41:26 +00:00
|
|
|
if (GTK_IS_LABEL(control))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
g_object_set(control, TR_ARG_TUPLE("halign", GTK_ALIGN_START), TR_ARG_TUPLE("valign", GTK_ALIGN_CENTER), NULL);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-09-17 01:21:49 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_object_set(control, "expand", TRUE, NULL);
|
|
|
|
gtk_grid_attach(GTK_GRID(t), control, 1, row, 1, 1);
|
2009-09-17 01:21:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void hig_workarea_add_control(GtkWidget* t, guint row, GtkWidget* control)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2020-08-27 23:41:26 +00:00
|
|
|
if (GTK_IS_LABEL(control))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
g_object_set(control, TR_ARG_TUPLE("halign", GTK_ALIGN_START), TR_ARG_TUPLE("valign", GTK_ALIGN_CENTER), NULL);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2007-06-07 17:53:54 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_widget_set_hexpand(control, TRUE);
|
|
|
|
gtk_grid_attach(GTK_GRID(t), control, 1, row, 1, 1);
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void hig_workarea_add_row_w(GtkWidget* t, guint* row, GtkWidget* label, GtkWidget* control, GtkWidget* mnemonic)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
hig_workarea_add_label_w(t, *row, label);
|
|
|
|
hig_workarea_add_control(t, *row, control);
|
|
|
|
|
|
|
|
if (GTK_IS_LABEL(label))
|
|
|
|
{
|
|
|
|
gtk_label_set_mnemonic_widget(GTK_LABEL(label), mnemonic ? mnemonic : control);
|
|
|
|
}
|
|
|
|
|
|
|
|
++*row;
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
GtkWidget* hig_workarea_add_row(GtkWidget* t, guint* row, char const* mnemonic_string, GtkWidget* control, GtkWidget* mnemonic)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWidget* l = gtk_label_new_with_mnemonic(mnemonic_string);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
hig_workarea_add_row_w(t, row, l, control, mnemonic);
|
2008-02-12 16:56:44 +00:00
|
|
|
return l;
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
GtkWidget* hig_workarea_add_tall_row(
|
|
|
|
GtkWidget* table,
|
|
|
|
guint* row,
|
|
|
|
char const* mnemonic_string,
|
|
|
|
GtkWidget* control,
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWidget* mnemonic)
|
2009-09-17 01:21:49 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWidget* l = gtk_label_new_with_mnemonic(mnemonic_string);
|
|
|
|
GtkWidget* h = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
GtkWidget* v = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(h), l, FALSE, FALSE, 0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(v), h, FALSE, FALSE, GUI_PAD_SMALL);
|
2012-12-05 17:29:46 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
hig_workarea_add_label_w(table, *row, v);
|
|
|
|
hig_workarea_add_tall_control(table, *row, control);
|
2012-12-05 17:29:46 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (GTK_IS_LABEL(l))
|
|
|
|
{
|
|
|
|
gtk_label_set_mnemonic_widget(GTK_LABEL(l), mnemonic ? mnemonic : control);
|
|
|
|
}
|
2009-09-17 01:21:49 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
++*row;
|
2009-09-17 01:21:49 +00:00
|
|
|
return l;
|
|
|
|
}
|