1 /*
2 * This file is part of XForms.
3 *
4 * XForms is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation; either version 2.1, or
7 * (at your option) any later version.
8 *
9 * XForms is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with XForms; see the file COPYING. If not, write to
16 * the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
17 * MA 02111-1307, USA.
18 */
19
20
21 /* This demo shows the use of menu's.
22 * The first two are PUSH_MENUs (pop-up).
23 * The third one is PULLDOWN_MENU
24 * and the last one is TOUCH_MENU
25 *
26 * a confusing demo, but a good testing program ..
27 */
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include "include/forms.h"
34 #include <stdlib.h>
35
36 extern FL_FORM *create_form(void);
37
38 FL_OBJECT *menu[ 4 ],
39 *abox[ 4 ];
40 int set[ 4 ];
41
42 /***************************************
43 ***************************************/
44
45 int
main(int argc,char * argv[])46 main( int argc,
47 char * argv[ ] )
48 {
49 FL_FORM *form;
50 int i,
51 j;
52
53 fl_initialize( &argc, argv, "FormDemo", 0, 0 );
54
55 form = create_form( );
56
57 /* fl_setpup_color( FL_SLATEBLUE, FL_BLACK ); */
58
59 for ( i = 0; i < 4; i++ )
60 {
61 fl_show_menu_symbol( menu[ i ], 1 );
62
63 fl_set_menu( menu[ i ],
64 "Red%r1|Green%r1|Yellow%r1|Blue%r1|Purple%r1|"
65 "Cyran%r1|White%r1");
66
67 fl_set_menu_item_shortcut( menu[ i ], 1, "Rr#R#r" );
68 fl_set_menu_item_shortcut( menu[ i ], 2, "Gg#G#g" );
69 fl_set_menu_item_shortcut( menu[ i ], 3, "Yy#Y#y" );
70 fl_set_menu_item_shortcut( menu[ i ], 4, "Bb#B#b" );
71 fl_set_menu_item_shortcut( menu[ i ], 5, "Pp#P#p" );
72 fl_set_menu_item_shortcut( menu[ i ], 6, "Cc#C#c" );
73 fl_set_menu_item_shortcut( menu[ i ], 7, "Ww#W#w" );
74
75 /* Initially the last three entries are enabled */
76
77 for ( j = 5; j <= 7; j++ )
78 fl_set_menu_item_mode( menu[ i ], j, FL_PUP_RADIO );
79
80 /* The first four are disabled except the item (i+1) */
81
82 for ( j = 1; j <= 4; j++ )
83 fl_set_menu_item_mode( menu[ i ], j, FL_PUP_GREY | FL_PUP_RADIO );
84
85 set[ i ] = i + 1;
86 fl_set_object_color( abox[ i ], FL_BLACK + set[ i ], FL_BLACK );
87 fl_set_menu_item_mode( menu[ i ], set[ i ],
88 FL_PUP_CHECK | FL_PUP_RADIO );
89 }
90
91 fl_show_form( form, FL_PLACE_CENTER, FL_TRANSIENT, "Menu" );
92
93 fl_do_forms( );
94 fl_hide_form( form );
95
96 return 0;
97 }
98
99
100 /***************************************
101 * m is the menu index 0 - 3
102 ***************************************/
103
104 static void
menu_cb(FL_OBJECT * obj,long m)105 menu_cb( FL_OBJECT * obj,
106 long m )
107 {
108 int i,
109 item = fl_get_menu( obj );
110
111 if ( item <= 0 || set[ m ] == item )
112 return;
113
114 for ( i = 0; i < 4; i++)
115 {
116 if ( i != m )
117 {
118 /* enable the old selected color for other menus*/
119
120 fl_set_menu_item_mode( menu[ i ], set[ m ], FL_PUP_RADIO );
121
122 /* disable the currently selected color for other menus */
123
124 fl_set_menu_item_mode( menu[ i ], item,
125 FL_PUP_GRAY | FL_PUP_RADIO );
126 }
127 }
128
129 set[ m ] = item;
130 fl_set_object_color( abox[ m ], FL_BLACK + item, FL_BLACK );
131 }
132
133
134 /***************************************
135 ***************************************/
136
137 static void
done_cb(FL_OBJECT * obj FL_UNUSED_ARG,long data FL_UNUSED_ARG)138 done_cb( FL_OBJECT * obj FL_UNUSED_ARG,
139 long data FL_UNUSED_ARG )
140 {
141 fl_finish( );
142 exit( 0 );
143 }
144
145
146 /***************************************
147 ***************************************/
148
149 FL_FORM *
create_form(void)150 create_form( void )
151 {
152 FL_FORM *form;
153 FL_OBJECT *obj;
154
155 form = fl_bgn_form( FL_NO_BOX, 440, 380 );
156
157 obj = fl_add_box( FL_BORDER_BOX, 0, 0, 440, 380, "" );
158 fl_set_object_color( obj, FL_SLATEBLUE, FL_COL1 );
159
160 menu[ 0 ] = obj = fl_add_menu( FL_PUSH_MENU, 0, 0, 110, 30, "Color 1" );
161 fl_set_menu_notitle( obj, 1 );
162 fl_set_object_shortcut( obj, "1#1", 1 );
163 fl_set_object_callback( obj, menu_cb, 0 );
164
165 menu[ 1 ] = obj = fl_add_menu( FL_PUSH_MENU, 110, 0, 110, 30, "Color 2" );
166 fl_set_object_shortcut( obj, "2#2", 1 );
167 fl_set_object_callback( obj, menu_cb, 1 );
168
169 menu[ 2 ] = obj = fl_add_menu( FL_PULLDOWN_MENU, 220, 0, 110, 30,
170 "Color 3" );
171 fl_set_object_shortcut( obj, "3#3", 1 );
172 fl_set_object_callback( obj, menu_cb, 2 );
173
174 menu[ 3 ] = obj = fl_add_menu( FL_TOUCH_MENU, 330, 0, 110, 30, "Color 4" );
175 fl_set_object_shortcut( obj, "4#4", 1 );
176 fl_set_object_callback( obj, menu_cb, 3 );
177
178 abox[ 0 ] = obj = fl_add_box( FL_SHADOW_BOX, 20, 80, 70, 230, "" );
179 abox[ 1 ] = obj = fl_add_box( FL_SHADOW_BOX, 130, 80, 70, 230, "" );
180 abox[ 2 ] = obj = fl_add_box( FL_SHADOW_BOX, 240, 80, 70, 230, "" );
181 abox[ 3 ] = obj = fl_add_box( FL_SHADOW_BOX, 350, 80, 70, 230, "" );
182
183 obj = fl_add_button( FL_NORMAL_BUTTON, 310, 330, 110, 30, "Quit" );
184 fl_set_object_shortcut( obj, "Q#Q", 1 );
185 fl_set_object_callback( obj, done_cb, 0 );
186
187 fl_end_form( );
188
189 fl_scale_form( form, 0.9, 0.9 );
190 fl_adjust_form_size( form );
191
192 return form;
193 }
194
195
196 /*
197 * Local variables:
198 * tab-width: 4
199 * indent-tabs-mode: nil
200 * End:
201 */
202