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.
27 // insert character c into string s at position p.
28 void strcins(char *s, int p, char c)
31 for (n = (int)strlen(s) - p; n >= 0; n--)
32 *(s+p+n+1) = *(s+p+n); // Move everything over
33 *(s+p) = c; // then insert the character
36 // delete n character from string s starting at position p
38 void strndel(char *s, int p, int n)
40 for (; (*(s+p) = *(s+p+n)) != '\0'; s++ )
41 *(s+p+n) = '\0'; // Delete and zero fill
44 void ui_draw_inputbox( UI_GADGET_INPUTBOX * inputbox )
48 if ((inputbox->status==1) || (inputbox->position != inputbox->oldposition))
51 gr_set_current_canvas( inputbox->canvas );
53 if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)inputbox)
55 if (inputbox->first_time)
56 gr_set_fontcolor( CBLACK, CRED );
58 gr_set_fontcolor( CRED, CBLACK );
61 gr_set_fontcolor( CWHITE, CBLACK );
65 gr_string( 2, 2, inputbox->text );
66 gr_get_string_size(inputbox->text, &w, &h, &aw );
68 gr_setcolor( CBLACK );
69 gr_rect( 2+w, 0, inputbox->width-1, inputbox->height-1 );
71 if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)inputbox && !inputbox->first_time )
74 Vline( 2,inputbox->height-3, 2+w+1 );
75 Vline( 2,inputbox->height-3, 2+w+2 );
82 UI_GADGET_INPUTBOX * ui_add_gadget_inputbox( UI_WINDOW * wnd, short x, short y, short length, short slength, char * text )
85 UI_GADGET_INPUTBOX * inputbox;
87 gr_get_string_size( NULL, &w, &h, &aw );
89 inputbox = (UI_GADGET_INPUTBOX *)ui_gadget_add( wnd, 6, x, y, x+aw*slength-1, y+h-1+4 );
93 inputbox->text = d_malloc(length + 1);
94 strncpy( inputbox->text, text, length );
95 inputbox->position = strlen(inputbox->text);
96 inputbox->oldposition = inputbox->position;
97 inputbox->width = aw*slength;
98 inputbox->height = h+4;
99 inputbox->length = length;
100 inputbox->slength = slength;
101 inputbox->pressed = 0;
102 inputbox->first_time = 1;
104 gr_set_current_canvas( inputbox->canvas );
105 gr_setcolor( CBLACK );
106 gr_rect( 0, 0, inputbox->width-1, inputbox->height-1 );
113 void ui_inputbox_do( UI_GADGET_INPUTBOX * inputbox, int keypress )
116 inputbox->oldposition = inputbox->position;
120 if (CurWindow->keyboard_focus_gadget==(UI_GADGET *)inputbox)
128 if (inputbox->position > 0)
129 inputbox->position--;
130 inputbox->text[inputbox->position] = 0;
131 inputbox->status = 1;
132 if (inputbox->first_time) inputbox->first_time = 0;
136 inputbox->status = 1;
137 if (inputbox->first_time) inputbox->first_time = 0;
140 ascii = key_to_ascii(keypress);
141 if ((ascii < 255 ) && (inputbox->position < inputbox->length-2))
143 if (inputbox->first_time) {
144 inputbox->first_time = 0;
145 inputbox->position = 0;
147 inputbox->text[inputbox->position++] = ascii;
148 inputbox->text[inputbox->position] = 0;
150 inputbox->status = 1;
154 inputbox->first_time = 1;
159 ui_draw_inputbox( inputbox );
163 void ui_inputbox_set_text(UI_GADGET_INPUTBOX *inputbox, char *text)
165 strncpy(inputbox->text, text, inputbox->length + 1);
166 inputbox->position = strlen(text);
167 inputbox->oldposition = inputbox->position;
168 inputbox->status = 1; // redraw
169 inputbox->first_time = 1; // select all