1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "gtkbutton.h"
21 #include "gtkhscrollbar.h"
22 #include "gtkhseparator.h"
24 #include "gtkpreview.h"
26 #include "gtkselection.h"
27 #include "gtksignal.h"
31 #include "gtkvscrollbar.h"
32 #include "gtkwidget.h"
33 #include "gtkwindow.h"
34 #include "gtkprivate.h"
37 /* Private type definitions
39 typedef struct _GtkInitFunction GtkInitFunction;
40 typedef struct _GtkTimeoutFunction GtkTimeoutFunction;
41 typedef struct _GtkIdleFunction GtkIdleFunction;
42 typedef struct _GtkInputFunction GtkInputFunction;
43 typedef struct _GtkKeySnooperData GtkKeySnooperData;
45 struct _GtkInitFunction
51 struct _GtkTimeoutFunction
60 GtkDestroyNotify destroy;
63 struct _GtkIdleFunction
69 GtkDestroyNotify destroy;
72 struct _GtkInputFunction
74 GtkCallbackMarshal callback;
76 GtkDestroyNotify destroy;
79 struct _GtkKeySnooperData
86 static void gtk_exit_func (void);
87 static void gtk_timeout_insert (GtkTimeoutFunction *timeoutf);
88 static void gtk_handle_current_timeouts (guint32 the_time);
89 static void gtk_handle_current_idles (void);
90 static gint gtk_invoke_key_snoopers (GtkWidget *grab_widget,
92 static void gtk_handle_timeouts (void);
93 static void gtk_handle_idle (void);
94 static void gtk_handle_timer (void);
95 static void gtk_propagate_event (GtkWidget *widget,
97 static void gtk_error (gchar *str);
98 static void gtk_warning (gchar *str);
99 static void gtk_message (gchar *str);
100 static void gtk_print (gchar *str);
104 static guint main_level = 0;
105 static gint initialized = FALSE;
106 static GdkEvent *next_event = NULL;
107 static GList *current_events = NULL;
109 static GSList *grabs = NULL; /* A stack of unique grabs. The grabbing
110 * widget is the first one on the list.
112 static GList *init_functions = NULL; /* A list of init functions.
114 static GList *timeout_functions = NULL; /* A list of timeout functions sorted by
115 * when the length of the time interval
116 * remaining. Therefore, the first timeout
117 * function to expire is at the head of
118 * the list and the last to expire is at
119 * the tail of the list.
121 static GList *idle_functions = NULL; /* A list of idle functions.
124 static GList *current_idles = NULL;
125 static GList *current_timeouts = NULL;
126 static GMemChunk *timeout_mem_chunk = NULL;
127 static GMemChunk *idle_mem_chunk = NULL;
129 static GSList *key_snoopers = NULL;
131 static GdkVisual *gtk_visual; /* The visual to be used in creating new
134 static GdkColormap *gtk_colormap; /* The colormap to be used in creating new
145 g_set_error_handler (gtk_error);
146 g_set_warning_handler (gtk_warning);
147 g_set_message_handler (gtk_message);
148 g_set_print_handler (gtk_print);
151 /* Initialize "gdk". We simply pass along the 'argc' and 'argv'
152 * parameters as they contain information that
154 gdk_init (argc, argv);
156 /* Initialize the default visual and colormap to be
157 * used in creating widgets. (We want to use the system
158 * defaults so as to be nice to the colormap).
160 gtk_visual = gdk_visual_get_system ();
161 gtk_colormap = gdk_colormap_get_system ();
166 /* Register an exit function to make sure we are able to cleanup.
168 if (ATEXIT (gtk_exit_func))
169 g_warning ("unable to register exit function");
171 /* Set the 'initialized' flag.
177 gtk_exit (int errorcode)
179 /* Only if "gtk" has been initialized should we de-initialize.
181 /* de-initialisation is done by the gtk_exit_funct(),
182 * no need to do this here (Alex J.)
190 return gdk_set_locale ();
198 GtkInitFunction *init;
203 tmp_list = functions = init_functions;
204 init_functions = NULL;
208 init = tmp_list->data;
209 tmp_list = tmp_list->next;
211 (* init->function) (init->data);
215 g_list_free (functions);
218 while (!gtk_main_iteration ())
226 gtk_main_level (void)
238 gtk_events_pending (void)
240 return gdk_events_pending() + (next_event != NULL) ? 1 : 0;
244 gtk_main_iteration ()
246 return gtk_main_iteration_do (TRUE);
250 gtk_main_iteration_do (gboolean blocking)
252 GtkWidget *event_widget;
253 GtkWidget *grab_widget;
254 GdkEvent *event = NULL;
259 /* If this is a recursive call, and there are pending timeouts or
260 * idles, finish them, then return immediately to avoid blocking
263 if (current_timeouts)
265 gtk_handle_current_timeouts( gdk_time_get());
270 gtk_handle_current_idles();
274 /* If there is a valid event in 'next_event' then move it to 'event'
282 /* If we don't have an event then get one.
286 /* Handle setting of the "gdk" timer. If there are no
287 * timeout functions, then the timer is turned off.
288 * If there are timeout functions, then the timer is
289 * set to the shortest timeout interval (which is
290 * the first timeout function).
294 if (blocking) event = gdk_event_get ();
297 /* "gdk_event_get" can return FALSE if the timer goes off
298 * and no events are pending. Therefore, we should make
299 * sure that we got an event before continuing.
303 /* If there are any events pending then get the next one.
305 if (gdk_events_pending () > 0)
306 next_event = gdk_event_get ();
308 /* Try to compress enter/leave notify events. These event
309 * pairs occur when the mouse is dragged quickly across
310 * a window with many buttons (or through a menu). Instead
311 * of highlighting and de-highlighting each widget that
312 * is crossed it is better to simply de-highlight the widget
313 * which contained the mouse initially and highlight the
314 * widget which ends up containing the mouse.
317 if (((event->type == GDK_ENTER_NOTIFY) ||
318 (event->type == GDK_LEAVE_NOTIFY)) &&
319 ((next_event->type == GDK_ENTER_NOTIFY) ||
320 (next_event->type == GDK_LEAVE_NOTIFY)) &&
321 (next_event->type != event->type) &&
322 (next_event->any.window == event->any.window))
324 gdk_event_free (event);
325 gdk_event_free (next_event);
331 /* Push the event onto a stack of current events for
332 * gtk_current_event_get().
334 current_events = g_list_prepend (current_events, event);
336 /* Find the widget which got the event. We store the widget
337 * in the user_data field of GdkWindow's.
339 event_widget = gtk_get_event_widget (event);
341 /* If there is a grab in effect...
345 grab_widget = grabs->data;
347 /* If the grab widget is an ancestor of the event widget
348 * then we send the event to the original event widget.
349 * This is the key to implementing modality.
351 if (gtk_widget_is_ancestor (event_widget, grab_widget))
352 grab_widget = event_widget;
356 grab_widget = event_widget;
359 /* Not all events get sent to the grabbing widget.
360 * The delete, destroy, expose, focus change and resize
361 * events still get sent to the event widget because
362 * 1) these events have no meaning for the grabbing widget
363 * and 2) redirecting these events to the grabbing widget
364 * could cause the display to be messed up.
372 gtk_widget_ref (event_widget);
373 if (gtk_widget_event (event_widget, event))
374 gtk_widget_destroy (event_widget);
375 gtk_widget_unref (event_widget);
379 gtk_widget_ref (event_widget);
380 gtk_widget_event (event_widget, event);
381 gtk_widget_destroy (event_widget);
382 gtk_widget_unref (event_widget);
385 case GDK_PROPERTY_NOTIFY:
386 /* To handle selection INCR transactions, we select
387 * PropertyNotify events on the requestor window and create
388 * a corresponding (fake) GdkWindow so that events get
389 * here. There won't be a widget though, so we have to handle
393 if (event_widget == NULL)
395 gtk_selection_incr_event (event->any.window,
399 /* otherwise fall through */
402 case GDK_FOCUS_CHANGE:
406 case GDK_SELECTION_CLEAR:
407 case GDK_SELECTION_REQUEST:
408 case GDK_SELECTION_NOTIFY:
409 case GDK_CLIENT_EVENT:
411 case GDK_DRAG_REQUEST:
414 case GDK_DROP_DATA_AVAIL:
415 case GDK_VISIBILITY_NOTIFY:
416 gtk_widget_event (event_widget, event);
420 case GDK_KEY_RELEASE:
423 if (gtk_invoke_key_snoopers (grab_widget, event))
426 /* else fall through */
427 case GDK_MOTION_NOTIFY:
428 case GDK_BUTTON_PRESS:
429 case GDK_2BUTTON_PRESS:
430 case GDK_3BUTTON_PRESS:
431 case GDK_BUTTON_RELEASE:
432 case GDK_PROXIMITY_IN:
433 case GDK_PROXIMITY_OUT:
434 case GDK_OTHER_EVENT:
435 gtk_propagate_event (grab_widget, event);
438 case GDK_ENTER_NOTIFY:
439 if (grab_widget && GTK_WIDGET_IS_SENSITIVE (grab_widget))
441 gtk_widget_event (grab_widget, event);
442 if (event_widget == grab_widget)
443 GTK_PRIVATE_SET_FLAGS (event_widget, GTK_LEAVE_PENDING);
447 case GDK_LEAVE_NOTIFY:
448 if (event_widget && GTK_WIDGET_LEAVE_PENDING (event_widget))
450 GTK_PRIVATE_UNSET_FLAGS (event_widget, GTK_LEAVE_PENDING);
451 gtk_widget_event (event_widget, event);
453 else if (grab_widget && GTK_WIDGET_IS_SENSITIVE (grab_widget))
454 gtk_widget_event (grab_widget, event);
458 tmp_list = current_events;
459 current_events = g_list_remove_link (current_events, tmp_list);
460 g_list_free_1 (tmp_list);
462 gdk_event_free (event);
466 if (gdk_events_pending() == 0)
470 /* Handle a timeout functions that may have expired.
472 gtk_handle_timeouts ();
490 gtk_grab_add (GtkWidget *widget)
492 g_return_if_fail (widget != NULL);
494 if (!GTK_WIDGET_HAS_GRAB (widget))
496 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_GRAB);
498 grabs = g_slist_prepend (grabs, widget);
499 gtk_widget_ref (widget);
504 gtk_grab_remove (GtkWidget *widget)
506 g_return_if_fail (widget != NULL);
508 if (GTK_WIDGET_HAS_GRAB (widget))
510 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_GRAB);
512 grabs = g_slist_remove (grabs, widget);
513 gtk_widget_unref (widget);
518 gtk_init_add (GtkFunction function,
521 GtkInitFunction *init;
523 init = g_new (GtkInitFunction, 1);
524 init->function = function;
527 init_functions = g_list_prepend (init_functions, init);
531 gtk_key_snooper_install (GtkKeySnoopFunc snooper,
534 GtkKeySnooperData *data;
535 static guint snooper_id = 1;
537 g_return_val_if_fail (snooper != NULL, 0);
539 data = g_new (GtkKeySnooperData, 1);
540 data->func = snooper;
541 data->func_data = func_data;
542 data->id = snooper_id++;
543 key_snoopers = g_slist_prepend (key_snoopers, data);
549 gtk_key_snooper_remove (gint snooper_id)
551 GtkKeySnooperData *data = NULL;
554 slist = key_snoopers;
558 if (data->id == snooper_id)
565 key_snoopers = g_slist_remove (key_snoopers, data);
569 gtk_invoke_key_snoopers (GtkWidget *grab_widget,
573 gint return_val = FALSE;
575 slist = key_snoopers;
576 while (slist && !return_val)
578 GtkKeySnooperData *data;
582 return_val = (*data->func) (grab_widget, (GdkEventKey*) event, data->func_data);
589 gtk_timeout_add_internal (guint32 interval,
591 GtkFunction function,
593 GtkDestroyNotify destroy)
595 static gint timeout_tag = 1;
596 GtkTimeoutFunction *timeoutf;
598 /* Create a new timeout function structure.
599 * The start time is the current time.
601 if (!timeout_mem_chunk)
602 timeout_mem_chunk = g_mem_chunk_new ("timeout mem chunk", sizeof (GtkTimeoutFunction),
603 1024, G_ALLOC_AND_FREE);
605 timeoutf = g_chunk_new (GtkTimeoutFunction, timeout_mem_chunk);
607 timeoutf->tag = timeout_tag++;
608 timeoutf->start = gdk_time_get ();
609 timeoutf->interval = interval;
610 timeoutf->originterval = interval;
611 timeoutf->interp = interp;
612 timeoutf->function = function;
613 timeoutf->data = data;
614 timeoutf->destroy = destroy;
616 gtk_timeout_insert (timeoutf);
618 return timeoutf->tag;
622 gtk_timeout_destroy (GtkTimeoutFunction *timeoutf)
624 if (timeoutf->destroy)
625 (timeoutf->destroy) (timeoutf->data);
626 g_mem_chunk_free (timeout_mem_chunk, timeoutf);
630 gtk_timeout_add (guint32 interval,
631 GtkFunction function,
634 return gtk_timeout_add_internal (interval, FALSE, function, data, NULL);
638 gtk_timeout_add_interp (guint32 interval,
639 GtkCallbackMarshal function,
641 GtkDestroyNotify destroy)
643 return gtk_timeout_add_internal (interval, TRUE,
644 (GtkFunction) function,
649 gtk_timeout_remove (gint tag)
651 GtkTimeoutFunction *timeoutf;
654 /* Remove a timeout function.
655 * (Which, basically, involves searching the
658 tmp_list = timeout_functions;
661 timeoutf = tmp_list->data;
663 if (timeoutf->tag == tag)
665 timeout_functions = g_list_remove_link (timeout_functions, tmp_list);
666 g_list_free (tmp_list);
667 gtk_timeout_destroy (timeoutf);
672 tmp_list = tmp_list->next;
675 tmp_list = current_timeouts;
678 timeoutf = tmp_list->data;
680 if (timeoutf->tag == tag)
682 current_timeouts = g_list_remove_link (current_timeouts, tmp_list);
683 g_list_free (tmp_list);
684 gtk_timeout_destroy (timeoutf);
689 tmp_list = tmp_list->next;
694 gtk_idle_add_internal (gint interp,
695 GtkFunction function,
697 GtkDestroyNotify destroy)
699 static gint idle_tag = 1;
700 GtkIdleFunction *idlef;
703 idle_mem_chunk = g_mem_chunk_new ("idle mem chunk", sizeof (GtkIdleFunction),
704 1024, G_ALLOC_AND_FREE);
706 idlef = g_chunk_new (GtkIdleFunction, idle_mem_chunk);
708 idlef->tag = idle_tag++;
709 idlef->interp = interp;
710 idlef->function = function;
712 idlef->destroy = destroy;
714 idle_functions = g_list_append (idle_functions, idlef);
720 gtk_idle_destroy (GtkIdleFunction *idlef)
723 idlef->destroy (idlef->data);
724 g_mem_chunk_free (idle_mem_chunk, idlef);
728 gtk_idle_add (GtkFunction function,
731 return gtk_idle_add_internal (FALSE, function, data, NULL);
735 gtk_idle_add_interp (GtkCallbackMarshal function,
737 GtkDestroyNotify destroy)
739 return gtk_idle_add_internal (TRUE, (GtkFunction)function, data, destroy);
743 gtk_idle_remove (gint tag)
745 GtkIdleFunction *idlef;
748 tmp_list = idle_functions;
751 idlef = tmp_list->data;
753 if (idlef->tag == tag)
755 idle_functions = g_list_remove_link (idle_functions, tmp_list);
756 g_list_free (tmp_list);
757 gtk_idle_destroy (idlef);
762 tmp_list = tmp_list->next;
765 tmp_list = current_idles;
768 idlef = tmp_list->data;
770 if (idlef->tag == tag)
772 current_idles = g_list_remove_link (current_idles, tmp_list);
773 g_list_free (tmp_list);
774 gtk_idle_destroy (idlef);
779 tmp_list = tmp_list->next;
784 gtk_idle_remove_by_data (gpointer data)
786 GtkIdleFunction *idlef;
789 tmp_list = idle_functions;
792 idlef = tmp_list->data;
794 if (idlef->data == data)
796 idle_functions = g_list_remove_link (idle_functions, tmp_list);
797 g_list_free (tmp_list);
798 g_mem_chunk_free (idle_mem_chunk, idlef);
803 tmp_list = tmp_list->next;
806 tmp_list = current_idles;
809 idlef = tmp_list->data;
811 if (idlef->data == data)
813 current_idles = g_list_remove_link (current_idles, tmp_list);
814 g_list_free (tmp_list);
815 g_mem_chunk_free (idle_mem_chunk, idlef);
820 tmp_list = tmp_list->next;
825 gtk_invoke_input_function (GtkInputFunction *input,
827 GdkInputCondition condition)
830 args[0].type = GTK_TYPE_INT;
832 GTK_VALUE_INT(args[0]) = source;
833 args[1].type = GTK_TYPE_GDK_INPUT_CONDITION;
835 GTK_VALUE_FLAGS(args[1]) = condition;
836 args[2].type = GTK_TYPE_NONE;
839 input->callback (NULL, input->data, 2, args);
843 gtk_destroy_input_function (GtkInputFunction *input)
846 (input->destroy) (input->data);
851 gtk_input_add_interp (gint source,
852 GdkInputCondition condition,
853 GtkCallbackMarshal callback,
855 GtkDestroyNotify destroy)
857 GtkInputFunction *input = g_new (GtkInputFunction, 1);
858 input->callback = callback;
860 input->destroy = destroy;
861 return gdk_input_add_interp (source,
863 (GdkInputFunction) gtk_invoke_input_function,
865 (GdkDestroyNotify) gtk_destroy_input_function);
869 gtk_input_remove (gint tag)
871 gdk_input_remove (tag);
875 gtk_get_current_event ()
878 return gdk_event_copy ((GdkEvent *) current_events->data);
884 gtk_get_event_widget (GdkEvent *event)
889 if (event->any.window)
890 gdk_window_get_user_data (event->any.window, (void**) &widget);
901 gtk_preview_uninit ();
906 gtk_timeout_insert (GtkTimeoutFunction *timeoutf)
908 GtkTimeoutFunction *temp;
912 g_assert (timeoutf != NULL);
914 /* Insert the timeout function appropriately.
915 * Appropriately meaning sort it into the list
916 * of timeout functions.
918 temp_list = timeout_functions;
921 temp = temp_list->data;
922 if (timeoutf->interval < temp->interval)
924 new_list = g_list_alloc ();
925 new_list->data = timeoutf;
926 new_list->next = temp_list;
927 new_list->prev = temp_list->prev;
929 temp_list->prev->next = new_list;
930 temp_list->prev = new_list;
932 if (temp_list == timeout_functions)
933 timeout_functions = new_list;
938 temp_list = temp_list->next;
941 timeout_functions = g_list_append (timeout_functions, timeoutf);
945 gtk_invoke_timeout_function (GtkTimeoutFunction *timeoutf)
947 if (!timeoutf->interp)
948 return timeoutf->function (timeoutf->data);
952 gint ret_val = FALSE;
954 args[0].type = GTK_TYPE_BOOL;
955 args[0].d.pointer_data = &ret_val;
956 ((GtkCallbackMarshal)timeoutf->function) (NULL,
964 gtk_handle_current_timeouts (guint32 the_time)
967 GtkTimeoutFunction *timeoutf;
969 while (current_timeouts)
971 tmp_list = current_timeouts;
972 timeoutf = tmp_list->data;
974 current_timeouts = g_list_remove_link (current_timeouts, tmp_list);
975 g_list_free (tmp_list);
977 if (gtk_invoke_timeout_function (timeoutf) == FALSE)
979 gtk_timeout_destroy (timeoutf);
983 timeoutf->interval = timeoutf->originterval;
984 timeoutf->start = the_time;
985 gtk_timeout_insert (timeoutf);
991 gtk_handle_timeouts ()
996 GtkTimeoutFunction *timeoutf;
998 /* Caller must already have called gtk_handle_current_timeouts if
1000 g_assert (current_timeouts == NULL);
1002 if (timeout_functions)
1004 the_time = gdk_time_get ();
1006 tmp_list = timeout_functions;
1009 timeoutf = tmp_list->data;
1011 if (timeoutf->interval <= (the_time - timeoutf->start))
1013 tmp_list2 = tmp_list;
1014 tmp_list = tmp_list->next;
1016 timeout_functions = g_list_remove_link (timeout_functions, tmp_list2);
1017 current_timeouts = g_list_concat (current_timeouts, tmp_list2);
1021 timeoutf->interval -= (the_time - timeoutf->start);
1022 timeoutf->start = the_time;
1023 tmp_list = tmp_list->next;
1027 if (current_timeouts)
1028 gtk_handle_current_timeouts(the_time);
1033 gtk_idle_invoke_function (GtkIdleFunction *idlef)
1036 return idlef->function (idlef->data);
1040 gint ret_val = FALSE;
1041 args[0].name = NULL;
1042 args[0].type = GTK_TYPE_BOOL;
1043 args[0].d.pointer_data = &ret_val;
1044 ((GtkCallbackMarshal)idlef->function) (NULL,
1052 gtk_handle_current_idles ()
1055 GtkIdleFunction *idlef;
1057 while (current_idles)
1059 tmp_list = current_idles;
1060 idlef = tmp_list->data;
1062 current_idles = g_list_remove_link (current_idles, tmp_list);
1064 if (gtk_idle_invoke_function (idlef) == FALSE)
1066 g_list_free (tmp_list);
1067 gtk_idle_destroy (idlef);
1071 idle_functions = g_list_concat (idle_functions, tmp_list);
1079 /* Caller must already have called gtk_handle_current_idles if
1082 g_assert (current_idles == NULL);
1086 current_idles = idle_functions;
1087 idle_functions = NULL;
1089 gtk_handle_current_idles();
1096 GtkTimeoutFunction *timeoutf;
1101 gdk_timer_enable ();
1103 else if (timeout_functions)
1105 timeoutf = timeout_functions->data;
1106 gdk_timer_set (timeoutf->interval);
1107 gdk_timer_enable ();
1112 gdk_timer_disable ();
1117 gtk_propagate_event (GtkWidget *widget,
1123 g_return_if_fail (widget != NULL);
1124 g_return_if_fail (event != NULL);
1126 handled_event = FALSE;
1128 if ((event->type == GDK_KEY_PRESS) ||
1129 (event->type == GDK_KEY_RELEASE))
1131 /* Only send key events to window widgets.
1132 * The window widget will in turn pass the
1133 * key event on to the currently focused widget
1136 parent = gtk_widget_get_ancestor (widget, gtk_window_get_type ());
1137 if (parent && GTK_WIDGET_IS_SENSITIVE (parent)
1138 && gtk_widget_event (parent, event))
1142 /* Other events get propagated up the widget tree
1143 * so that parents can see the button and motion
1144 * events of the children.
1146 while (!handled_event && widget)
1148 parent = widget->parent;
1149 handled_event = (!GTK_WIDGET_IS_SENSITIVE (widget) ||
1150 gtk_widget_event (widget, event));
1157 gtk_error (gchar *str)
1163 gtk_warning (gchar *str)
1169 gtk_message (gchar *str)
1175 gtk_print (gchar *str)
1177 static GtkWidget *window = NULL;
1178 static GtkWidget *text;
1179 static int level = 0;
1183 GtkWidget *hscrollbar;
1184 GtkWidget *vscrollbar;
1185 GtkWidget *separator;
1190 fputs (str, stdout);
1197 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1199 gtk_signal_connect (GTK_OBJECT (window), "destroy",
1200 (GtkSignalFunc) gtk_widget_destroyed,
1203 gtk_window_set_title (GTK_WINDOW (window), "Messages");
1205 box1 = gtk_vbox_new (FALSE, 0);
1206 gtk_container_add (GTK_CONTAINER (window), box1);
1207 gtk_widget_show (box1);
1210 box2 = gtk_vbox_new (FALSE, 10);
1211 gtk_container_border_width (GTK_CONTAINER (box2), 10);
1212 gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
1213 gtk_widget_show (box2);
1216 table = gtk_table_new (2, 2, FALSE);
1217 gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
1218 gtk_table_set_col_spacing (GTK_TABLE (table), 0, 2);
1219 gtk_box_pack_start (GTK_BOX (box2), table, TRUE, TRUE, 0);
1220 gtk_widget_show (table);
1222 text = gtk_text_new (NULL, NULL);
1223 gtk_text_set_editable (GTK_TEXT (text), FALSE);
1224 gtk_table_attach_defaults (GTK_TABLE (table), text, 0, 1, 0, 1);
1225 gtk_widget_show (text);
1226 gtk_widget_realize (text);
1228 hscrollbar = gtk_hscrollbar_new (GTK_TEXT (text)->hadj);
1229 gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 1, 2,
1230 GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
1231 gtk_widget_show (hscrollbar);
1233 vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
1234 gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1,
1235 GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
1236 gtk_widget_show (vscrollbar);
1238 separator = gtk_hseparator_new ();
1239 gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
1240 gtk_widget_show (separator);
1243 box2 = gtk_vbox_new (FALSE, 10);
1244 gtk_container_border_width (GTK_CONTAINER (box2), 10);
1245 gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
1246 gtk_widget_show (box2);
1249 button = gtk_button_new_with_label ("close");
1250 gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
1251 (GtkSignalFunc) gtk_widget_hide,
1252 GTK_OBJECT (window));
1253 gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1254 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1255 gtk_widget_grab_default (button);
1256 gtk_widget_show (button);
1260 gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, str, -1);
1263 if (!GTK_WIDGET_VISIBLE (window))
1264 gtk_widget_show (window);