aboutsummaryrefslogtreecommitdiffstats
path: root/gtk/stream_prefs.c
blob: 8f50b2706eed4e853f6363befe569bc4036005d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/* stream_prefs.c
 * Dialog boxes for preferences for the stream window
 *
 * $Id: stream_prefs.c,v 1.1 1999/12/02 04:30:15 gerald Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@zing.org>
 * Copyright 1998 Gerald Combs
 *
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (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
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <errno.h>

#ifndef __GLOBALS_H__
#include "globals.h"
#endif

#include "stream_prefs.h"

#ifndef __KEYS_H__
#include "keys.h"
#endif

#ifndef __PRINT_H__
#include "print.h"
#endif

#ifndef __PREFS_DLG_H__
#include "prefs_dlg.h"
#endif

#ifndef __UTIL_H__
#include "util.h"
#endif

static void update_text_color(GtkWidget *, gpointer);
static void update_current_color(GtkWidget *, gpointer);
static void copy_color_vals(GdkColor *, GdkColor *);

static GdkColor tcolors[4], *curcolor = NULL;

#define SAMPLE_CLIENT_TEXT "Sample client text\n"
#define SAMPLE_SERVER_TEXT "Sample server text\n"
#define CFG_IDX 0
#define CBG_IDX 1
#define SFG_IDX 2
#define SBG_IDX 3
#define STREAM_SAMPLE_KEY "stream_entry"
#define STREAM_CS_KEY "stream_colorselection"
#define CS_RED 0
#define CS_GREEN 1
#define CS_BLUE 2
#define CS_OPACITY 3

GtkWidget *
stream_prefs_show()
{
  GtkWidget *main_vb, *main_tb, *label, *optmenu, *menu, *menuitem;
  GtkWidget *sample, *colorsel;
  int        width, height, i;
  gchar     *mt[] = { "Client foreground", "Client background",
                      "Server foreground", "Server background" };
  int mcount = sizeof(mt) / sizeof (gchar *);
  gdouble scolor[4];

  copy_color_vals(&tcolors[CFG_IDX], &prefs.st_client_fg);
  copy_color_vals(&tcolors[CBG_IDX], &prefs.st_client_bg);
  copy_color_vals(&tcolors[SFG_IDX], &prefs.st_server_fg);
  copy_color_vals(&tcolors[SBG_IDX], &prefs.st_server_bg);
  
  curcolor = &tcolors[CFG_IDX];

  scolor[CS_RED]     = (gdouble) (curcolor->red)   / 65535.0;
  scolor[CS_GREEN]   = (gdouble) (curcolor->green) / 65535.0;
  scolor[CS_BLUE]    = (gdouble) (curcolor->blue)  / 65535.0;
  scolor[CS_OPACITY] = 1.0;
  
  /* Enclosing containers for each row of widgets */
  main_vb = gtk_vbox_new(FALSE, 5);
  gtk_container_border_width(GTK_CONTAINER(main_vb), 5);

  main_tb = gtk_table_new(3, 3, FALSE);
  gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0);
  gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10);
  gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15);
  gtk_widget_show(main_tb);

  label = gtk_label_new("Set:");
  gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
  gtk_table_attach_defaults(GTK_TABLE(main_tb), label, 0, 1, 0, 1);
  gtk_widget_show(label);

  /* We have to create this now, and configure it below. */
  colorsel = gtk_color_selection_new();

  optmenu = gtk_option_menu_new ();
  menu = gtk_menu_new ();
  for (i = 0; i < mcount; i++){
    menuitem = gtk_menu_item_new_with_label (mt[i]);
    gtk_object_set_data(GTK_OBJECT(menuitem), STREAM_CS_KEY, 
      (gpointer) colorsel);
    gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
      GTK_SIGNAL_FUNC(update_current_color), &tcolors[i]);
    gtk_widget_show (menuitem);
    gtk_menu_append (GTK_MENU (menu), menuitem);
  }
  gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu), menu);
  gtk_table_attach_defaults(GTK_TABLE(main_tb), optmenu, 1, 2, 0, 1);
  gtk_widget_show(optmenu);

  sample = gtk_text_new(FALSE, FALSE);
  height = 2 * (sample->style->font->ascent + sample->style->font->descent);
  width = gdk_string_width(sample->style->font, "Sample server text");
  gtk_widget_set_usize(GTK_WIDGET(sample), width, height);
  gtk_text_set_editable(GTK_TEXT(sample), FALSE);
  gtk_text_insert(GTK_TEXT(sample), NULL, &tcolors[CFG_IDX], &tcolors[CBG_IDX],
    SAMPLE_CLIENT_TEXT, -1);
  gtk_text_insert(GTK_TEXT(sample), NULL, &tcolors[SFG_IDX], &tcolors[SBG_IDX],
    SAMPLE_SERVER_TEXT, -1);
  gtk_table_attach_defaults(GTK_TABLE(main_tb), sample, 2, 3, 0, 2);
  gtk_widget_show(sample);

  gtk_color_selection_set_color(GTK_COLOR_SELECTION(colorsel), &scolor[CS_RED]);
  gtk_table_attach_defaults(GTK_TABLE(main_tb), colorsel, 0, 3, 2, 3);
  gtk_object_set_data(GTK_OBJECT(colorsel), STREAM_SAMPLE_KEY,
    (gpointer) sample);
  gtk_signal_connect(GTK_OBJECT(colorsel), "color-changed", 
    GTK_SIGNAL_FUNC(update_text_color), NULL);
  gtk_widget_show(colorsel);

  gtk_widget_show(main_vb);
  return(main_vb);
}

static void
update_text_color(GtkWidget *w, gpointer data) {
  GtkText  *sample   = gtk_object_get_data(GTK_OBJECT(w), STREAM_SAMPLE_KEY);
  gdouble   scolor[4];

  gtk_color_selection_get_color(GTK_COLOR_SELECTION(w), &scolor[CS_RED]);
  
  curcolor->red   = (gushort) (scolor[CS_RED]   * 65535.0);
  curcolor->green = (gushort) (scolor[CS_GREEN] * 65535.0);
  curcolor->blue  = (gushort) (scolor[CS_BLUE]  * 65535.0);
  
  gtk_text_freeze(sample);
  gtk_text_set_point(sample, 0);
  gtk_text_forward_delete(sample, gtk_text_get_length(sample));
  gtk_text_insert(sample, NULL, &tcolors[CFG_IDX], &tcolors[CBG_IDX],
    SAMPLE_CLIENT_TEXT, -1);
  gtk_text_insert(sample, NULL, &tcolors[SFG_IDX], &tcolors[SBG_IDX],
    SAMPLE_SERVER_TEXT, -1);
  gtk_text_thaw(sample);
}

static void
update_current_color(GtkWidget *w, gpointer data)
{
  GtkColorSelection *colorsel = GTK_COLOR_SELECTION(gtk_object_get_data(GTK_OBJECT(w),
    STREAM_CS_KEY));
  gdouble            scolor[4];

  curcolor = (GdkColor *) data;
  
  scolor[CS_RED]     = (gdouble) (curcolor->red)   / 65535.0;
  scolor[CS_GREEN]   = (gdouble) (curcolor->green) / 65535.0;
  scolor[CS_BLUE]    = (gdouble) (curcolor->blue)  / 65535.0;
  scolor[CS_OPACITY] = 1.0;
  
  gtk_color_selection_set_color(colorsel, &scolor[CS_RED]);
}

static void
copy_color_vals(GdkColor *target, GdkColor *source)
{
  target->pixel = source->pixel;
  target->red   = source->red;
  target->green = source->green;
  target->blue  = source->blue;
}

void
stream_prefs_ok(GtkWidget *w)
{
  copy_color_vals(&prefs.st_client_fg, &tcolors[CFG_IDX]);
  copy_color_vals(&prefs.st_client_bg, &tcolors[CBG_IDX]);
  copy_color_vals(&prefs.st_server_fg, &tcolors[SFG_IDX]);
  copy_color_vals(&prefs.st_server_bg, &tcolors[SBG_IDX]);

  stream_prefs_delete(w);
}

void
stream_prefs_save(GtkWidget *w)
{
  stream_prefs_ok(w);
}

void
stream_prefs_cancel(GtkWidget *w)
{
  stream_prefs_delete(w);
}

void
stream_prefs_delete(GtkWidget *w)
{
}