2008-04-21 16:57:30 +02:00
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* Copyright (C) 2008 Jonathan Moore Liles */
|
|
|
|
/* */
|
|
|
|
/* This program is free software; you can redistribute it and/or modify it */
|
|
|
|
/* under the terms of the GNU General Public License as published by the */
|
|
|
|
/* Free Software Foundation; either version 2 of the License, or (at your */
|
|
|
|
/* option) any later version. */
|
|
|
|
/* */
|
|
|
|
/* This program 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 General Public License for */
|
|
|
|
/* more details. */
|
|
|
|
/* */
|
|
|
|
/* You should have received a copy of the GNU General Public License along */
|
|
|
|
/* with This program; see the file COPYING. If not,write to the Free Software */
|
|
|
|
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
2009-12-25 01:25:33 +01:00
|
|
|
#pragma once
|
2008-04-21 16:57:30 +02:00
|
|
|
|
|
|
|
/* Just like an Fl_Input, except that when not being edited it
|
|
|
|
* displays just like a label. */
|
|
|
|
|
2008-05-27 05:32:35 +02:00
|
|
|
#include <FL/Fl.H>
|
2009-12-25 01:25:33 +01:00
|
|
|
#include <FL/Fl_Window.H>
|
2008-05-27 05:32:35 +02:00
|
|
|
|
2008-04-21 16:57:30 +02:00
|
|
|
class Fl_Sometimes_Input : public Fl_Input
|
|
|
|
{
|
|
|
|
|
2009-12-26 09:31:59 +01:00
|
|
|
Fl_Boxtype _up_box;
|
|
|
|
|
2008-04-21 16:57:30 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
Fl_Sometimes_Input ( int X, int Y, int W, int H, const char *L=0 )
|
|
|
|
: Fl_Input( X, Y, W, H, L )
|
|
|
|
{
|
2008-05-27 05:32:35 +02:00
|
|
|
clear_visible_focus();
|
2009-12-26 09:31:59 +01:00
|
|
|
up_box( FL_NO_BOX );
|
2008-04-21 16:57:30 +02:00
|
|
|
}
|
|
|
|
|
2009-12-26 09:31:59 +01:00
|
|
|
void up_box ( Fl_Boxtype b ) { _up_box = b; }
|
|
|
|
Fl_Boxtype up_box ( void ) const { return _up_box; }
|
|
|
|
|
2008-04-21 16:57:30 +02:00
|
|
|
virtual void
|
|
|
|
draw ( void )
|
|
|
|
{
|
2008-05-27 05:32:35 +02:00
|
|
|
if ( this == Fl::focus() )
|
2008-04-21 16:57:30 +02:00
|
|
|
Fl_Input::draw();
|
|
|
|
else
|
|
|
|
{
|
2009-12-26 09:31:59 +01:00
|
|
|
fl_draw_box( up_box(), x(), y(), w(), h(), color() );
|
2008-04-27 05:50:58 +02:00
|
|
|
fl_color( FL_FOREGROUND_COLOR /* textcolor() */ );
|
2008-04-21 16:57:30 +02:00
|
|
|
fl_font( textfont(), textsize() );
|
|
|
|
fl_draw( value(), x(), y(), w(), h(), FL_ALIGN_CENTER );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-21 05:56:45 +02:00
|
|
|
virtual void
|
|
|
|
take_focus ( void )
|
|
|
|
{
|
|
|
|
set_visible_focus();
|
|
|
|
Fl_Widget::take_focus();
|
|
|
|
clear_visible_focus();
|
|
|
|
}
|
|
|
|
|
2008-04-21 16:57:30 +02:00
|
|
|
virtual int
|
|
|
|
handle ( int m )
|
|
|
|
{
|
|
|
|
int r = Fl_Input::handle( m );
|
|
|
|
|
|
|
|
switch ( m )
|
|
|
|
{
|
|
|
|
case FL_FOCUS:
|
|
|
|
redraw();
|
|
|
|
return 1;
|
|
|
|
case FL_PUSH:
|
2008-05-27 05:32:35 +02:00
|
|
|
take_focus();
|
2008-04-21 16:57:30 +02:00
|
|
|
redraw();
|
2008-07-21 05:56:45 +02:00
|
|
|
return 1;
|
2008-04-21 16:57:30 +02:00
|
|
|
case FL_UNFOCUS:
|
|
|
|
|
2008-04-27 05:50:58 +02:00
|
|
|
if ( window() )
|
|
|
|
window()->damage( FL_DAMAGE_EXPOSE, x(), y(), w(), h() );
|
2008-04-21 16:57:30 +02:00
|
|
|
|
|
|
|
redraw();
|
|
|
|
return r;
|
|
|
|
default:
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|