Beispiel #1
0
static GObject *
gimp_message_box_constructor (GType                  type,
                              guint                  n_params,
                              GObjectConstructParam *params)
{
  GObject        *object;
  GimpMessageBox *box;

  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);

  box = GIMP_MESSAGE_BOX (object);

  if (box->stock_id)
    {
      gtk_widget_push_composite_child ();
      box->image = gtk_image_new_from_stock (box->stock_id,
                                             GTK_ICON_SIZE_DIALOG);
      gtk_widget_pop_composite_child ();

      gtk_misc_set_alignment (GTK_MISC (box->image), 0.0, 0.0);
      gtk_widget_set_parent (box->image, GTK_WIDGET (box));
      gtk_widget_show (box->image);
    }

  return object;
}
Beispiel #2
0
void
gui_abort (const gchar *abort_message)
{
  GtkWidget *dialog;
  GtkWidget *box;

  g_return_if_fail (abort_message != NULL);

  dialog = gimp_dialog_new (_("GIMP Message"), "gimp-abort",
                            NULL, GTK_DIALOG_MODAL, NULL, NULL,
                            GTK_STOCK_OK, GTK_RESPONSE_OK,
                            NULL);

  gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);

  box = g_object_new (GIMP_TYPE_MESSAGE_BOX,
                      "icon-name",    GIMP_STOCK_WILBER_EEK,
                      "border-width", 12,
                      NULL);

  gimp_message_box_set_text (GIMP_MESSAGE_BOX (box), "%s", abort_message);

  gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
                      box, TRUE, TRUE, 0);
  gtk_widget_show (box);

  gimp_dialog_run (GIMP_DIALOG (dialog));

  exit (EXIT_FAILURE);
}
static void
gimp_message_box_size_allocate (GtkWidget     *widget,
                                GtkAllocation *allocation)
{
  GimpMessageBox *box       = GIMP_MESSAGE_BOX (widget);
  GtkContainer   *container = GTK_CONTAINER (widget);
  gint            width     = 0;
  gboolean        rtl;

  rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);

  if (box->image && gtk_widget_get_visible (box->image))
    {
      GtkRequisition  child_requisition;
      GtkAllocation   child_allocation;
      gint            border_width;
      gint            height;

      gtk_widget_size_request (box->image, &child_requisition);

      border_width = gtk_container_get_border_width (container);

      width  = MIN (allocation->width - 2 * border_width,
                    child_requisition.width + GIMP_MESSAGE_BOX_SPACING);
      width  = MAX (1, width);

      height = allocation->height - 2 * border_width;
      height = MAX (1, height);

      if (rtl)
        child_allocation.x  = (allocation->width -
                               border_width      -
                               child_requisition.width);
      else
        child_allocation.x  = allocation->x + border_width;

      child_allocation.y      = allocation->y + border_width;
      child_allocation.width  = width;
      child_allocation.height = height;

      gtk_widget_size_allocate (box->image, &child_allocation);
    }

  allocation->x     += rtl ? 0 : width;
  allocation->width -= width;

  GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);

  allocation->x      -= rtl ? 0 : width;
  allocation->width  += width;

  gtk_widget_set_allocation (widget, allocation);
}
static void
gimp_message_box_finalize (GObject *object)
{
  GimpMessageBox *box = GIMP_MESSAGE_BOX (object);

  if (box->stock_id)
    {
      g_free (box->stock_id);
      box->stock_id = NULL;
    }

  G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_message_box_dispose (GObject *object)
{
  GimpMessageBox *box = GIMP_MESSAGE_BOX (object);

  if (box->image)
    {
      gtk_widget_unparent (box->image);
      box->image = NULL;
    }

  G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
gimp_message_box_forall (GtkContainer *container,
                         gboolean      include_internals,
                         GtkCallback   callback,
                         gpointer      callback_data)
{
  if (include_internals)
    {
      GimpMessageBox *box = GIMP_MESSAGE_BOX (container);

      if (box->image)
        (* callback) (box->image, callback_data);
    }

  GTK_CONTAINER_CLASS (parent_class)->forall (container, include_internals,
                                              callback, callback_data);
}
Beispiel #7
0
static void
gimp_message_box_size_allocate (GtkWidget     *widget,
                                GtkAllocation *allocation)
{
  GimpMessageBox *box   = GIMP_MESSAGE_BOX (widget);
  gint            width = 0;
  gboolean        rtl;

  rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);

  if (box->image && gtk_widget_get_visible (box->image))
    {
      GtkRequisition child_requisition;
      GtkAllocation  child_allocation;
      gint           height;

      gtk_widget_get_preferred_size (box->image, &child_requisition, NULL);

      width  = MIN (allocation->width,
                    child_requisition.width + GIMP_MESSAGE_BOX_SPACING);
      width  = MAX (1, width);

      height = allocation->height;

      if (rtl)
        child_allocation.x = allocation->width - child_requisition.width;
      else
        child_allocation.x = allocation->x;

      child_allocation.y      = allocation->y;
      child_allocation.width  = width;
      child_allocation.height = height;

      gtk_widget_size_allocate (box->image, &child_allocation);
    }

  allocation->x     += rtl ? 0 : width;
  allocation->width -= width;

  GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);

  allocation->x      -= rtl ? 0 : width;
  allocation->width  += width;

  gtk_widget_set_allocation (widget, allocation);
}
Beispiel #8
0
static void
gimp_message_box_finalize (GObject *object)
{
  GimpMessageBox *box = GIMP_MESSAGE_BOX (object);

  if (box->idle_id)
    g_source_remove (box->idle_id);
  box->idle_id = 0;

  if (box->icon_name)
    {
      g_free (box->icon_name);
      box->icon_name = NULL;
    }

  G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_message_box_get_property (GObject    *object,
                               guint       property_id,
                               GValue     *value,
                               GParamSpec *pspec)
{
  GimpMessageBox *box = GIMP_MESSAGE_BOX (object);

  switch (property_id)
    {
    case PROP_STOCK_ID:
      g_value_set_string (value, box->stock_id);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}
Beispiel #10
0
static void
gimp_message_box_set_property (GObject      *object,
                               guint         property_id,
                               const GValue *value,
                               GParamSpec   *pspec)
{
  GimpMessageBox *box = GIMP_MESSAGE_BOX (object);

  switch (property_id)
    {
    case PROP_ICON_NAME:
      box->icon_name = g_value_dup_string (value);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}
Beispiel #11
0
static void
gimp_message_box_constructed (GObject *object)
{
  GimpMessageBox *box = GIMP_MESSAGE_BOX (object);

  G_OBJECT_CLASS (parent_class)->constructed (object);

  if (box->icon_name)
    {
      box->image = gtk_image_new_from_icon_name (box->icon_name,
                                                 GTK_ICON_SIZE_DIALOG);

      gtk_widget_set_halign (box->image, GTK_ALIGN_START);
      gtk_widget_set_valign (box->image, GTK_ALIGN_START);
      gtk_widget_set_parent (box->image, GTK_WIDGET (box));
      gtk_widget_show (box->image);
    }
}
Beispiel #12
0
static void
gimp_message_box_constructed (GObject *object)
{
  GimpMessageBox *box = GIMP_MESSAGE_BOX (object);

  G_OBJECT_CLASS (parent_class)->constructed (object);

  if (box->stock_id)
    {
      gtk_widget_push_composite_child ();
      box->image = gtk_image_new_from_stock (box->stock_id,
                                             GTK_ICON_SIZE_DIALOG);
      gtk_widget_pop_composite_child ();

      gtk_misc_set_alignment (GTK_MISC (box->image), 0.0, 0.0);
      gtk_widget_set_parent (box->image, GTK_WIDGET (box));
      gtk_widget_show (box->image);
    }
}
static void
gimp_message_box_size_request (GtkWidget      *widget,
                               GtkRequisition *requisition)
{
  GimpMessageBox *box = GIMP_MESSAGE_BOX (widget);

  GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition);

  if (box->image && gtk_widget_get_visible (box->image))
    {
      GtkRequisition  child_requisition;
      gint            border_width;

      gtk_widget_size_request (box->image, &child_requisition);

      border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));

      requisition->width  += child_requisition.width + GIMP_MESSAGE_BOX_SPACING;
      requisition->height = MAX (requisition->height,
                                 child_requisition.height +
                                 2 * border_width);
    }
}
Beispiel #14
0
static void
gimp_message_box_get_preferred_height (GtkWidget *widget,
                                       gint      *minimum_height,
                                       gint      *natural_height)
{
  GimpMessageBox *box = GIMP_MESSAGE_BOX (widget);

  GTK_WIDGET_CLASS (parent_class)->get_preferred_height (widget,
                                                         minimum_height,
                                                         natural_height);

  if (box->image && gtk_widget_get_visible (box->image))
    {
      gint image_minimum;
      gint image_natural;

      gtk_widget_get_preferred_height (box->image,
                                       &image_minimum, &image_natural);

      *minimum_height = MAX (*minimum_height, image_minimum);
      *natural_height = MAX (*natural_height, image_natural);
    }
}
Beispiel #15
0
static void
gimp_message_box_get_preferred_width (GtkWidget *widget,
                                      gint      *minimum_width,
                                      gint      *natural_width)
{
  GimpMessageBox *box = GIMP_MESSAGE_BOX (widget);

  GTK_WIDGET_CLASS (parent_class)->get_preferred_width (widget,
                                                        minimum_width,
                                                        natural_width);

  if (box->image && gtk_widget_get_visible (box->image))
    {
      gint image_minimum;
      gint image_natural;

      gtk_widget_get_preferred_width (box->image,
                                      &image_minimum, &image_natural);

      *minimum_width += image_minimum + GIMP_MESSAGE_BOX_SPACING;
      *natural_width += image_natural + GIMP_MESSAGE_BOX_SPACING;
    }
}
Beispiel #16
0
void
gimp_error_dialog_add (GimpErrorDialog *dialog,
                       const gchar     *stock_id,
                       const gchar     *domain,
                       const gchar     *message)
{
  GtkWidget *box;
  gboolean   overflow = FALSE;

  g_return_if_fail (GIMP_IS_ERROR_DIALOG (dialog));
  g_return_if_fail (domain != NULL);
  g_return_if_fail (message != NULL);

  if (dialog->last_box     &&
      dialog->last_domain  && strcmp (dialog->last_domain,  domain)  == 0 &&
      dialog->last_message && strcmp (dialog->last_message, message) == 0)
    {
      if (gimp_message_box_repeat (GIMP_MESSAGE_BOX (dialog->last_box)))
        return;
    }

  if (dialog->num_messages >= GIMP_ERROR_DIALOG_MAX_MESSAGES)
    {
      g_printerr ("%s: %s\n\n", domain, message);

      overflow = TRUE;
      stock_id = GIMP_STOCK_WILBER_EEK;
      domain   = _("Too many error messages!");
      message  = _("Messages are redirected to stderr.");

      if (dialog->last_domain  && strcmp (dialog->last_domain,  domain)  == 0 &&
          dialog->last_message && strcmp (dialog->last_message, message) == 0)
        {
          return;
        }
    }

  box = g_object_new (GIMP_TYPE_MESSAGE_BOX,
                      "stock-id", stock_id,
                      NULL);

  dialog->num_messages++;

  if (overflow)
    gimp_message_box_set_primary_text (GIMP_MESSAGE_BOX (box), "%s", domain);
  else
    gimp_message_box_set_primary_text (GIMP_MESSAGE_BOX (box),
                                       /* %s is a message domain,
                                        * like "GIMP Message" or
                                        * "PNG Message"
                                        */
                                       _("%s Message"), domain);

  gimp_message_box_set_text (GIMP_MESSAGE_BOX (box), "%s", message);

  gtk_box_pack_start (GTK_BOX (dialog->vbox), box, TRUE, TRUE, 0);
  gtk_widget_show (box);

  dialog->last_box = box;

  g_free (dialog->last_domain);
  dialog->last_domain = g_strdup (domain);

  g_free (dialog->last_message);
  dialog->last_message = g_strdup (message);
}