Adding some missing GPL headers - Alex
[terminatorX.git] / terminatorX / src / tX_glade_callbacks.cc
1 /*
2     terminatorX - realtime audio scratching software
3     Copyright (C) 1999-2003  Alexander K├Ânig
4  
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9  
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14  
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */    
20
21 #ifdef HAVE_CONFIG_H
22 #  include <config.h>
23 #endif
24
25 #include <gtk/gtk.h>
26
27 #include "tX_glade_callbacks.h"
28 #include "tX_glade_interface.h"
29 #include "tX_glade_support.h"
30 #include "tX_dialog.h"
31 #include "tX_global.h"
32 #include "tX_mastergui.h"
33 #include "tX_sequencer.h"
34
35 void
36 on_pref_cancel_clicked                 (GtkButton       *button,
37                                         gpointer         user_data)
38 {
39         gtk_widget_destroy(opt_dialog);
40 }
41
42
43 void
44 on_pref_apply_clicked                  (GtkButton       *button,
45                                         gpointer         user_data)
46 {
47         apply_options(opt_dialog);      
48 }
49
50
51 void
52 on_pref_ok_clicked                     (GtkButton       *button,
53                                         gpointer         user_data)
54 {
55         apply_options(opt_dialog);
56         gtk_widget_destroy(opt_dialog);
57 }
58
59
60 void
61 on_tx_options_destroy                  (GtkObject       *object,
62                                         gpointer         user_data)
63 {
64         opt_dialog=NULL;
65 }
66
67
68 void
69 on_alsa_buffer_time_value_changed      (GtkRange        *range,
70                                         gpointer         user_data)
71 {
72         GtkAdjustment *buffer_time=gtk_range_get_adjustment(GTK_RANGE(user_data));
73         GtkAdjustment *period_time=gtk_range_get_adjustment(GTK_RANGE(range));
74
75         period_time->upper=buffer_time->value;
76         gtk_adjustment_changed(period_time);
77 }
78
79 void
80 on_pref_reset_clicked                  (GtkButton       *button,
81                                         gpointer         user_data)
82 {
83         GtkWidget *dialog=gtk_message_dialog_new(GTK_WINDOW(opt_dialog->window), 
84                 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
85                 "Loose all your settings and set default values?");
86         
87         int res=gtk_dialog_run(GTK_DIALOG(dialog));
88         gtk_widget_destroy(dialog);
89                 
90         if (res!=GTK_RESPONSE_YES) {
91                 return;
92         }
93         
94         set_global_defaults();
95         init_tx_options(opt_dialog);
96 }
97
98 void
99 on_del_mode_cancel_clicked             (GtkButton       *button,
100                                         gpointer         user_data)
101 {
102         gtk_widget_destroy(del_dialog);
103         del_dialog=NULL;
104 }
105
106
107 void
108 on_del_mode_ok_clicked                 (GtkButton       *button,
109                                         gpointer         user_data)
110 {
111         tX_sequencer::del_mode mode;
112         
113         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(del_dialog, "all_events")))) {
114                 mode=tX_sequencer::DELETE_ALL;
115         } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(del_dialog, "upto_current")))) {
116                 mode=tX_sequencer::DELETE_UPTO_CURRENT;         
117         } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(del_dialog, "from_current")))) {
118                 mode=tX_sequencer::DELETE_FROM_CURRENT;         
119         } else {
120                 tX_error("Invalid tX_sequencer::del_mode selected.");
121                 return;
122         }
123         
124         switch(menu_del_mode) {
125                 case ALL_EVENTS_ALL_TURNTABLES:
126                         sequencer.delete_all_events(mode);
127                         break;
128                 case ALL_EVENTS_FOR_TURNTABLE:
129                         sequencer.delete_all_events_for_vtt(del_vtt, mode);
130                         break;
131                 case ALL_EVENTS_FOR_SP:
132                         sequencer.delete_all_events_for_sp(del_sp, mode);
133                         break;
134                 default:
135                         tX_error("Invalid del_mode");
136         }
137         
138         gtk_widget_destroy(del_dialog);
139         del_dialog=NULL;
140 }
141
142 void
143 color_clicked                          (GtkButton       *button,
144                                         gpointer         user_data)
145 {
146         GdkColor p;
147         GtkWidget *dialog=create_tX_color_selection();
148         GtkWidget *sel=lookup_widget(dialog, "color_selection");
149         g_object_set_data(G_OBJECT(dialog), "Button", button);
150         
151         gdk_color_parse((const char *) g_object_get_data(G_OBJECT(button), "Color"), &p);
152         gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(sel), &p);
153         gtk_widget_show(dialog);
154 }
155
156
157 void
158 on_color_selection_ok_clicked          (GtkButton       *button,
159                                         gpointer         user_data)
160 {
161         char tmp[56];
162         char *col;
163         GdkColor p;
164         
165         GtkWidget *dialog=gtk_widget_get_parent(gtk_widget_get_parent(gtk_widget_get_parent(GTK_WIDGET(button))));
166         GtkWidget *c_but=(GtkWidget *) g_object_get_data(G_OBJECT(dialog), "Button");
167         
168         GtkWidget *sel=lookup_widget(dialog, "color_selection");
169         gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(sel), &p);
170
171         col=(char *) g_object_get_data(G_OBJECT(c_but), "Color");
172         sprintf(col, "#%02X%02X%02X", p.red >> 8, p.green >> 8, p.blue >> 8);   
173         sprintf(tmp, "<span foreground=\"%s\"><b>%s</b></span>", col, col);
174         gtk_label_set_markup(GTK_LABEL(gtk_container_get_children(GTK_CONTAINER(c_but))->data), tmp);
175         
176         gtk_widget_destroy(dialog);
177 }
178
179
180 void
181 on_color_selection_cancel_clicked      (GtkButton       *button,
182                                         gpointer         user_data)
183 {
184         gtk_widget_destroy(
185                 gtk_widget_get_parent(
186                         gtk_widget_get_parent(
187                                 gtk_widget_get_parent(GTK_WIDGET(button))
188                         )
189                 )
190         );
191 }