3c9fa73dc1e0baaf5a61e9980a0f4dcd7f373282
[terminatorX.git] / terminatorX / src / tX_extdial.cc
1 #include "tX_extdial.h"
2 #include "tX_seqpar.h"
3 #include <string.h>
4
5 #define WID_DYN TRUE, TRUE, 0
6 #define WID_FIX FALSE, FALSE, 0
7
8 GtkSignalFunc tX_extdial :: f_entry(GtkWidget *w, tX_extdial *ed)
9 {
10         strcpy(ed->sval, gtk_entry_get_text(GTK_ENTRY(ed->entry)));
11         ed->s2f();
12         gtk_adjustment_set_value(ed->adj, ed->fval);
13         return NULL;
14 }
15
16 GtkSignalFunc tX_extdial :: f_adjustment(GtkWidget *w, tX_extdial *ed)
17 {
18         ed->fval=ed->adj->value;
19         ed->f2s();
20         gtk_entry_set_text(GTK_ENTRY(ed->entry), ed->sval);
21         return NULL;    
22 }
23
24 tX_extdial :: tX_extdial(const char *l, GtkAdjustment *a, tX_seqpar * sp, bool text_below)
25 {
26         adj=a;
27         fval=adj->value;
28         f2s();
29         if (l) label=gtk_label_new(l);
30         dial=gtk_tx_dial_new(adj);
31         entry=gtk_entry_new();
32         gtk_entry_set_max_length(GTK_ENTRY(entry), 5);
33         gtk_entry_set_text(GTK_ENTRY(entry), sval);
34         ignore_adj=0;
35         
36         eventbox=gtk_event_box_new();           
37         mainbox=gtk_vbox_new(FALSE, text_below ? 5 : 0);
38         gtk_container_add(GTK_CONTAINER(eventbox), mainbox);
39         
40         subbox=gtk_hbox_new(TRUE, 0);
41         gtk_box_pack_start(GTK_BOX(subbox), dial, WID_FIX);
42         gtk_box_pack_start(GTK_BOX(mainbox), subbox, WID_FIX);
43         gtk_box_pack_start(GTK_BOX(text_below ? mainbox : subbox), entry, WID_DYN);
44         if (l) gtk_box_pack_start(GTK_BOX(mainbox), label, WID_FIX);
45         
46         if (l) gtk_widget_show(label);
47         gtk_widget_show(entry);
48         gtk_entry_set_width_chars(GTK_ENTRY(entry), 4);
49         gtk_widget_show(dial);
50         gtk_widget_show(subbox);
51         gtk_widget_show(mainbox);
52         gtk_widget_show(eventbox);
53         
54         g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(tX_extdial::f_entry), (void *) this);
55         g_signal_connect(G_OBJECT(adj), "value_changed", G_CALLBACK(tX_extdial::f_adjustment), (void *) this);
56         
57         if (sp) {
58                 g_signal_connect(G_OBJECT(dial), "button_press_event", G_CALLBACK(tX_seqpar::tX_seqpar_press), sp);
59                 g_signal_connect(G_OBJECT(entry), "button_press_event", G_CALLBACK(tX_seqpar::tX_seqpar_press), sp);                    
60                 g_signal_connect(G_OBJECT(eventbox), "button_press_event", G_CALLBACK(tX_seqpar::tX_seqpar_press), sp);                 
61         }
62 }
63
64 tX_extdial :: ~tX_extdial()
65 {
66         gtk_object_destroy(GTK_OBJECT(adj));
67         gtk_widget_destroy(entry);
68         gtk_widget_destroy(label);
69         gtk_widget_destroy(dial);
70         gtk_widget_destroy(subbox);
71         gtk_widget_destroy(mainbox);
72         gtk_widget_destroy(eventbox);   
73 }