/****************************************************************************
GLUI User Interface Toolkit
---------------------------
glui_textbox.cpp - GLUI_TextBox control class
--------------------------------------------------
Copyright (c) 1998 Paul Rademacher, 2004 John Kew
WWW: http://sourceforge.net/projects/glui/
Forums: http://sourceforge.net/forum/?group_id=92496
This library 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 of the License, or (at your option) any later version.
This library 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 this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*****************************************************************************/
#include "glui_internal_control.h"
#include <cmath>
static const int LINE_HEIGHT = 15;
/****************************** GLUI_TextBox::GLUI_TextBox() **********/
GLUI_TextBox::GLUI_TextBox(GLUI_Node *parent, GLUI_String &live_var,
bool scroll, int id, GLUI_CB callback )
{
common_construct(parent, &live_var, scroll, id, callback);
}
/****************************** GLUI_TextBox::GLUI_TextBox() **********/
GLUI_TextBox::GLUI_TextBox( GLUI_Node *parent, bool scroll, int id,
GLUI_CB callback )
{
common_construct(parent, NULL, scroll, id, callback);
}
/****************************** GLUI_TextBox::common_construct() **********/
void GLUI_TextBox::common_construct(
GLUI_Node *parent, GLUI_String *data,
bool scroll, int id, GLUI_CB callback)
{
common_init();
GLUI_Node *tb_panel = parent;
if (scroll) {
GLUI_Panel *p = new GLUI_Panel(parent,"",GLUI_PANEL_NONE);
p->x_off = 1;
tb_panel = p;
}
this->ptr_val = data;
if (data) {
this->live_type = GLUI_LIVE_STRING;
} else {
this->live_type = GLUI_LIVE_NONE;
}
this->user_id = id;
this->callback = callback;
this->name = "textbox";
tb_panel->add_control( this );
if (scroll) {
new GLUI_Column(tb_panel, false);
scrollbar =
new GLUI_Scrollbar(tb_panel,
"scrollbar",
GLUI_SCROLL_VERTICAL,
GLUI_SCROLL_INT);
scrollbar->set_object_callback(GLUI_TextBox::scrollbar_callback, this);
scrollbar->set_alignment(GLUI_ALIGN_LEFT);
// scrollbar->can_activate = false; //kills ability to mouse drag too
}
init_live();
}
/****************************** GLUI_TextBox::mouse_down_handler() **********/
int GLUI_TextBox::mouse_down_handler( int local_x, int local_y )
{
int tmp_insertion_pt;
if ( debug ) dump( stdout, "-> MOUSE DOWN" );
tmp_insertion_pt = find_insertion_pt( local_x, local_y );
if ( tmp_insertion_pt == -1 ) {
if ( glui )
glui->deactivate_current_control( );
return false;
}
insertion_pt = tmp_insertion_pt;
sel_start = sel_end = insertion_pt;
keygoal_x = insert_x;
if ( can_draw())
update_and_draw_text();
if ( debug ) dump( stdout, "<- MOUSE UP" );
return true;
}
/******************************** GLUI_TextBox::mouse_up_handler() **********/
int GLUI_TextBox::mouse_up_handler( int local_x, int local_y, bool inside )
{
return false;
}
/***************************** GLUI_TextBox::mouse_held_down_handler() ******/
int GLUI_TextBox::mouse_held_down_handler( int local_x, int local_y,
bool new_inside)
{
int tmp_pt;
if ( NOT new_inside ) return false;
if ( debug ) dump( stdout, "-> HELD DOWN" );
tmp_pt = find_insertion_pt( local_x, local_y );
keygoal_x = insert_x;
if ( tmp_pt == -1 AND sel_end !=