Add a tiny bit of space right of the text entry fields.
[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         
64         gtk_container_add(GTK_CONTAINER(eventbox), mainbox);
65         
66         subbox=gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
67         gtk_box_set_homogeneous(GTK_BOX(subbox), TRUE);
68         gtk_box_pack_start(GTK_BOX(subbox), dial, WID_FIX);
69         gtk_box_pack_start(GTK_BOX(mainbox), subbox, WID_FIX);
70         if (text_below) {
71                 gtk_box_pack_start(GTK_BOX(mainbox), entry, WID_DYN);
72         } else {
73                 gtk_box_pack_start(GTK_BOX(subbox), entry, TRUE, TRUE, 3);
74         }
75         if (l) gtk_box_pack_start(GTK_BOX(mainbox), label, WID_FIX);
76         
77         if (l) gtk_widget_show(label);
78         if (!hide_entry){ gtk_widget_show(entry); }
79         gtk_entry_set_width_chars(GTK_ENTRY(entry), 4);
80         gtk_entry_set_max_width_chars(GTK_ENTRY(entry), 4);
81         gtk_widget_show(dial);
82         gtk_widget_show(subbox);
83         gtk_widget_show(mainbox);
84         gtk_widget_show(eventbox);
85         
86         g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(tX_extdial::f_entry), (void *) this);
87         g_signal_connect(G_OBJECT(adj), "value_changed", G_CALLBACK(tX_extdial::f_adjustment), (void *) this);
88         
89         if (sp) {
90                 g_signal_connect(G_OBJECT(dial), "button_press_event", G_CALLBACK(tX_seqpar::tX_seqpar_press), sp);
91                 g_signal_connect(G_OBJECT(entry), "button_press_event", G_CALLBACK(tX_seqpar::tX_seqpar_press), sp);                    
92                 g_signal_connect(G_OBJECT(eventbox), "button_press_event", G_CALLBACK(tX_seqpar::tX_seqpar_press), sp);                 
93         }
94 }
95
96 tX_extdial :: ~tX_extdial()
97 {
98         gtk_widget_destroy(entry);
99         gtk_widget_destroy(label);
100         gtk_widget_destroy(dial);
101         gtk_widget_destroy(subbox);
102         gtk_widget_destroy(mainbox);
103         gtk_widget_destroy(eventbox);   
104 }