Commit e1f157f1 authored by John Beranek's avatar John Beranek
Browse files

Added comments to the bits that I fixed in c/TextArea and c/TextMan in...

Added comments to the bits that I fixed in c/TextArea and c/TextMan in preparation for eventual merging to the trunk.
parent 65a52b2d
...@@ -622,9 +622,7 @@ static void key_pressed(WimpKeyPressedEvent *event, PrivateTextArea *tdata) ...@@ -622,9 +622,7 @@ static void key_pressed(WimpKeyPressedEvent *event, PrivateTextArea *tdata)
if (tdata->state & Gadget_Faded) if (tdata->state & Gadget_Faded)
{ {
#ifndef Daytona_BUILD /* wimp_process_key(key); This shouldn't be called in a gadget. JBeranek */
wimp_process_key(key);
#endif
return; return;
} }
...@@ -735,9 +733,7 @@ static void key_pressed(WimpKeyPressedEvent *event, PrivateTextArea *tdata) ...@@ -735,9 +733,7 @@ static void key_pressed(WimpKeyPressedEvent *event, PrivateTextArea *tdata)
#endif #endif
&& (key != 10)) && (key != 10))
{ {
#ifndef Daytona_BUILD /* wimp_process_key(key); This shouldn't be called in a gadget. JBeranek */
wimp_process_key(key);
#endif
return; return;
} }
...@@ -746,19 +742,25 @@ static void key_pressed(WimpKeyPressedEvent *event, PrivateTextArea *tdata) ...@@ -746,19 +742,25 @@ static void key_pressed(WimpKeyPressedEvent *event, PrivateTextArea *tdata)
{ {
if(text->sel_stop_pos < text->insert_pos) if(text->sel_stop_pos < text->insert_pos)
{ {
/* JBeranek fixes (Start) */
er = replace_text(text, text->sel_stop_pos, er = replace_text(text, text->sel_stop_pos,
text->insert_pos, str, &first_line, text->insert_pos, str, &first_line,
&last_line, &line_delta); &last_line, &line_delta);
/* if there's an error from replace_text return straight away */
if (er) if (er)
return; return;
/* JBeranek fixes (End) */
} }
else else
{ {
/* JBeranek fixes (Start) */
er = replace_text(text, text->insert_pos, er = replace_text(text, text->insert_pos,
text->sel_stop_pos, str, &first_line, text->sel_stop_pos, str, &first_line,
&last_line, &line_delta); &last_line, &line_delta);
/* if there's an error from replace_text return straight away */
if (er) if (er)
return; return;
/* JBeranek fixes (End) */
close_insertion(text); close_insertion(text);
create_insertion(text, text->insert_pos + 1); create_insertion(text, text->insert_pos + 1);
...@@ -768,9 +770,12 @@ static void key_pressed(WimpKeyPressedEvent *event, PrivateTextArea *tdata) ...@@ -768,9 +770,12 @@ static void key_pressed(WimpKeyPressedEvent *event, PrivateTextArea *tdata)
} }
else else
{ {
/* JBeranek fixes (Start) */
er = insert_text(text, str, &first_line, &last_line, &line_delta); er = insert_text(text, str, &first_line, &last_line, &line_delta);
/* if there's an error from insert_text return straight away */
if (er) if (er)
return; return;
/* JBeranek fixes (End) */
} }
if(line_delta >= 0) if(line_delta >= 0)
...@@ -948,9 +953,12 @@ textarea_add(TextArea *tdata, int wimpw, ObjectId parent_id, ...@@ -948,9 +953,12 @@ textarea_add(TextArea *tdata, int wimpw, ObjectId parent_id,
TextArea_DefaultHeight, 0, 0, (&tb->font_handle)); TextArea_DefaultHeight, 0, 0, (&tb->font_handle));
if (e) tb->font_handle = 0; if (e) tb->font_handle = 0;
/* JBeranek fixes (Start) */
e = create_text(0, tb->font_handle, &tb->text); e = create_text(0, tb->font_handle, &tb->text);
/* If there's an error from create_text return straight away */
if (e) if (e)
return e; return e;
/* JBeranek fixes (End) */
if(tb->state & TextArea_WordWrap) if(tb->state & TextArea_WordWrap)
{ {
...@@ -1140,10 +1148,13 @@ static _kernel_oserror *_set_text(PrivateTextArea *handle, const char *text) ...@@ -1140,10 +1148,13 @@ static _kernel_oserror *_set_text(PrivateTextArea *handle, const char *text)
window_get_wimp_handle(0, handle->object_id, &window_handle); window_get_wimp_handle(0, handle->object_id, &window_handle);
/* JBeranek fixes (Start) */
er = replace_text(handle->text, 0, -1, text, er = replace_text(handle->text, 0, -1, text,
&first_line, &last_line, &line_delta); &first_line, &last_line, &line_delta);
/* If there's an error from replace_text return straight away */
if (er) if (er)
return er; return er;
/* JBeranek fixes (End) */
char_pos(handle->text, handle->text->insert_pos, &caret_x, &caret_y); 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);
...@@ -1195,10 +1206,13 @@ static _kernel_oserror *_insert_text(PrivateTextArea *tdata, int index, ...@@ -1195,10 +1206,13 @@ static _kernel_oserror *_insert_text(PrivateTextArea *tdata, int index,
window_get_wimp_handle(0, tdata->object_id, &window_handle); window_get_wimp_handle(0, tdata->object_id, &window_handle);
/* JBeranek fixes (Start) */
er = replace_text(tdata->text, index, index, buffer, er = replace_text(tdata->text, index, index, buffer,
&first_line, &last_line, &line_delta); &first_line, &last_line, &line_delta);
/* If there's an error from replace_text return straight away */
if (er) if (er)
return er; return er;
/* JBeranek fixes (End) */
char_pos(tdata->text, tdata->text->insert_pos, &caret_x, &caret_y); 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);
...@@ -1227,10 +1241,13 @@ static _kernel_oserror *_replace_text(PrivateTextArea *tdata, ...@@ -1227,10 +1241,13 @@ static _kernel_oserror *_replace_text(PrivateTextArea *tdata,
window_get_wimp_handle(0, tdata->object_id, &window_handle); window_get_wimp_handle(0, tdata->object_id, &window_handle);
/* JBeranek fixes (Start) */
er = replace_text(tdata->text, start, end, buffer, er = replace_text(tdata->text, start, end, buffer,
&first_line, &last_line, &line_delta); &first_line, &last_line, &line_delta);
/* If there's an error from replace_text return straight away */
if (er) if (er)
return er; return er;
/* JBeranek fixes (End) */
char_pos(tdata->text, tdata->text->insert_pos, &caret_x, &caret_y); 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);
...@@ -1391,9 +1408,12 @@ static void _set_state(PrivateTextArea *handle, unsigned int state) ...@@ -1391,9 +1408,12 @@ static void _set_state(PrivateTextArea *handle, unsigned int state)
else else
handle->text->margin = 0xffffff; handle->text->margin = 0xffffff;
/* JBeranek fixes (Start) */
er = compose_text(handle->text); er = compose_text(handle->text);
/* If there's an error from compose_text return straight away */
if (er) if (er)
return; return;
/* JBeranek fixes (End) */
} }
if(state & TextArea_WordWrap) if(state & TextArea_WordWrap)
......
...@@ -385,8 +385,13 @@ _kernel_oserror *compose_text(Text *text) ...@@ -385,8 +385,13 @@ _kernel_oserror *compose_text(Text *text)
scan.max_line = (end - base + 1) / 20 + 5; scan.max_line = (end - base + 1) / 20 + 5;
scan.new_lines = malloc((scan.max_line + 1) * sizeof(int)); scan.new_lines = malloc((scan.max_line + 1) * sizeof(int));
/* If the malloc fails ... */
if (scan.new_lines == NULL) if (scan.new_lines == NULL)
{
/* ... return an error message */
return (_kernel_oserror*)" JBERANEK> Out of memory."; return (_kernel_oserror*)" JBERANEK> Out of memory.";
}
scan.line_no = 0; scan.line_no = 0;
...@@ -486,7 +491,10 @@ _kernel_oserror *replace_text(Text *text, int from, int ex_to, const char *s, ...@@ -486,7 +491,10 @@ _kernel_oserror *replace_text(Text *text, int from, int ex_to, const char *s,
/* If expand_tabs failed */ /* If expand_tabs failed */
if (str == NULL) if (str == NULL)
{
/* return an error message */
return (_kernel_oserror*)" JBERANEK> Out of memory."; return (_kernel_oserror*)" JBERANEK> Out of memory.";
}
if((ex_to == -1) || (to > line_end(text, text->no_of_lines - 1))) if((ex_to == -1) || (to > line_end(text, text->no_of_lines - 1)))
to = line_end(text, text->no_of_lines - 1); to = line_end(text, text->no_of_lines - 1);
...@@ -551,8 +559,11 @@ _kernel_oserror *replace_text(Text *text, int from, int ex_to, const char *s, ...@@ -551,8 +559,11 @@ _kernel_oserror *replace_text(Text *text, int from, int ex_to, const char *s,
scan.max_line = (last_line_end - first_line_start + 1 + delta) / 20 + 5; scan.max_line = (last_line_end - first_line_start + 1 + delta) / 20 + 5;
scan.new_lines = malloc((scan.max_line + 1) * sizeof(int)); scan.new_lines = malloc((scan.max_line + 1) * sizeof(int));
/* If the malloc fails ... */
if (scan.new_lines == NULL) if (scan.new_lines == NULL)
{ {
/* ... attempt to clean up, this is largely intelligent guesswork */
if((to < insert_pos) && (from != insert_pos)) if((to < insert_pos) && (from != insert_pos))
{ {
if (delta > 0) if (delta > 0)
...@@ -570,8 +581,11 @@ _kernel_oserror *replace_text(Text *text, int from, int ex_to, const char *s, ...@@ -570,8 +581,11 @@ _kernel_oserror *replace_text(Text *text, int from, int ex_to, const char *s,
shrink_block(text->text_data, from + gap_size, -delta); shrink_block(text->text_data, from + gap_size, -delta);
} }
} }
/* and return an error */
return (_kernel_oserror*)" JBERANEK> Out of memory."; return (_kernel_oserror*)" JBERANEK> Out of memory.";
} }
scan.line_no = scan.x_pos = 0; scan.line_no = scan.x_pos = 0;
scan.split_pos = NULL; scan.split_pos = NULL;
...@@ -769,12 +783,21 @@ _kernel_oserror *insert_text(Text *text, char *s, ...@@ -769,12 +783,21 @@ _kernel_oserror *insert_text(Text *text, char *s,
int old_split = 0; int old_split = 0;
int old_line_no; int old_line_no;
/* If expand_tabs failed */
if (str == NULL) if (str == NULL)
{
/* return an error message */
return (_kernel_oserror*)" JBERANEK> Out of memory."; return (_kernel_oserror*)" JBERANEK> Out of memory.";
}
scan.new_lines = malloc(10 * sizeof(int)); scan.new_lines = malloc(10 * sizeof(int));
/* If the malloc fails */
if (scan.new_lines == NULL) if (scan.new_lines == NULL)
{
/* return an error message */
return (_kernel_oserror*)" JBERANEK> Out of memory."; return (_kernel_oserror*)" JBERANEK> Out of memory.";
}
scan.max_line = 9; scan.max_line = 9;
scan.line_no = 0; scan.line_no = 0;
......
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