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