e30b8a3ee14ece9aa2651b41515cefe5403b97ac
[terminatorX.git] / terminatorX / src / tX_panel.cc
1 #include "tX_panel.h"
2 #include "tX_pbutton.h"
3 #include <string.h>
4 #include <stdio.h>
5
6 #define WID_DYN TRUE, TRUE, 0
7 #define WID_FIX FALSE, FALSE, 0
8
9 void tX_panel :: minimize(GtkWidget *w, tX_panel *p)
10 {
11         p->client_hidden=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p->minbutton));
12         
13         if (p->client_hidden)
14                 gtk_widget_hide(p->clientframe);
15         else
16                 gtk_widget_show(p->clientframe);
17                 
18         gboolean expand;
19         gboolean fill;
20         guint padding;
21         GtkPackType pack_type;
22                 
23         if (p->container) {
24                 gtk_box_query_child_packing(GTK_BOX(p->container), p->mainbox,
25                                                                         &expand, &fill, &padding, &pack_type);
26                 gtk_box_set_child_packing(GTK_BOX(p->container), p->mainbox,
27                                                                         expand, fill, padding, pack_type);
28                 gtk_container_check_resize(GTK_CONTAINER(p->container));                            
29         }
30 }
31
32 void tX_panel_make_label_bold(GtkWidget *widget) {
33         char label[128];        
34         sprintf(label, "<b>%s</b>", gtk_label_get_text(GTK_LABEL(widget)));
35         gtk_label_set_markup(GTK_LABEL (widget), label);
36 }
37
38 tX_panel :: tX_panel (const char *name, GtkWidget *par)
39 {
40         GtkWidget *pixmap;
41         client_hidden=0;
42         
43         container=par;
44         minbutton=gtk_toggle_button_new();
45         pixmap=tx_pixmap_widget(TX_ICON_MINIMIZE);
46         gtk_container_add (GTK_CONTAINER (minbutton), pixmap);
47         labelbutton=gtk_button_new_with_label(name);
48         gtk_container_foreach(GTK_CONTAINER(labelbutton), (GtkCallback) tX_panel_make_label_bold, NULL);
49         mainbox=gtk_vbox_new(FALSE, 0);
50         
51         topbox=gtk_hbox_new(FALSE, 0);
52         clientbox=gtk_vbox_new(FALSE, 0);
53         clientframe=gtk_frame_new((char *) NULL);
54         gtk_container_set_border_width( GTK_CONTAINER(clientframe), 0);
55         gtk_container_add(GTK_CONTAINER(clientframe), clientbox);
56         
57         gtk_box_pack_start(GTK_BOX(mainbox), topbox, WID_FIX);
58         gtk_box_pack_start(GTK_BOX(mainbox), clientframe, WID_FIX);
59         
60         gtk_box_pack_start(GTK_BOX(topbox), labelbutton, WID_DYN);
61         gtk_box_pack_start(GTK_BOX(topbox), minbutton, WID_FIX);
62         
63         gtk_widget_show(pixmap);
64         gtk_widget_show(labelbutton);
65         gtk_widget_show(minbutton);
66         gtk_widget_show(topbox);
67         gtk_widget_show(clientbox);
68         gtk_widget_show(clientframe);   
69         gtk_widget_show(mainbox);
70         
71         g_signal_connect(G_OBJECT(minbutton), "clicked", (GtkSignalFunc) tX_panel::minimize, (void *) this);
72 }
73
74 void tX_panel :: add_client_widget(GtkWidget *w)
75 {
76         gtk_box_pack_start(GTK_BOX(clientbox), w, WID_FIX);
77         gtk_widget_show(w);
78 }
79
80
81 tX_panel :: ~tX_panel()
82 {
83         gtk_widget_destroy(minbutton);
84         gtk_widget_destroy(labelbutton);
85         gtk_widget_destroy(clientbox);
86         gtk_widget_destroy(clientframe);
87         gtk_widget_destroy(topbox);
88         gtk_widget_destroy(mainbox);
89 }