2010-12-24 04:26:24 +00:00
|
|
|
/* $Id: inputbox.c,v 1.1.1.1 2006/03/17 19:52:23 zicodxx Exp $ */
|
2006-03-20 16:43:15 +00:00
|
|
|
/*
|
|
|
|
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
|
|
|
|
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
|
|
|
|
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
|
|
|
|
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
|
|
|
|
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
|
|
|
|
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
|
|
|
|
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
|
|
|
|
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
|
2010-12-24 04:26:24 +00:00
|
|
|
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
|
2006-03-20 16:43:15 +00:00
|
|
|
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef RCS
|
2010-12-24 04:26:24 +00:00
|
|
|
static char rcsid[] = "$Id: inputbox.c,v 1.1.1.1 2006/03/17 19:52:23 zicodxx Exp $";
|
2006-03-20 16:43:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "u_mem.h"
|
|
|
|
#include "fix.h"
|
2008-01-02 03:37:13 +00:00
|
|
|
#include "pstypes.h"
|
2011-10-25 01:38:12 +00:00
|
|
|
#include "event.h"
|
2006-03-20 16:43:15 +00:00
|
|
|
#include "gr.h"
|
|
|
|
#include "ui.h"
|
|
|
|
#include "key.h"
|
2012-03-18 10:04:16 +00:00
|
|
|
#include "mouse.h"
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
// insert character c into string s at position p.
|
|
|
|
void strcins(char *s, int p, char c)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
for (n=strlen(s)-p; n>=0; n-- )
|
|
|
|
*(s+p+n+1) = *(s+p+n); // Move everything over
|
|
|
|
*(s+p) = c; // then insert the character
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete n character from string s starting at position p
|
|
|
|
|
|
|
|
void strndel(char *s, int p, int n)
|
|
|
|
{
|
|
|
|
for (; (*(s+p) = *(s+p+n)) != '\0'; s++ )
|
|
|
|
*(s+p+n) = '\0'; // Delete and zero fill
|
|
|
|
}
|
|
|
|
|
2012-03-03 12:12:25 +00:00
|
|
|
void ui_draw_inputbox( UI_DIALOG *dlg, UI_GADGET_INPUTBOX * inputbox )
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
|
|
|
int w, h, aw;
|
|
|
|
|
2012-03-31 12:11:39 +00:00
|
|
|
#if 0 //ndef OGL
|
2006-03-20 16:43:15 +00:00
|
|
|
if ((inputbox->status==1) || (inputbox->position != inputbox->oldposition))
|
2012-03-31 10:35:06 +00:00
|
|
|
#endif
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
|
|
|
gr_set_current_canvas( inputbox->canvas );
|
|
|
|
|
2012-04-11 02:52:19 +00:00
|
|
|
gr_setcolor( CBLACK );
|
|
|
|
gr_rect( 0, 0, inputbox->width-1, inputbox->height-1 );
|
|
|
|
gr_get_string_size(inputbox->text, &w, &h, &aw );
|
|
|
|
|
2012-03-03 12:12:25 +00:00
|
|
|
if (dlg->keyboard_focus_gadget == (UI_GADGET *)inputbox)
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
|
|
|
if (inputbox->first_time)
|
2012-04-11 02:52:19 +00:00
|
|
|
{
|
|
|
|
gr_set_fontcolor( CBLACK, -1 );
|
|
|
|
gr_setcolor( CRED );
|
|
|
|
gr_rect(2, 2, 2 + w, 2 + h);
|
|
|
|
}
|
2006-03-20 16:43:15 +00:00
|
|
|
else
|
2012-04-11 02:52:19 +00:00
|
|
|
gr_set_fontcolor( CRED, -1 );
|
2006-03-20 16:43:15 +00:00
|
|
|
}
|
|
|
|
else
|
2012-04-11 02:52:19 +00:00
|
|
|
gr_set_fontcolor( CWHITE, -1 );
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
inputbox->status = 0;
|
|
|
|
|
|
|
|
gr_string( 2, 2, inputbox->text );
|
|
|
|
|
2012-04-11 02:52:19 +00:00
|
|
|
//gr_setcolor( CBLACK );
|
|
|
|
//gr_rect( 2+w, 0, inputbox->width-1, inputbox->height-1 );
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2012-03-03 12:12:25 +00:00
|
|
|
if (dlg->keyboard_focus_gadget == (UI_GADGET *)inputbox && !inputbox->first_time )
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
|
|
|
gr_setcolor(CRED);
|
|
|
|
Vline( 2,inputbox->height-3, 2+w+1 );
|
|
|
|
Vline( 2,inputbox->height-3, 2+w+2 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-17 14:41:05 +00:00
|
|
|
UI_GADGET_INPUTBOX * ui_add_gadget_inputbox( UI_DIALOG * dlg, short x, short y, short length, short slength, char * text )
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
2011-09-26 23:31:17 +00:00
|
|
|
int h, w, aw;
|
2006-03-20 16:43:15 +00:00
|
|
|
UI_GADGET_INPUTBOX * inputbox;
|
|
|
|
|
|
|
|
gr_get_string_size( NULL, &w, &h, &aw );
|
|
|
|
|
2011-01-17 14:41:05 +00:00
|
|
|
inputbox = (UI_GADGET_INPUTBOX *)ui_gadget_add( dlg, 6, x, y, x+aw*slength-1, y+h-1+4 );
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2010-12-24 04:26:24 +00:00
|
|
|
inputbox->text = d_malloc(length + 1);
|
2006-03-20 16:43:15 +00:00
|
|
|
strncpy( inputbox->text, text, length );
|
|
|
|
inputbox->position = strlen(inputbox->text);
|
|
|
|
inputbox->oldposition = inputbox->position;
|
|
|
|
inputbox->width = aw*slength;
|
|
|
|
inputbox->height = h+4;
|
|
|
|
inputbox->length = length;
|
|
|
|
inputbox->slength = slength;
|
|
|
|
inputbox->pressed = 0;
|
|
|
|
inputbox->first_time = 1;
|
|
|
|
|
|
|
|
return inputbox;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-03 12:12:25 +00:00
|
|
|
int ui_inputbox_do( UI_DIALOG *dlg, UI_GADGET_INPUTBOX * inputbox, d_event *event )
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
2010-12-24 04:26:24 +00:00
|
|
|
unsigned char ascii;
|
2011-10-25 01:38:12 +00:00
|
|
|
int keypress = 0;
|
|
|
|
int rval = 0;
|
|
|
|
|
|
|
|
if (event->type == EVENT_KEY_COMMAND)
|
|
|
|
keypress = event_key_get(event);
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2011-10-25 01:38:12 +00:00
|
|
|
inputbox->oldposition = inputbox->position;
|
2006-03-20 16:43:15 +00:00
|
|
|
inputbox->pressed=0;
|
|
|
|
|
2012-03-03 12:12:25 +00:00
|
|
|
if (dlg->keyboard_focus_gadget==(UI_GADGET *)inputbox)
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
|
|
|
switch( keypress )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case (KEY_LEFT):
|
|
|
|
case (KEY_BACKSP):
|
|
|
|
if (inputbox->position > 0)
|
|
|
|
inputbox->position--;
|
|
|
|
inputbox->text[inputbox->position] = 0;
|
|
|
|
inputbox->status = 1;
|
|
|
|
if (inputbox->first_time) inputbox->first_time = 0;
|
2011-11-05 12:11:48 +00:00
|
|
|
rval = 1;
|
2006-03-20 16:43:15 +00:00
|
|
|
break;
|
|
|
|
case (KEY_ENTER):
|
|
|
|
inputbox->pressed=1;
|
|
|
|
inputbox->status = 1;
|
|
|
|
if (inputbox->first_time) inputbox->first_time = 0;
|
2011-11-05 12:11:48 +00:00
|
|
|
rval = 1;
|
2006-03-20 16:43:15 +00:00
|
|
|
break;
|
|
|
|
default:
|
2008-11-17 23:38:43 +00:00
|
|
|
ascii = key_ascii();
|
2006-03-20 16:43:15 +00:00
|
|
|
if ((ascii < 255 ) && (inputbox->position < inputbox->length-2))
|
|
|
|
{
|
|
|
|
if (inputbox->first_time) {
|
|
|
|
inputbox->first_time = 0;
|
|
|
|
inputbox->position = 0;
|
|
|
|
}
|
|
|
|
inputbox->text[inputbox->position++] = ascii;
|
|
|
|
inputbox->text[inputbox->position] = 0;
|
2011-11-05 12:11:48 +00:00
|
|
|
rval = 1;
|
2006-03-20 16:43:15 +00:00
|
|
|
}
|
|
|
|
inputbox->status = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
inputbox->first_time = 1;
|
|
|
|
}
|
2012-03-03 12:12:25 +00:00
|
|
|
|
|
|
|
if (inputbox->pressed)
|
|
|
|
{
|
|
|
|
ui_gadget_send_event(dlg, EVENT_UI_GADGET_PRESSED, (UI_GADGET *)inputbox);
|
|
|
|
rval = 1;
|
|
|
|
}
|
|
|
|
|
2012-03-31 10:35:06 +00:00
|
|
|
if (event->type == EVENT_WINDOW_DRAW)
|
|
|
|
ui_draw_inputbox( dlg, inputbox );
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2011-10-25 01:38:12 +00:00
|
|
|
return rval;
|
2006-03-20 16:43:15 +00:00
|
|
|
}
|
2010-12-24 04:26:24 +00:00
|
|
|
|
|
|
|
void ui_inputbox_set_text(UI_GADGET_INPUTBOX *inputbox, char *text)
|
|
|
|
{
|
|
|
|
strncpy(inputbox->text, text, inputbox->length + 1);
|
|
|
|
inputbox->position = strlen(text);
|
|
|
|
inputbox->oldposition = inputbox->position;
|
|
|
|
inputbox->status = 1; // redraw
|
|
|
|
inputbox->first_time = 1; // select all
|
|
|
|
}
|
|
|
|
|