void
gimp_display_shell_clear_software_cursor (GimpDisplayShell *shell)
{
  GimpStatusbar     *statusbar;
  GimpSessionInfo   *session_info;

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

  gimp_canvas_item_set_visible (shell->cursor, FALSE);

  statusbar = gimp_display_shell_get_statusbar (shell);

  gimp_statusbar_clear_cursor (statusbar);

  session_info = gimp_dialog_factory_find_session_info (gimp_dialog_factory_get_singleton (),
                                                        "gimp-cursor-view");
  if (session_info && gimp_session_info_get_widget (session_info))
    {
      GtkWidget *cursor_view;

      cursor_view = gtk_bin_get_child (GTK_BIN (gimp_session_info_get_widget (session_info)));

      if (cursor_view)
        gimp_cursor_view_clear_cursor (GIMP_CURSOR_VIEW (cursor_view));
    }
}
Beispiel #2
0
static gboolean
dialogs_actions_toolbox_exists (Gimp *gimp)
{
  GimpDialogFactory *factory       = gimp_dialog_factory_get_singleton ();
  GimpSessionInfo   *info          = NULL;
  GList             *windows       = gimp ? gimp_get_image_windows (gimp) : NULL;
  gboolean           toolbox_found = FALSE;
  GList             *iter;

  /* First look in session managed windows */
  info = gimp_dialog_factory_find_session_info (factory, "gimp-toolbox-window");
  toolbox_found = info && gimp_session_info_get_widget (info);

  /* Then in image windows */
  if (! toolbox_found)
    {
      for (iter = windows; iter; iter = g_list_next (iter))
        {
          GimpImageWindow *window = GIMP_IMAGE_WINDOW (windows->data);
      
          if (gimp_image_window_has_toolbox (window))
            {
              toolbox_found = TRUE;
              break;
            }
        }
    }

  return toolbox_found;
}
Beispiel #3
0
/**
 * gimp_dialog_factory_dialog_raise:
 * @factory:      a #GimpDialogFactory
 * @screen:       the #GdkScreen the dialog should appear on
 * @identifiers:  a '|' separated list of identifiers of dialogs as
 *                registered with gimp_dialog_factory_register_entry()
 * @view_size:
 *
 * Raises any of a list of already existing toplevel dialog or
 * #GimpDockable if it was already created by this %facory.
 *
 * Implicitly creates the first dialog in the list if none of the dialogs
 * were found.
 *
 * Return value: the raised or newly created dialog.
 **/
GtkWidget *
gimp_dialog_factory_dialog_raise (GimpDialogFactory *factory,
                                  GdkScreen         *screen,
                                  const gchar       *identifiers,
                                  gint               view_size)
{
  GtkWidget *dialog;

  g_return_val_if_fail (GIMP_IS_DIALOG_FACTORY (factory), NULL);
  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
  g_return_val_if_fail (identifiers != NULL, NULL);

  /*  If the identifier is a list, try to find a matching dialog and
   *  raise it. If there's no match, use the first list item.
   */
  if (strchr (identifiers, '|'))
    {
      gchar **ids = g_strsplit (identifiers, "|", 0);
      gint    i;

      for (i = 0; ids[i]; i++)
        {
          GimpSessionInfo *info;

          info = gimp_dialog_factory_find_session_info (factory, ids[i]);
          if (info && info->widget)
            break;
        }

      dialog = gimp_dialog_factory_dialog_new_internal (factory,
                                                        screen,
                                                        NULL,
                                                        ids[i] ? ids[i] : ids[0],
                                                        view_size,
                                                        TRUE,
                                                        TRUE);
      g_strfreev (ids);
    }
  else
    {
      dialog = gimp_dialog_factory_dialog_new_internal (factory,
                                                        screen,
                                                        NULL,
                                                        identifiers,
                                                        view_size,
                                                        TRUE,
                                                        TRUE);
    }

  return dialog;
}
static GimpColormapEditor *
context_get_colormap_editor (void)
{
  GimpSessionInfo *info = NULL;

  g_return_val_if_fail (GIMP_IS_DIALOG_FACTORY (gimp_dialog_factory_get_singleton ()), NULL);

  info = gimp_dialog_factory_find_session_info (gimp_dialog_factory_get_singleton (),
                                                "gimp-indexed-palette");
  if (info && gimp_session_info_get_widget (info))
    return GIMP_COLORMAP_EDITOR (gtk_bin_get_child (GTK_BIN (gimp_session_info_get_widget (info))));

  return NULL;
}
static GimpPaletteEditor *
context_get_palette_editor (void)
{
  GimpSessionInfo *info = NULL;

  g_return_val_if_fail (GIMP_IS_DIALOG_FACTORY (gimp_dialog_factory_get_singleton ()), NULL);

  info = gimp_dialog_factory_find_session_info (gimp_dialog_factory_get_singleton (),
                                                "gimp-palette-editor");
  if (info && gimp_session_info_get_widget (info))
    return GIMP_PALETTE_EDITOR (gtk_bin_get_child (GTK_BIN (gimp_session_info_get_widget (info))));

  return NULL;
}
Beispiel #6
0
void
gimp_display_shell_clear_cursor (GimpDisplayShell *shell)
{
    GimpDialogFactory *factory;
    GimpSessionInfo   *session_info;

    g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

    gimp_statusbar_clear_cursor (GIMP_STATUSBAR (shell->statusbar));

    factory = gimp_dialog_factory_from_name ("dock");
    session_info = gimp_dialog_factory_find_session_info (factory,
                   "gimp-cursor-view");
    if (session_info && session_info->widget)
    {
        GtkWidget *cursor_view;

        cursor_view = gtk_bin_get_child (GTK_BIN (session_info->widget));

        if (cursor_view)
            gimp_cursor_view_clear_cursor (GIMP_CURSOR_VIEW (cursor_view));
    }
}
Beispiel #7
0
static gboolean
gui_message_error_console (GimpMessageSeverity  severity,
                           const gchar         *domain,
                           const gchar         *message)
{
  GtkWidget *dockable = NULL;

  /* try to avoid raising the error console for not so severe messages */
  if (severity < GIMP_MESSAGE_ERROR)
    {
      GimpSessionInfo *info;

      info = gimp_dialog_factory_find_session_info (global_dock_factory,
                                                    "gimp-error-console");

      if (info && GIMP_IS_DOCKABLE (info->widget))
        dockable = info->widget;
    }

  if (! dockable)
    dockable = gimp_dialog_factory_dialog_raise (global_dock_factory,
                                                 gdk_screen_get_default (),
                                                 "gimp-error-console", -1);

  if (dockable)
    {
      GtkWidget *child = gtk_bin_get_child (GTK_BIN (dockable));

      gimp_error_console_add (GIMP_ERROR_CONSOLE (child),
                              severity, domain, message);

      return TRUE;
    }

  return FALSE;
}
void
gimp_display_shell_update_software_cursor (GimpDisplayShell    *shell,
                                           GimpCursorPrecision  precision,
                                           gint                 display_x,
                                           gint                 display_y,
                                           gdouble              image_x,
                                           gdouble              image_y)
{
  GimpStatusbar   *statusbar;
  GimpSessionInfo *session_info;
  GimpImage       *image;

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

  image = gimp_display_get_image (shell->display);

  if (shell->draw_cursor &&
      shell->proximity   &&
      display_x >= 0     &&
      display_y >= 0)
    {
      gimp_canvas_item_begin_change (shell->cursor);

      gimp_canvas_cursor_set (shell->cursor,
                              display_x,
                              display_y);
      gimp_canvas_item_set_visible (shell->cursor, TRUE);

      gimp_canvas_item_end_change (shell->cursor);
    }
  else
    {
      gimp_canvas_item_set_visible (shell->cursor, FALSE);
    }

  /*  use the passed image_coords for the statusbar because they are
   *  possibly snapped...
   */
  statusbar = gimp_display_shell_get_statusbar (shell);

  gimp_statusbar_update_cursor (statusbar, precision, image_x, image_y);

  session_info = gimp_dialog_factory_find_session_info (gimp_dialog_factory_get_singleton (),
                                                        "gimp-cursor-view");
  if (session_info && gimp_session_info_get_widget (session_info))
    {
      GtkWidget *cursor_view;

      cursor_view = gtk_bin_get_child (GTK_BIN (gimp_session_info_get_widget (session_info)));

      if (cursor_view)
        {
          gint t_x = -1;
          gint t_y = -1;

          /*  ...but use the unsnapped display_coords for the info window  */
          if (display_x >= 0 && display_y >= 0)
            gimp_display_shell_untransform_xy (shell, display_x, display_y,
                                               &t_x, &t_y, FALSE);

          gimp_cursor_view_update_cursor (GIMP_CURSOR_VIEW (cursor_view),
                                          image, shell->unit,
                                          t_x, t_y);
        }
    }
}
Beispiel #9
0
static void
gimp_color_tool_real_picked (GimpColorTool      *color_tool,
                             GimpColorPickState  pick_state,
                             GimpImageType       sample_type,
                             GimpRGB            *color,
                             gint                color_index)
{
  GimpTool          *tool = GIMP_TOOL (color_tool);
  GimpContext       *context;
  GimpDialogFactory *dialog_factory;

  /*  use this tool's own options here (NOT color_tool->options)  */
  context = GIMP_CONTEXT (gimp_tool_get_options (tool));

  dialog_factory = gimp_dialog_factory_from_name ("dock");

  if (color_tool->pick_mode == GIMP_COLOR_PICK_MODE_FOREGROUND ||
      color_tool->pick_mode == GIMP_COLOR_PICK_MODE_BACKGROUND)
    {
      GimpSessionInfo *info;

      if (GIMP_IMAGE_TYPE_IS_INDEXED (sample_type))
        {
          info = gimp_dialog_factory_find_session_info (dialog_factory,
                                                        "gimp-indexed-palette");
          if (info && info->widget)
            {
              GimpColormapEditor *editor;

              editor = GIMP_COLORMAP_EDITOR (gtk_bin_get_child (GTK_BIN (info->widget)));

              gimp_colormap_editor_set_index (editor, color_index, NULL);
            }
        }

      if (TRUE)
        {
          info = gimp_dialog_factory_find_session_info (dialog_factory,
                                                        "gimp-palette-editor");
          if (info && info->widget)
            {
              GimpPaletteEditor *editor;
              gint               index;

              editor = GIMP_PALETTE_EDITOR (gtk_bin_get_child (GTK_BIN (info->widget)));

              index = gimp_palette_editor_get_index (editor, color);
              if (index != -1)
                gimp_palette_editor_set_index (editor, index, NULL);
            }
        }
    }

  switch (color_tool->pick_mode)
    {
    case GIMP_COLOR_PICK_MODE_NONE:
      break;

    case GIMP_COLOR_PICK_MODE_FOREGROUND:
      gimp_context_set_foreground (context, color);
      break;

    case GIMP_COLOR_PICK_MODE_BACKGROUND:
      gimp_context_set_background (context, color);
      break;

    case GIMP_COLOR_PICK_MODE_PALETTE:
      {
        GdkScreen *screen;
        GtkWidget *dockable;

        screen = gtk_widget_get_screen (tool->display->shell);
        dockable = gimp_dialog_factory_dialog_raise (dialog_factory, screen,
                                                     "gimp-palette-editor",
                                                     -1);
        if (dockable)
          {
            GtkWidget *palette_editor;
            GimpData  *data;

            /* don't blink like mad when updating */
            if (pick_state == GIMP_COLOR_PICK_STATE_UPDATE)
              gimp_dockable_blink_cancel (GIMP_DOCKABLE (dockable));

            palette_editor = gtk_bin_get_child (GTK_BIN (dockable));

            data = gimp_data_editor_get_data (GIMP_DATA_EDITOR (palette_editor));

            if (! data)
              {
                data = GIMP_DATA (gimp_context_get_palette (context));

                gimp_data_editor_set_data (GIMP_DATA_EDITOR (palette_editor),
                                           data);
              }

            gimp_palette_editor_pick_color (GIMP_PALETTE_EDITOR (palette_editor),
                                            color, pick_state);
          }
      }
      break;
    }
}
Beispiel #10
0
void
gimp_display_shell_update_cursor (GimpDisplayShell *shell,
                                  gint              display_x,
                                  gint              display_y,
                                  gint              image_x,
                                  gint              image_y)
{
    GimpDialogFactory *factory;
    GimpSessionInfo   *session_info;
    GimpImage         *image;
    gboolean           new_cursor;

    g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

    image = shell->display->image;

    new_cursor = (shell->draw_cursor &&
                  shell->proximity   &&
                  display_x >= 0     &&
                  display_y >= 0);

    /* Erase old cursor, if necessary */

    if (shell->have_cursor && (! new_cursor                 ||
                               display_x != shell->cursor_x ||
                               display_y != shell->cursor_y))
    {
        gimp_display_shell_expose_area (shell,
                                        shell->cursor_x - 7,
                                        shell->cursor_y - 7,
                                        15, 15);
        if (! new_cursor)
            shell->have_cursor = FALSE;
    }

    shell->have_cursor = new_cursor;
    shell->cursor_x    = display_x;
    shell->cursor_y    = display_y;

    /*  use the passed image_coords for the statusbar because they are
     *  possibly snapped...
     */
    gimp_statusbar_update_cursor (GIMP_STATUSBAR (shell->statusbar),
                                  image_x, image_y);

    factory = gimp_dialog_factory_from_name ("dock");
    session_info = gimp_dialog_factory_find_session_info (factory,
                   "gimp-cursor-view");
    if (session_info && session_info->widget)
    {
        GtkWidget *cursor_view;

        cursor_view = gtk_bin_get_child (GTK_BIN (session_info->widget));

        if (cursor_view)
        {
            gint t_x = -1;
            gint t_y = -1;

            /*  ...but use the unsnapped display_coords for the info window  */
            if (display_x >= 0 && display_y >= 0)
                gimp_display_shell_untransform_xy (shell, display_x, display_y,
                                                   &t_x, &t_y, FALSE, FALSE);

            gimp_cursor_view_update_cursor (GIMP_CURSOR_VIEW (cursor_view),
                                            shell->display->image, shell->unit,
                                            t_x, t_y);
        }
    }
}
Beispiel #11
0
static GtkWidget *
gimp_dialog_factory_dialog_new_internal (GimpDialogFactory *factory,
                                         GdkScreen         *screen,
                                         GimpContext       *context,
                                         const gchar       *identifier,
                                         gint               view_size,
                                         gboolean           return_existing,
                                         gboolean           present)
{
  GimpDialogFactoryEntry *entry;
  GtkWidget              *dialog = NULL;

  g_return_val_if_fail (GIMP_IS_DIALOG_FACTORY (factory), NULL);
  g_return_val_if_fail (identifier != NULL, NULL);

  entry = gimp_dialog_factory_find_entry (factory, identifier);

  if (! entry)
    {
      g_warning ("%s: no entry registered for \"%s\"",
                 G_STRFUNC, identifier);
      return NULL;
    }

  if (! entry->new_func)
    {
      g_warning ("%s: entry for \"%s\" has no constructor",
                 G_STRFUNC, identifier);
      return NULL;
    }

  /*  a singleton dialog is always returned if it already exisits  */
  if (return_existing || entry->singleton)
    {
      GimpSessionInfo *info;

      info = gimp_dialog_factory_find_session_info (factory, identifier);

      if (info)
        dialog = info->widget;
    }

  /*  create the dialog if it was not found  */
  if (! dialog)
    {
      GtkWidget *dock = NULL;

      /*  If the dialog will be a dockable (factory->new_dock_func) and
       *  we are called from gimp_dialog_factory_dialog_raise() (! context),
       *  create a new dock _before_ creating the dialog.
       *  We do this because the new dockable needs to be created in it's
       *  dock's context.
       */
      if (factory->new_dock_func && ! context)
        {
          GtkWidget *dockbook;

          dock     = gimp_dialog_factory_dock_new (factory, screen);
          dockbook = gimp_dockbook_new (factory->menu_factory);

          gimp_dock_add_book (GIMP_DOCK (dock),
                              GIMP_DOCKBOOK (dockbook),
                              0);
        }

      /*  Create the new dialog in the appropriate context which is
       *  - the passed context if not NULL
       *  - the newly created dock's context if we just created it
       *  - the factory's context, which happens when raising a toplevel
       *    dialog was the original request.
       */
      if (view_size < GIMP_VIEW_SIZE_TINY)
        view_size = entry->view_size;

      if (context)
        dialog = factory->constructor (factory, entry,
                                       context,
                                       view_size);
      else if (dock)
        dialog = factory->constructor (factory, entry,
                                       GIMP_DOCK (dock)->context,
                                       view_size);
      else
        dialog = factory->constructor (factory, entry,
                                       factory->context,
                                       view_size);

      if (dialog)
        {
          gimp_dialog_factory_set_widget_data (dialog, factory, entry);

          /*  If we created a dock before, the newly created dialog is
           *  supposed to be a GimpDockable.
           */
          if (dock)
            {
              if (GIMP_IS_DOCKABLE (dialog))
                {
                  gimp_dock_add (GIMP_DOCK (dock), GIMP_DOCKABLE (dialog),
                                 0, 0);

                  gtk_widget_show (dock);
                }
              else
                {
                  g_warning ("%s: GimpDialogFactory is a dockable factory "
                             "but constructor for \"%s\" did not return a "
                             "GimpDockable",
                             G_STRFUNC, identifier);

                  gtk_widget_destroy (dialog);
                  gtk_widget_destroy (dock);

                  dialog = NULL;
                  dock   = NULL;
                }
            }
        }
      else if (dock)
        {
          g_warning ("%s: constructor for \"%s\" returned NULL",
                     G_STRFUNC, identifier);

          gtk_widget_destroy (dock);

          dock = NULL;
        }

      if (dialog)
        gimp_dialog_factory_add_dialog (factory, dialog);
    }

  /*  Finally, if we found an existing dialog or created a new one, raise it.
   */
  if (! dialog)
    return NULL;

  if (GTK_WIDGET_TOPLEVEL (dialog))
    {
      gtk_window_set_screen (GTK_WINDOW (dialog), screen);

      if (present)
        gtk_window_present (GTK_WINDOW (dialog));
    }
  else if (GIMP_IS_DOCKABLE (dialog))
    {
      GimpDockable *dockable = GIMP_DOCKABLE (dialog);

      if (dockable->dockbook && dockable->dockbook->dock)
        {
          GtkNotebook *notebook = GTK_NOTEBOOK (dockable->dockbook);
          gint         num      = gtk_notebook_page_num (notebook, dialog);

          if (num != -1)
            {
              gtk_notebook_set_current_page (notebook, num);

              gimp_dockable_blink (dockable);
            }
        }

      if (present)
        {
          GtkWidget *toplevel = gtk_widget_get_toplevel (dialog);

          if (GTK_IS_WINDOW (toplevel))
            gtk_window_present (GTK_WINDOW (toplevel));
        }
    }

  return dialog;
}