static int generic_setattr(genericobject *g, char *name, PyObject *v) { int ret; if (v == NULL) { PyErr_SetString(PyExc_TypeError, "can't delete forms object attributes"); return -1; } /* "label" is an exception: setmember doesn't set strings; and FORMS wants you to call a function to set the label */ if (strcmp(name, "label") == 0) { if (!PyString_Check(v)) { PyErr_SetString(PyExc_TypeError, "label attr must be string"); return -1; } fl_set_object_label(g->ob_generic, PyString_AsString(v)); return 0; } ret = PyMember_Set((char *)g->ob_generic, generic_memberlist, name, v); /* Rather than calling all the various set_object_* functions, we call fl_redraw_object here. This is sometimes redundant but I doubt that's a big problem */ if (ret == 0) fl_redraw_object(g->ob_generic); return ret; }
void fl_set_formbrowser_vscrollbar( FL_OBJECT * ob, int how ) { FLI_FORMBROWSER_SPEC *sp = ob->spec; if ( sp->v_pref != how ) { sp->v_pref = how; fl_redraw_object( ob ); } }
void fl_set_formbrowser_scroll( FL_OBJECT * ob, int how ) { FLI_FORMBROWSER_SPEC *sp = ob->spec; if ( sp->scroll != how ) { if ( ( sp->scroll = how ) == FL_JUMP_SCROLL ) sp->top_edge = 0; fl_redraw_object( ob ); } }
void fl_set_button( FL_OBJECT * obj, int pushed ) { FL_BUTTON_STRUCT *sp = obj->spec; pushed = pushed ? 1 : 0; /* button can only be on or off */ /* Nothing to do if the new state is already what the button is set to */ if ( sp->val == pushed ) return; /* If this is a radio button to be shown as switched on unset other radio button in its group */ if ( obj->type == FL_RADIO_BUTTON && pushed ) fli_do_radio_push( obj, obj->x, obj->y, FL_MBUTTON1, NULL, 1 ); /* Set new state and redraw the button */ sp->val = pushed; fl_redraw_object( obj ); }
static int handle_button( FL_OBJECT * obj, int event, FL_Coord mx, FL_Coord my, int key, void * ev ) { static int oldval; int newval; FL_BUTTON_STRUCT *sp = obj->spec; FL_DrawButton drawit; FL_CleanupButton cleanup; int ret = FL_RETURN_NONE; switch ( event ) { case FL_DRAW : sp->event = FL_DRAW; if ( obj->type != FL_HIDDEN_BUTTON && obj->type != FL_HIDDEN_RET_BUTTON ) { if ( ( drawit = lookup_drawfunc( obj->objclass ) ) ) drawit( obj ); else M_err( "handle_button", "Unknown button class: %d", obj->objclass ); } break; case FL_DRAWLABEL : sp->event = FL_DRAWLABEL; break; /* TODO. Missing labels */ case FL_LEAVE: /* FL_MENU_BUTTON objects never get a FL_RELEASE event, so we have to "fake" one */ if ( obj->type == FL_MENU_BUTTON ) { sp->event = FL_RELEASE; sp->is_pushed = 0; sp->val = 0; } /* fall through */ case FL_ENTER : /* Keep active radio buttons from reacting */ if ( obj->type == FL_RADIO_BUTTON && sp->val == 1 ) obj->belowmouse = 0; sp->event = event; fl_redraw_object( obj ); break; case FL_PUSH : /* Don't accept pushes for an already pushed button (e.g. if the user pushes another mouse button) or for mouse buttons the button isn't set up to react to */ if ( sp->is_pushed ) break; if ( key < FL_MBUTTON1 || key > FL_MBUTTON5 || ! sp->react_to[ key - 1 ] ) { fli_int.pushobj = NULL; break; } sp->event = FL_PUSH; if ( obj->type == FL_RADIO_BUTTON ) { obj->belowmouse = 0; sp->val = 1; fl_redraw_object( obj ); return FL_RETURN_CHANGED | FL_RETURN_END; } oldval = sp->val; sp->val = ! sp->val; sp->is_pushed = 1; sp->mousebut = key; sp->timdel = 1; fl_redraw_object( obj ); if ( obj->type == FL_MENU_BUTTON ) ret |= FL_RETURN_END; if ( obj->type == FL_INOUT_BUTTON || obj->type == FL_MENU_BUTTON || obj->type == FL_TOUCH_BUTTON ) ret |= FL_RETURN_CHANGED; break; case FL_MOTION : if ( obj->type == FL_RADIO_BUTTON || obj->type == FL_INOUT_BUTTON || obj->type == FL_MENU_BUTTON ) break; newval = sp->val; if ( WITHIN( obj, mx, my ) ) { obj->belowmouse = 1; if ( sp->react_to[ key - 1 ] ) newval = ! oldval; } else { obj->belowmouse = 0; if ( sp->react_to[ key - 1 ] ) newval = oldval; } if ( sp->val != newval ) { sp->val = newval; fl_redraw_object( obj ); } break; case FL_RELEASE : if ( key != sp->mousebut && obj->type != FL_RADIO_BUTTON ) { fli_int.pushobj = obj; break; } sp->event = FL_RELEASE; sp->is_pushed = 0; if ( obj->type == FL_INOUT_BUTTON && ! WITHIN( obj, mx, my ) ) obj->belowmouse = 0; if ( obj->type == FL_PUSH_BUTTON ) { fl_redraw_object( obj ); if ( sp->val != oldval ) ret |= FL_RETURN_END | FL_RETURN_CHANGED; } else if ( sp->val == 0 && obj->type != FL_MENU_BUTTON ) fl_redraw_object( obj ); else { sp->val = 0; fl_redraw_object( obj ); if ( obj->type != FL_MENU_BUTTON && obj->type != FL_TOUCH_BUTTON ) ret |= FL_RETURN_END | FL_RETURN_CHANGED; if ( obj->type == FL_TOUCH_BUTTON ) ret |= FL_RETURN_END; } break; case FL_UPDATE : /* only FL_TOUCH_BUTTON receives it */ sp->event = FL_UPDATE; if ( sp->val && sp->timdel++ > 10 && ( sp->timdel & 1 ) == 0 ) ret |= FL_RETURN_CHANGED; break; case FL_SHORTCUT : sp->event = FL_SHORTCUT; /* This is a horrible hack */ if ( obj->type == FL_PUSH_BUTTON || obj->type == FL_RADIO_BUTTON ) { sp->val = ! sp->val; obj->pushed = obj->type == FL_RADIO_BUTTON; fl_redraw_object( obj ); wait_for_release( ev ); } else if ( obj->type == FL_NORMAL_BUTTON || obj->type == FL_RETURN_BUTTON ) { int obl = obj->belowmouse; sp->val = obj->belowmouse = 1; fl_redraw_object( obj ); wait_for_release( ev ); sp->val = 0; obj->belowmouse = obl; fl_redraw_object( obj ); } sp->mousebut = FL_SHORTCUT + key; ret |= FL_RETURN_END | FL_RETURN_CHANGED; break; case FL_FREEMEM : if ( ( cleanup = lookup_cleanupfunc( obj->objclass ) ) ) cleanup( sp ); free_pixmap( sp ); fli_safe_free( obj->spec ); break; } return ret; }