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 License
15  *  along with XForms.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 
19 /**
20  * \file fd_fake.c
21  *
22  *  This file is part of XForms package
23  *  Copyright (c) 1996-2002  T.C. Zhao and Mark Overmars
24  *  All rights reserved.
25  *.
26  *  Fdesign is not capable of handing real canvas classes. Here
27  *  we use frame/box classes to simulate the appearance of a canvas
28  */
29 
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33 
34 #include "fd_main.h"
35 #include "private/pcanvas.h"
36 
37 
38 /***************************************
39  ***************************************/
40 
41 static int
handle_simu_canvas(FL_OBJECT * ob,int event,FL_Coord mx FL_UNUSED_ARG,FL_Coord my FL_UNUSED_ARG,int key FL_UNUSED_ARG,void * ev FL_UNUSED_ARG)42 handle_simu_canvas( FL_OBJECT * ob,
43                     int         event,
44                     FL_Coord    mx   FL_UNUSED_ARG,
45                     FL_Coord    my   FL_UNUSED_ARG,
46                     int         key  FL_UNUSED_ARG,
47                     void      * ev   FL_UNUSED_ARG )
48 {
49     int ftype;
50 
51     switch ( event )
52     {
53         case FL_DRAW:
54             fl_draw_box( FL_FLAT_BOX, ob->x, ob->y, ob->w, ob->h,
55                          ob->col1, ob->bw );
56             ftype = fli_boxtype2frametype( ob->boxtype );
57             fl_draw_frame( ftype, ob->x, ob->y, ob->w, ob->h, ob->col2,
58                            ob->bw );
59             fl_draw_text( ob->align, ob->x, ob->y, ob->w, ob->h,
60                           ob->lcol, ob->lstyle, ob->lsize, ob->label );
61             break;
62 
63         case FL_DRAWLABEL:
64             if ( ! fl_is_center_lalign( ob->align ) )
65                 fl_draw_text( ob->align, ob->x, ob->y, ob->w, ob->h,
66                               ob->lcol, ob->lstyle, ob->lsize, ob->label );
67             break;
68     }
69 
70     return 0;
71 }
72 
73 
74 /***************************************
75  ***************************************/
76 
77 FL_OBJECT *
fl_create_simu_canvas(int type,FL_Coord x,FL_Coord y,FL_Coord w,FL_Coord h,const char * label)78 fl_create_simu_canvas( int          type,
79                        FL_Coord     x,
80                        FL_Coord     y,
81                        FL_Coord     w,
82                        FL_Coord     h,
83                        const char * label )
84 {
85     FL_OBJECT *ob;
86     FLI_CANVAS_SPEC *sp;
87 
88     ob = fl_make_object( FL_CANVAS, type, x, y, w, h, label,
89                          handle_simu_canvas );
90     ob->boxtype   = FL_CANVAS_BOXTYPE;
91     ob->col1      = FL_NoColor;
92     ob->col2      = FL_BLACK;
93     ob->lcol      = FL_LCOL;
94     ob->align     = FL_ALIGN_CENTER;
95     ob->active    = 0;
96     ob->spec = sp = fl_calloc( 1, sizeof *sp );
97 
98     return ob;
99 }
100 
101 
102 /***************************************
103  ***************************************/
104 
105 FL_OBJECT *
fl_add_simu_canvas(int type,FL_Coord x,FL_Coord y,FL_Coord w,FL_Coord h,const char * label)106 fl_add_simu_canvas( int          type,
107                     FL_Coord     x,
108                     FL_Coord     y,
109                     FL_Coord     w,
110                     FL_Coord     h,
111                     const char * label )
112 {
113     FL_OBJECT *ob;
114 
115     ob = fl_create_simu_canvas( type, x, y, w, h, label );
116     fl_add_object( fl_current_form, ob );
117 
118     return ob;
119 }
120 
121 
122 /***************************************
123  * glcanvas
124  ***************************************/
125 
126 FL_OBJECT *
fl_create_simu_glcanvas(int type,FL_Coord x,FL_Coord y,FL_Coord w,FL_Coord h,const char * label)127 fl_create_simu_glcanvas( int          type,
128                          FL_Coord     x,
129                          FL_Coord     y,
130                          FL_Coord     w,
131                          FL_Coord     h,
132                          const char * label )
133 {
134     FL_OBJECT *ob;
135     FLI_CANVAS_SPEC *sp;
136 
137     ob = fl_make_object( FL_GLCANVAS, type, x, y, w, h, label,
138                          handle_simu_canvas );
139     ob->boxtype = FL_CANVAS_BOXTYPE;
140     ob->col1    = FL_NoColor;
141     ob->col2    = FL_BLACK;
142     ob->lcol    = FL_LCOL;
143     ob->align   = FL_ALIGN_CENTER;
144     ob->active  = 0;
145     ob->spec    = sp = fl_calloc( 1, sizeof *sp );
146 
147     return ob;
148 }
149 
150 
151 /***************************************
152  ***************************************/
153 
154 FL_OBJECT *
fl_add_simu_glcanvas(int type,FL_Coord x,FL_Coord y,FL_Coord w,FL_Coord h,const char * label)155 fl_add_simu_glcanvas( int          type,
156                       FL_Coord     x,
157                       FL_Coord     y,
158                       FL_Coord     w,
159                       FL_Coord     h,
160                       const char * label )
161 {
162     FL_OBJECT *ob;
163 
164     ob = fl_create_simu_glcanvas( type, x, y, w, h, label );
165     fl_add_object( fl_current_form, ob );
166     return ob;
167 }
168 
169 
170 /***************************************
171  * fake tabfolder
172  ***************************************/
173 
174 static int
handle_tabfolder(FL_OBJECT * ob,int event,FL_Coord mx FL_UNUSED_ARG,FL_Coord my FL_UNUSED_ARG,int key FL_UNUSED_ARG,void * ev FL_UNUSED_ARG)175 handle_tabfolder( FL_OBJECT * ob,
176                   int         event,
177                   FL_Coord    mx   FL_UNUSED_ARG,
178                   FL_Coord    my   FL_UNUSED_ARG,
179                   int         key  FL_UNUSED_ARG,
180                   void      * ev   FL_UNUSED_ARG )
181 {
182     if ( event == FL_DRAW )
183     {
184         fl_draw_box( ob->boxtype, ob->x, ob->y, ob->w, ob->h, ob->col1,
185                      ob->bw );
186         fl_draw_object_label( ob );
187     }
188 
189     return 0;
190 }
191 
192 
193 /***************************************
194  ***************************************/
195 
196 FL_OBJECT *
fl_create_ntabfolder(int type,FL_Coord x,FL_Coord y,FL_Coord w,FL_Coord h,const char * label)197 fl_create_ntabfolder( int          type,
198                       FL_Coord     x,
199                       FL_Coord     y,
200                       FL_Coord     w,
201                       FL_Coord     h,
202                       const char * label )
203 {
204     FL_OBJECT *ob;
205 
206     ob = fl_make_object( FL_NTABFOLDER, type, x, y, w, h, label,
207                          handle_tabfolder );
208 
209     ob->boxtype = FL_UP_BOX;
210     ob->resize  = FL_RESIZE_NONE;
211     ob->col1    = FL_COL1;
212     ob->col2    = FL_COL1;
213     ob->align   = FL_ALIGN_LEFT_TOP;
214 
215     return ob;
216 }
217 
218 
219 /***************************************
220  ***************************************/
221 
222 FL_OBJECT *
fl_add_ntabfolder(int type,FL_Coord x,FL_Coord y,FL_Coord w,FL_Coord h,const char * label)223 fl_add_ntabfolder( int          type,
224                    FL_Coord     x,
225                    FL_Coord     y,
226                    FL_Coord     w,
227                    FL_Coord     h,
228                    const char * label )
229 {
230     FL_OBJECT *ob = fl_create_ntabfolder( type, x, y, w, h, label );
231 
232     fl_add_object( fl_current_form, ob );
233     return ob;
234 }
235 
236 
237 /***************************************
238  * fake formbrowser
239  ***************************************/
240 
241 static int
handle_formbrowser(FL_OBJECT * ob,int event,FL_Coord mx FL_UNUSED_ARG,FL_Coord my FL_UNUSED_ARG,int key FL_UNUSED_ARG,void * ev FL_UNUSED_ARG)242 handle_formbrowser( FL_OBJECT * ob,
243                     int         event,
244                     FL_Coord    mx   FL_UNUSED_ARG,
245                     FL_Coord    my   FL_UNUSED_ARG,
246                     int         key  FL_UNUSED_ARG,
247                     void      * ev   FL_UNUSED_ARG )
248 {
249     if ( event == FL_DRAW )
250     {
251         fl_draw_box( ob->boxtype, ob->x, ob->y, ob->w, ob->h, ob->col1,
252                      ob->bw );
253         fl_draw_object_label( ob );
254     }
255 
256     return 0;
257 }
258 
259 
260 /***************************************
261  ***************************************/
262 
263 FL_OBJECT *
fl_create_nformbrowser(int type,FL_Coord x,FL_Coord y,FL_Coord w,FL_Coord h,const char * label)264 fl_create_nformbrowser( int          type,
265                         FL_Coord     x,
266                         FL_Coord     y,
267                         FL_Coord     w,
268                         FL_Coord     h,
269                         const char * label )
270 {
271     FL_OBJECT *ob;
272 
273     ob = fl_make_object( FL_FORMBROWSER, type, x, y, w, h, label,
274                          handle_formbrowser );
275 
276     ob->boxtype = FL_DOWN_BOX;
277     ob->resize  = FL_RESIZE_NONE;
278     ob->col1    = FL_COL1;
279     ob->col2    = FL_COL1;
280     ob->align   = FL_ALIGN_BOTTOM;
281 
282     return ob;
283 }
284 
285 
286 /***************************************
287  ***************************************/
288 
289 FL_OBJECT *
fl_add_nformbrowser(int type,FL_Coord x,FL_Coord y,FL_Coord w,FL_Coord h,const char * label)290 fl_add_nformbrowser( int          type,
291                      FL_Coord     x,
292                      FL_Coord     y,
293                      FL_Coord     w,
294                      FL_Coord     h,
295                      const char * label )
296 {
297     FL_OBJECT *ob = fl_create_nformbrowser( type, x, y, w, h, label );
298 
299     fl_add_object( fl_current_form, ob );
300     return ob;
301 }
302 
303 
304 /*
305  * Local variables:
306  * tab-width: 4
307  * indent-tabs-mode: nil
308  * End:
309  */
310