window-commands.c 4.38 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2 3
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7 8 9 10 11 12 13 14
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19
 */

#include "config.h"

20 21
#include <string.h>

22
#include <gegl.h>
23 24 25 26 27 28
#include <gtk/gtk.h>

#include "libgimpwidgets/gimpwidgets.h"

#include "actions-types.h"

29 30 31
#include "widgets/gimpmessagebox.h"
#include "widgets/gimpmessagedialog.h"

32 33 34
#include "actions.h"
#include "window-commands.h"

35 36
#include "gimp-intl.h"

37 38 39 40 41 42 43 44 45 46

/*  public functions  */

void
window_close_cmd_callback (GtkAction *action,
                           gpointer   data)
{
  GtkWidget *widget;
  return_if_no_widget (widget, data);

Michael Natterer's avatar
Michael Natterer committed
47
  if (! gtk_widget_is_toplevel (widget))
48 49
    widget = gtk_widget_get_toplevel (widget);

50
  if (widget && gtk_widget_get_window (widget))
51 52 53
    {
      GdkEvent *event = gdk_event_new (GDK_DELETE);

54
      event->any.window     = g_object_ref (gtk_widget_get_window (widget));
55 56 57 58 59 60 61
      event->any.send_event = TRUE;

      gtk_main_do_event (event);
      gdk_event_free (event);
    }
}

62 63 64 65 66 67 68 69 70
void
window_open_display_cmd_callback (GtkAction *action,
                                  gpointer   data)
{
  GtkWidget *widget;
  GtkWidget *dialog;
  GtkWidget *entry;
  return_if_no_widget (widget, data);

71
  dialog = gimp_message_dialog_new ("Open Display", GIMP_ICON_WILBER_EEK,
72 73 74
                                    widget, GTK_DIALOG_MODAL,
                                    NULL, NULL,

75 76
                                    _("_Cancel"), GTK_RESPONSE_CANCEL,
                                    _("_OK"),     GTK_RESPONSE_OK,
77 78 79

                                    NULL);

80
  gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
81 82 83
                                           GTK_RESPONSE_OK,
                                           GTK_RESPONSE_CANCEL,
                                           -1);
84 85 86 87 88 89 90 91 92 93

  gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
                                     "Experimental multi-display stuff!\n"
                                     "Click OK and have fun crashing GIMP...");

  gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box,
                             "Please enter the name of the new display:");

  entry = gtk_entry_new ();
  gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
94 95
  gtk_box_pack_start (GTK_BOX (GIMP_MESSAGE_DIALOG (dialog)->box), entry,
                      TRUE, TRUE, 0);
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

  gtk_widget_grab_focus (entry);
  gtk_widget_show_all (dialog);

  while (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
    {
      gchar *screen_name;

      screen_name = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1);

      if (strcmp (screen_name, ""))
        {
          GdkDisplay *display;

          gtk_widget_set_sensitive (dialog, FALSE);

          display = gdk_display_open (screen_name);

          if (! display)
            gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box,
                                       "Can't open display '%s'. "
                                       "Please try another one:",
                                       screen_name);

          g_free (screen_name);

          gtk_widget_set_sensitive (dialog, TRUE);

          if (display)
            break;
        }

      gtk_widget_grab_focus (entry);
    }

  gtk_widget_destroy (dialog);
}

134 135 136 137 138 139 140 141 142
void
window_move_to_screen_cmd_callback (GtkAction *action,
                                    GtkAction *current,
                                    gpointer   data)
{
  GtkWidget *widget;
  GdkScreen *screen;
  return_if_no_widget (widget, data);

Michael Natterer's avatar
Michael Natterer committed
143
  if (! gtk_widget_is_toplevel (widget))
144 145 146 147 148 149 150 151 152
    widget = gtk_widget_get_toplevel (widget);

  screen = g_object_get_data (G_OBJECT (current), "screen");

  if (GDK_IS_SCREEN (screen) && screen != gtk_widget_get_screen (widget))
    {
      gtk_window_set_screen (GTK_WINDOW (widget), screen);
    }
}