2 * Copyright (C) 2001 Sun Microsystems Inc.
3 * Author: Erwann Chenede <erwann.chenede@sun.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
24 gchar *screen2_name = NULL;
34 get_screen_response (GtkDialog *dialog,
38 if (response_id == GTK_RESPONSE_DELETE_EVENT)
40 g_free (screen2_name);
41 screen2_name = g_strdup (gtk_entry_get_text (entry));
45 entry_dialog_response (GtkDialog *dialog,
49 if (response_id == GTK_RESPONSE_APPLY)
50 gtk_entry_set_text (de->e2, gtk_entry_get_text (de->e1));
56 make_selection_dialog (GdkScreen * screen,
58 GtkWidget * other_entry)
60 GtkWidget *window, *vbox;
61 GtkWidget *content_area;
62 MyDoubleGtkEntry *double_entry = g_new (MyDoubleGtkEntry, 1);
63 double_entry->e1 = GTK_ENTRY (entry);
64 double_entry->e2 = GTK_ENTRY (other_entry);
67 screen = gdk_screen_get_default ();
69 window = g_object_new (GTK_TYPE_DIALOG,
72 "type", GTK_WINDOW_TOPLEVEL,
73 "title", "MultiDisplay Cut & Paste",
74 "border_width", 10, NULL);
75 g_signal_connect (window, "destroy",
76 G_CALLBACK (gtk_main_quit), NULL);
78 content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
80 vbox = g_object_new (GTK_TYPE_BOX,
82 "orientation", GTK_ORIENTATION_VERTICAL,
84 gtk_box_pack_start (GTK_BOX (content_area), vbox, FALSE, FALSE, 0);
86 gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
87 gtk_widget_grab_focus (entry);
89 gtk_dialog_add_buttons (GTK_DIALOG (window),
90 GTK_STOCK_APPLY, GTK_RESPONSE_APPLY,
91 GTK_STOCK_QUIT, GTK_RESPONSE_DELETE_EVENT,
93 gtk_dialog_set_default_response (GTK_DIALOG (window), GTK_RESPONSE_APPLY);
95 g_signal_connect (window, "response",
96 G_CALLBACK (entry_dialog_response), double_entry);
98 gtk_widget_show_all (window);
102 main (int argc, char *argv[])
104 GtkWidget *dialog, *display_entry, *dialog_label;
105 GtkWidget *entry, *entry2;
106 GtkWidget *content_area;
108 GdkScreen *scr2 = NULL; /* Quiet GCC */
109 gboolean correct_second_display = FALSE;
111 gtk_init (&argc, &argv);
114 screen2_name = g_strdup (argv[1]);
116 /* Get the second display information */
118 dialog = gtk_dialog_new_with_buttons ("Second Display Selection",
122 GTK_RESPONSE_OK, NULL);
124 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
125 display_entry = gtk_entry_new ();
126 gtk_entry_set_activates_default (GTK_ENTRY (display_entry), TRUE);
128 gtk_label_new ("Please enter the name of\nthe second display\n");
130 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
132 gtk_container_add (GTK_CONTAINER (content_area), dialog_label);
133 gtk_container_add (GTK_CONTAINER (content_area), display_entry);
134 g_signal_connect (dialog, "response",
135 G_CALLBACK (get_screen_response), display_entry);
137 gtk_widget_grab_focus (display_entry);
138 gtk_widget_show_all (gtk_bin_get_child (GTK_BIN (dialog)));
140 while (!correct_second_display)
144 if (!g_ascii_strcasecmp (screen2_name, ""))
145 g_printerr ("No display name, reverting to default display\n");
147 dpy2 = gdk_display_open (screen2_name);
150 scr2 = gdk_display_get_default_screen (dpy2);
151 correct_second_display = TRUE;
156 g_strdup_printf ("Can't open display :\n\t%s\nplease try another one\n",
158 gtk_label_set_text (GTK_LABEL (dialog_label), error_msg);
163 if (!correct_second_display)
164 gtk_dialog_run (GTK_DIALOG (dialog));
167 gtk_widget_destroy (dialog);
169 entry = g_object_new (GTK_TYPE_ENTRY,
170 "activates_default", TRUE,
173 entry2 = g_object_new (GTK_TYPE_ENTRY,
174 "activates_default", TRUE,
178 /* for default display */
179 make_selection_dialog (NULL, entry2, entry);
180 /* for selected display */
181 make_selection_dialog (scr2, entry, entry2);