Commit 6864b4e4 authored by Andrew Hodgkinson's avatar Andrew Hodgkinson
Browse files

A bit more tidying up

parent f3e8124f
...@@ -79,8 +79,6 @@ static unsigned int hotlist_bbar_size = 0; /* Height in OS units ...@@ -79,8 +79,6 @@ static unsigned int hotlist_bbar_size = 0; /* Height in OS units
static unsigned int alter_new; /* Remembers if the edit dialogue is Alter or New; see */ static unsigned int alter_new; /* Remembers if the edit dialogue is Alter or New; see */
/* HOTLIST_MENUSECTION_NEW and HOTLIST_MENUSECTION_ALTER */ /* HOTLIST_MENUSECTION_NEW and HOTLIST_MENUSECTION_ALTER */
static unsigned int item_number; /* Current item being considered for drawing */
static hotlist_item * hotlist_save_item = NULL; /* Item whose URL is being saved */ static hotlist_item * hotlist_save_item = NULL; /* Item whose URL is being saved */
static int hotlist_ram_transfer_sent; /* Number of bytes which have already been sent by ram transfer */ static int hotlist_ram_transfer_sent; /* Number of bytes which have already been sent by ram transfer */
static int hotlist_save_type = HL_SAVE_NONE; /* Variety of save currently in progress */ static int hotlist_save_type = HL_SAVE_NONE; /* Variety of save currently in progress */
...@@ -167,11 +165,10 @@ static _kernel_oserror * hotlist_draw (hotlist_item * list, u ...@@ -167,11 +165,10 @@ static _kernel_oserror * hotlist_draw (hotlist_item * list, u
static _kernel_oserror * hotlist_draw_r (hotlist_item *list, unsigned int first_item, unsigned int last_item, int * curr_item, unsigned int indent, unsigned int item_height, unsigned int item_dir_width, unsigned int item_url_width); static _kernel_oserror * hotlist_draw_r (hotlist_item *list, unsigned int first_item, unsigned int last_item, int * curr_item, unsigned int indent, unsigned int item_height, unsigned int item_dir_width, unsigned int item_url_width);
static unsigned int hotlist_contents_selected (hotlist_item * item); static unsigned int hotlist_contents_selected (hotlist_item * item);
static unsigned int hotlist_no_contents_selected (hotlist_item * item); static unsigned int hotlist_no_contents_selected (hotlist_item * item);
// Need renaming to hotlist_get_max_width_r and hotlist_redraw_now_r
static void _hotlist_get_max_width (hotlist_item * list, unsigned int indent);
static void _hotlist_redraw_now (hotlist_item * list);
static void hotlist_redraw_now (void);
static unsigned int hotlist_get_max_width (hotlist_item * list); static unsigned int hotlist_get_max_width (hotlist_item * list);
static _kernel_oserror * hotlist_get_max_width_r (hotlist_item *list, unsigned int indent, int * max_width, unsigned int item_height, unsigned int item_dir_width, unsigned int item_url_width);
static void hotlist_redraw_now (void);
static void hotlist_redraw_now_r (hotlist_item * list, int * curr_item);
static void hotlist_get_shape (unsigned int * xmin, unsigned int * xmax, hotlist_item * item); static void hotlist_get_shape (unsigned int * xmin, unsigned int * xmax, hotlist_item * item);
static void hotlist_directory_open_close (hotlist_item * item, unsigned int itemno); static void hotlist_directory_open_close (hotlist_item * item, unsigned int itemno);
static void hotlist_redraw_items (unsigned int firstitem, unsigned int lastitem); static void hotlist_redraw_items (unsigned int firstitem, unsigned int lastitem);
...@@ -983,7 +980,7 @@ static _kernel_oserror * hotlist_get_entry_sizes(unsigned int * item_height, uns ...@@ -983,7 +980,7 @@ static _kernel_oserror * hotlist_get_entry_sizes(unsigned int * item_height, uns
/* Set the URL width to the value found above and add 8 to */ /* Set the URL width to the value found above and add 8 to */
/* all of them for aesthetics. */ /* all of them for aesthetics. */
if (item_url_width) *item_url_width = width + 8; /* +8 for aesthetics */ if (item_url_width) *item_url_width = width + 8;
if (item_dir_width) *item_dir_width += 8; if (item_dir_width) *item_dir_width += 8;
if (item_height) *item_height += 8; if (item_height) *item_height += 8;
...@@ -1650,106 +1647,183 @@ static _kernel_oserror * hotlist_draw_r(hotlist_item *list, unsigned int first_i ...@@ -1650,106 +1647,183 @@ static _kernel_oserror * hotlist_draw_r(hotlist_item *list, unsigned int first_i
} }
/*************************************************/ /*************************************************/
/* _hotlist_get_max_width */ /* hotlist_get_max_width_r */
/* */
/* Recursive back-end to hotlist_get_max_width. */
/* */
/* Parameters: Pointer to a hotlist_item struct */
/* to start at; */
/* */ /* */
/* This function does all the work for */ /* An indent in OS units, as for */
/* hotlist_get_max_width */ /* redrawing the hotlist; */
/* */
/* Pointer to an int, in which the */
/* width of the widest item so far */
/* is accumulated; */
/* */
/* Height of a hotlist item in OS */
/* units; */
/* */
/* Width of a hotlist directory */
/* sprite in OS units; */
/* */
/* Width of a hotlist URL sprite in */
/* OS units. */
/* */
/* Assumes: The pointer to the int may *not* */
/* be NULL. */
/*************************************************/ /*************************************************/
static void _hotlist_get_max_width(hotlist_item *list, unsigned int indent) static _kernel_oserror * hotlist_get_max_width_r(hotlist_item *list, unsigned int indent, int * max_width,
unsigned int item_height, unsigned int item_dir_width, unsigned int item_url_width)
{ {
unsigned int item_height, item_dir_width, item_url_width; _kernel_oserror * e;
unsigned int temp_width; unsigned int item_width;
int text_width; int text_width;
hotlist_get_entry_sizes(&item_height, &item_dir_width, &item_url_width); while (list)
while(list)
{ {
switch(list->type) /* Get width of the icon */
switch (list->type)
{ {
case hl_directory: case hl_directory: item_width = item_dir_width; break;
temp_width = item_dir_width; case hl_url: item_width = item_url_width; break;
break; default: item_width = 0; break;
}
case hl_url: /* Work out width of the text */
temp_width = item_url_width;
break;
default: if (list->type == hl_url && hl_show_urls) e = utils_text_width(list->data.url, &text_width, 0);
temp_width = 0; else e = utils_text_width(list->name, &text_width, 0);
break;
} if (e) return e;
if (list->type == hl_url && hl_show_urls) utils_text_width(list->data.url, &text_width, 0); /* Account for the indent and spacers (aesthetics) */
else utils_text_width(list->name, &text_width, 0);
temp_width += indent + 2 + text_width + 12; item_width += indent + 2 + text_width + 12;
if (temp_width > item_number) item_number = temp_width; /* If this is wider than so far recorded, store the new value */
if (item_width > *max_width) *max_width = item_width;
/* Recursive call for open directories */
if (list->type == hl_directory && list->flags & HOTLIST_D_IS_OPEN) if (list->type == hl_directory && list->flags & HOTLIST_D_IS_OPEN)
{ {
_hotlist_get_max_width(list->data.directory_content, indent + item_dir_width); RetError(hotlist_get_max_width_r(list->data.directory_content,
indent + item_dir_width,
max_width,
item_height,
item_dir_width,
item_url_width));
} }
/* Move on down the list */
list = list->next; list = list->next;
item_number++;
} }
return NULL;
} }
/*************************************************/ /*************************************************/
/* hotlist_get_max_width() */ /* hotlist_get_max_width() */
/* */ /* */
/* This function returns the maximum width of */ /* This function returns the maximum width of */
/* of the displayed hotlist entries */ /* of the displayed hotlist entries. */
/* */ /* */
/* Parameters: Pointer to a hotlist_item struct */
/* to start at. This is assumed to */
/* be at zero indent from the left */
/* hand side. */
/* */ /* */
/* Returns: Of all visible entries, the width */
/* of the widest, in OS units. */
/*************************************************/ /*************************************************/
static unsigned int hotlist_get_max_width(hotlist_item *list) static unsigned int hotlist_get_max_width(hotlist_item * list)
{ {
item_number = 0; unsigned int item_height, item_dir_width, item_url_width;
_hotlist_get_max_width(list, 0); int widest = 0;
return item_number;
/* Find basic item size information */
if (hotlist_get_entry_sizes(&item_height, &item_dir_width, &item_url_width)) return 0;
/* Scan the directory and all open directories with in it for */
/* the widest item */
if (hotlist_get_max_width_r(list,
0,
&widest,
item_height,
item_dir_width,
item_url_width)) return 0;
/* Return the result */
return widest;
} }
/*************************************************/ /*************************************************/
/* _hotlist_redraw_now() */
/* */
/* This function does the work for */
/* hotlist_redraw_now() */ /* hotlist_redraw_now() */
/* */
/* This function redraws all visible items with */
/* the HOTLIST_G_REDRAW_NOW bit set. */
/*************************************************/ /*************************************************/
static void _hotlist_redraw_now(hotlist_item *list) static void hotlist_redraw_now(void)
{ {
while(list) int curr_item = 0;
hotlist_redraw_now_r(hotlist_root->data.directory_content, &curr_item);
}
/*************************************************/
/* hotlist_redraw_now_r() */
/* */
/* Recursive back-end to hotlist_redraw_now. */
/* */
/* Parameters: Pointer to a hotlist_item struct */
/* to start on; */
/* */
/* Pointer to an int, in which the */
/* current item number being redrawn */
/* is accumulated. */
/* */
/* Assumes: The pointer to the int may *not* */
/* be NULL. */
/*************************************************/
static void hotlist_redraw_now_r(hotlist_item * list, int * curr_item)
{
while (list)
{ {
if (list->flags & HOTLIST_G_REDRAW_NOW) if (list->flags & HOTLIST_G_REDRAW_NOW)
{ {
hotlist_redraw_items(item_number, item_number); /* Redraw just the one item */
hotlist_redraw_items(*curr_item, *curr_item);
/* Clear the flag */
list->flags &= ~HOTLIST_G_REDRAW_NOW; list->flags &= ~HOTLIST_G_REDRAW_NOW;
} }
item_number++;
*curr_item += 1;
if (list->type == hl_directory && list->flags & HOTLIST_D_IS_OPEN) if (list->type == hl_directory && list->flags & HOTLIST_D_IS_OPEN)
{ {
_hotlist_redraw_now(list->data.directory_content); /* Recursive call for open directories */
hotlist_redraw_now_r(list->data.directory_content, curr_item);
} }
list = list->next; list = list->next;
} }
} }
/*************************************************/
/* hotlist_redraw_now() */
/* */
/* This function redraws all visible items with */
/* the HOTLIST_G_REDRAW_NOW bit set */
/*************************************************/
static void hotlist_redraw_now(void)
{
item_number = 0;
_hotlist_redraw_now(hotlist_root->data.directory_content);
}
/*************************************************/ /*************************************************/
/* hotlist_add() */ /* hotlist_add() */
/* */ /* */
...@@ -2432,10 +2506,6 @@ static _kernel_oserror * hotlist_save_entries(FILE * fileptr, hotlist_item * lis ...@@ -2432,10 +2506,6 @@ static _kernel_oserror * hotlist_save_entries(FILE * fileptr, hotlist_item * lis
int written; int written;
_kernel_oserror * e; _kernel_oserror * e;
/* Write the entry header */
//HotlistWrite(fprintf(fileptr, "<ul>\n"));
/* Follow the directory list */ /* Follow the directory list */
while (list) while (list)
...@@ -2461,9 +2531,17 @@ static _kernel_oserror * hotlist_save_entries(FILE * fileptr, hotlist_item * lis ...@@ -2461,9 +2531,17 @@ static _kernel_oserror * hotlist_save_entries(FILE * fileptr, hotlist_item * lis
{ {
HotlistWrite(fprintf(fileptr, "<h4>%s</h4>\n", list->name)); HotlistWrite(fprintf(fileptr, "<h4>%s</h4>\n", list->name));
/* Recursive call for the directory contents */ /* Recursive call for the directory contents. First, */
/* write the entry header. */
HotlistWrite(fprintf(fileptr, "<ul>\n")); HotlistWrite(fprintf(fileptr, "<ul>\n"));
/* Do the contents */
RetError(hotlist_save_entries(fileptr, list->data.directory_content, type)); RetError(hotlist_save_entries(fileptr, list->data.directory_content, type));
/* Write the entry footer */
HotlistWrite(fprintf(fileptr, "</ul>\n")); HotlistWrite(fprintf(fileptr, "</ul>\n"));
} }
} }
...@@ -2475,10 +2553,6 @@ static _kernel_oserror * hotlist_save_entries(FILE * fileptr, hotlist_item * lis ...@@ -2475,10 +2553,6 @@ static _kernel_oserror * hotlist_save_entries(FILE * fileptr, hotlist_item * lis
list = list->next; list = list->next;
} }
/* Write the entry footer */
//HotlistWrite(fprintf(fileptr, "</ul>\n"));
return NULL; return NULL;
} }
...@@ -2488,13 +2562,14 @@ static _kernel_oserror * hotlist_save_entries(FILE * fileptr, hotlist_item * lis ...@@ -2488,13 +2562,14 @@ static _kernel_oserror * hotlist_save_entries(FILE * fileptr, hotlist_item * lis
/* This function saves the hotlist as an HTML */ /* This function saves the hotlist as an HTML */
/* file. */ /* file. */
/* */ /* */
/* Parameters: Pointer to the filename to load */ /* Parameters: Pointer to the filename to save */
/* (null terminated). */ /* to (null terminated); */
/* */ /* */
/* 0 - save all of hotlist */ /* 0 to save all of hotlist, 1 to */
/* 1 - only save selection portions */ /* save only the selected portions. */
/*************************************************/ /*************************************************/
_kernel_oserror * hotlist_save_hotlist(char *filename, int type)
_kernel_oserror * hotlist_save_hotlist(char * filename, int type)
{ {
FILE * fileptr; FILE * fileptr;
_kernel_oserror * e; _kernel_oserror * e;
...@@ -2546,10 +2621,10 @@ _kernel_oserror * hotlist_save_hotlist(char *filename, int type) ...@@ -2546,10 +2621,10 @@ _kernel_oserror * hotlist_save_hotlist(char *filename, int type)
/* hotlist_save() */ /* hotlist_save() */
/* */ /* */
/* Veneer onto hotlist_save_hotlist - saves all */ /* Veneer onto hotlist_save_hotlist - saves all */
/* of the hotlist, created to preserve API */ /* of the hotlist, created to preserve API. */
/* */ /* */
/* Parameters: Pointer to the filename to load */ /* Parameters: Pointer to the filename to save */
/* (null terminated). */ /* under (null terminated). */
/*************************************************/ /*************************************************/
_kernel_oserror * hotlist_save(char * filename) _kernel_oserror * hotlist_save(char * filename)
......
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