From e387d5e34a2ae57b0f4d58bb16f844d9b923650e Mon Sep 17 00:00:00 2001 From: Richard Wilson Date: Thu, 8 Jul 2004 22:05:35 +0000 Subject: [PATCH] [project @ 2004-07-08 22:05:35 by rjw] Lose compiler warnings. Fix for dragging hotlist item to itself failing. Initial work on adding/editing entries. svn path=/import/netsurf/; revision=1061 --- !NetSurf/Resources/en/Templates,fec | Bin 7203 -> 7140 bytes !NetSurf/Resources/fr/Templates,fec | Bin 7282 -> 7219 bytes riscos/dialog.c | 5 +- riscos/gui.h | 5 +- riscos/hotlist.c | 126 +++++++++++++++++++++------- riscos/menus.c | 49 +++++++++-- riscos/wimp.c | 29 +++++++ riscos/wimp.h | 1 + 8 files changed, 173 insertions(+), 42 deletions(-) diff --git a/!NetSurf/Resources/en/Templates,fec b/!NetSurf/Resources/en/Templates,fec index 0f84a755fb1062b0fbba3cb1341b9c672db50d9a..6573fd60b30d63717b8fc6f4e88827c138fee135 100644 GIT binary patch delta 326 zcmZ2%@x*+?6h=v3Mg|5TV#rG^k5A1jDXQcx;Jqfrz`(b8E#n<=z9OL9A|Os;W?-me zn*3T=Zt_-18BP_T(0?FMn0!mpg6A^>yD3n>42T;h%SoB=0tHlo95oK`ua(R{&{SLk961K(YHk%nrl>K=B-)_!A(# l0V>Z1WOD*Bx=WmkQWHy36@Ve4kd~j5l3Ik_Da=4e0|2!aSatva delta 391 zcmaE2zSv^J6h_HvMg|5TV#rG^k5A1jDXQcx;AN3!V36Oumhp}_-wL2y1QP?p3}yxf z6XwaUh2R0*BrSM8GO#-W1^j`SZ?c?}2`^AU0?1JV2{25Kml9*m z2QtehS4m0Nn*v!jK+FNOG`uLYBrz!`RUtDuKaV${prk0i94M4(?Ol?{>s*wYSdz*c zWTs=xON2rNpbr!vK5$OVOHR$<4KfAl>;pR90%%nj$W+IemzOu7prk0iyeP9I)!Mrx5rgmV z%^PF}RM-b}lm*a$Iu-_o8$cQc;0`R7)?j+VFnO-DQ~fufs*wYSdyv$3_^vp{G623BJ8eZ H209l2LXTqI delta 422 zcmdmN@yTMt6h_HvMg|5TV#rG^k5A1jDXQcx;0=~$V36OumQhiGd*l zh+*JA5C}0Sv`qdXslgcsQ~(kXoUAEj!Sj)U-4Q6@55#6vdYVg;K4(OA>jVi&7Iy zQh9^Sbc}h4P^bX(j{?L$&WU-+sX4qsra+z3n1OBpTGz(Pz_1QT3t;%iRa%3ImvM5w zv{U^PpyVeY<^$pjKwJX!q6<*d3LtH3$RN%LayJmO1LXpMbPiDb36S0ZmA?TLzYoM9 PzY*_zxN9e~%ZLB~IZt%W diff --git a/riscos/dialog.c b/riscos/dialog.c index 7e7c96c8b..208850c0d 100644 --- a/riscos/dialog.c +++ b/riscos/dialog.c @@ -36,7 +36,8 @@ wimp_w dialog_info, dialog_saveas, dialog_config, dialog_config_br, dialog_401li, #endif dialog_zoom, dialog_pageinfo, dialog_objinfo, dialog_tooltip, - dialog_warning, dialog_config_th_pane, dialog_debug; + dialog_warning, dialog_config_th_pane, dialog_debug, + dialog_folder, dialog_entry; static int font_size; static int font_min_size; @@ -90,6 +91,8 @@ void ro_gui_dialog_init(void) dialog_tooltip = ro_gui_dialog_create("tooltip"); dialog_warning = ro_gui_dialog_create("warning"); dialog_debug = ro_gui_dialog_create("debug"); + dialog_folder = ro_gui_dialog_create("new_folder"); + dialog_entry = ro_gui_dialog_create("new_entry"); set_browser_choices(); set_proxy_choices(); diff --git a/riscos/gui.h b/riscos/gui.h index 7bace115c..ae8ae8ef2 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -24,7 +24,7 @@ extern wimp_w dialog_info, dialog_saveas, dialog_config, dialog_config_br, dialog_config_prox, dialog_config_th, dialog_zoom, dialog_pageinfo, dialog_objinfo, dialog_tooltip, dialog_warning, dialog_config_th_pane, - dialog_debug; + dialog_debug, dialog_folder, dialog_entry; extern wimp_w history_window; extern wimp_w hotlist_window; extern wimp_menu *iconbar_menu, *browser_menu, *combo_menu, *hotlist_menu; @@ -38,6 +38,7 @@ extern gui_window *current_gui; extern gui_window *ro_gui_current_redraw_gui; extern osspriteop_area *gui_sprites; extern struct toolbar *hotlist_toolbar; +extern bool dialog_folder_add, dialog_entry_add, hotlist_insert; typedef enum { GUI_BROWSER_WINDOW } gui_window_type; typedef enum { GUI_SAVE_SOURCE, GUI_SAVE_DRAW, GUI_SAVE_TEXT, @@ -198,6 +199,8 @@ void ro_gui_hotlist_set_selected(bool selected); void ro_gui_hotlist_set_expanded(bool expand, bool folders, bool links); void ro_gui_hotlist_delete_selected(void); void ro_gui_hotlist_save_as(const char *file); +void ro_gui_hotlist_prepare_folder_dialog(bool selected); +void ro_gui_hotlist_prepare_entry_dialog(bool selected); /* in save.c */ void ro_gui_save_click(wimp_pointer *pointer); diff --git a/riscos/hotlist.c b/riscos/hotlist.c index 6d5374991..f703fe1cd 100644 --- a/riscos/hotlist.c +++ b/riscos/hotlist.c @@ -193,10 +193,19 @@ wimp_mouse_state drag_buttons; bool menu_selection = false; bool menu_open = false; +/* Whether the editing facilities are for add so that we know how + to reset the dialog boxes on a adjust-cancel and the action to + perform on ok. +*/ +bool dialog_folder_add = false; +bool dialog_entry_add = false; +bool hotlist_insert = false; + /* Hotlist loading buffer */ char *load_buf; +static bool ro_gui_hotlist_initialise_sprite(const char *name, int number); static bool ro_gui_hotlist_load(void); static bool ro_gui_hotlist_save_entry(FILE *fp, struct hotlist_entry *entry); static bool ro_gui_hotlist_load_entry(FILE *fp, struct hotlist_entry *entry); @@ -242,37 +251,16 @@ void ro_gui_hotlist_init(void) { return; } - /* Get our sprite ids for faster plotting. This could be done in a - far more elegant manner, but it's late and my girlfriend will - kill me if I don't go to bed soon. Sorry. + /* Get our sprite ids for faster plotting. */ - error = xosspriteop_select_sprite(osspriteop_USER_AREA, gui_sprites, - (osspriteop_id)"tr_expand", - (osspriteop_header **)&sprite[HOTLIST_EXPAND]); - if (!error) - error = xosspriteop_select_sprite(osspriteop_USER_AREA, gui_sprites, - (osspriteop_id)"tr_collapse", - (osspriteop_header **)&sprite[HOTLIST_COLLAPSE]); - if (!error) - error = xosspriteop_select_sprite(osspriteop_USER_AREA, gui_sprites, - (osspriteop_id)"tr_entry", - (osspriteop_header **)&sprite[HOTLIST_ENTRY]); - if (!error) - error = xosspriteop_select_sprite(osspriteop_USER_AREA, gui_sprites, - (osspriteop_id)"tr_line", - (osspriteop_header **)&sprite[HOTLIST_LINE]); - if (!error) - error = xosspriteop_select_sprite(osspriteop_USER_AREA, gui_sprites, - (osspriteop_id)"tr_halflinet", - (osspriteop_header **)&sprite[HOTLIST_TLINE]); - if (!error) - error = xosspriteop_select_sprite(osspriteop_USER_AREA, gui_sprites, - (osspriteop_id)"tr_halflineb", - (osspriteop_header **)&sprite[HOTLIST_BLINE]); - if (error) { - warn_user("MiscError", error->errmess); + if (ro_gui_hotlist_initialise_sprite("expand", HOTLIST_EXPAND) || + ro_gui_hotlist_initialise_sprite("collapse", HOTLIST_COLLAPSE) || + ro_gui_hotlist_initialise_sprite("entry", HOTLIST_ENTRY) || + ro_gui_hotlist_initialise_sprite("line", HOTLIST_LINE) || + ro_gui_hotlist_initialise_sprite("halflinet", HOTLIST_TLINE) || + ro_gui_hotlist_initialise_sprite("halflineb", HOTLIST_BLINE)) { return; - } + } /* Update our text icon */ @@ -308,6 +296,27 @@ void ro_gui_hotlist_init(void) { } } +/** + * Initialise a hotlist sprite + * + * \param name the name of the sprite + * \param number the sprite cache number + * \return whether an error occurred + */ +bool ro_gui_hotlist_initialise_sprite(const char *name, int number) { + os_error *error; + sprintf(icon_name, "tr_%s", name); + error = xosspriteop_select_sprite(osspriteop_USER_AREA, gui_sprites, + (osspriteop_id)icon_name, + (osspriteop_header **)&sprite[number]); + if (error) { + warn_user("MiscError", error->errmess); + LOG(("Failed to load hotlist sprite 'tr_%s'", name)); + return true; + } + return false; +} + /** * Shows the hotlist window. @@ -374,6 +383,7 @@ void ro_gui_hotlist_show(void) { -100, 32, -1); } + bool ro_gui_hotlist_load(void) { FILE *fp; fileswitch_object_type obj_type = 0; @@ -824,7 +834,7 @@ struct hotlist_entry *ro_gui_hotlist_create(const char *title, const char *url, void ro_gui_hotlist_link_entry(struct hotlist_entry *link, struct hotlist_entry *entry, bool before) { struct hotlist_entry *link_entry; - if (!link || !entry) return; + if ((!link || !entry) || (link == entry)) return; /* Check if the parent is a folder or an entry */ @@ -2083,7 +2093,6 @@ void ro_gui_hotlist_move_drag_end(wimp_dragged *drag) { /* No parent of the destination can be processed */ test_entry = entry; - if (entry->children == -1) test_entry = entry->parent_entry; while (test_entry != NULL) { if (test_entry->process) return; test_entry = test_entry->parent_entry; @@ -2222,6 +2231,16 @@ void ro_gui_hotlist_toolbar_click(wimp_pointer* pointer) { /* Handle the buttons appropriately */ switch (pointer->i) { + case ICON_TOOLBAR_CREATE: + hotlist_insert = false; + if (pointer->buttons == wimp_CLICK_SELECT) { + ro_gui_hotlist_prepare_folder_dialog(false); + ro_gui_dialog_open_persistant(hotlist_window, dialog_folder); + } else { + ro_gui_hotlist_prepare_entry_dialog(false); + ro_gui_dialog_open_persistant(hotlist_window, dialog_entry); + } + break; case ICON_TOOLBAR_OPEN: selection = ro_gui_hotlist_get_selected(true); ro_gui_hotlist_update_expansion(root.child_entry, (selection != 0), true, false, @@ -2244,6 +2263,51 @@ void ro_gui_hotlist_toolbar_click(wimp_pointer* pointer) { } +void ro_gui_hotlist_prepare_folder_dialog(bool selected) { + struct hotlist_entry *entry = NULL; + if (selected) entry = ro_gui_hotlist_first_selection(root.child_entry); + + /* Update the title + */ + dialog_folder_add = selected; + if (selected) { + ro_gui_set_window_title(dialog_folder, messages_get("EditFolder")); + } else { + ro_gui_set_window_title(dialog_folder, messages_get("NewFolder")); + } + + /* Update the icons + */ + if (entry == NULL) { + ro_gui_set_icon_string(dialog_folder, 1, messages_get("Folder")); + } else { + ro_gui_set_icon_string(dialog_folder, 1, entry->title); + } +} + +void ro_gui_hotlist_prepare_entry_dialog(bool selected) { + struct hotlist_entry *entry = NULL; + if (selected) entry = ro_gui_hotlist_first_selection(root.child_entry); + + /* Update the title + */ + dialog_entry_add = selected; + if (selected) { + ro_gui_set_window_title(dialog_entry, messages_get("EditLink")); + } else { + ro_gui_set_window_title(dialog_entry, messages_get("NewLink")); + } + + /* Update the icons + */ + if (entry == NULL) { + ro_gui_set_icon_string(dialog_entry, 1, messages_get("Link")); + ro_gui_set_icon_string(dialog_entry, 3, ""); + } else { + ro_gui_set_icon_string(dialog_entry, 1, entry->title); + ro_gui_set_icon_string(dialog_entry, 3, entry->url); + } +} /** diff --git a/riscos/menus.c b/riscos/menus.c index eeb02e913..668e09182 100644 --- a/riscos/menus.c +++ b/riscos/menus.c @@ -280,8 +280,8 @@ wimp_menu *browser_menu = (wimp_menu *) &menu; static wimp_MENU(2) hotlist_new = { { "New" }, 7,2,7,0, 300, 44, 0, { - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Folder" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Link" } }, + { wimp_MENU_GIVE_WARNING, (wimp_menu *)1, DEFAULT_FLAGS, { "Folder" } }, + { wimp_MENU_LAST | wimp_MENU_GIVE_WARNING, (wimp_menu *)1, DEFAULT_FLAGS, { "Link" } }, } }; @@ -324,7 +324,7 @@ static wimp_MENU(4) hotlist_save = { static wimp_MENU(5) hotlist_file = { { "Hotlist" }, 7,2,7,0, 300, 44, 0, { - { wimp_MENU_GIVE_WARNING, (wimp_menu *)&hotlist_new, DEFAULT_FLAGS, { "New" } }, + { 0, (wimp_menu *)&hotlist_new, DEFAULT_FLAGS, { "New" } }, { wimp_MENU_GIVE_WARNING, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Save" } }, { wimp_MENU_GIVE_WARNING | wimp_MENU_SEPARATE, (wimp_menu *)1, DEFAULT_FLAGS, { "Export" } }, { 0, (wimp_menu *)&hotlist_expand, DEFAULT_FLAGS, { "Expand" } }, @@ -977,6 +977,18 @@ void ro_gui_menu_hotlist_warning(wimp_message_menu_warning *warning) { case 0: /* Hotlist-> */ switch (warning->selection.items[1]) { case 0: /* New-> */ + hotlist_insert = true; + switch (warning->selection.items[2]) { + case 0: /* Folder */ + ro_gui_hotlist_prepare_folder_dialog(false); + error = xwimp_create_sub_menu((wimp_menu *) dialog_folder, + warning->pos.x, warning->pos.y); + break; + case 1: /* Entry */ + ro_gui_hotlist_prepare_entry_dialog(false); + error = xwimp_create_sub_menu((wimp_menu *) dialog_entry, + warning->pos.x, warning->pos.y); + } break; case 2: /* Export-> */ gui_current_save_type = GUI_HOTLIST_EXPORT_HTML; @@ -995,7 +1007,17 @@ void ro_gui_menu_hotlist_warning(wimp_message_menu_warning *warning) { break; case 0: /* Save-> */ break; - case 1: /* Edit title-> */ + case 1: /* Edit-> */ + hotlist_insert = true; + if (ro_gui_hotlist_get_selected(false) == 0) { + ro_gui_hotlist_prepare_folder_dialog(true); + error = xwimp_create_sub_menu((wimp_menu *) dialog_folder, + warning->pos.x, warning->pos.y); + } else { + ro_gui_hotlist_prepare_entry_dialog(true); + error = xwimp_create_sub_menu((wimp_menu *) dialog_entry, + warning->pos.x, warning->pos.y); + } break; } break; @@ -1305,24 +1327,33 @@ void ro_gui_menu_prepare_scale(void) { */ void ro_gui_menu_prepare_hotlist(void) { int selection; + int selection_full; selection = ro_gui_hotlist_get_selected(false); - if (selection == 0) { + selection_full = ro_gui_hotlist_get_selected(true); + + if (selection_full == 0) { hotlist_menu->entries[1].icon_flags |= wimp_ICON_SHADED; hotlist_menu->entries[3].icon_flags |= wimp_ICON_SHADED; - hotlist_select_menu->entries[2].icon_flags |= wimp_ICON_SHADED; - hotlist_select_menu->entries[4].icon_flags |= wimp_ICON_SHADED; } else { hotlist_menu->entries[1].icon_flags &= ~wimp_ICON_SHADED; hotlist_menu->entries[3].icon_flags &= ~wimp_ICON_SHADED; + } + if (selection == 0) { + hotlist_select_menu->entries[2].icon_flags |= wimp_ICON_SHADED; + hotlist_select_menu->entries[4].icon_flags |= wimp_ICON_SHADED; + } else { hotlist_select_menu->entries[2].icon_flags &= ~wimp_ICON_SHADED; hotlist_select_menu->entries[4].icon_flags &= ~wimp_ICON_SHADED; } - if (selection != 1) { + if (selection_full != 1) { hotlist_select_menu->entries[1].icon_flags |= wimp_ICON_SHADED; + } else { + hotlist_select_menu->entries[1].icon_flags &= ~wimp_ICON_SHADED; + } + if (selection != 1) { hotlist_save_menu->entries[0].icon_flags |= wimp_ICON_SHADED; hotlist_save_menu->entries[1].icon_flags |= wimp_ICON_SHADED; } else { - hotlist_select_menu->entries[1].icon_flags &= ~wimp_ICON_SHADED; hotlist_save_menu->entries[0].icon_flags &= ~wimp_ICON_SHADED; hotlist_save_menu->entries[1].icon_flags &= ~wimp_ICON_SHADED; } diff --git a/riscos/wimp.c b/riscos/wimp.c index ce07237d6..3a6ee3fd4 100644 --- a/riscos/wimp.c +++ b/riscos/wimp.c @@ -239,6 +239,35 @@ int ro_gui_get_icon_selected_state(wimp_w w, wimp_i i) { #define ro_gui_set_icon_shaded_state(w, i, state) xwimp_set_icon_state(w, i, (state ? wimp_ICON_SHADED : 0), wimp_ICON_SHADED) +/** + * Set a window title (does *not* redraw the title) + * + * \param w window handle + * \param text new title (copied) + */ +void ro_gui_set_window_title(wimp_w w, const char *text) { + wimp_window_info_base window; + os_error *error; + + /* Get the window details + */ + window.w = w; + error = xwimp_get_window_info_header_only((wimp_window_info *)&window); + if (error) { + LOG(("xwimp_get_window_info: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + return; + } + + /* Set the title string + */ + strncpy(window.title_data.indirected_text.text, text, + (unsigned int)window.title_data.indirected_text.size - 1); + window.title_data.indirected_text.text[window.title_data.indirected_text.size - 1] = '\0'; +} + + /** * Load a sprite file into memory. * diff --git a/riscos/wimp.h b/riscos/wimp.h index f759e0487..763f00631 100644 --- a/riscos/wimp.h +++ b/riscos/wimp.h @@ -39,6 +39,7 @@ void ro_gui_set_icon_integer(wimp_w w, wimp_i i, int value); #define ro_gui_set_icon_selected_state(w, i, state) xwimp_set_icon_state(w, i, (state ? wimp_ICON_SELECTED : 0), wimp_ICON_SELECTED) int ro_gui_get_icon_selected_state(wimp_w w, wimp_i i); #define ro_gui_set_icon_shaded_state(w, i, state) xwimp_set_icon_state(w, i, (state ? wimp_ICON_SHADED : 0), wimp_ICON_SHADED) +void ro_gui_set_window_title(wimp_w w, const char *title); osspriteop_area *ro_gui_load_sprite_file(const char *pathname);