c087704618ba1884630ab0e35362415f52456cc7
[terminatorX.git] / src / tX_extdial.cc
1 /*
2     terminatorX - realtime audio scratching software
3     Copyright (C) 1999-2016  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, see <http://www.gnu.org/licenses/>.
17
18 */    
19
20 #include "tX_extdial.h"
21 #include "tX_seqpar.h"
22 #include <string.h>
23
24 #define WID_DYN TRUE, TRUE, 0
25 #define WID_FIX FALSE, FALSE, 0
26
27 GCallback tX_extdial :: f_entry(GtkWidget *w, tX_extdial *ed)
28 {
29         strcpy(ed->sval, gtk_entry_get_text(GTK_ENTRY(ed->entry)));
30         ed->s2f();
31         gtk_adjustment_set_value(ed->adj, ed->fval);
32         return NULL;
33 }
34
35 GCallback tX_extdial :: f_adjustment(GtkWidget *w, tX_extdial *ed)
36 {
37         ed->fval=gtk_adjustment_get_value(ed->adj);
38         ed->f2s();
39         gtk_entry_set_text(GTK_ENTRY(ed->entry), ed->sval);
40         return NULL;    
41 }
42
43 tX_extdial :: tX_extdial(const char *l, GtkAdjustment *a, tX_seqpar * sp, bool text_below, bool hide_entry)
44 {
45         adj=a;
46         fval=gtk_adjustment_get_value(adj);
47         f2s();
48         if (l) {
49                 label=gtk_label_new(NULL);
50                 gtk_label_set_markup(GTK_LABEL(label),l); 
51         }
52         dial=gtk_tx_dial_new(adj);
53         entry=gtk_entry_new();
54         gtk_entry_set_max_length(GTK_ENTRY(entry), 5);
55         gtk_entry_set_text(GTK_ENTRY(entry), sval);
56 #if GTK_CHECK_VERSION(2,4,0)
57         gtk_entry_set_alignment(GTK_ENTRY(entry), 0.5);
58 #endif
59         ignore_adj=0;
60         
61         eventbox=gtk_event_box_new();           
62         mainbox=gtk_box_new(GTK_ORIENTATION_VERTICAL,  text_below ? 5 : 0);
63         gtk_container_add(GTK_CONTAINER(eventbox), mainbox);
64         
65         subbox=gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
66         gtk_box_set_homogeneous(GTK_BOX(subbox), TRUE);
67         gtk_box_pack_start(GTK_BOX(subbox), dial, WID_FIX);
68         gtk_box_pack_start(GTK_BOX(mainbox), subbox, WID_FIX);
69         gtk_box_pack_start(GTK_BOX(text_below ? mainbox : subbox), entry, WID_DYN);
70         if (l) gtk_box_pack_start(GTK_BOX(mainbox), label, WID_FIX);
71         
72         if (l) gtk_widget_show(label);
73         if (!hide_entry){ gtk_widget_show(entry); }
74         gtk_entry_set_width_chars(GTK_ENTRY(entry), 4);
75         gtk_entry_set_max_width_chars(GTK_ENTRY(entry), 4);
76         gtk_widget_show(dial);
77         gtk_widget_show(subbox);
78         gtk_widget_show(mainbox);
79         gtk_widget_show(eventbox);
80         
81         g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(tX_extdial::f_entry), (void *) this);
82         g_signal_connect(G_OBJECT(adj), "value_changed", G_CALLBACK(tX_extdial::f_adjustment), (void *) this);
83         
84         if (sp) {
85                 g_signal_connect(G_OBJECT(dial), "button_press_event", G_CALLBACK(tX_seqpar::tX_seqpar_press), sp);
86                 g_signal_connect(G_OBJECT(entry), "button_press_event", G_CALLBACK(tX_seqpar::tX_seqpar_press), sp);                    
87                 g_signal_connect(G_OBJECT(eventbox), "button_press_event", G_CALLBACK(tX_seqpar::tX_seqpar_press), sp);                 
88         }
89 }
90
91 tX_extdial :: ~tX_extdial()
92 {
93         gtk_widget_destroy(entry);
94         gtk_widget_destroy(label);
95         gtk_widget_destroy(dial);
96         gtk_widget_destroy(subbox);
97         gtk_widget_destroy(mainbox);
98         gtk_widget_destroy(eventbox);   
99 }