File: pup.c.old

package info (click to toggle)
libforms 1.0.93sp1-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 11,548 kB
  • ctags: 9,107
  • sloc: ansic: 97,227; sh: 9,236; makefile: 858
file content (316 lines) | stat: -rw-r--r-- 7,190 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/*
 *
 * This file is part of XForms.
 *
 * XForms is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1, or
 * (at your option) any later version.
 *
 * XForms is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with XForms; see the file COPYING.  If not, write to
 * the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
 * MA 02111-1307, USA.
 *
 */


/* Demo: complete pop-ups.
 * test font/cursor change
 * test attaching pup to menu
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "include/forms.h"
#include <stdlib.h>

FL_FORM *pup;

FL_OBJECT *done,
          *pret,
          *b1,
          *b2,
          *b3,
          *menu;

void create_form_pup( void );

void init_menu( void );

int post( FL_OBJECT *, 
		  int,
		  FL_Coord,
		  FL_Coord,
		  int,
		  void * );


/***************************************
 ***************************************/

int
main( int    argc,
	  char * argv[ ] )
{
    FL_IOPT aa;
    unsigned int mask = FL_PDVisual;

    aa.vclass = FL_DefaultVisual;
    fl_set_defaults( mask, &aa );

    fl_initialize( &argc, argv, "FormDemo", 0, 0 );

    create_form_pup( );

    /* initialize */

    fl_set_object_posthandler( b1, post );
    fl_set_object_posthandler( b2, post );
    fl_set_object_posthandler( b3, post );

    fl_show_form( pup, FL_PLACE_MOUSE, FL_TRANSIENT, "PupDemo" );
    init_menu( );

    fl_do_forms( );

    return 0;
}


static int subm = -1,
           m = -1,
           ssm;


/* post-handler */

/***************************************
 ***************************************/

int
post( FL_OBJECT * ob,
	  int         ev,
	  FL_Coord    mx   FL_UNUSED_ARG,
	  FL_Coord    my   FL_UNUSED_ARG,
	  int         key  FL_UNUSED_ARG,
	  void      * xev  FL_UNUSED_ARG )
{
    static int n1 = -1,
		       n2 = -1;

    if ( n1 == -1 )
    {
		n1 = fl_defpup( FL_ObjWin( ob ), "line1|line2" );
		fl_setpup_shadow( n1, 0 );
		fl_setpup_bw( n1, 0 );
		fl_setpup_pad( n1, 3, 0 );

		n2 = fl_defpup( FL_ObjWin( ob ), "button1|button2" );
		fl_setpup_shadow( n2, 0 );
		fl_setpup_bw( n2, -1 );
		fl_setpup_pad( n2, 3, 0 );
    }

    if ( ev == FL_ENTER )
    {
		if ( ob == b3 )
			fl_show_oneliner( "button3", ob->form->x + ob->x + 5,
							  ob->form->y + ob->y + ob->h + 5 );
		else
		{
			fl_setpup_position( ob->form->x+ob->x,
								ob->form->y + ob->y + ob->h + 5 );
			fl_showpup( ob == b1 ? n1 : n2 );
       }
    }
    else if ( ev == FL_LEAVE )
    {
		if ( ob == b3 )
			fl_hide_oneliner( );
		else
			fl_hidepup( ob == b1 ? n1 : n2 );
    }

    return 0;
}


/***************************************
 ***************************************/

void
show_return_val( int i )
{
    char buf[ 128 ];

    if ( i >= 0 )
       sprintf( buf, "Returned %d (%s)", i, fl_getpup_text( m, i ) );
    else
       sprintf( buf, "Returned %d", i );

    fl_set_object_label( pret, buf );
}


/***************************************
 ***************************************/

int
ssm_cb( int a )
{
   show_return_val( a );
   return a;
}


/***************************************
 ***************************************/

void
do_pup( FL_OBJECT * ob,
		long        q  FL_UNUSED_ARG )
{
   static int n;

   if ( subm == -1 )
   {
      ssm  = fl_newpup( FL_ObjWin( ob ) );
      subm = fl_newpup( FL_ObjWin( ob ) );
      m    = fl_newpup( FL_ObjWin( ob ) );

/*      fl_addtopup( ssm, "SubSubM%F%t", ssm_cb );*/
      fl_addtopup( ssm, "SSMItem20%x20%R1" );
      fl_addtopup( ssm, "SSMItem21%x21%r1" );
      fl_addtopup( ssm, "SSMItem22%x22%r1%l" );
      fl_addtopup( ssm, "SSMitem30%x30%R2" );
      fl_addtopup( ssm, "SSMItem31%x31%r2" );
      fl_addtopup( ssm, "SSMItem32%x32%b" );

/*      fl_addtopup( subm, "SubMenu%t" );*/
      fl_addtopup( subm, "SMItemA\tAlt-A%x10%h","#a" );
      fl_addtopup( subm, "SMItemB\tAlt-B%x11%h","#b" );
      fl_addtopup( subm, "SM%%ItemC\tAlt-C%x12%h","#c" );
      fl_addtopup( subm, "SMItemD\tAlt-F5%x13%h%m","#&5", ssm );
      fl_addtopup( subm, "SMItemE\tAlt-E%x14","#E" );

      fl_setpup_mode( subm, 14, FL_PUP_GREY );

      fl_addtopup( m, "PopUP%t" );
      fl_addtopup( m, "MenuItem1%h","1#1" );

      fl_addtopup( m, "MenuItem2%h", "2#2" );
      fl_setpup_submenu( m, 2, subm );
      fl_addtopup( m, "MenuItem3%h","3#3" );
      fl_addtopup( m, "MenuItem4%h", "4#4" );
   }

   if ( fl_get_button_numb( ob ) >= FL_SHORTCUT )
	   fl_setpup_position( ob->form->x + ob->x,
						   ob->form->y + ob->y + ob->h );

   show_return_val( fl_dopup( m ) );

   /* test if changing size/style ok */

   n = ! n;
   fl_setpup_fontsize( n ? 14 : 12 );
   fl_setpup_fontstyle( n ? FL_TIMES_STYLE : FL_BOLDITALIC_STYLE );
   fl_setpup_cursor( m, n ? XC_hand2 : XC_sb_right_arrow );
}


/***************************************
 ***************************************/

void
init_menu( void )
{
    int mm,
		smm;

    mm = fl_newpup( fl_default_win( ) );
    fl_setpup_bw( mm, -2 );
    fl_setpup_shadow( mm, 0 );
    smm = fl_newpup( 0 );
    fl_setpup_shadow( smm, 0 );

    fl_addtopup( mm, "MenuItem1|MenuItem2%m|MenuItem3", smm );
    fl_addtopup( smm, "SubItem1%x11|SubItem2%x12|SubItem3%x13" );

    /* attach pup to menu */

    fl_set_menu_popup( menu, mm );
}


/***************************************
 ***************************************/

void
do_menu( FL_OBJECT * ob,
		 long        data  FL_UNUSED_ARG )
{
    char buf[ 128 ];

    if ( fl_get_menu( ob ) >= 0 )
       sprintf( buf, "%d (%s)", fl_get_menu( ob ), fl_get_menu_text( ob ) );
    else
       sprintf( buf, "%d", fl_get_menu( ob ) );

    fl_set_object_label( pret, buf );
}


/***************************************
 ***************************************/

void
done_cb( FL_OBJECT * ob    FL_UNUSED_ARG,
		 long        data  FL_UNUSED_ARG )
{
	fl_finish( );
	exit( 0 );
}


/***************************************
 ***************************************/

void create_form_pup( void )
{
	FL_OBJECT *obj;

	if ( pup )
		return;

	pup = fl_bgn_form( FL_UP_BOX, 260, 210 );

	fl_add_box( FL_UP_BOX, 0, 0, 260, 210, "" );

	done = obj = fl_add_button( FL_NORMAL_BUTTON, 150, 150, 90, 35, "Done" );
    fl_set_object_callback( obj, done_cb, 0 );

	obj = fl_add_button( FL_MENU_BUTTON, 30, 90, 100, 30, "PopUp" );
	fl_set_button_shortcut( obj, "Pp#p",1 );
	fl_set_object_callback( obj, do_pup, 0 );

	menu = obj = fl_add_menu( FL_PULLDOWN_MENU, 160, 95, 60, 25, "Menu" );
	fl_set_object_callback( obj, do_menu, 0 );

	pret = obj = fl_add_text( FL_NORMAL_TEXT, 20, 60, 220, 30, "" );
    fl_set_object_lalign( obj, FL_ALIGN_CENTER );

	b1 = fl_add_button( FL_NORMAL_BUTTON,  20, 10, 60, 30, "Button1" );
	b2 = fl_add_button( FL_NORMAL_BUTTON,  90, 10, 60, 30, "Button2" );
	b3 = fl_add_button( FL_NORMAL_BUTTON,  160, 10, 60, 30, "Button3" );

	fl_end_form( );
}