static void pnl_tab_update_edge (PnlTab *self) { g_assert (PNL_IS_TAB (self)); switch (self->edge) { case GTK_POS_TOP: gtk_label_set_angle (self->title, 0.0); gtk_widget_set_hexpand (GTK_WIDGET (self), TRUE); gtk_widget_set_vexpand (GTK_WIDGET (self), FALSE); break; case GTK_POS_BOTTOM: gtk_label_set_angle (self->title, 0.0); gtk_widget_set_hexpand (GTK_WIDGET (self), TRUE); gtk_widget_set_vexpand (GTK_WIDGET (self), FALSE); break; case GTK_POS_LEFT: gtk_label_set_angle (self->title, -90.0); gtk_widget_set_hexpand (GTK_WIDGET (self), FALSE); gtk_widget_set_vexpand (GTK_WIDGET (self), TRUE); break; case GTK_POS_RIGHT: gtk_label_set_angle (self->title, 90.0); gtk_widget_set_hexpand (GTK_WIDGET (self), FALSE); gtk_widget_set_vexpand (GTK_WIDGET (self), TRUE); break; default: g_assert_not_reached (); } }
GtkWidget * pnl_tab_get_widget (PnlTab *self) { g_return_val_if_fail (PNL_IS_TAB (self), NULL); return self->widget; }
GtkPositionType pnl_tab_get_edge (PnlTab *self) { g_return_val_if_fail (PNL_IS_TAB (self), 0); return self->edge; }
const gchar * pnl_tab_get_title (PnlTab *self) { g_return_val_if_fail (PNL_IS_TAB (self), NULL); return gtk_label_get_label (self->title); }
static void pnl_tab_strip_child_title_changed (PnlTabStrip *self, GParamSpec *pspec, GtkWidget *child) { g_autofree gchar *title = NULL; GtkWidget *parent; PnlTab *tab; g_assert (PNL_IS_TAB_STRIP (self)); g_assert (GTK_IS_WIDGET (child)); tab = g_object_get_data (G_OBJECT (child), "PNL_TAB"); if (!PNL_IS_TAB (tab)) return; parent = gtk_widget_get_parent (child); gtk_container_child_get (GTK_CONTAINER (parent), child, "title", &title, NULL); pnl_tab_set_title (tab, title); }
static void pnl_tab_strip_child_position_changed (PnlTabStrip *self, GParamSpec *pspec, GtkWidget *child) { GVariant *state; GtkWidget *parent; PnlTab *tab; guint position; g_assert (PNL_IS_TAB_STRIP (self)); g_assert (GTK_IS_WIDGET (child)); tab = g_object_get_data (G_OBJECT (child), "PNL_TAB"); if (!tab || !PNL_IS_TAB (tab)) return; parent = gtk_widget_get_parent (child); gtk_container_child_get (GTK_CONTAINER (parent), child, "position", &position, NULL); gtk_container_child_set (GTK_CONTAINER (self), GTK_WIDGET (tab), "position", position, NULL); state = g_variant_new_int32 (position); gtk_actionable_set_action_target_value (GTK_ACTIONABLE (tab), state); }
void pnl_tab_set_title (PnlTab *self, const gchar *title) { g_return_if_fail (PNL_IS_TAB (self)); gtk_label_set_label (self->title, title); }
static void pnl_tab_strip_update_edge (GtkWidget *widget, gpointer user_data) { GtkPositionType edge = GPOINTER_TO_INT (user_data); g_assert (GTK_IS_WIDGET (widget)); if (PNL_IS_TAB (widget)) pnl_tab_set_edge (PNL_TAB (widget), edge); }
static void set_tab_state (GSimpleAction *action, GVariant *state, gpointer user_data) { PnlTabStrip *self = user_data; PnlTabStripPrivate *priv = pnl_tab_strip_get_instance_private (self); PnlTab *tab = NULL; const GList *iter; GList *list; gint stateval; g_assert (G_IS_SIMPLE_ACTION (action)); g_assert (PNL_IS_TAB_STRIP (self)); g_assert (state != NULL); g_assert (g_variant_is_of_type (state, G_VARIANT_TYPE_INT32)); g_simple_action_set_state (action, state); stateval = g_variant_get_int32 (state); list = gtk_container_get_children (GTK_CONTAINER (priv->stack)); for (iter = list; iter != NULL; iter = iter->next) { GtkWidget *child = iter->data; gint position = 0; gtk_container_child_get (GTK_CONTAINER (priv->stack), GTK_WIDGET (child), "position", &position, NULL); if (position == stateval) { tab = g_object_get_data (G_OBJECT (child), "PNL_TAB"); gtk_stack_set_visible_child (priv->stack, child); break; } } /* * When clicking an active toggle button, we get the state callback but then * the toggle button disables the checked state. So ensure it stays on by * manually setting the state. */ if (PNL_IS_TAB (tab)) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tab), TRUE); g_list_free (list); }
void pnl_tab_set_edge (PnlTab *self, GtkPositionType edge) { g_return_if_fail (PNL_IS_TAB (self)); g_return_if_fail (edge >= 0); g_return_if_fail (edge <= 3); if (self->edge != edge) { self->edge = edge; pnl_tab_update_edge (self); g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_EDGE]); } }
static void pnl_tab_strip_add (GtkContainer *container, GtkWidget *widget) { PnlTabStrip *self = (PnlTabStrip *)container; PnlTabStripPrivate *priv = pnl_tab_strip_get_instance_private (self); g_assert (PNL_IS_TAB_STRIP (self)); g_assert (GTK_IS_WIDGET (widget)); if (PNL_IS_TAB (widget)) pnl_tab_set_edge (PNL_TAB (widget), priv->edge); GTK_CONTAINER_CLASS (pnl_tab_strip_parent_class)->add (container, widget); }
static void pnl_tab_strip_stack_remove (PnlTabStrip *self, GtkWidget *widget, GtkStack *stack) { PnlTab *tab; g_assert (PNL_IS_TAB_STRIP (self)); g_assert (GTK_IS_WIDGET (widget)); g_assert (GTK_IS_STACK (stack)); tab = g_object_get_data (G_OBJECT (widget), "PNL_TAB"); if (PNL_IS_TAB (tab)) gtk_container_remove (GTK_CONTAINER (self), GTK_WIDGET (tab)); }
static void pnl_tab_strip_stack_notify_visible_child (PnlTabStrip *self, GParamSpec *pspec, GtkStack *stack) { GtkWidget *visible; g_assert (PNL_IS_TAB_STRIP (self)); g_assert (GTK_IS_STACK (stack)); visible = gtk_stack_get_visible_child (stack); if (visible != NULL) { PnlTab *tab = g_object_get_data (G_OBJECT (visible), "PNL_TAB"); if (PNL_IS_TAB (tab)) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tab), TRUE); } }
void pnl_tab_set_widget (PnlTab *self, GtkWidget *widget) { g_return_if_fail (PNL_IS_TAB (self)); if (self->widget != widget) { if (self->widget) g_object_remove_weak_pointer (G_OBJECT (self->widget), (gpointer *)&self->widget); self->widget = widget; if (widget) g_object_add_weak_pointer (G_OBJECT (self->widget), (gpointer *)&self->widget); gtk_label_set_mnemonic_widget (self->title, widget); g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_WIDGET]); } }