From 6864b4e42a797256a6267ca16c7beef4817de197 Mon Sep 17 00:00:00 2001 From: Andrew Hodgkinson <ahodgkin@gitlab.riscosopen.org> Date: Mon, 1 Sep 1997 11:52:05 +0000 Subject: [PATCH] A bit more tidying up --- c/Hotlist | 227 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 151 insertions(+), 76 deletions(-) diff --git a/c/Hotlist b/c/Hotlist index 9e201f8..bc3ea73 100644 --- a/c/Hotlist +++ b/c/Hotlist @@ -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 */ /* 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 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 */ @@ -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 unsigned int hotlist_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 _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_directory_open_close (hotlist_item * item, unsigned int itemno); 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 /* Set the URL width to the value found above and add 8 to */ /* 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_height) *item_height += 8; @@ -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 */ -/* hotlist_get_max_width */ +/* An indent in OS units, as for */ +/* 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; - unsigned int temp_width; - int text_width; + _kernel_oserror * e; + unsigned int item_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: - temp_width = item_dir_width; - break; + case hl_directory: item_width = item_dir_width; break; + case hl_url: item_width = item_url_width; break; + default: item_width = 0; break; + } - case hl_url: - temp_width = item_url_width; - break; + /* Work out width of the text */ - default: - temp_width = 0; - break; - } + if (list->type == hl_url && hl_show_urls) e = utils_text_width(list->data.url, &text_width, 0); + else e = utils_text_width(list->name, &text_width, 0); + + if (e) return e; - if (list->type == hl_url && hl_show_urls) utils_text_width(list->data.url, &text_width, 0); - else utils_text_width(list->name, &text_width, 0); + /* Account for the indent and spacers (aesthetics) */ - 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) { - _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; - item_number++; } + + return NULL; } /*************************************************/ /* hotlist_get_max_width() */ /* */ /* 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; - _hotlist_get_max_width(list, 0); - return item_number; + unsigned int item_height, item_dir_width, item_url_width; + int widest = 0; + + /* 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() */ +/* */ +/* 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) { - 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; } - item_number++; + + *curr_item += 1; + 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; } } -/*************************************************/ -/* 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() */ /* */ @@ -2432,10 +2506,6 @@ static _kernel_oserror * hotlist_save_entries(FILE * fileptr, hotlist_item * lis int written; _kernel_oserror * e; - /* Write the entry header */ - - //HotlistWrite(fprintf(fileptr, "<ul>\n")); - /* Follow the directory list */ while (list) @@ -2461,9 +2531,17 @@ static _kernel_oserror * hotlist_save_entries(FILE * fileptr, hotlist_item * lis { 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")); + + /* Do the contents */ + RetError(hotlist_save_entries(fileptr, list->data.directory_content, type)); + + /* Write the entry footer */ + HotlistWrite(fprintf(fileptr, "</ul>\n")); } } @@ -2475,10 +2553,6 @@ static _kernel_oserror * hotlist_save_entries(FILE * fileptr, hotlist_item * lis list = list->next; } - /* Write the entry footer */ - - //HotlistWrite(fprintf(fileptr, "</ul>\n")); - return NULL; } @@ -2488,13 +2562,14 @@ static _kernel_oserror * hotlist_save_entries(FILE * fileptr, hotlist_item * lis /* This function saves the hotlist as an HTML */ /* file. */ /* */ -/* Parameters: Pointer to the filename to load */ -/* (null terminated). */ +/* Parameters: Pointer to the filename to save */ +/* to (null terminated); */ /* */ -/* 0 - save all of hotlist */ -/* 1 - only save selection portions */ +/* 0 to save all of hotlist, 1 to */ +/* 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; _kernel_oserror * e; @@ -2546,10 +2621,10 @@ _kernel_oserror * hotlist_save_hotlist(char *filename, int type) /* hotlist_save() */ /* */ /* 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 */ -/* (null terminated). */ +/* Parameters: Pointer to the filename to save */ +/* under (null terminated). */ /*************************************************/ _kernel_oserror * hotlist_save(char * filename) -- GitLab