コード例 #1
0
static gboolean
gimp_container_grid_view_focus (GtkWidget        *widget,
                                GtkDirectionType  direction)
{
  GimpContainerGridView *view = GIMP_CONTAINER_GRID_VIEW (widget);

  if (gtk_widget_get_can_focus (widget) && ! gtk_widget_has_focus (widget))
    {
      gtk_widget_grab_focus (GTK_WIDGET (widget));
      return TRUE;
    }

  switch (direction)
    {
    case GTK_DIR_UP:
      return gimp_container_grid_view_move_by (view,  0, -1);
    case GTK_DIR_DOWN:
      return gimp_container_grid_view_move_by (view,  0,  1);
    case GTK_DIR_LEFT:
      return gimp_container_grid_view_move_by (view, -1,  0);
    case GTK_DIR_RIGHT:
      return gimp_container_grid_view_move_by (view,  1,  0);

    case GTK_DIR_TAB_FORWARD:
    case GTK_DIR_TAB_BACKWARD:
      break;
    }

  return FALSE;
}
コード例 #2
0
static void
gimp_container_grid_view_menu_position (GtkMenu  *menu,
                                        gint     *x,
                                        gint     *y,
                                        gpointer  data)
{
  GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (data);
  GtkWidget             *widget;

  if (grid_view->selected_item)
    widget = GTK_WIDGET (grid_view->selected_item);
  else
    widget = GTK_WIDGET (grid_view->wrap_box);

  gdk_window_get_origin (widget->window, x, y);

  if (GTK_WIDGET_NO_WINDOW (widget))
    {
      *x += widget->allocation.x;
      *y += widget->allocation.y;
    }

  if (grid_view->selected_item)
    {
      *x += widget->allocation.width  / 2;
      *y += widget->allocation.height / 2;
    }
  else
    {
      *x += widget->style->xthickness;
      *y += widget->style->ythickness;
    }

  gimp_menu_position (menu, x, y);
}
コード例 #3
0
static gboolean
gimp_container_grid_view_popup_menu (GtkWidget *widget)
{
  GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (widget);

  return gimp_editor_popup_menu (GIMP_EDITOR (widget),
                                 gimp_container_grid_view_menu_position,
                                 grid_view);
}
コード例 #4
0
static void
gimp_container_grid_view_reorder_item (GimpContainerView *container_view,
                                       GimpViewable      *viewable,
                                       gint               new_index,
                                       gpointer           insert_data)
{
  GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (container_view);
  GtkWidget             *view      = GTK_WIDGET (insert_data);

  gtk_wrap_box_reorder_child (GTK_WRAP_BOX (grid_view->wrap_box),
                              view, new_index);
}
コード例 #5
0
static void
gimp_container_grid_view_clear_items (GimpContainerView *view)
{
  GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (view);

  grid_view->selected_item = NULL;

  while (GTK_WRAP_BOX (grid_view->wrap_box)->children)
    gtk_container_remove (GTK_CONTAINER (grid_view->wrap_box),
                          GTK_WRAP_BOX (grid_view->wrap_box)->children->widget);

  parent_view_iface->clear_items (view);
}
コード例 #6
0
static void
gimp_container_grid_view_remove_item (GimpContainerView *container_view,
                                      GimpViewable      *viewable,
                                      gpointer           insert_data)
{
  GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (container_view);
  GtkWidget             *view      = GTK_WIDGET (insert_data);

  if (view == (GtkWidget *) grid_view->selected_item)
    grid_view->selected_item = NULL;

  gtk_container_remove (GTK_CONTAINER (grid_view->wrap_box), view);
}
コード例 #7
0
static void
gimp_container_grid_view_rename_item (GimpContainerView *container_view,
                                      GimpViewable      *viewable,
                                      gpointer           insert_data)
{
  GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (container_view);
  GtkWidget             *view      = GTK_WIDGET (insert_data);

  if (view == (GtkWidget *) grid_view->selected_item)
    {
      gchar *name = gimp_viewable_get_description (viewable, NULL);

      gimp_editor_set_name (GIMP_EDITOR (container_view), name);
      g_free (name);
    }
}
コード例 #8
0
static void
gimp_container_grid_view_set_context (GimpContainerView *view,
                                      GimpContext       *context)
{
  GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (view);
  GtkWrapBoxChild       *child;

  parent_view_iface->set_context (view, context);

  for (child = GTK_WRAP_BOX (grid_view->wrap_box)->children;
       child;
       child = child->next)
    {
      GimpView *view = GIMP_VIEW (child->widget);

      gimp_view_renderer_set_context (view->renderer, context);
    }
}
コード例 #9
0
static gpointer
gimp_container_grid_view_insert_item (GimpContainerView *container_view,
                                      GimpViewable      *viewable,
                                      gpointer           parent_insert_data,
                                      gint               index)
{
  GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (container_view);
  GtkWidget             *view;
  gint                   view_size;

  view_size = gimp_container_view_get_view_size (container_view, NULL);

  view = gimp_view_new_full (gimp_container_view_get_context (container_view),
                             viewable,
                             view_size, view_size, 1,
                             FALSE, TRUE, TRUE);
  gimp_view_renderer_set_border_type (GIMP_VIEW (view)->renderer,
                                      GIMP_VIEW_BORDER_WHITE);
  gimp_view_renderer_remove_idle (GIMP_VIEW (view)->renderer);

  gtk_wrap_box_pack (GTK_WRAP_BOX (grid_view->wrap_box), view,
                     FALSE, FALSE, FALSE, FALSE);

  if (index != -1)
    gtk_wrap_box_reorder_child (GTK_WRAP_BOX (grid_view->wrap_box),
                                view, index);

  gtk_widget_show (view);

  g_signal_connect (view, "button-press-event",
                    G_CALLBACK (gimp_container_grid_view_item_selected),
                    container_view);
  g_signal_connect (view, "double-clicked",
                    G_CALLBACK (gimp_container_grid_view_item_activated),
                    container_view);
  g_signal_connect (view, "context",
                    G_CALLBACK (gimp_container_grid_view_item_context),
                    container_view);

  return (gpointer) view;
}
コード例 #10
0
static void
gimp_container_grid_view_menu_position (GtkMenu  *menu,
                                        gint     *x,
                                        gint     *y,
                                        gpointer  data)
{
  GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (data);
  GtkWidget             *widget;
  GtkAllocation          allocation;

  if (grid_view->selected_item)
    widget = GTK_WIDGET (grid_view->selected_item);
  else
    widget = GTK_WIDGET (grid_view->wrap_box);

  gtk_widget_get_allocation (widget, &allocation);

  gdk_window_get_origin (gtk_widget_get_window (widget), x, y);

  if (! gtk_widget_get_has_window (widget))
    {
      *x += allocation.x;
      *y += allocation.y;
    }

  if (grid_view->selected_item)
    {
      *x += allocation.width  / 2;
      *y += allocation.height / 2;
    }
  else
    {
      GtkStyle *style = gtk_widget_get_style (widget);

      *x += style->xthickness;
      *y += style->ythickness;
    }

  gimp_menu_position (menu, x, y);
}
コード例 #11
0
static void
gimp_container_grid_view_set_view_size (GimpContainerView *view)
{
  GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (view);
  GtkWrapBoxChild       *child;
  gint                   view_size;

  view_size = gimp_container_view_get_view_size (view, NULL);

  for (child = GTK_WRAP_BOX (grid_view->wrap_box)->children;
       child;
       child = child->next)
    {
      GimpView *view = GIMP_VIEW (child->widget);

      gimp_view_renderer_set_size (view->renderer,
                                   view_size,
                                   view->renderer->border_width);
    }

  gtk_widget_queue_resize (grid_view->wrap_box);
}
コード例 #12
0
static void
gimp_container_grid_view_highlight_item (GimpContainerView *container_view,
                                         GimpViewable      *viewable,
                                         gpointer           insert_data)
{
  GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (container_view);
  GimpContainerBox      *box       = GIMP_CONTAINER_BOX (container_view);
  GimpContainer         *container;
  GimpView              *view      = NULL;

  container = gimp_container_view_get_container (container_view);

  if (insert_data)
    view = GIMP_VIEW (insert_data);

  if (grid_view->selected_item && grid_view->selected_item != view)
    {
      gimp_view_renderer_set_border_type (grid_view->selected_item->renderer,
                                          GIMP_VIEW_BORDER_WHITE);
      gimp_view_renderer_update (grid_view->selected_item->renderer);
    }

  if (view)
    {
      GtkRequisition  view_requisition;
      GtkAdjustment  *adj;
      gint            item_height;
      gint            index;
      gint            row;
      gchar          *name;

      adj = gtk_scrolled_window_get_vadjustment
        (GTK_SCROLLED_WINDOW (box->scrolled_win));

      gtk_widget_size_request (GTK_WIDGET (view), &view_requisition);

      item_height = view_requisition.height;

      index = gimp_container_get_child_index (container,
                                              GIMP_OBJECT (viewable));

      row = index / grid_view->columns;

      if (row * item_height < gtk_adjustment_get_value (adj))
        {
          gtk_adjustment_set_value (adj, row * item_height);
        }
      else if ((row + 1) * item_height > (gtk_adjustment_get_value (adj) +
                                          gtk_adjustment_get_page_size (adj)))
        {
          gtk_adjustment_set_value (adj,
                                    (row + 1) * item_height -
                                    gtk_adjustment_get_page_size (adj));
        }

      gimp_view_renderer_set_border_type (view->renderer,
                                          GIMP_VIEW_BORDER_BLACK);
      gimp_view_renderer_update (view->renderer);

      name = gimp_viewable_get_description (view->renderer->viewable, NULL);
      gimp_editor_set_name (GIMP_EDITOR (grid_view), name);
      g_free (name);
    }
  else
    {
      gimp_editor_set_name (GIMP_EDITOR (grid_view), NULL);
    }

  grid_view->selected_item = view;
}