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 /*
22 * Showing the use of non-modal file selector
23 *
24 * T.C. Zhao and M. Overmars
25 */
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include "include/forms.h"
32 #include "fd/pmbrowse_gui.h"
33 #include <stdlib.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <unistd.h>
37
38 FD_ttt *fd_ttt;
39
40 static int load_file( const char *,
41 void * );
42
43 /***************************************
44 ***************************************/
45
46 int
main(int argc,char * argv[])47 main( int argc,
48 char * argv[ ] )
49 {
50 fl_initialize( &argc, argv, "FormDemo", 0, 0 );
51 fd_ttt = create_form_ttt( );
52
53 fl_show_form( fd_ttt->ttt, FL_PLACE_CENTER, FL_TRANSIENT, "PixmapBrowser" );
54
55 fl_set_fselector_placement( FL_PLACE_FREE );
56 fl_set_fselector_callback( load_file, 0 );
57 fl_show_fselector( "Load a Pixmap file", NULL, "*.x?m", NULL );
58 fl_do_forms( );
59 return 0;
60 }
61
62
63 /***************************************
64 ***************************************/
65
66 static int
load_file(const char * fname,void * data FL_UNUSED_ARG)67 load_file( const char * fname,
68 void * data FL_UNUSED_ARG )
69 {
70 char *p;
71 struct stat buff;
72
73 if ( ! fname || ! *fname )
74 {
75 fprintf( stderr, "Missing file name\n" );
76 return 0;
77 }
78
79 if ( ! stat( fname, &buff ) )
80 {
81 if ( ! S_ISDIR( buff.st_mode ) )
82 {
83 if ( ( p = strrchr( fname, '.' ) ) )
84 {
85 if ( ! strcmp( p + 1, "xpm" ) )
86 {
87 fl_hide_object( fd_ttt->bm );
88 fl_free_pixmap_pixmap( fd_ttt->pm );
89 fl_set_pixmap_file( fd_ttt->pm, fname );
90 fl_show_object( fd_ttt->pm );
91 }
92 else if ( ! strcmp( p + 1, "xbm" ) )
93 {
94 fl_hide_object( fd_ttt->pm );
95 fl_set_bitmap_file( fd_ttt->bm, fname );
96 fl_show_object( fd_ttt->bm );
97 }
98 else
99 {
100 fprintf( stderr, "Invalid file extension: %s\n", p + 1 );
101 return 0;
102 }
103 }
104 else
105 {
106 fprintf( stderr, "Neither .xpm nor .xbm file\n" );
107 return 0;
108 }
109 }
110 }
111 else
112 {
113 fprintf( stderr, "Can't stat() file %s\n", fname );
114 return 0;
115 }
116
117 return 1;
118 }
119
120
121 /***************************************
122 ***************************************/
123
done(FL_OBJECT * ob FL_UNUSED_ARG,long q FL_UNUSED_ARG)124 void done( FL_OBJECT * ob FL_UNUSED_ARG,
125 long q FL_UNUSED_ARG )
126 {
127 fl_finish( );
128 exit( 0 );
129 }
130
131
132 /***************************************
133 ***************************************/
134
reload(FL_OBJECT * ob FL_UNUSED_ARG,long q FL_UNUSED_ARG)135 void reload( FL_OBJECT * ob FL_UNUSED_ARG,
136 long q FL_UNUSED_ARG )
137 {
138 fl_set_fselector_placement( FL_PLACE_MOUSE );
139 fl_set_fselector_callback( load_file, 0 );
140 fl_show_fselector( "Load a Pix/bitMap file", NULL, NULL, NULL );
141 }
142
143
144 /*
145 * Local variables:
146 * tab-width: 4
147 * indent-tabs-mode: nil
148 * End:
149 */
150