]> Pileus Git - ~andy/gtk/blob - tests/testmultidisplay.c
Updated Serbian translation
[~andy/gtk] / tests / testmultidisplay.c
1 /* testmultidisplay.c
2  * Copyright (C) 2001 Sun Microsystems Inc.
3  * Author: Erwann Chenede <erwann.chenede@sun.com>
4  *
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.
9  *
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.
14  *
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.
19  */
20
21 #include <config.h>
22 #include <gtk/gtk.h>
23 #include <gtk/gtkstock.h>
24 #include <gdk/gdk.h>
25
26 gchar *screen2_name = NULL;
27
28 typedef struct
29 {
30   GtkEntry *e1;
31   GtkEntry *e2;
32 }
33 MyDoubleGtkEntry;
34
35 void
36 get_screen_response (GtkDialog *dialog,
37                      gint       response_id,
38                      GtkEntry  *entry)
39 {
40   if (response_id == GTK_RESPONSE_DELETE_EVENT)
41     return;
42   g_free (screen2_name);
43   screen2_name = g_strdup (gtk_entry_get_text (entry));
44 }
45
46 void
47 entry_dialog_response (GtkDialog        *dialog,
48                        gint              response_id,
49                        MyDoubleGtkEntry *de)
50 {
51   if (response_id == GTK_RESPONSE_APPLY)
52     gtk_entry_set_text (de->e2, gtk_entry_get_text (de->e1));
53   else
54     gtk_main_quit ();
55 }
56
57 void
58 make_selection_dialog (GdkScreen * screen,
59                        GtkWidget * entry,
60                        GtkWidget * other_entry)
61 {
62   GtkWidget *window, *vbox;
63   MyDoubleGtkEntry *double_entry = g_new (MyDoubleGtkEntry, 1);
64   double_entry->e1 = GTK_ENTRY (entry);
65   double_entry->e2 = GTK_ENTRY (other_entry);
66
67   if (!screen)
68     screen = gdk_screen_get_default ();
69
70   window = gtk_widget_new (GTK_TYPE_DIALOG,
71                            "screen", screen,
72                            "user_data", NULL,
73                            "type", GTK_WINDOW_TOPLEVEL,
74                            "title", "MultiDisplay Cut & Paste",
75                            "border_width", 10, NULL);
76   g_signal_connect (window, "destroy",
77                     G_CALLBACK (gtk_main_quit), NULL);
78
79
80   vbox = gtk_widget_new (GTK_TYPE_VBOX,
81                          "border_width", 5,
82                          NULL);
83   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), vbox, FALSE, FALSE, 0);
84
85   gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
86   gtk_widget_grab_focus (entry);
87
88   gtk_dialog_add_buttons (GTK_DIALOG (window),
89                           GTK_STOCK_APPLY, GTK_RESPONSE_APPLY,
90                           GTK_STOCK_QUIT, GTK_RESPONSE_DELETE_EVENT,
91                           NULL);
92   gtk_dialog_set_default_response (GTK_DIALOG (window), GTK_RESPONSE_APPLY);
93
94   g_signal_connect (window, "response",
95                     G_CALLBACK (entry_dialog_response), double_entry);
96
97   gtk_widget_show_all (window);
98 }
99
100 int
101 main (int argc, char *argv[])
102 {
103   GtkWidget *dialog, *display_entry, *dialog_label;
104   GtkWidget *entry, *entry2;
105   GdkDisplay *dpy2;
106   GdkScreen *scr2 = NULL;       /* Quiet GCC */
107   gboolean correct_second_display = FALSE;
108
109   gtk_init (&argc, &argv);
110
111   if (argc == 2)
112     screen2_name = g_strdup (argv[1]);
113   
114   /* Get the second display information */
115
116   dialog = gtk_dialog_new_with_buttons ("Second Display Selection",
117                                         NULL,
118                                         GTK_DIALOG_MODAL,
119                                         GTK_STOCK_OK,
120                                         GTK_RESPONSE_OK, NULL);
121
122   gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
123   display_entry = gtk_entry_new ();
124   gtk_entry_set_activates_default (GTK_ENTRY (display_entry), TRUE);
125   dialog_label =
126     gtk_label_new ("Please enter the name of\nthe second display\n");
127
128   gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), dialog_label);
129   gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),
130                      display_entry);
131   g_signal_connect (dialog, "response",
132                     G_CALLBACK (get_screen_response), display_entry);
133
134   gtk_widget_grab_focus (display_entry);
135   gtk_widget_show_all (GTK_BIN (dialog)->child);
136   
137   while (!correct_second_display)
138     {
139       if (screen2_name)
140         {
141           if (!g_ascii_strcasecmp (screen2_name, ""))
142             g_printerr ("No display name, reverting to default display\n");
143           
144           dpy2 = gdk_display_open (screen2_name);
145           if (dpy2)
146             {
147               scr2 = gdk_display_get_default_screen (dpy2);
148               correct_second_display = TRUE;
149             }
150           else
151             {
152               char *error_msg =
153                 g_strdup_printf  ("Can't open display :\n\t%s\nplease try another one\n",
154                                   screen2_name);
155               gtk_label_set_text (GTK_LABEL (dialog_label), error_msg);
156               g_free (error_msg);
157             }
158        }
159
160       if (!correct_second_display)
161         gtk_dialog_run (GTK_DIALOG (dialog));
162     }
163   
164   gtk_widget_destroy (dialog);
165
166   entry = gtk_widget_new (GTK_TYPE_ENTRY,
167                           "activates_default", TRUE,
168                           "visible", TRUE,
169                           NULL);
170   entry2 = gtk_widget_new (GTK_TYPE_ENTRY,
171                            "activates_default", TRUE,
172                            "visible", TRUE,
173                            NULL);
174
175   /* for default display */
176   make_selection_dialog (NULL, entry2, entry);
177   /* for selected display */
178   make_selection_dialog (scr2, entry, entry2);
179   gtk_main ();
180
181   return 0;
182 }