Counters should be unsigned.
[terminatorX.git] / src / tX_panel.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_panel.h"
21 #include "tX_pbutton.h"
22 #include <string.h>
23 #include <stdio.h>
24
25 #define WID_DYN TRUE, TRUE, 0
26 #define WID_FIX FALSE, FALSE, 0
27
28 void tX_panel :: minimize(GtkWidget *w, tX_panel *p)
29 {
30         if (!p->client_hidden) {
31                 gtk_widget_hide(p->pixmap_min);
32                 gtk_widget_show(p->pixmap_max);
33                 gtk_widget_hide(p->clientframe);
34                 p->client_hidden=1;
35         } else {
36                 gtk_widget_hide(p->pixmap_max);
37                 gtk_widget_show(p->pixmap_min);
38                 gtk_widget_show(p->clientframe);
39                 p->client_hidden=0;
40         }
41                 
42         gboolean expand;
43         gboolean fill;
44         guint padding;
45         GtkPackType pack_type;
46                 
47         if (p->container) {
48                 gtk_box_query_child_packing(GTK_BOX(p->container), p->mainbox,
49                 &expand, &fill, &padding, &pack_type);
50                 gtk_box_set_child_packing(GTK_BOX(p->container), p->mainbox,
51                 expand, fill, padding, pack_type);
52                 gtk_container_check_resize(GTK_CONTAINER(p->container));                            
53         }
54 }
55
56 void tX_panel_make_label_bold(GtkWidget *widget) {
57         char label[128];
58         sprintf(label, "<b>%s</b>", gtk_label_get_text(GTK_LABEL(widget)));
59         gtk_label_set_markup(GTK_LABEL (widget), label);
60 }
61
62 tX_panel :: tX_panel (const char *name, GtkWidget *par)
63 {
64         client_hidden=0;
65         
66         container=par;
67         minbutton=gtk_button_new();
68         pixmap_min=tx_pixmap_widget(MINIMIZE);
69         pixmap_max=tx_pixmap_widget(MAXIMIZE);
70         labelbutton=gtk_label_new(name);
71         gtk_widget_set_halign(labelbutton, GTK_ALIGN_START);
72         tX_panel_make_label_bold(labelbutton);
73  
74         button_box=gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
75                
76         gtk_box_pack_start(GTK_BOX(button_box), pixmap_min, WID_FIX);
77         gtk_box_pack_start(GTK_BOX(button_box), pixmap_max, WID_FIX);
78         gtk_box_pack_start(GTK_BOX(button_box), labelbutton, WID_DYN);
79
80         gtk_container_set_border_width(GTK_CONTAINER(button_box), 2);
81         
82         gtk_container_add (GTK_CONTAINER (minbutton), button_box);
83         mainbox=gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
84         
85         topbox=gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
86         clientbox=gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
87         clientframe=gtk_frame_new((char *) NULL);
88         gtk_container_set_border_width( GTK_CONTAINER(clientframe), 0);
89         gtk_container_add(GTK_CONTAINER(clientframe), clientbox);
90         
91         gtk_box_pack_start(GTK_BOX(mainbox), topbox, WID_FIX);
92         gtk_box_pack_start(GTK_BOX(mainbox), clientframe, WID_FIX);
93         
94         gtk_box_pack_start(GTK_BOX(topbox), minbutton, WID_DYN);
95         
96         gtk_widget_show(pixmap_min);
97         gtk_widget_show(button_box);
98         gtk_widget_show(labelbutton);
99         gtk_widget_show(minbutton);
100         gtk_widget_show(topbox);
101         gtk_widget_show(clientbox);
102         gtk_widget_show(clientframe);   
103         gtk_widget_show(mainbox);
104         
105         g_signal_connect(G_OBJECT(minbutton), "clicked", (GCallback) tX_panel::minimize, (void *) this);
106 }
107
108 void tX_panel :: add_client_widget(GtkWidget *w)
109 {
110         gtk_box_pack_start(GTK_BOX(clientbox), w, WID_FIX);
111         gtk_widget_show(w);
112 }
113
114
115 tX_panel :: ~tX_panel()
116 {
117         gtk_widget_destroy(minbutton);
118         gtk_widget_destroy(clientbox);
119         gtk_widget_destroy(clientframe);
120         gtk_widget_destroy(topbox);
121         gtk_widget_destroy(mainbox);
122 }