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  * Routines implementing the "crossbutton" class
23  *
24  *  ob->col1 is the color of the box. ob->col2 is the color of cross
25  *
26  *  This file is part of xforms package
27  *  T.C. Zhao and M. Overmars
28  */
29 
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33 
34 #include "include/forms.h"
35 #include "crossbut.h"
36 
37 
38 /***************************************
39  * How to draw it
40  ***************************************/
41 
42 static void
draw_crossbutton(FL_OBJECT * ob)43 draw_crossbutton( FL_OBJECT * ob )
44 {
45     FL_Coord xx,
46              yy,
47              ww,
48              hh;
49     FL_BUTTON_STRUCT *sp = ob->spec;
50 
51     /* if redraw is demanded by FL_ENTER, ignore it */
52 
53     if ( sp->event == FL_ENTER )
54         return;
55 
56     /* Draw the bounding box first */
57 
58     fl_draw_box( ob->boxtype, ob->x, ob->y, ob->w, ob->h, ob->col1, ob->bw );
59 
60     /* Draw the box that contains the cross */
61 
62     ww = hh = 0.5 * FL_min( ob->w, ob->h ) - 1;
63     xx = ob->x + FL_BOUND_WIDTH;
64     yy = ob->y + ( ob->h - hh ) / 2;
65 
66     /* If pushed, draw a down box with the cross */
67 
68     if ( sp->val )
69     {
70         fl_draw_box( FL_DOWN_BOX, xx, yy, ww, hh, ob->col1, ob->bw );
71         fl_draw_text( FL_ALIGN_CENTER, xx - 2, yy - 2, ww + 4, hh + 4,
72                       ob->col2, 0, 0, "@9plus");
73     }
74     else
75         fl_draw_box( FL_UP_BOX, xx, yy, ww, hh, ob->col1, ob->bw );
76 
77     /* label */
78 
79     if ( fl_is_center_lalign( ob->align ) )
80         fl_draw_text( FL_ALIGN_LEFT, xx + ww + 3, ob->y, 0, ob->h,
81                       ob->lcol, ob->lstyle, ob->lsize, ob->label );
82     else
83         fl_draw_object_label_outside( ob );
84 
85     if ( ob->type == FL_RETURN_BUTTON )
86         fl_draw_text( FL_ALIGN_CENTER,
87                       ob->x + ob->w - 0.8 * ob->h,
88                       ob->y + 0.2 * ob->h,
89                       0.6 * ob->h, 0.6 * ob->h, ob->lcol, 0, 0,
90                       "@returnarrow" );
91 }
92 
93 
94 /***************************************
95  * creation
96  ***************************************/
97 
98 FL_OBJECT *
fl_create_crossbutton(int type,FL_Coord x,FL_Coord y,FL_Coord w,FL_Coord h,const char * label)99 fl_create_crossbutton( int          type,
100                        FL_Coord     x,
101                        FL_Coord     y,
102                        FL_Coord     w,
103                        FL_Coord     h,
104                        const char * label )
105 {
106      FL_OBJECT *ob;
107 
108      fl_add_button_class( FL_CROSSBUTTON, draw_crossbutton, 0 );
109      ob = fl_create_generic_button( FL_CROSSBUTTON, type, x, y,w, h, label );
110      ob->boxtype = FL_NO_BOX;
111      ob->col2 = FL_BLACK;   /* cross color */
112 
113      return ob;
114 }
115 
116 
117 /***************************************
118  ***************************************/
119 
120 FL_OBJECT *
fl_add_crossbutton(int type,FL_Coord x,FL_Coord y,FL_Coord w,FL_Coord h,const char * label)121 fl_add_crossbutton( int          type,
122                     FL_Coord     x,
123                     FL_Coord     y,
124                     FL_Coord     w,
125                     FL_Coord     h,
126                     const char * label )
127 {
128     FL_OBJECT *ob = fl_create_crossbutton( type, x, y, w, h, label );
129 
130     fl_add_object( fl_current_form, ob );
131     return ob;
132 }
133 
134 
135 /*
136  * Local variables:
137  * tab-width: 4
138  * indent-tabs-mode: nil
139  * End:
140  */
141