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
|
/*
* 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. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "include/forms.h"
#include "fd_main.h"
#include <ctype.h>
/***************************************
* Returns a string suitable to be passed to fl_set_menu() which then
* initializes the menu for selection of the return type of an object.
* In the calling code some of the entries typically must be disabled,
* which can be done with a call of fl_set_menu_item_mode() with the
* menu object as the first, the menu item number as the second and
* 'FL_PUP_BOX | FL_PUP_GRAY' as the third argument.
***************************************/
void
setup_how_return_menu( FL_OBJECT * obj )
{
fl_set_menu( obj,
"Never%b|" /* menu item 1 */
"End & Changed%b|" /* menu item 2 */
"Whenever Changed%b|" /* menu item 3 */
"At End%b|" /* menu item 4 */
"On Selection%b|" /* menu item 5 */
"On Deselection%b|" /* menu item 6 */
"Always%b" ); /* menu item 7 */
}
/***************************************
* Sets the check boxes of the menu entries of a menu as set up with
* the string returned by set_up_how_return_menu() (see above) according
* to the return settings of an object.
***************************************/
void
reset_how_return_menu( FL_OBJECT * menu,
unsigned int how_return )
{
int i;
unsigned int modes[ 8 ];
for ( i = 1; i <= 7; i++ )
{
modes[ i ] = fl_get_menu_item_mode( menu, i ) & FL_PUP_GRAY;
fl_set_menu_item_mode( menu, i, modes[ i ] | FL_PUP_BOX );
}
if ( how_return == FL_RETURN_NONE )
fl_set_menu_item_mode( menu, 1,
modes[ 1 ] | FL_PUP_BOX | FL_PUP_CHECK );
else if ( how_return == FL_RETURN_ALWAYS )
fl_set_menu_item_mode( menu, 7,
modes[ 7 ] | FL_PUP_BOX | FL_PUP_CHECK );
else
{
if ( how_return & FL_RETURN_END_CHANGED )
fl_set_menu_item_mode( menu, 2,
modes[ 2 ] | FL_PUP_BOX | FL_PUP_CHECK );
if ( how_return & FL_RETURN_CHANGED )
fl_set_menu_item_mode( menu, 3,
modes[ 3 ] | FL_PUP_BOX | FL_PUP_CHECK );
if ( how_return & FL_RETURN_END )
fl_set_menu_item_mode( menu, 4,
modes[ 4 ] | FL_PUP_BOX | FL_PUP_CHECK );
if ( how_return & FL_RETURN_SELECTION )
fl_set_menu_item_mode( menu, 5,
modes[ 5 ] | FL_PUP_BOX | FL_PUP_CHECK );
if ( how_return & FL_RETURN_DESELECTION )
fl_set_menu_item_mode( menu, 6,
modes[ 6 ] | FL_PUP_BOX | FL_PUP_CHECK );
}
}
/***************************************
***************************************/
void
handle_how_return_changes( FL_OBJECT * menu,
FL_OBJECT * target )
{
SuperSPEC *sp = target->u_vdata;
int hr = FL_RETURN_NONE;
if ( fl_get_menu_item_mode( menu, 1 ) & FL_PUP_CHECK
&& target->how_return != FL_RETURN_NONE )
/* empty */ ;
else if ( fl_get_menu_item_mode( menu, 7 ) & FL_PUP_CHECK
&& target->how_return != FL_RETURN_ALWAYS )
hr = FL_RETURN_ALWAYS;
else
{
if ( fl_get_menu_item_mode( menu, 2 ) & FL_PUP_CHECK
&& ! ( target->how_return & FL_RETURN_END_CHANGED ) )
hr = FL_RETURN_END_CHANGED;
else
{
if ( fl_get_menu_item_mode( menu, 3 ) & FL_PUP_CHECK )
hr |= FL_RETURN_CHANGED;
if ( fl_get_menu_item_mode( menu, 4 ) & FL_PUP_CHECK )
hr |= FL_RETURN_END;
}
if ( fl_get_menu_item_mode( menu, 5 ) & FL_PUP_CHECK )
hr |= FL_RETURN_SELECTION;
if ( fl_get_menu_item_mode( menu, 6 ) & FL_PUP_CHECK )
hr |= FL_RETURN_DESELECTION;
}
fl_set_object_return( target, hr );
sp->how_return = target->how_return;
reset_how_return_menu( menu, sp->how_return );
}
/***************************************
***************************************/
#define VN( v ) { v, #v }
static FLI_VN_PAIR howreturn[ ] =
{
VN( FL_RETURN_NONE ),
VN( FL_RETURN_END_CHANGED ),
VN( FL_RETURN_CHANGED ),
VN( FL_RETURN_END ),
VN( FL_RETURN_SELECTION ),
VN( FL_RETURN_DESELECTION ),
VN( FL_RETURN_ALWAYS ),
{ -1, NULL }
};
/***************************************
***************************************/
int
get_how_return_val( const char * s )
{
char *tmp = fl_strdup( s ),
*p = strtok( tmp, "|" ),
*st;
int val = 0;
while ( p )
{
while ( *p && isspace( ( int ) *p ) )
p++;
st = p;
while ( *p && ! isspace( ( int ) *p ) )
p++;
*p = '\0';
if ( ! strcmp( st, "FL_RETURN_NONE" ) )
{
val = FL_RETURN_NONE;
break;
}
else if ( ! strcmp( st, "FL_RETURN_ALWAYS" ) )
{
val = FL_RETURN_ALWAYS;
break;
}
else if ( ! strcmp( st, "FL_RETURN_END_CHANGED" ) )
{
val |= FL_RETURN_END_CHANGED;
val &= ~ ( FL_RETURN_CHANGED | FL_RETURN_END );
}
else if ( ! strcmp( st, "FL_RETURN_CHANGED" ) )
{
val |= FL_RETURN_CHANGED;
val &= ~ FL_RETURN_END_CHANGED;
}
else if ( ! strcmp( st, "FL_RETURN_END" ) )
{
val |= FL_RETURN_END;
val &= ~ FL_RETURN_END_CHANGED;
}
else if ( ! strcmp( st, "FL_RETURN_SELECTION" ) )
val |= FL_RETURN_SELECTION;
else if ( ! strcmp( st, "FL_RETURN_DESELECTION" ) )
val |= FL_RETURN_DESELECTION;
val |= fli_get_vn_value( howreturn, st );
p = strtok( NULL, "|" );
}
fl_safe_free( tmp );
return val;
}
/***************************************
* Returns a string suitable for output in a C file (with 'withspaces'
* set to 1) or a .fd file (with 'withspaces' set to 0) of the return
* setting of an object as passed as the first argument.
***************************************/
const char *
get_how_return_name( unsigned int how_return,
int with_spaces )
{
static char buf[ 256 ];
FLI_VN_PAIR *hr = howreturn;
if ( how_return == FL_RETURN_ALWAYS )
return "FL_RETURN_ALWAYS";
if ( how_return == FL_RETURN_NONE )
return "FL_RETURN_NONE";
*buf = '\0';
while ( ( ++hr )->val != ( int ) FL_RETURN_ALWAYS )
{
if ( how_return & hr->val )
strcat( strcat( buf, with_spaces ? " | " : "|" ), hr->name );
}
return buf + ( with_spaces ? 3 : 1 );
}
/*
* Local variables:
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/
|