1 /*
2  * File:		 rollup.c
3  *
4  * Description:  provides "tool roll up" functionality, as seen in many of the
5  *               popular 3d and drawing packages.  Tool buttons can be
6  *               organized into "pages", which can be hidden or shown by
7  *               clicking on the button at the head of each page.  It is
8  *               recommended that you wrap the rollup widget in a scrolled win.
9  *
10  * This source code is part of kludge3d, and is released under the
11  * GNU General Public License.
12  *
13  *
14  */
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <gtk/gtk.h>
20 
21 #include "rollup.h"
22 
23 #ifdef MEMWATCH
24 #include "memwatch.h"
25 #endif
26 
27 /* PROTOTYPES ***********************************************************/
28 
29 void rollup_switch_arrow_cb( GtkButton *button, gpointer data ) ;
30 void rollup_toggle_frame_cb( GtkButton *button, gpointer data ) ;
31 
32 
33 /* FUNCS ****************************************************************/
34 
rollup_new(void)35 GtkWidget * rollup_new( void ) {
36 	return gtk_vbox_new( FALSE, 0 );
37 }
38 
39 
rollup_append_page(GtkWidget * rollup,GtkWidget * child,char * labelstr,int expanded)40 void rollup_append_page(
41 	GtkWidget *rollup, GtkWidget *child, char *labelstr, int expanded )
42 {
43 	GtkWidget *frame, *label, *button, *hbox, *arrow;
44 
45 	if( rollup == NULL || child == NULL ) return;
46 
47 	button = gtk_button_new();
48 	hbox = gtk_hbox_new( FALSE, 0 );
49 	gtk_container_add( GTK_CONTAINER( button ), hbox );
50 
51 	/* 'expanded' indicator on button */
52 	arrow = gtk_arrow_new( GTK_ARROW_DOWN, GTK_SHADOW_NONE );
53 	gtk_box_pack_start( GTK_BOX( hbox ), arrow, FALSE, FALSE, 0 );
54 
55 	/* label on button */
56 	label = gtk_label_new( labelstr );
57 	gtk_box_pack_start( GTK_BOX( hbox ), label, TRUE, TRUE, 0 );
58 
59 	frame = gtk_frame_new( NULL );
60 	gtk_container_add( GTK_CONTAINER( frame ), child );
61 
62 	gtk_widget_show_all( button );
63 	gtk_widget_show_all( frame );
64 	gtk_box_pack_start( GTK_BOX( rollup ), button, FALSE, FALSE, 0 );
65 	gtk_box_pack_start( GTK_BOX( rollup ), frame, FALSE, FALSE, 0 );
66 
67 	/* signal handlers for the button */
68 	g_signal_connect( G_OBJECT( button ), "clicked",
69 						G_CALLBACK( rollup_switch_arrow_cb ), arrow );
70 	g_signal_connect( G_OBJECT( button ), "clicked",
71 						G_CALLBACK( rollup_toggle_frame_cb ), frame );
72 
73 	if( !expanded ) {
74 		rollup_switch_arrow_cb( GTK_BUTTON(button), arrow );
75 		rollup_toggle_frame_cb( GTK_BUTTON(button), frame );
76 	}
77 }
78 
79 
80 /* CALLBACKS ************************************************************/
81 
rollup_switch_arrow_cb(GtkButton * button,gpointer data)82 void rollup_switch_arrow_cb( GtkButton *button, gpointer data ) {
83 	GtkArrow *arrow = GTK_ARROW( data );
84 	gtk_arrow_set( arrow,
85 		arrow->arrow_type == GTK_ARROW_DOWN ? GTK_ARROW_RIGHT : GTK_ARROW_DOWN,
86 		GTK_SHADOW_NONE );
87 }
88 
89 
rollup_toggle_frame_cb(GtkButton * button,gpointer data)90 void rollup_toggle_frame_cb( GtkButton *button, gpointer data ) {
91 	GtkWidget *widget = GTK_WIDGET( data );
92 	if( GTK_WIDGET_VISIBLE( widget ) ) {
93 		gtk_widget_hide( widget );
94 	} else {
95 		gtk_widget_show( widget );
96 	}
97 }
98 
99 
100