2 * Definitions for single color filter edit dialog boxes
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 #include <epan/packet.h>
32 #include "../color_filters.h"
34 #include "ui/simple_dialog.h"
36 #include "ui/gtk/color_dlg.h"
37 #include "ui/gtk/color_utils.h"
38 #include "ui/gtk/dlg_utils.h"
39 #include "ui/gtk/gui_utils.h"
40 #include "ui/gtk/stock_icons.h"
41 #include "ui/gtk/filter_dlg.h"
42 #include "ui/gtk/dfilter_expr_dlg.h"
43 #include "ui/gtk/color_edit_dlg.h"
44 #include "ui/gtk/filter_autocomplete.h"
46 #include "ui/gtk/old-gtk-compat.h"
51 * There are two dialog windows:
54 * - color_selection_dlg (Gtk2) aka color_chooser_dlg (gtk 3.4 and newer).
55 * The color_selection_dlg window can be instantiated (serially or in parallel)
56 * to select the foreground and/or the background color for the filter.
57 * The color_selection_dlg windows are 'transient_for' and 'destroyed_with'
58 * the color_edit_dlg window.
61 * The information needed by the various dlg callback functions is passed via
62 * the callback 'user_data' parameter.
64 * There are two different structs passed via a pointer in 'user_data':
65 * - (color_edit_dlg_info_t *)user_data
66 * supplied to the color_edit_dlg Ok and Cancel button "clicked"
67 * callbacks and to the color_edit_dlg "destroy" callback.
69 * - (color_selection_dlg_info_t *)user_data
70 * supplied to the color_edit_dlg FG/BG button "clicked" and "destroy"
71 * callbacks and to the color_selection_dlg "response" and "destroy" callbacks.
73 * Note that there are two separate instances of this struct:
74 * - "foreground" info associated with the color_edit_dlg Foreground button;
75 * - "background" info associated with the color_edit_dlg Background button.
78 static void color_edit_dlg_ok_cb(GtkWidget
*w
, gpointer user_data
);
79 static void color_edit_dlg_cancel_cb(GtkWidget
*w
, gpointer user_data
);
80 static void color_edit_dlg_destroy_cb(GObject
*object
, gpointer user_data
);
81 static void color_edit_dlg_fg_bg_btn_cb(GtkWidget
*button
, gpointer user_data
);
82 static void color_edit_dlg_fg_bg_btn_destroy_cb(GObject
*object
, gpointer user_data
);
84 static void color_selection_dlg_response_cb(GtkWidget
*color_selection_dlg
, gint response
, gpointer data
);
85 static void color_selection_dlg_destroy_cb(GObject
*object
, gpointer user_data
);
88 COLOR_SELECTION_TYPE_FG
= 1,
89 COLOR_SELECTION_TYPE_BG
= 2
90 } color_selection_type_t
;
92 /* info sent to color_edit_dlg Ok, cancel & destroy callbacks;
93 * pointed to by colof->color_edit_dlg_info and by user_data for the callbacks
95 struct _color_edit_dlg_info_t
{
96 GtkWidget
*color_edit_dlg
;
97 GtkWidget
*color_filters
; /* Treeview */
98 color_filter_t
*colorf
;
99 /* color_edit_dlg widgets */
100 GtkWidget
*filt_name_entry
;
101 GtkWidget
*filt_text_entry
;
102 GtkWidget
*disabled_cb
;
105 /* info sent to color_edit_dlg FG/BG button callbacks and also to color_selection_dlg callbacks;
106 * pointed by user data for the callbacks
108 struct _color_selection_dlg_info_t
{
109 GtkWidget
*color_selection_dlg
;
110 color_selection_type_t color_selection_type
; /* FG/BG */
111 color_filter_t
*colorf
;
112 color_t
*color
; /* ptr to FG or BG color struct in colorf */
113 const gchar
*color_selection_type_text
;
114 GtkWidget
*filt_name_entry
;
116 typedef struct _color_selection_dlg_info_t color_selection_dlg_info_t
;
120 filter_expr_cb(GtkWidget
*w _U_
, gpointer filter_te
)
122 dfilter_expr_dlg_new(GTK_WIDGET(filter_te
));
126 /* Create "colorize filter" button for the "color edit" dialog, add it to hbox and connect callbacka */
128 colorize_filter_new(GtkWidget
*colorize_hbox
,
129 color_selection_type_t color_selection_type
,
130 const gchar
*t1
, /* "Foreground" */
131 const gchar
*t2
, /* "Foreground Color..." */
132 const gchar
*t3
, /* "Select foreground color for data display" */
133 color_filter_t
*colorf
,
135 GtkWidget
*filt_name_entry
)
137 GtkWidget
*colorize_filter
;
138 color_selection_dlg_info_t
*csdi
;
140 colorize_filter
= gtk_button_new_with_label(t2
);
141 gtk_box_pack_start (GTK_BOX (colorize_hbox
), colorize_filter
, TRUE
, FALSE
, 0);
142 gtk_widget_set_tooltip_text(colorize_filter
, t3
);
144 csdi
= g_new(color_selection_dlg_info_t
, 1);
145 csdi
->color_selection_dlg
= NULL
;
146 csdi
->color_selection_type
= color_selection_type
;
147 csdi
->colorf
= colorf
;
149 csdi
->color_selection_type_text
= t1
;
150 csdi
->filt_name_entry
= filt_name_entry
;
152 g_signal_connect(colorize_filter
, "clicked", G_CALLBACK(color_edit_dlg_fg_bg_btn_cb
), csdi
);
153 g_signal_connect(colorize_filter
, "destroy", G_CALLBACK(color_edit_dlg_fg_bg_btn_destroy_cb
), csdi
);
157 /* Create a "color edit dialog" for a given color filter, and
158 associate it with that color filter. */
160 color_edit_dlg_new(GtkWidget
*color_filters
,
161 gboolean is_new_filter
)
163 color_edit_dlg_info_t
*cedi
;
164 color_filter_t
*colorf
;
166 GtkWidget
*color_edit_dlg
;
167 GtkWidget
*dialog_vbox
;
168 GtkWidget
*filter_fr
;
169 GtkWidget
*filter_fr_vbox
;
170 GtkWidget
*filter_name_hbox
;
171 GtkWidget
*filt_name_entry
;
172 GtkWidget
*filt_text_entry
;
173 GtkWidget
*color_filter_name
;
174 GtkWidget
*filter_string_hbox
;
175 GtkWidget
*add_expression_bt
;
176 GtkWidget
*color_filter_text
;
178 GtkWidget
*settings_hbox
;
180 GtkWidget
*colorize_fr
;
181 GtkWidget
*colorize_hbox
;
183 GtkWidget
*status_fr
;
184 GtkWidget
*status_vbox
;
186 GtkWidget
*disabled_cb
;
189 GtkWidget
*edit_color_filter_ok
;
190 GtkWidget
*edit_color_filter_cancel
;
195 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters
));
197 gtk_tree_model_iter_nth_child(model
, &iter
, NULL
, color_dlg_row_selected
);
198 gtk_tree_model_get(model
, &iter
, 5, &colorf
, -1);
200 if (colorf
->color_edit_dlg_info
!= NULL
) {
201 cedi
= (color_edit_dlg_info_t
*)colorf
->color_edit_dlg_info
;
202 g_assert(cedi
->color_edit_dlg
!= NULL
);
203 /* There's already an edit box open for this filter; reactivate it. */
204 reactivate_window(cedi
->color_edit_dlg
);
209 color_edit_dlg
= dlg_conf_window_new ("Wireshark: Edit Color Filter");
210 gtk_window_set_default_size(GTK_WINDOW(color_edit_dlg
), 500, -1);
211 /* XXX: set color_edit_dlg as 'modal' to prevent simultaneously opening
212 * dialog windows for different filters ? is 'transient for' also needed ?
215 dialog_vbox
= ws_gtk_box_new(GTK_ORIENTATION_VERTICAL
, 0, FALSE
);
216 gtk_container_set_border_width (GTK_CONTAINER (dialog_vbox
), 5);
217 gtk_container_add (GTK_CONTAINER (color_edit_dlg
), dialog_vbox
);
220 filter_fr
= gtk_frame_new("Filter");
221 gtk_box_pack_start (GTK_BOX (dialog_vbox
), filter_fr
, FALSE
, FALSE
, 0);
223 filter_fr_vbox
= ws_gtk_box_new(GTK_ORIENTATION_VERTICAL
, 0, FALSE
);
224 gtk_container_set_border_width (GTK_CONTAINER (filter_fr_vbox
), 5);
225 gtk_container_add(GTK_CONTAINER(filter_fr
), filter_fr_vbox
);
227 /* filter name hbox */
228 filter_name_hbox
= ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 0, FALSE
);
229 gtk_box_pack_start (GTK_BOX (filter_fr_vbox
), filter_name_hbox
, TRUE
, FALSE
, 3);
231 color_filter_name
= gtk_label_new (("Name: "));
232 gtk_box_pack_start (GTK_BOX (filter_name_hbox
), color_filter_name
, FALSE
, FALSE
, 0);
234 filt_name_entry
= gtk_entry_new ();
235 gtk_entry_set_text(GTK_ENTRY(filt_name_entry
), colorf
->filter_name
);
237 #if GTK_CHECK_VERSION(3,0,0)
239 GdkRGBA bg_rgba_color
, fg_rgba_color
;
240 color_t_to_gdkRGBAcolor(&bg_rgba_color
, &colorf
->bg_color
);
241 color_t_to_gdkRGBAcolor(&fg_rgba_color
, &colorf
->fg_color
);
242 gtk_widget_override_background_color(filt_name_entry
, GTK_STATE_FLAG_NORMAL
, &bg_rgba_color
);
243 gtk_widget_override_color(filt_name_entry
, GTK_STATE_FLAG_NORMAL
, &fg_rgba_color
);
247 GdkColor bg_color
, fg_color
;
248 color_t_to_gdkcolor(&bg_color
, &colorf
->bg_color
);
249 color_t_to_gdkcolor(&fg_color
, &colorf
->fg_color
);
251 gtk_widget_modify_base(filt_name_entry
, GTK_STATE_NORMAL
, &bg_color
);
252 gtk_widget_modify_text(filt_name_entry
, GTK_STATE_NORMAL
, &fg_color
);
255 gtk_box_pack_start (GTK_BOX (filter_name_hbox
), filt_name_entry
, TRUE
, TRUE
, 0);
256 gtk_widget_set_tooltip_text(filt_name_entry
, "This is the editable name of the filter. (No @ characters allowed.)");
258 /* filter string hbox */
259 filter_string_hbox
= ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 0, FALSE
);
260 gtk_box_pack_start (GTK_BOX (filter_fr_vbox
), filter_string_hbox
, TRUE
, FALSE
, 3);
262 color_filter_text
= gtk_label_new (("String: "));
263 gtk_box_pack_start (GTK_BOX (filter_string_hbox
), color_filter_text
, FALSE
, FALSE
, 0);
265 filt_text_entry
= gtk_entry_new ();
266 g_signal_connect(filt_text_entry
, "changed", G_CALLBACK(filter_te_syntax_check_cb
), NULL
);
267 g_object_set_data(G_OBJECT(filter_string_hbox
), E_FILT_AUTOCOMP_PTR_KEY
, NULL
);
268 g_signal_connect(filt_text_entry
, "key-press-event", G_CALLBACK (filter_string_te_key_pressed_cb
), NULL
);
269 g_signal_connect(color_edit_dlg
, "key-press-event", G_CALLBACK (filter_parent_dlg_key_pressed_cb
), NULL
);
270 gtk_entry_set_text(GTK_ENTRY(filt_text_entry
), colorf
->filter_text
);
272 gtk_box_pack_start (GTK_BOX (filter_string_hbox
), filt_text_entry
, TRUE
, TRUE
, 0);
273 gtk_widget_set_tooltip_text(filt_text_entry
, "This is the editable text of the filter");
275 /* Create the "Add Expression..." button, to pop up a dialog
276 for constructing filter comparison expressions. */
277 add_expression_bt
= gtk_button_new_from_stock(WIRESHARK_STOCK_ADD_EXPRESSION
);
278 g_signal_connect(add_expression_bt
, "clicked", G_CALLBACK(filter_expr_cb
), filt_text_entry
);
279 gtk_box_pack_start (GTK_BOX(filter_string_hbox
), add_expression_bt
, FALSE
, FALSE
, 3);
280 gtk_widget_set_tooltip_text(add_expression_bt
, "Add an expression to the filter string");
282 /* Show the (in)validity of the default filter string */
283 filter_te_syntax_check_cb(filt_text_entry
, NULL
);
285 /* settings_hbox for "choose color frame" and "status frame" */
286 settings_hbox
= ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 0, FALSE
);
287 gtk_box_pack_start (GTK_BOX (dialog_vbox
), settings_hbox
, FALSE
, FALSE
, 0);
289 /* choose color frame */
290 colorize_fr
= gtk_frame_new("Display Colors");
291 gtk_box_pack_start (GTK_BOX (settings_hbox
), colorize_fr
, TRUE
, TRUE
, 0);
293 colorize_hbox
= ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 0, FALSE
);
294 gtk_container_set_border_width (GTK_CONTAINER (colorize_hbox
), 5);
295 gtk_container_add(GTK_CONTAINER(colorize_fr
), colorize_hbox
);
297 colorize_filter_new(colorize_hbox
,
298 COLOR_SELECTION_TYPE_FG
,
299 "Foreground", "Foreground Color...", "Select foreground color for data display",
300 colorf
, &colorf
->fg_color
,
303 colorize_filter_new(colorize_hbox
,
304 COLOR_SELECTION_TYPE_BG
,
305 "Background", "Background Color...", "Select background color for data display",
306 colorf
, &colorf
->bg_color
,
310 status_fr
= gtk_frame_new("Status");
311 gtk_box_pack_start (GTK_BOX (settings_hbox
), status_fr
, TRUE
, TRUE
, 0);
313 status_vbox
= ws_gtk_box_new(GTK_ORIENTATION_VERTICAL
, 0, FALSE
);
314 gtk_container_set_border_width (GTK_CONTAINER (status_vbox
), 5);
315 gtk_container_add(GTK_CONTAINER(status_fr
), status_vbox
);
317 /** "Disabled" check box */
318 disabled_cb
= gtk_check_button_new_with_label("Disabled");
319 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(disabled_cb
), colorf
->disabled
);
320 gtk_box_pack_start (GTK_BOX (status_vbox
), disabled_cb
, TRUE
, FALSE
, 0);
321 gtk_widget_set_tooltip_text(disabled_cb
, "Color rule won't be checked if this box is selected");
324 bbox
= dlg_button_row_new(GTK_STOCK_OK
, GTK_STOCK_CANCEL
, NULL
);
325 gtk_box_pack_start(GTK_BOX(dialog_vbox
), bbox
, FALSE
, FALSE
, 0);
326 gtk_container_set_border_width (GTK_CONTAINER (bbox
), 0);
329 edit_color_filter_cancel
= (GtkWidget
*)g_object_get_data(G_OBJECT(bbox
), GTK_STOCK_CANCEL
);
330 gtk_widget_set_tooltip_text(edit_color_filter_cancel
, "Reject filter color change");
331 /* escape will select cancel */
332 window_set_cancel_button(color_edit_dlg
, edit_color_filter_cancel
, window_cancel_button_cb
);
335 edit_color_filter_ok
= (GtkWidget
*)g_object_get_data(G_OBJECT(bbox
), GTK_STOCK_OK
);
336 gtk_widget_set_tooltip_text(edit_color_filter_ok
, "Accept filter color change");
337 gtk_widget_grab_default(edit_color_filter_ok
);
339 cedi
= g_new(color_edit_dlg_info_t
, 1);
340 colorf
->color_edit_dlg_info
= cedi
;
342 cedi
->color_filters
= color_filters
;
343 cedi
->colorf
= colorf
;
344 cedi
->color_edit_dlg
= color_edit_dlg
;
345 cedi
->filt_name_entry
= filt_name_entry
;
346 cedi
->filt_text_entry
= filt_text_entry
;
347 cedi
->disabled_cb
= disabled_cb
;
349 g_signal_connect(color_edit_dlg
, "destroy", G_CALLBACK(color_edit_dlg_destroy_cb
), cedi
);
351 g_signal_connect(edit_color_filter_ok
, "clicked", G_CALLBACK(color_edit_dlg_ok_cb
), cedi
);
354 g_signal_connect(edit_color_filter_cancel
, "clicked",
355 G_CALLBACK(color_edit_dlg_cancel_cb
), cedi
);
358 g_signal_connect(color_edit_dlg
, "delete_event", G_CALLBACK(window_delete_event_cb
), NULL
);
360 gtk_widget_show_all(color_edit_dlg
);
361 window_present(color_edit_dlg
);
365 /* accept color (and potential content) change */
367 color_edit_dlg_ok_cb(GtkWidget
*w _U_
, gpointer user_data
)
369 color_edit_dlg_info_t
*cedi
= (color_edit_dlg_info_t
*)user_data
;
373 gboolean filter_disabled
;
374 color_filter_t
*colorf
;
375 dfilter_t
*compiled_filter
;
378 gchar fg_str
[14], bg_str
[14];
380 filter_name
= g_strdup(gtk_entry_get_text(GTK_ENTRY(cedi
->filt_name_entry
)));
381 filter_text
= g_strdup(gtk_entry_get_text(GTK_ENTRY(cedi
->filt_text_entry
)));
382 filter_disabled
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cedi
->disabled_cb
));
384 if (strchr(filter_name
,'@') || strchr(filter_text
,'@')) {
385 simple_dialog(ESD_TYPE_ERROR
, ESD_BTN_OK
,
386 "Filter names and strings must not"
387 " use the '@' character. Filter unchanged.");
393 if (!dfilter_compile(filter_text
, &compiled_filter
)) {
394 simple_dialog(ESD_TYPE_ERROR
, ESD_BTN_OK
,
395 "Filter \"%s\" didn't compile correctly.\n"
396 " Please try again. Filter unchanged.\n%s\n", filter_name
,
403 colorf
= cedi
->colorf
;
405 g_free(colorf
->filter_name
);
406 g_free(colorf
->filter_text
);
408 colorf
->filter_name
= filter_name
;
409 colorf
->filter_text
= filter_text
;
411 colorf
->disabled
= filter_disabled
;
413 #if GTK_CHECK_VERSION(3,0,0)
415 GtkStyleContext
*context
;
416 GdkRGBA new_rgba_fg_color
;
417 GdkRGBA new_rgba_bg_color
;
419 context
= gtk_widget_get_style_context (cedi
->filt_name_entry
);
421 gtk_style_context_get_color(context
, (GtkStateFlags
)GTK_STATE_NORMAL
, &new_rgba_fg_color
); /* aka foreground color */
422 gtk_style_context_get_background_color(context
, (GtkStateFlags
)GTK_STATE_NORMAL
, &new_rgba_bg_color
);
424 gdkRGBAcolor_to_color_t(&colorf
->fg_color
, &new_rgba_fg_color
);
425 gdkRGBAcolor_to_color_t(&colorf
->bg_color
, &new_rgba_bg_color
);
430 GdkColor new_fg_color
;
431 GdkColor new_bg_color
;
433 style
= gtk_widget_get_style(cedi
->filt_name_entry
);
434 new_bg_color
= style
->base
[GTK_STATE_NORMAL
];
435 new_fg_color
= style
->text
[GTK_STATE_NORMAL
];
437 gdkcolor_to_color_t(&colorf
->fg_color
, &new_fg_color
);
438 gdkcolor_to_color_t(&colorf
->bg_color
, &new_bg_color
);
442 g_snprintf(fg_str
, sizeof(fg_str
), "#%04X%04X%04X",
443 colorf
->fg_color
.red
, colorf
->fg_color
.green
, colorf
->fg_color
.blue
);
444 g_snprintf(bg_str
, sizeof(bg_str
), "#%04X%04X%04X",
445 colorf
->bg_color
.red
, colorf
->bg_color
.green
, colorf
->bg_color
.blue
);
447 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(cedi
->color_filters
));
448 gtk_tree_model_iter_nth_child(model
, &iter
, NULL
, color_dlg_row_selected
);
449 gtk_list_store_set(GTK_LIST_STORE(model
), &iter
, 0, filter_name
,
450 1, filter_text
, 2, fg_str
, 3, bg_str
,
451 4, filter_disabled
, -1);
453 if (colorf
->c_colorfilter
!= NULL
) {
454 dfilter_free(colorf
->c_colorfilter
);
456 colorf
->c_colorfilter
= compiled_filter
;
458 /* Destroy the dialog box. */
459 window_destroy(cedi
->color_edit_dlg
);
463 /* reject new color filter addition */
465 color_edit_dlg_cancel_cb(GtkWidget
*w _U_
, gpointer user_data
)
467 color_edit_dlg_info_t
*cedi
= (color_edit_dlg_info_t
*)user_data
;
469 /* Delete the entry. As a side effect this destroys the edit_dialog window.
470 Before the edit dialogue was launched, the color filter list was
471 prepended with a default entry. This is the entry at position 0 that we
472 want to delete now. */
473 color_delete_single(0, cedi
->color_filters
); /* calls color_edit_dlg_destroy() */
478 color_edit_dlg_destroy(color_edit_dlg_info_t
*cedi
)
483 g_assert(cedi
->color_edit_dlg
!= NULL
);
484 window_destroy(cedi
->color_edit_dlg
); /* invokes color_edit_dlg_destroy_cb */
488 /* Called when the color_edit_dlg is being destroyed;
489 * null out the pointer to this dialog.
490 * Note: any color_selection_dlg windows associated with
491 * this color_edit_dlg window will automatically be destroyed.
492 * (this is because the color_selection_dlg windows
493 * have done 'set_transient_for() & destroy_with_parent()
494 * ToDo: worry about 'order'
497 color_edit_dlg_destroy_cb(GObject
*object _U_
, gpointer user_data
)
499 color_edit_dlg_info_t
*cedi
= (color_edit_dlg_info_t
*)user_data
;
501 g_assert(cedi
->color_edit_dlg
);
503 cedi
->colorf
->color_edit_dlg_info
= NULL
;
509 /* Pop up a color selection (GTK3: color chooser) dialog to choose the foreground or background color. */
511 color_edit_dlg_fg_bg_btn_cb(GtkWidget
*button
, gpointer user_data
)
513 color_selection_dlg_info_t
*csdi
= (color_selection_dlg_info_t
*)user_data
;
515 GtkWidget
*color_selection_dlg
;
519 /* Do we already have one open for this dialog? */
520 if (csdi
->color_selection_dlg
!= NULL
) {
521 /* Yes. Just reactivate it. */
522 reactivate_window(csdi
->color_selection_dlg
);
526 title
= g_strdup_printf("Wireshark: Choose %s color for \"%s\"",
527 csdi
->color_selection_type_text
,
528 csdi
->colorf
->filter_name
);
530 #if GTK_CHECK_VERSION(3,4,0)
531 { /* GTK >= GTK 3.4: Use GtkColorChooser */
533 color_selection_dlg
= gtk_color_chooser_dialog_new(title
, GTK_WINDOW(gtk_widget_get_toplevel(button
)));
534 csdi
->color_selection_dlg
= color_selection_dlg
;
536 color_t_to_gdkRGBAcolor(&rgba_color
, csdi
->color
);
537 gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(color_selection_dlg
), &rgba_color
);
540 { /* GTK < GTK 3.4: Use GtkColorSelection */
542 GtkWidget
*color_selection
;
543 GtkWidget
*color_selection_dlg_help_btn
;
545 color_selection_dlg
= gtk_color_selection_dialog_new(title
);
546 gtk_container_set_border_width (GTK_CONTAINER (color_selection_dlg
), 10);
547 gtk_window_set_transient_for(GTK_WINDOW(color_selection_dlg
), GTK_WINDOW(gtk_widget_get_toplevel(button
)));
548 gtk_window_set_destroy_with_parent(GTK_WINDOW(color_selection_dlg
), TRUE
);
550 /* suppress the "help" button (brutally) */
551 g_object_get(color_selection_dlg
, "help-button", &color_selection_dlg_help_btn
, NULL
);
552 gtk_widget_destroy(color_selection_dlg_help_btn
);
555 gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(color_selection_dlg
));
557 color_t_to_gdkcolor(&gcolor
, csdi
->color
);
558 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(color_selection
), &gcolor
);
560 csdi
->color_selection_dlg
= color_selection_dlg
;
562 #endif /* GTK_CHECK(3,4,0) */
566 g_signal_connect(G_OBJECT(color_selection_dlg
), "response", G_CALLBACK(color_selection_dlg_response_cb
), csdi
);
567 g_signal_connect(G_OBJECT(color_selection_dlg
), "destroy", G_CALLBACK(color_selection_dlg_destroy_cb
), csdi
);
569 gtk_widget_show_all(color_selection_dlg
);
573 /* here when color_edit_dlg FG/BG button destroyed */
575 color_edit_dlg_fg_bg_btn_destroy_cb(GObject
*object _U_
, gpointer user_data
)
577 color_selection_dlg_info_t
*csdi
= (color_selection_dlg_info_t
*)user_data
;
584 color_selection_dlg_response_cb(GtkWidget
*color_selection_dlg
, gint response
, gpointer user_data
)
586 color_selection_dlg_info_t
*csdi
= (color_selection_dlg_info_t
*)user_data
;
588 if (response
!= GTK_RESPONSE_OK
) {
589 window_destroy(color_selection_dlg
);
593 /* Handle GTK_RESPONSE_OK */
595 #if GTK_CHECK_VERSION(3,4,0)
596 { /* GTK >= GTK 3.4: Using GtkColorChooser */
597 GdkRGBA new_rgba_color
;
599 gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(color_selection_dlg
), &new_rgba_color
);
601 /* now apply the change to the fore/background */
602 if (csdi
->color_selection_type
== COLOR_SELECTION_TYPE_FG
)
603 gtk_widget_override_color(csdi
->filt_name_entry
, GTK_STATE_FLAG_NORMAL
, &new_rgba_color
);
605 gtk_widget_override_background_color(csdi
->filt_name_entry
, GTK_STATE_FLAG_NORMAL
, &new_rgba_color
);
608 #elif GTK_CHECK_VERSION(3,0,0)
609 { /* (GTK >= GTK 3.0) && (GTK < GTK 3.4): Using GtkColorSelection (RGBA Color) */
610 GtkWidget
*color_selection
;
611 GdkRGBA new_rgba_color
;
614 gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(color_selection_dlg
));
616 gtk_color_selection_get_current_rgba(GTK_COLOR_SELECTION(color_selection
), &new_rgba_color
);
618 /* now apply the change to the fore/background */
619 if (csdi
->color_selection_type
== COLOR_SELECTION_TYPE_FG
)
620 gtk_widget_override_color(csdi
->filt_name_entry
, GTK_STATE_FLAG_NORMAL
, &new_rgba_color
);
622 gtk_widget_override_background_color(csdi
->filt_name_entry
, GTK_STATE_FLAG_NORMAL
, &new_rgba_color
);
625 { /* GTK2: Using GtkColorSelection (GDK Color) */
626 GtkWidget
*color_selection
;
630 gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(color_selection_dlg
));
632 gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(color_selection
), &new_color
);
634 /* now apply the change to the fore/background */
635 if (csdi
->color_selection_type
== COLOR_SELECTION_TYPE_FG
)
636 gtk_widget_modify_text(csdi
->filt_name_entry
, GTK_STATE_NORMAL
, &new_color
);
638 gtk_widget_modify_base(csdi
->filt_name_entry
, GTK_STATE_NORMAL
, &new_color
);
640 #endif /* GTK_CHECK_VERSION(3,4,0) */
642 window_destroy(color_selection_dlg
);
647 color_selection_dlg_destroy_cb(GObject
*object _U_
, gpointer user_data
)
649 color_selection_dlg_info_t
*csdi
= (color_selection_dlg_info_t
*)user_data
;
651 g_assert(csdi
->color_selection_dlg
);
653 csdi
->color_selection_dlg
= NULL
;
657 * Editor modelines - http://www.wireshark.org/tools/modelines.html
662 * indent-tabs-mode: nil
665 * vi: set shiftwidth=2 tabstop=8 expandtab:
666 * :indentSize=2:tabSize=8:noTabs=true: