1 /* SCCS Id: @(#)gnmesg.c 3.3 2000/07/16 */
2 /* Copyright (C) 1998 by Erik Andersen <andersee@debian.org> */
3 /* NetHack may be freely redistributed. See license for details. */
4
5 #include "gnmesg.h"
6 #include "gnsignal.h"
7
8 /* Pick an arbitrary number of chars such as 80 col X 40 rows text = 3200 chars */
9 #define nCharsBeforeDeletingStuff 3200
10
11 /* Message Window widgets */
12 GtkWidget *MW_table;
13 GtkWidget *MW_text;
14 GtkWidget *MW_scrollbar;
15
16
ghack_message_window_clear(GtkWidget * widget,gpointer data)17 void ghack_message_window_clear(GtkWidget *widget, gpointer data)
18 {
19 /* Seems nethack calls this after every move -- we don't want
20 * to really clear the window at all though. Ignore the request */
21 gint len;
22
23 len = gtk_text_get_length(GTK_TEXT(MW_text));
24
25 if(len < nCharsBeforeDeletingStuff)
26 return;
27
28 gtk_text_freeze(GTK_TEXT(MW_text));
29 gtk_text_set_point(GTK_TEXT(MW_text), 0);
30 gtk_text_forward_delete(GTK_TEXT(MW_text), len-((guint)(nCharsBeforeDeletingStuff*0.5)));
31 gtk_text_set_point(GTK_TEXT(MW_text), (guint)(nCharsBeforeDeletingStuff*0.5));
32 gtk_text_thaw(GTK_TEXT(MW_text));
33 }
34
ghack_message_window_destroy(GtkWidget * win,gpointer data)35 void ghack_message_window_destroy( GtkWidget *win, gpointer data)
36 {
37
38 }
39
ghack_message_window_display(GtkWidget * widget,boolean block,gpointer data)40 void ghack_message_window_display(GtkWidget *widget, boolean block,
41 gpointer data)
42 {
43
44 }
45
ghack_message_window_put_string(GtkWidget * widget,int attr,const char * text,gpointer data)46 void ghack_message_window_put_string(GtkWidget *widget, int attr,
47 const char* text, gpointer data)
48 {
49
50 if(text == NULL)
51 return;
52
53 /* Don't bother with attributes yet */
54 gtk_text_insert(GTK_TEXT(MW_text), NULL, NULL, NULL, text, -1);
55 gtk_text_insert(GTK_TEXT(MW_text), NULL, NULL, NULL, "\n", -1);
56 }
57
ghack_message_window_use_RIP(int how)58 void ghack_message_window_use_RIP(int how)
59 {
60
61 }
62
ghack_message_window_scroll(int dx,int dy)63 void ghack_message_window_scroll(int dx, int dy)
64 {
65
66 }
67
ghack_init_message_window(void)68 GtkWidget* ghack_init_message_window(void)
69 {
70
71 MW_table = gtk_table_new(2, 1, FALSE);
72 gtk_table_set_row_spacing(GTK_TABLE(MW_table), 0, 2);
73
74 MW_text = gtk_text_new(NULL, NULL);
75 gtk_text_set_editable(GTK_TEXT(MW_text), FALSE);
76 gtk_text_set_word_wrap(GTK_TEXT(MW_text), TRUE);
77 gtk_table_attach(GTK_TABLE(MW_table), MW_text, 0, 1, 0, 1,
78 (GTK_EXPAND | GTK_FILL),
79 (GTK_EXPAND | GTK_FILL),
80 0, 0);
81
82 MW_scrollbar = gtk_vscrollbar_new(GTK_TEXT(MW_text)->vadj);
83 gtk_table_attach(GTK_TABLE(MW_table), MW_scrollbar, 1, 2, 0, 1,
84 GTK_FILL, (GTK_EXPAND | GTK_FILL), 0, 0);
85
86 gtk_signal_connect(GTK_OBJECT(MW_table), "ghack_putstr",
87 GTK_SIGNAL_FUNC(ghack_message_window_put_string),
88 NULL);
89
90 gtk_signal_connect(GTK_OBJECT(MW_table), "ghack_clear",
91 GTK_SIGNAL_FUNC(ghack_message_window_clear),
92 NULL);
93
94 gtk_signal_connect(GTK_OBJECT(MW_table), "gnome_delay_output",
95 GTK_SIGNAL_FUNC(ghack_delay), NULL);
96
97 gtk_widget_show_all(MW_table);
98
99 return GTK_WIDGET(MW_table);
100 }
101
102
103