Commit 6aed779f authored by Rob Lougher's avatar Rob Lougher
Browse files

Changed _insert_text to call set_caret, forcing window to scroll. Also uses ...

Changed _insert_text to call set_caret, forcing window to scroll.  Also uses  more efficient insert_text.  Changes to set_caret to allow invisibility.
......@@ -273,6 +273,50 @@ static void deselect(PrivateTextArea *tdata)
tdata->text->sel_stop_line = -1;
}
static void set_caret(int win, Text *text, int caret_x, int caret_y, int force, int invisible)
{
WimpGetWindowStateBlock state;
int xmax, ymax, new_x = -1, new_y = -1;
state.window_handle = win;
wimp_get_window_state(&state);
xmax = state.visible_area.xmax - state.visible_area.xmin + state.xscroll;
ymax = state.visible_area.ymax - state.visible_area.ymin - state.yscroll;
if(xmax < caret_x)
new_x = caret_x - xmax + state.xscroll + 10;
else
if(state.xscroll > caret_x)
new_x = caret_x;
if(ymax < caret_y)
new_y = caret_y - ymax - state.yscroll;
else
if(-state.yscroll > (caret_y - text->line_height))
new_y = (caret_y - text->line_height);
if((new_x != -1) || (new_y != -1))
{
state.xscroll = new_x == -1 ? state.xscroll : new_x;
state.yscroll = new_y == -1 ? state.yscroll : -new_y;
wimp_open_window((WimpOpenWindowBlock *) &state);
}
if(!force)
{
WimpGetCaretPositionBlock block;
wimp_get_caret_position(&block);
if(block.window_handle != win)
return;
}
wimp_set_caret_position(win, -1, caret_x, -caret_y,
text->line_height | (invisible ? 1<<25 : 0), -1);
}
static void _set_selection(PrivateTextArea *tdata, int from, int to)
{
int caret_x, caret_y;
......@@ -287,16 +331,14 @@ static void _set_selection(PrivateTextArea *tdata, int from, int to)
if((to == -1) || (to > get_text_size(text)))
to = get_text_size(text);
char_pos(text, from, &caret_x, &caret_y);
wimp_set_caret_position(window, -1, caret_x, -caret_y,
text->line_height, -1);
close_insertion(text);
create_insertion(text, from);
text->sel_stop_pos = to;
text->sel_stop_line = line_index_of_char(text, to);
char_pos(text, text->insert_pos, &caret_x, &caret_y);
set_caret(window, text, caret_x, caret_y, 1, 1);
update_display(tdata, text->insert_line, text->sel_stop_line, 0);
}
......@@ -571,45 +613,6 @@ static void update_display(PrivateTextArea *tdata,
}
}
static void set_caret(int win, Text *text, int caret_x, int caret_y, int force)
{
WimpGetWindowStateBlock state;
WimpGetCaretPositionBlock block;
int xmax, ymax, new_x = -1, new_y = -1;
state.window_handle = win;
wimp_get_window_state(&state);
xmax = state.visible_area.xmax - state.visible_area.xmin + state.xscroll;
ymax = state.visible_area.ymax - state.visible_area.ymin - state.yscroll;
if(xmax < caret_x)
new_x = caret_x - xmax + state.xscroll + 10;
else
if(state.xscroll > caret_x)
new_x = caret_x;
if(ymax < caret_y)
new_y = caret_y - ymax - state.yscroll;
else
if(-state.yscroll > (caret_y - text->line_height))
new_y = (caret_y - text->line_height);
if((new_x != -1) || (new_y != -1))
{
state.xscroll = new_x == -1 ? state.xscroll : new_x;
state.yscroll = new_y == -1 ? state.yscroll : -new_y;
wimp_open_window((WimpOpenWindowBlock *) &state);
}
wimp_get_caret_position(&block);
if (force || block.window_handle == win)
wimp_set_caret_position(win, -1, caret_x, -caret_y,
text->line_height, -1);
}
static void key_pressed(WimpKeyPressedEvent *event, PrivateTextArea *tdata)
{
static char str[] = " ";
......@@ -650,7 +653,7 @@ static void key_pressed(WimpKeyPressedEvent *event, PrivateTextArea *tdata)
&first_line, &last_line, &line_delta);
}
char_pos(text, text->insert_pos, &caret_x, &caret_y);
set_caret(win, text, caret_x, caret_y, 1);
set_caret(win, text, caret_x, caret_y, 1, 0);
update_display(tdata, first_line, last_line, line_delta);
}
#ifdef DAYTONA_BUILD
......@@ -732,12 +735,12 @@ static void key_pressed(WimpKeyPressedEvent *event, PrivateTextArea *tdata)
{
update_display(tdata, first_line, last_line, line_delta);
char_pos(text, text->insert_pos, &caret_x, &caret_y);
set_caret(win, text, caret_x, caret_y, 1);
set_caret(win, text, caret_x, caret_y, 1, 0);
}
else
{
char_pos(text, text->insert_pos, &caret_x, &caret_y);
set_caret(win, text, caret_x, caret_y, 1);
set_caret(win, text, caret_x, caret_y, 1, 0);
update_display(tdata, first_line, last_line, line_delta);
}
}
......@@ -778,7 +781,7 @@ static void key_pressed(WimpKeyPressedEvent *event, PrivateTextArea *tdata)
}
char_pos(text, text->insert_pos, &caret_x, &caret_y);
set_caret(win, text, caret_x, caret_y, 1);
set_caret(win, text, caret_x, caret_y, 1, 0);
}
}
return;
......@@ -1043,8 +1046,7 @@ static _kernel_oserror *textarea_mclick(PrivateTextArea *tdata,
char_block(text, xcoord, ycoord, &l, &index, &xpos, &ypos);
close_insertion(text);
create_insertion(text, index);
set_caret(win, text, xpos, ypos, 1);
set_caret(win, text, xpos, ypos, 1, 0);
}
return NULL;
......@@ -1094,7 +1096,7 @@ static _kernel_oserror *_set_text(PrivateTextArea *handle, const char *text)
&first_line, &last_line, &line_delta);
char_pos(handle->text, handle->text->insert_pos, &caret_x, &caret_y);
set_caret(window_handle, handle->text, caret_x, caret_y, 0);
set_caret(window_handle, handle->text, caret_x, caret_y, 0, 1);
update_display(handle, first_line, last_line, line_delta);
#ifdef MemCheck_MEMCHECK
......@@ -1123,6 +1125,8 @@ static _kernel_oserror *_get_text(PrivateTextArea *handle, char *buffer,
return NULL;
}
FILE *debug = NULL;
static _kernel_oserror *_insert_text(PrivateTextArea *tdata, int index,
char *buffer)
{
......@@ -1140,13 +1144,26 @@ static _kernel_oserror *_insert_text(PrivateTextArea *tdata, int index,
if(tdata->text->sel_stop_pos != -1)
deselect(tdata);
if(!debug)
debug = fopen("adfs::rlougher.$.crappy", "w");
fprintf(debug, "Inserting text at: %d...\n", index);
window_get_wimp_handle(0, tdata->object_id, &window_handle);
replace_text(tdata->text, index, index, buffer,
close_insertion(tdata->text);
create_insertion(tdata->text, index);
insert_text(tdata->text, buffer,
&first_line, &last_line, &line_delta);
// replace_text(tdata->text, index, index, buffer,
// &first_line, &last_line, &line_delta);
fprintf(debug, "Returns first_line %d last_line %d line_delta %d\n", first_line, last_line, line_delta);
char_pos(tdata->text, tdata->text->insert_pos, &caret_x, &caret_y);
set_caret(window_handle, tdata->text, caret_x, caret_y, 0);
set_caret(window_handle, tdata->text, caret_x, caret_y, 0, 1);
update_display(tdata, first_line, last_line, line_delta);
return NULL;
......@@ -1175,7 +1192,7 @@ static _kernel_oserror *_replace_text(PrivateTextArea *tdata,
&first_line, &last_line, &line_delta);
char_pos(tdata->text, tdata->text->insert_pos, &caret_x, &caret_y);
set_caret(window_handle, tdata->text, caret_x, caret_y, 0);
set_caret(window_handle, tdata->text, caret_x, caret_y, 0, 0);
update_display(tdata, first_line, last_line, line_delta);
return NULL;
......@@ -1260,7 +1277,7 @@ static _kernel_oserror *_set_font(PrivateTextArea *handle, const char *font,
window_get_wimp_handle(0, handle->object_id, &window_handle);
char_pos(handle->text, handle->text->insert_pos, &caret_x, &caret_y);
set_caret(window_handle, handle->text, caret_x, caret_y, 0);
set_caret(window_handle, handle->text, caret_x, caret_y, 0, 0);
// Generate a force_redraw
window_force_redraw(0, handle->object_id, &redraw_all_box);
......@@ -1358,7 +1375,7 @@ static void _set_state(PrivateTextArea *handle, unsigned int state)
parent, alignment);
char_pos(handle->text, handle->text->insert_pos, &caret_x, &caret_y);
set_caret(win, handle->text, caret_x, caret_y, 0);
set_caret(win, handle->text, caret_x, caret_y, 0, 0);
window_force_redraw(0, handle->object_id, &redraw_all_box);
}
......
......@@ -647,7 +647,7 @@ _kernel_oserror *replace_text(Text *text, int from, int ex_to, const char *s,
}
else
{
if(first_line < insert_line)
if(first_line <= insert_line)
text->insert_line += ld;
for(i = last_line + 1; i < text->no_of_lines; i++)
text->line_table[i] += delta;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment