68f9dbcfc931ba747119d922200221d15878d233
[terminatorX.git] / terminatorX / src / tX_glade_callbacks.cc
1 #ifdef HAVE_CONFIG_H
2 #  include <config.h>
3 #endif
4
5 #include <gtk/gtk.h>
6
7 #include "tX_glade_callbacks.h"
8 #include "tX_glade_interface.h"
9 #include "tX_glade_support.h"
10 #include "tX_dialog.h"
11 #include "tX_global.h"
12 #include "tX_mastergui.h"
13 #include "tX_sequencer.h"
14
15 void
16 on_pref_cancel_clicked                 (GtkButton       *button,
17                                         gpointer         user_data)
18 {
19         gtk_widget_destroy(opt_dialog);
20 }
21
22
23 void
24 on_pref_apply_clicked                  (GtkButton       *button,
25                                         gpointer         user_data)
26 {
27         apply_options(opt_dialog);      
28 }
29
30
31 void
32 on_pref_ok_clicked                     (GtkButton       *button,
33                                         gpointer         user_data)
34 {
35         apply_options(opt_dialog);
36         gtk_widget_destroy(opt_dialog);
37 }
38
39
40 void
41 on_tx_options_destroy                  (GtkObject       *object,
42                                         gpointer         user_data)
43 {
44         opt_dialog=NULL;
45 }
46
47
48 void
49 on_alsa_buffer_time_value_changed      (GtkRange        *range,
50                                         gpointer         user_data)
51 {
52         GtkAdjustment *buffer_time=gtk_range_get_adjustment(GTK_RANGE(user_data));
53         GtkAdjustment *period_time=gtk_range_get_adjustment(GTK_RANGE(range));
54
55         period_time->upper=buffer_time->value;
56         gtk_adjustment_changed(period_time);
57 }
58
59 void
60 on_pref_reset_clicked                  (GtkButton       *button,
61                                         gpointer         user_data)
62 {
63         GtkWidget *dialog=gtk_message_dialog_new(GTK_WINDOW(opt_dialog->window), 
64                 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
65                 "Loose all your settings and set default values?");
66         
67         int res=gtk_dialog_run(GTK_DIALOG(dialog));
68         gtk_widget_destroy(dialog);
69                 
70         if (res!=GTK_RESPONSE_YES) {
71                 return;
72         }
73         
74         set_global_defaults();
75         init_tx_options(opt_dialog);
76 }
77
78 void
79 on_del_mode_cancel_clicked             (GtkButton       *button,
80                                         gpointer         user_data)
81 {
82         gtk_widget_destroy(del_dialog);
83         del_dialog=NULL;
84 }
85
86
87 void
88 on_del_mode_ok_clicked                 (GtkButton       *button,
89                                         gpointer         user_data)
90 {
91         tX_sequencer::del_mode mode;
92         
93         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(del_dialog, "all_events")))) {
94                 mode=tX_sequencer::DELETE_ALL;
95         } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(del_dialog, "upto_current")))) {
96                 mode=tX_sequencer::DELETE_UPTO_CURRENT;         
97         } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(del_dialog, "from_current")))) {
98                 mode=tX_sequencer::DELETE_FROM_CURRENT;         
99         } else {
100                 tX_error("Invalid tX_sequencer::del_mode selected.");
101                 return;
102         }
103         
104         switch(menu_del_mode) {
105                 case ALL_EVENTS_ALL_TURNTABLES:
106                         sequencer.delete_all_events(mode);
107                         break;
108                 case ALL_EVENTS_FOR_TURNTABLE:
109                         sequencer.delete_all_events_for_vtt(del_vtt, mode);
110                         break;
111                 case ALL_EVENTS_FOR_SP:
112                         sequencer.delete_all_events_for_sp(del_sp, mode);
113                         break;
114                 default:
115                         tX_error("Invalid del_mode");
116         }
117         
118         gtk_widget_destroy(del_dialog);
119         del_dialog=NULL;
120 }
121
122 void
123 color_clicked                          (GtkButton       *button,
124                                         gpointer         user_data)
125 {
126         GdkColor p;
127         GtkWidget *dialog=create_tX_color_selection();
128         GtkWidget *sel=lookup_widget(dialog, "color_selection");
129         g_object_set_data(G_OBJECT(dialog), "Button", button);
130         
131         gdk_color_parse((const char *) g_object_get_data(G_OBJECT(button), "Color"), &p);
132         gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(sel), &p);
133         gtk_widget_show(dialog);
134 }
135
136
137 void
138 on_color_selection_ok_clicked          (GtkButton       *button,
139                                         gpointer         user_data)
140 {
141         char tmp[56];
142         char *col;
143         GdkColor p;
144         
145         GtkWidget *dialog=gtk_widget_get_parent(gtk_widget_get_parent(gtk_widget_get_parent(GTK_WIDGET(button))));
146         GtkWidget *c_but=(GtkWidget *) g_object_get_data(G_OBJECT(dialog), "Button");
147         
148         GtkWidget *sel=lookup_widget(dialog, "color_selection");
149         gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(sel), &p);
150
151         col=(char *) g_object_get_data(G_OBJECT(c_but), "Color");
152         sprintf(col, "#%02X%02X%02X", p.red >> 8, p.green >> 8, p.blue >> 8);   
153         sprintf(tmp, "<span foreground=\"%s\"><b>%s</b></span>", col, col);
154         gtk_label_set_markup(GTK_LABEL(gtk_container_get_children(GTK_CONTAINER(c_but))->data), tmp);
155         
156         gtk_widget_destroy(dialog);
157 }
158
159
160 void
161 on_color_selection_cancel_clicked      (GtkButton       *button,
162                                         gpointer         user_data)
163 {
164         gtk_widget_destroy(
165                 gtk_widget_get_parent(
166                         gtk_widget_get_parent(
167                                 gtk_widget_get_parent(GTK_WIDGET(button))
168                         )
169                 )
170         );
171 }