annotate gui/mplayer/gtk/common.c @ 24992:5701e23ebcb4

Better handling of win32 GUI thread: 1. Use _beginthreadex to create the GUI thread to avoid possible memory leak when linked to MS CRT. 2. Terminate the GUI thread in an cleaner way using PostThreadMessage() rather than the unrecommended TerminateThread().
author zuxy
date Sun, 11 Nov 2007 08:14:57 +0000
parents 17bf4f4b0715
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
1
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
2 #include <gdk/gdkkeysyms.h>
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
3 #include <gtk/gtk.h>
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
4
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
5 #include "common.h"
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
6
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
7 void WidgetDestroy( GtkWidget * widget,GtkWidget ** widget_pointer )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
8 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
9 if ( !widget_pointer ) return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
10 gtk_widget_hide( *widget_pointer );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
11 gtk_widget_destroy( *widget_pointer );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
12 *widget_pointer=NULL;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
13 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
14
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
15 GtkWidget * AddDialogFrame( GtkWidget * parent )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
16 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
17 GtkWidget * frame;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
18 frame=AddFrame( NULL,GTK_SHADOW_IN,parent,1 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
19 gtk_container_set_border_width( GTK_CONTAINER( frame ),1 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
20 frame=AddFrame( NULL,GTK_SHADOW_NONE,frame,1 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
21 frame=AddFrame( NULL,GTK_SHADOW_ETCHED_OUT,frame,1 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
22 frame=AddFrame( NULL,GTK_SHADOW_NONE,frame,1 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
23 return frame;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
24 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
25
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
26 GtkWidget * AddFrame( const char * title,int type,GtkWidget * parent,int add )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
27 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
28 GtkWidget * frame = NULL;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
29 frame=gtk_frame_new( title );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
30 gtk_widget_set_name( frame,"frame" );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
31 gtk_widget_show( frame );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
32 gtk_frame_set_shadow_type( GTK_FRAME( frame ),type );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
33 if ( !parent ) return frame;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
34 if ( add ) gtk_container_add( GTK_CONTAINER( parent ),frame );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
35 else gtk_box_pack_start( GTK_BOX( parent ),frame,FALSE,FALSE,0 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
36 return frame;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
37 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
38
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
39 GtkWidget * AddLabel( const char * title,GtkWidget * parent )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
40 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
41 GtkWidget * label;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
42 label=gtk_label_new( title );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
43 gtk_widget_set_name( label,"label" );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
44 gtk_widget_show( label );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
45 if ( parent ) gtk_box_pack_start( GTK_BOX( parent ),label,FALSE,FALSE,0 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
46 gtk_misc_set_alignment( GTK_MISC( label ),0,0.5 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
47 gtk_misc_set_padding( GTK_MISC( label ),4,0 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
48 return label;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
49 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
50
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
51 GtkWidget * AddVBox( GtkWidget * parent,int type )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
52 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
53 GtkWidget * vbox;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
54 vbox=gtk_vbox_new( FALSE,0 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
55 gtk_widget_set_name( vbox,"vbox" );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
56 gtk_widget_show( vbox );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
57 if ( parent )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
58 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
59 if ( type ) gtk_box_pack_start( GTK_BOX( parent ),vbox,FALSE,FALSE,0 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
60 else gtk_container_add( GTK_CONTAINER( parent ),vbox );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
61 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
62 return vbox;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
63 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
64
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
65 GtkWidget * AddHBox( GtkWidget * parent,int type )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
66 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
67 GtkWidget * hbox;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
68 hbox=gtk_hbox_new( FALSE,0 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
69 gtk_widget_set_name( hbox,"hbox" );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
70 gtk_widget_show( hbox );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
71 if ( parent )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
72 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
73 if ( type ) gtk_box_pack_start( GTK_BOX( parent ),hbox,FALSE,FALSE,0 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
74 else gtk_container_add( GTK_CONTAINER( parent ),hbox );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
75 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
76 return hbox;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
77 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
78
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
79 GtkWidget * AddCheckButton( const char * title, GtkWidget * parent )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
80 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
81 GtkWidget * CB;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
82 CB=gtk_check_button_new_with_label( title );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
83 gtk_widget_set_name( CB,"CB" );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
84 gtk_widget_show( CB );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
85 gtk_box_pack_start( GTK_BOX( parent ),CB,FALSE,FALSE,0 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
86 return CB;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
87 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
88
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
89 GtkWidget * AddRadioButton( const char * title,GSList ** group,GtkWidget * parent )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
90 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
91 GtkWidget * RB;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
92 RB=gtk_radio_button_new_with_label( *group,title );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
93 *group=gtk_radio_button_group( GTK_RADIO_BUTTON( RB ) );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
94 gtk_widget_set_name( RB,"RB" );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
95 gtk_widget_show( RB );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
96 gtk_box_pack_start( GTK_BOX( parent ),RB,FALSE,FALSE,0 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
97 return RB;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
98 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
99
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
100 GtkWidget * AddSpinButton( const char * title,GtkAdjustment * adj,GtkWidget * parent )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
101 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
102 GtkWidget * SB;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
103 GtkWidget * label;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
104 label=gtk_label_new( title );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
105 gtk_misc_set_alignment( GTK_MISC( label ),0,0.5 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
106 gtk_box_pack_start( GTK_BOX( parent ),label,FALSE,FALSE,0 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
107 gtk_widget_show( label );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
108 SB=gtk_spin_button_new( adj,0,0 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
109 gtk_widget_set_name( SB,"SB" );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
110 gtk_box_pack_start( GTK_BOX( parent ),SB,FALSE,FALSE,0 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
111 gtk_widget_show( SB );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
112 return SB;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
113 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
114
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
115 GtkWidget * AddButton( const char * title,GtkWidget * parent )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
116 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
117 GtkWidget * B;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
118 B=gtk_button_new_with_label( title );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
119 gtk_widget_set_name( B,"B" );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
120 gtk_widget_show( B );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
121 gtk_container_add( GTK_CONTAINER( parent ),B );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
122 return B;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
123 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
124
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
125 GtkWidget * AddHSeparator( GtkWidget * parent )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
126 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
127 GtkWidget * hseparator;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
128 hseparator=gtk_hseparator_new();
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
129 gtk_widget_set_name( hseparator,"hseparator1" );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
130 gtk_widget_show( hseparator );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
131 gtk_box_pack_start( GTK_BOX( parent ),hseparator,FALSE,FALSE,0 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
132 gtk_widget_set_usize( hseparator,-2,6 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
133 return hseparator;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
134 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
135
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
136 GtkWidget * AddHButtonBox( GtkWidget * parent )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
137 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
138 GtkWidget * hbuttonbox;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
139 hbuttonbox=gtk_hbutton_box_new();
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
140 gtk_widget_set_name( hbuttonbox,"hbuttonbox" );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
141 gtk_widget_show( hbuttonbox );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
142 gtk_box_pack_start( GTK_BOX( parent ),hbuttonbox,FALSE,FALSE,0 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
143 gtk_button_box_set_child_size( GTK_BUTTON_BOX( hbuttonbox ),85,20 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
144 return hbuttonbox;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
145 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
146
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
147 GtkWidget * AddHScaler( GtkAdjustment * adj,GtkWidget * parent,int digit )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
148 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
149 GtkWidget * HS;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
150 HS=gtk_hscale_new( adj );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
151 gtk_widget_set_name( HS,"HS" );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
152 gtk_widget_show( HS );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
153 if ( parent ) gtk_box_pack_start( GTK_BOX( parent ),HS,TRUE,TRUE,0 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
154 gtk_scale_set_value_pos( GTK_SCALE( HS ),GTK_POS_RIGHT );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
155 gtk_scale_set_digits( GTK_SCALE( HS ),digit );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
156 return HS;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
157 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
158
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
159 GtkWidget * AddVScaler( GtkAdjustment * adj,GtkWidget * parent,int digit )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
160 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
161 GtkWidget * VS;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
162 VS=gtk_vscale_new( adj );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
163 gtk_widget_set_name( VS,"VS" );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
164 gtk_widget_show( VS );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
165 if ( parent ) gtk_box_pack_start( GTK_BOX( parent ),VS,TRUE,TRUE,0 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
166 // gtk_scale_set_value_pos( GTK_SCALE( VS ),GTK_POS_RIGHT );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
167 if ( digit == -1 ) gtk_scale_set_draw_value( GTK_SCALE( VS ),FALSE );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
168 else gtk_scale_set_digits( GTK_SCALE( VS ),digit );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
169 return VS;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
170 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
171
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
172 GtkWidget * AddComboBox( GtkWidget * parent )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
173 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
174 GtkWidget * CB;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
175 CB=gtk_combo_new();
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
176 gtk_widget_set_name( CB,"CB" );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
177 gtk_widget_show( CB );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
178 if ( parent ) gtk_box_pack_start( GTK_BOX( parent ),CB,TRUE,TRUE,0 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
179 return CB;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
180 }