2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
14 #pragma off (unreferenced)
15 static char rcsid[] = "$Id: inputbox.c,v 1.1.1.1 2001-01-19 03:30:15 bradleyb Exp $";
16 #pragma on (unreferenced)
28 // insert character c into string s at position p.
29 void strcins(char *s, int p, char c)
32 for (n=strlen(s)-p; n>=0; n-- )
33 *(s+p+n+1) = *(s+p+n); // Move everything over
34 *(s+p) = c; // then insert the character
37 // delete n character from string s starting at position p
39 void strndel(char *s, int p, int n)
41 for (; (*(s+p) = *(s+p+n)) != '\0'; s++ )
42 *(s+p+n) = '\0'; // Delete and zero fill
45 void ui_draw_inputbox( UI_GADGET_INPUTBOX * inputbox )
49 if ((inputbox->status==1) || (inputbox->position != inputbox->oldposition))
52 gr_set_current_canvas( inputbox->canvas );
54 if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)inputbox)
56 if (inputbox->first_time)
57 gr_set_fontcolor( CBLACK, CRED );
59 gr_set_fontcolor( CRED, CBLACK );
62 gr_set_fontcolor( CWHITE, CBLACK );
66 gr_string( 2, 2, inputbox->text );
67 gr_get_string_size(inputbox->text, &w, &h, &aw );
69 gr_setcolor( CBLACK );
70 gr_rect( 2+w, 0, inputbox->width-1, inputbox->height-1 );
72 if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)inputbox && !inputbox->first_time )
75 Vline( 2,inputbox->height-3, 2+w+1 );
76 Vline( 2,inputbox->height-3, 2+w+2 );
83 UI_GADGET_INPUTBOX * ui_add_gadget_inputbox( UI_WINDOW * wnd, short x, short y, short length, short slength, char * text )
86 UI_GADGET_INPUTBOX * inputbox;
88 gr_get_string_size( NULL, &w, &h, &aw );
90 inputbox = (UI_GADGET_INPUTBOX *)ui_gadget_add( wnd, 6, x, y, x+aw*slength-1, y+h-1+4 );
94 inputbox->text = malloc( length + 1);
95 strncpy( inputbox->text, text, length );
96 inputbox->position = strlen(inputbox->text);
97 inputbox->oldposition = inputbox->position;
98 inputbox->width = aw*slength;
99 inputbox->height = h+4;
100 inputbox->length = length;
101 inputbox->slength = slength;
102 inputbox->pressed = 0;
103 inputbox->first_time = 1;
105 gr_set_current_canvas( inputbox->canvas );
106 gr_setcolor( CBLACK );
107 gr_rect( 0, 0, inputbox->width-1, inputbox->height-1 );
114 void ui_inputbox_do( UI_GADGET_INPUTBOX * inputbox, int keypress )
117 inputbox->oldposition = inputbox->position;
121 if (CurWindow->keyboard_focus_gadget==(UI_GADGET *)inputbox)
129 if (inputbox->position > 0)
130 inputbox->position--;
131 inputbox->text[inputbox->position] = 0;
132 inputbox->status = 1;
133 if (inputbox->first_time) inputbox->first_time = 0;
137 inputbox->status = 1;
138 if (inputbox->first_time) inputbox->first_time = 0;
141 ascii = key_to_ascii(keypress);
142 if ((ascii < 255 ) && (inputbox->position < inputbox->length-2))
144 if (inputbox->first_time) {
145 inputbox->first_time = 0;
146 inputbox->position = 0;
148 inputbox->text[inputbox->position++] = ascii;
149 inputbox->text[inputbox->position] = 0;
151 inputbox->status = 1;
155 inputbox->first_time = 1;
160 ui_draw_inputbox( inputbox );