コード例 #1
0
ファイル: pnl-tab.c プロジェクト: matthiasclasen/panel-gtk
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 ();
    }
}
コード例 #2
0
ファイル: pnl-tab.c プロジェクト: matthiasclasen/panel-gtk
GtkWidget *
pnl_tab_get_widget (PnlTab *self)
{
  g_return_val_if_fail (PNL_IS_TAB (self), NULL);

  return self->widget;
}
コード例 #3
0
ファイル: pnl-tab.c プロジェクト: matthiasclasen/panel-gtk
GtkPositionType
pnl_tab_get_edge (PnlTab *self)
{
  g_return_val_if_fail (PNL_IS_TAB (self), 0);

  return self->edge;
}
コード例 #4
0
ファイル: pnl-tab.c プロジェクト: matthiasclasen/panel-gtk
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);
}
コード例 #5
0
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);
}
コード例 #6
0
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);
}
コード例 #7
0
ファイル: pnl-tab.c プロジェクト: matthiasclasen/panel-gtk
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);
}
コード例 #8
0
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);
}
コード例 #9
0
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);
}
コード例 #10
0
ファイル: pnl-tab.c プロジェクト: matthiasclasen/panel-gtk
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]);
    }
}
コード例 #11
0
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);
}
コード例 #12
0
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));
}
コード例 #13
0
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);
    }
}
コード例 #14
0
ファイル: pnl-tab.c プロジェクト: matthiasclasen/panel-gtk
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]);
    }
}