FL/Fl_Sometimes_Input: Allow user to abort edit with Escape key.
This commit is contained in:
parent
628fef30e9
commit
e42b50814a
|
@ -30,6 +30,7 @@
|
||||||
class Fl_Sometimes_Input : public Fl_Input
|
class Fl_Sometimes_Input : public Fl_Input
|
||||||
{
|
{
|
||||||
Fl_Boxtype _up_box;
|
Fl_Boxtype _up_box;
|
||||||
|
char *_text;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -53,7 +54,7 @@ public:
|
||||||
{
|
{
|
||||||
fl_draw_box( up_box(), x(), y(), w(), h(), color() );
|
fl_draw_box( up_box(), x(), y(), w(), h(), color() );
|
||||||
|
|
||||||
Fl_Color c = fl_contrast( textcolor(), color() );
|
Fl_Color c = textcolor();// fl_contrast( textcolor(), color() );
|
||||||
|
|
||||||
fl_color( active_r() ? c : fl_inactive( c ) );
|
fl_color( active_r() ? c : fl_inactive( c ) );
|
||||||
|
|
||||||
|
@ -80,19 +81,30 @@ public:
|
||||||
case FL_KEYDOWN:
|
case FL_KEYDOWN:
|
||||||
{
|
{
|
||||||
if ( ( Fl::event_key() == FL_Enter ||
|
if ( ( Fl::event_key() == FL_Enter ||
|
||||||
Fl::event_key() == FL_Tab ) )
|
Fl::event_key() == FL_Tab ) )
|
||||||
{
|
{
|
||||||
|
do_callback();
|
||||||
|
free( _text );
|
||||||
Fl::focus( NULL );
|
Fl::focus( NULL );
|
||||||
r = 1;
|
r = 1;
|
||||||
}
|
}
|
||||||
|
else if ( Fl::event_key() == FL_Escape )
|
||||||
|
{
|
||||||
|
value( _text );
|
||||||
|
Fl::focus( NULL );
|
||||||
|
|
||||||
|
r = 1;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FL_FOCUS:
|
case FL_FOCUS:
|
||||||
|
_text = strdup( value() );
|
||||||
redraw();
|
redraw();
|
||||||
r = 1;
|
r = 1;
|
||||||
break;
|
break;
|
||||||
case FL_UNFOCUS:
|
case FL_UNFOCUS:
|
||||||
do_callback();
|
_text = NULL;
|
||||||
|
redraw();
|
||||||
r = 1;
|
r = 1;
|
||||||
break;
|
break;
|
||||||
case FL_PUSH:
|
case FL_PUSH:
|
||||||
|
|
Loading…
Reference in New Issue