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 all four types of nmenu's.
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include "include/forms.h"
29 #include <stdlib.h>
30
31 extern FL_FORM *create_form( void );
32
33 FL_OBJECT *menu[ 4 ],
34 *abox[ 4 ];
35 int set[ 4 ];
36
37 /***************************************
38 ***************************************/
39
40 int
main(int argc,char * argv[])41 main( int argc,
42 char * argv[ ] )
43 {
44 FL_FORM *form;
45 int i;
46
47 fl_initialize( &argc, argv, "FormDemo", 0, 0 );
48
49 form = create_form( );
50
51 for ( i = 0; i < 4; i++ )
52 {
53 fl_add_nmenu_items( menu[ i ],
54 "Red%SR%r%s%d|Green%SG%r%s%d|Yellow%SY%r%s%d|"
55 "Blue%SB%r%s%d|Purple%SP%r%s|Cyan%SC%r%s|"
56 "White%SW%r%s",
57 1, "Rr#R#r", 1, "Gg#G#g", 1, "Yy#Y#y", 1, "Bb#B#b",
58 1, "Pp#P#p", 1, "Cc#C#c", 1, "Ww#W#w" );
59
60 fl_popup_entry_set_state( fl_get_nmenu_item_by_value( menu[ i ], i ),
61 FL_POPUP_CHECKED );
62
63 set[ i ] = i;
64 fl_set_object_color( abox[ i ], FL_RED + set[ i ], FL_BLACK );
65 }
66
67 fl_show_form( form, FL_PLACE_CENTER, FL_TRANSIENT, "Nmenu" );
68
69 fl_do_forms( );
70 fl_hide_form( form );
71
72 fl_finish( );
73
74 return 0;
75 }
76
77
78 /***************************************
79 * m is the menu index 0 - 3
80 ***************************************/
81
82 static void
menu_cb(FL_OBJECT * obj,long m)83 menu_cb( FL_OBJECT * obj,
84 long m )
85 {
86 FL_POPUP_RETURN *r = fl_get_nmenu_item( obj );
87 int i;
88
89 if ( set[ m ] == r->val )
90 return;
91
92 for ( i = 0; i < 4; i++)
93 {
94 if ( i != m )
95 {
96 /* enable the old selected color for other menus*/
97
98 fl_popup_entry_set_state( fl_get_nmenu_item_by_value( menu[ i ],
99 set[ m ] ),
100 0 );
101
102 /* disable the currently selected color for other menus */
103
104 fl_popup_entry_set_state( fl_get_nmenu_item_by_value( menu[ i ],
105 r->val ),
106 FL_POPUP_DISABLED );
107 }
108 }
109
110 set[ m ] = r->val;
111 fl_set_object_color( abox[ m ], FL_RED + r->val, FL_BLACK );
112 }
113
114
115 /***************************************
116 ***************************************/
117
118 static void
done_cb(FL_OBJECT * ob FL_UNUSED_ARG,long data FL_UNUSED_ARG)119 done_cb( FL_OBJECT * ob FL_UNUSED_ARG,
120 long data FL_UNUSED_ARG )
121 {
122 fl_finish( );
123 exit( 0 );
124 }
125
126
127 /***************************************
128 ***************************************/
129
130 FL_FORM *
create_form(void)131 create_form( void )
132 {
133 FL_FORM *form;
134 FL_OBJECT *obj;
135
136 form = fl_bgn_form( FL_NO_BOX, 444, 380 );
137
138 obj = fl_add_box( FL_BORDER_BOX, 0, 0, 444, 380, "" );
139 fl_set_object_color( obj, FL_SLATEBLUE, FL_COL1 );
140
141 obj = fl_add_box( FL_UP_BOX, 0, 0, 444, 29, "" );
142 fl_set_object_color( obj, FL_COL1, FL_COL1 );
143
144 menu[ 0 ] = obj = fl_add_nmenu( FL_NORMAL_NMENU, 2, 2, 110, 25, "Color 1" );
145 fl_set_object_shortcut( obj, "1#1", 1 );
146 fl_set_object_callback( obj, menu_cb, 0 );
147
148 menu[ 1 ] = obj = fl_add_nmenu( FL_NORMAL_TOUCH_NMENU, 112, 2, 110, 25,
149 "Color 2" );
150 fl_set_object_shortcut( obj, "2#2", 1 );
151 fl_set_object_callback( obj, menu_cb, 1 );
152
153 menu[ 2 ] = obj = fl_add_nmenu( FL_BUTTON_NMENU, 222, 2, 110, 25,
154 "Color 3" );
155 fl_set_object_shortcut( obj, "3#3", 1 );
156 fl_set_object_callback( obj, menu_cb, 2 );
157
158 menu[ 3 ] = obj = fl_add_nmenu( FL_BUTTON_TOUCH_NMENU, 332, 2, 110, 25,
159 "Color 4" );
160 fl_set_object_shortcut( obj, "4#4", 1 );
161 fl_set_object_callback( obj, menu_cb, 3 );
162
163 abox[ 0 ] = obj = fl_add_box( FL_SHADOW_BOX, 20, 80, 70, 230, "" );
164 abox[ 1 ] = obj = fl_add_box( FL_SHADOW_BOX, 130, 80, 70, 230, "" );
165 abox[ 2 ] = obj = fl_add_box( FL_SHADOW_BOX, 240, 80, 70, 230, "" );
166 abox[ 3 ] = obj = fl_add_box( FL_SHADOW_BOX, 350, 80, 70, 230, "" );
167
168 obj = fl_add_button( FL_NORMAL_BUTTON, 310, 330, 110, 30, "Quit" );
169 fl_set_object_shortcut( obj, "Q#Q", 1 );
170 fl_set_object_callback( obj, done_cb, 0 );
171
172 fl_end_form( );
173
174 return form;
175 }
176
177
178 /*
179 * Local variables:
180 * tab-width: 4
181 * indent-tabs-mode: nil
182 * End:
183 */
184