Minor GUI tweaking - Alex
[terminatorX.git] / 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         {
25                 gtk_box_query_child_packing(GTK_BOX(p->container),
26                                             p->mainbox,
27                                             &expand,
28                                             &fill,
29                                             &padding,
30                                             &pack_type);
31                 gtk_box_set_child_packing(GTK_BOX(p->container),
32                                             p->mainbox,
33                                             expand,
34                                             fill,
35                                             padding,
36                                             pack_type);
37                 gtk_container_check_resize(GTK_CONTAINER(p->container));                            
38                 //gtk_widget_set_usize(p->container, p->container->allocation.width, p->container->allocation.height);
39         }
40 }
41
42 void tX_panel_make_label_bold(GtkWidget *widget) {
43         char label[128];
44         strcpy(label, "<b>");
45         strcat(label, gtk_label_get_text(GTK_LABEL(widget)));
46         strcat(label, "</b>");
47         gtk_label_set_markup(GTK_LABEL (widget), label);
48 }
49
50 tX_panel :: tX_panel (const char *name, GtkWidget *par)
51 {
52         GtkWidget *pixmap;
53         client_hidden=0;
54         
55         container=par;
56         minbutton=gtk_toggle_button_new();
57         pixmap=tx_pixmap_widget(TX_ICON_MINIMIZE);
58         gtk_container_add (GTK_CONTAINER (minbutton), pixmap);
59         labelbutton=gtk_button_new_with_label(name);
60         gtk_container_foreach(GTK_CONTAINER(labelbutton), (GtkCallback) tX_panel_make_label_bold, NULL);
61         mainbox=gtk_vbox_new(FALSE, 0);
62         
63         topbox=gtk_hbox_new(FALSE, 0);
64         clientbox=gtk_vbox_new(FALSE, 0);
65         clientframe=gtk_frame_new((char *) NULL);
66         gtk_container_set_border_width( GTK_CONTAINER(clientframe), 0);
67         gtk_container_add(GTK_CONTAINER(clientframe), clientbox);
68         
69         gtk_box_pack_start(GTK_BOX(mainbox), topbox, WID_FIX);
70         gtk_box_pack_start(GTK_BOX(mainbox), clientframe, WID_FIX);
71         
72         gtk_box_pack_start(GTK_BOX(topbox), labelbutton, WID_DYN);
73         gtk_box_pack_start(GTK_BOX(topbox), minbutton, WID_FIX);
74         
75         gtk_widget_show(pixmap);
76         gtk_widget_show(labelbutton);
77         gtk_widget_show(minbutton);
78         gtk_widget_show(topbox);
79         gtk_widget_show(clientbox);
80         gtk_widget_show(clientframe);   
81         gtk_widget_show(mainbox);
82         
83         gtk_signal_connect(GTK_OBJECT(minbutton), "clicked", (GtkSignalFunc) tX_panel::minimize, (void *) this);
84 }
85
86 void tX_panel :: add_client_widget(GtkWidget *w)
87 {
88         gtk_box_pack_start(GTK_BOX(clientbox), w, WID_FIX);
89         gtk_widget_show(w);
90 }
91
92
93 tX_panel :: ~tX_panel()
94 {
95         //gtk_widget_destroy(pixmap);
96         gtk_widget_destroy(minbutton);
97         gtk_widget_destroy(labelbutton);
98         gtk_widget_destroy(clientbox);
99         gtk_widget_destroy(clientframe);
100         gtk_widget_destroy(topbox);
101         gtk_widget_destroy(mainbox);
102 }