From 6173bb0e6c3bf51cd463f7bc4f725429d9087b2b Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Tue, 5 Oct 2010 19:14:46 +0000 Subject: [PATCH] Merge treeview-redux to trunk svn path=/trunk/netsurf/; revision=10865 --- !NetSurf/Resources/Icons/content.png | Bin 0 -> 685 bytes !NetSurf/Resources/Icons/directory.png | Bin 0 -> 259 bytes !NetSurf/Resources/de/Messages | 10 + !NetSurf/Resources/en/Messages | 33 +- !NetSurf/Resources/fr/Messages | 10 + !NetSurf/Resources/it/Messages | 10 + !NetSurf/Resources/nl/Messages | 10 + Makefile.sources | 27 +- amiga/cookies.c | 149 +- amiga/cookies.h | 5 +- amiga/gui.c | 89 +- amiga/gui.h | 12 +- amiga/history.c | 357 +- amiga/history.h | 3 +- amiga/hotlist.c | 138 +- amiga/hotlist.h | 9 +- amiga/menu.c | 478 +-- amiga/menu.h | 15 +- amiga/object.c | 14 +- amiga/object.h | 1 + amiga/options.h | 3 - amiga/plotters.c | 20 +- amiga/resources/Themes/AISS/Theme | 8 +- amiga/resources/Themes/Default/Theme | 8 +- amiga/resources/Themes/Default/content.png | 1 + amiga/resources/Themes/Default/directory.png | 1 + amiga/sslcert.c | 216 +- windows/hotlist.c => amiga/sslcert.h | 12 +- amiga/theme.c | 17 +- amiga/theme.h | 2 +- amiga/tree.c | 1411 +++++--- amiga/tree.h | 29 +- beos/beos_bitmap.cpp | 10 + beos/beos_gui.cpp | 7 - beos/beos_history.cpp | 183 - beos/beos_scaffolding.cpp | 1 - beos/beos_treeview.cpp | 146 +- content/urldb.c | 64 +- content/urldb.h | 3 +- desktop/browser.c | 1 + desktop/cookies.c | 531 +++ desktop/cookies.h | 36 +- desktop/history_global_core.c | 464 +++ desktop/history_global_core.h | 44 + desktop/hotlist.c | 457 +++ desktop/hotlist.h | 54 + desktop/options.c | 363 +- desktop/options.h | 5 +- desktop/sslcert.c | 276 ++ desktop/sslcert.h | 43 + desktop/tree.c | 3404 ++++++++++++------ desktop/tree.h | 281 +- desktop/tree_url_node.c | 846 +++++ desktop/tree_url_node.h | 56 + framebuffer/misc.c | 6 - framebuffer/tree.c | 83 +- gtk/gtk_cookies.c | 213 ++ framebuffer/hotlist.c => gtk/gtk_cookies.h | 20 +- gtk/gtk_gui.c | 149 +- gtk/gtk_history.c | 779 ++-- gtk/gtk_history.h | 18 +- gtk/gtk_hotlist.c | 277 ++ framebuffer/history.c => gtk/gtk_hotlist.h | 30 +- gtk/gtk_menu.c | 3 + gtk/gtk_menu.h | 1 + gtk/gtk_plotters.c | 14 +- gtk/gtk_scaffolding.c | 33 +- gtk/gtk_scaffolding.h | 2 + gtk/gtk_theme.c | 2 + gtk/gtk_toolbar.c | 2 + gtk/gtk_toolbar.h | 1 + gtk/gtk_treeview.c | 587 ++- gtk/gtk_treeview.h | 50 + gtk/gtk_window.c | 2 +- gtk/options.h | 3 + gtk/res/cookies.glade | 174 + gtk/res/history.glade | 372 +- gtk/res/hotlist.glade | 218 ++ gtk/res/icons | 1 + gtk/res/ssl.glade | 19 +- riscos/configure/con_home.c | 6 +- riscos/cookies.c | 366 +- riscos/cookies.h | 10 +- riscos/dialog.c | 74 +- riscos/global_history.c | 540 ++- riscos/global_history.h | 12 +- riscos/gui.c | 81 +- riscos/gui.h | 17 +- riscos/help.c | 28 +- riscos/hotlist.c | 560 ++- beos/beos_history.h => riscos/hotlist.h | 28 +- riscos/menus.c | 678 ++-- riscos/menus.h | 20 + riscos/save.c | 14 +- riscos/sslcert.c | 555 ++- riscos/sslcert.h | 32 + riscos/textselection.c | 25 +- riscos/theme.c | 28 +- riscos/treeview.c | 2236 +++++------- riscos/treeview.h | 49 +- riscos/url_complete.c | 6 +- riscos/url_suggest.c | 200 + windows/history.c => riscos/url_suggest.h | 29 +- riscos/wimp_event.c | 205 +- riscos/wimp_event.h | 22 +- riscos/window.c | 78 +- utils/messages.c | 31 + utils/messages.h | 12 + windows/tree.c | 83 +- 109 files changed, 11511 insertions(+), 7946 deletions(-) create mode 100644 !NetSurf/Resources/Icons/content.png create mode 100644 !NetSurf/Resources/Icons/directory.png create mode 120000 amiga/resources/Themes/Default/content.png create mode 120000 amiga/resources/Themes/Default/directory.png rename windows/hotlist.c => amiga/sslcert.h (76%) delete mode 100644 beos/beos_history.cpp create mode 100644 desktop/cookies.c create mode 100644 desktop/history_global_core.c create mode 100644 desktop/history_global_core.h create mode 100644 desktop/hotlist.c create mode 100644 desktop/hotlist.h create mode 100644 desktop/sslcert.c create mode 100644 desktop/sslcert.h create mode 100644 desktop/tree_url_node.c create mode 100644 desktop/tree_url_node.h create mode 100644 gtk/gtk_cookies.c rename framebuffer/hotlist.c => gtk/gtk_cookies.h (68%) create mode 100644 gtk/gtk_hotlist.c rename framebuffer/history.c => gtk/gtk_hotlist.h (65%) create mode 100644 gtk/gtk_treeview.h create mode 100644 gtk/res/cookies.glade create mode 100644 gtk/res/hotlist.glade create mode 120000 gtk/res/icons rename beos/beos_history.h => riscos/hotlist.h (57%) create mode 100644 riscos/sslcert.h create mode 100644 riscos/url_suggest.c rename windows/history.c => riscos/url_suggest.h (65%) diff --git a/!NetSurf/Resources/Icons/content.png b/!NetSurf/Resources/Icons/content.png new file mode 100644 index 0000000000000000000000000000000000000000..53234c38cc07816790756e731818b96ad72974e9 GIT binary patch literal 685 zcmV;e0#f~nP)t>_AB&KJoZaSi&wE1!E0~v;z6h(1_TcZTAO&N)D7!8$?G9*h%vSghIzxA`OW{$ zdqd2OPTSqxy>E<}6hizwJw5#~H8pjPe;9Rx?CtG+?d$8C2Y}1VOBiDUDdlftOqH3> zEz9~9MbV!qiVFFB{)^QK*xK64WV6}lL$=%%a*4Y7LI@22qJtr{)-Q+%LI~K!B6^mWK}3+%Dy+jp#4#a63wTY*_V)I)@B0sh zXtLGD25@yi&&`3;X@qNQ?W!6#AjxF%oo(Af?(BfV5Yf_7Qyvj6R#t$k+hYYpq_05= zg~Gkj(b1%oxTn=Vo0X#MaIz9$fDgZOg;v&d(K|~S&z|3G~luD(~K@f1Q zR^wW&#uuxr+!!2W23n&rJj@rxB8OqfVHonk!NGTCZYn92O3L%RXYpGA0ME=Inx2MO zUk61I*!RH`6M*MIT%}X5*AuOD!Z3W}`~HLWd;x%z0%m6sx1;DNH4!;2NGg?jrIZr? z>x(XZ(wsLpH}mOq`f*(Qxc=>a``Q@O@&OP4SX%2(Qp!7R5^q%j07pkhNF)+qW<*hx z0RZdl>}>wz=;j2yTURv;F=3C-r*$b#HHPFfcIiu|4(|F52S3 TdOCIr00000NkvXXu0mjfr?NVK literal 0 HcmV?d00001 diff --git a/!NetSurf/Resources/Icons/directory.png b/!NetSurf/Resources/Icons/directory.png new file mode 100644 index 0000000000000000000000000000000000000000..de3d7687fa0d0c9c8d8b4e0b4c3f33c7dc114b6b GIT binary patch literal 259 zcmeAS@N?(olHy`uVBq!ia0vp^f*{Pn1|+R>-G2cowj^(N7lxZ)`0>yTpvVqS7sn8b z)5(AS|F>se+R)j^)zI45*r;f>er3zVXf3wcP5FJHV zsy!{x*pYvA*ZcMVH~ya;b^O4AfacQz$7b|&MfNyJt>nq6v6%b&|J$qjJ@s{YDJdy` zniY?q*wWTI(Rsq$Kx4V}^ChP;S4v1oEZTT#?%SWIkDNI0B|YHCxfP0AyuSVa|35k9 z&%d@D=70bHA3t&E$J4hx_0Oxh gtkAddBookMarks:_Add to Bookmarks… gtkShowBookMarks:_Show Bookmarks… gtkShowBookMarksAccel:F6 +gtkShowCookies:Show _Cookies… +gtkShowCookiesAccel:F9 gtkOpenLocation:_Open Location… gtkOpenLocationAccel:l @@ -607,15 +620,15 @@ Cancel:Cancel # SSLCerts:SSL certificates SSLError:NetSurf failed to verify the authenticity of an SSL certificate. Please verify the details presented below. -Subject:Subject -Issuer:Issuer -Version:Version -ValidFrom:Valid from -ValidTo:Valid until -Type:Type -Serial:Serial -Accept:Accept -Reject:Reject +SSL_Certificate_Subject:Subject: %s +SSL_Certificate_Issuer:Issuer: %s +SSL_Certificate_Version:Version: %ld +SSL_Certificate_ValidFrom:Valid from: %s +SSL_Certificate_ValidTo:Valid until: %s +SSL_Certificate_Type:Type: %i +SSL_Certificate_Serial:Serial: %ld +SSL_Certificate_Accept:Accept +SSL_Certificate_Reject:Reject # Content @@ -723,7 +736,7 @@ Resolvers:No domain name servers are configured, so only browsing local files wi NoDiscSpace:Not enough space available on disc. Template:A window template is missing from the Templates file. Please reinstall NetSurf. HotlistSaveError:The hotlist was unable to be correctly saved. -HotlistLoadError:The hotlist was unable to be correctly loaded. +TreeLoadError:The tree was unable to be correctly loaded. NoDirError:%s is not a directory NoPathError:To save, drag the icon to a directory display NoNameError:Please enter a name diff --git a/!NetSurf/Resources/fr/Messages b/!NetSurf/Resources/fr/Messages index bfe563d90..c16d0f09a 100644 --- a/!NetSurf/Resources/fr/Messages +++ b/!NetSurf/Resources/fr/Messages @@ -189,6 +189,8 @@ ResetUsage:RAZ des statistiques New:Nouveau Expand:Déployer Collapse:Regrouper +Tree:Tree +TreeExport:Export... # New hotlist entry menu # @@ -200,6 +202,7 @@ Link:Adresse All:Tout Folders:Dossiers Links:Adresses +Domains:Domains # Other menus # @@ -373,6 +376,13 @@ DateYesterday:Hier Date1Week:La semaine dernière Date2Week:Il y a 2 semaines Date3Week:Il y a 3 semaines +Sunday:Sunday +Monday:Monday +Tuesday:Tuesday +Wednesday:Wednesday +Thursday:Thursday +Friday:Friday +Saturday:Saturday # Download user interface tokens diff --git a/!NetSurf/Resources/it/Messages b/!NetSurf/Resources/it/Messages index e79ce93a5..7d4e834de 100755 --- a/!NetSurf/Resources/it/Messages +++ b/!NetSurf/Resources/it/Messages @@ -191,6 +191,8 @@ ResetUsage:Resetta statistiche New:Nuovo Expand:Espandi Collapse:Raggruppa +Tree:Tree +TreeExport:Export... # New hotlist entry menu # @@ -202,6 +204,7 @@ Link:Indirizzo All:Tutte Folders:Cartelle Links:Indirizzi +Domains:Domains # Other menus # @@ -375,6 +378,13 @@ DateYesterday:Ieri Date1Week:Ultima settimana Date2Week:2 settimane fa Date3Week:3 settimane fa +Sunday:Sunday +Monday:Monday +Tuesday:Tuesday +Wednesday:Wednesday +Thursday:Thursday +Friday:Friday +Saturday:Saturday # Download user interface tokens diff --git a/!NetSurf/Resources/nl/Messages b/!NetSurf/Resources/nl/Messages index 2c1b3fa9b..f837f7dbd 100644 --- a/!NetSurf/Resources/nl/Messages +++ b/!NetSurf/Resources/nl/Messages @@ -189,6 +189,8 @@ ResetUsage:Statistiek op nul zetten New:Nieuw Expand:Uitklappen Collapse:Inklappen +Tree:Tree +TreeExport:Export... # New hotlist entry menu # @@ -200,6 +202,7 @@ Link:Adres All:Alles Folders:Mappen Links:Adressen +Domains:Domains # Other menus # @@ -373,6 +376,13 @@ DateYesterday:gisteren Date1Week:vorige week Date2Week:2 weken geleden Date3Week:3 weken geleden +Sunday:Sunday +Monday:Monday +Tuesday:Tuesday +Wednesday:Wednesday +Thursday:Thursday +Friday:Friday +Saturday:Saturday # Download user interface tokens diff --git a/Makefile.sources b/Makefile.sources index 57166df51..2239cc7cd 100644 --- a/Makefile.sources +++ b/Makefile.sources @@ -13,8 +13,9 @@ S_RENDER := box.c box_construct.c box_normalise.c favicon.c \ hubbub_binding.c imagemap.c layout.c list.c table.c textplain.c S_UTILS := base64.c filename.c hashtable.c http.c locale.c messages.c \ talloc.c url.c utf8.c utils.c useragent.c findresource.c -S_DESKTOP := knockout.c options.c plot_style.c print.c search.c \ - searchweb.c scroll.c textarea.c tree.c version.c +S_DESKTOP := cookies.c history_global_core.c hotlist.c knockout.c \ + options.c plot_style.c print.c search.c searchweb.c scroll.c \ + sslcert.c textarea.c tree.c tree_url_node.c version.c \ # S_COMMON are sources common to all builds S_COMMON := $(addprefix content/,$(S_CONTENT)) \ @@ -47,7 +48,7 @@ S_RISCOS := 401login.c artworks.c assert.c awrender.s bitmap.c buffer.c \ schedule.c search.c searchweb.c sprite.c sslcert.c \ textarea.c textselection.c theme.c theme_install.c thumbnail.c \ treeview.c ucstables.c uri.c url_complete.c url_protocol.c \ - wimp.c wimp_event.c window.c gui/progress_bar.c \ + url_suggest.c wimp.c wimp_event.c window.c gui/progress_bar.c \ gui/status_bar.c \ $(addprefix configure/,con_cache.c con_connect.c con_content.c \ con_fonts.c con_home.c con_image.c con_inter.c con_language.c \ @@ -62,22 +63,22 @@ S_GTK := font_pango.c gtk_bitmap.c gtk_gui.c gtk_schedule.c \ gtk_completion.c gtk_login.c gtk_throbber.c gtk_selection.c \ gtk_history.c gtk_window.c gtk_filetype.c gtk_download.c \ gtk_menu.c gtk_print.c gtk_save.c gtk_search.c gtk_tabs.c \ - gtk_theme.c gtk_toolbar.c sexy_icon_entry.c gtk_compat.c \ + gtk_theme.c gtk_toolbar.c sexy_icon_entry.c gtk_compat.c \ + gtk_cookies.c gtk_hotlist.c \ $(addprefix dialogs/,gtk_options.c gtk_about.c gtk_source.c) S_GTK := $(addprefix gtk/,$(S_GTK)) $(addprefix utils/,container.c) # code in utils/container.ch is non-universal it seems # S_WINDOWS are sources purely for the windows build -S_WINDOWS := about.c bitmap.c download.c filetype.c findfile.c font.c \ - gui.c history.c hotlist.c localhistory.c login.c misc.c plot.c \ - prefs.c schedule.c thumbnail.c tree.c +S_WINDOWS := about.c bitmap.c download.c filetype.c findfile.c font.c \ + gui.c localhistory.c login.c misc.c plot.c prefs.c schedule.c \ + thumbnail.c tree.c S_WINDOWS := $(addprefix windows/,$(S_WINDOWS)) # S_BEOS are sources purely for the BeOS build S_BEOS := beos_about.cpp beos_bitmap.cpp beos_fetch_rsrc.cpp \ - beos_filetype.cpp beos_font.cpp beos_gui.cpp beos_history.cpp \ - beos_login.cpp beos_options.cpp beos_plotters.cpp \ - beos_save_complete.cpp \ + beos_filetype.cpp beos_font.cpp beos_gui.cpp beos_login.cpp \ + beos_options.cpp beos_plotters.cpp beos_save_complete.cpp \ beos_scaffolding.cpp beos_search.cpp beos_schedule.cpp \ beos_thumbnail.cpp beos_treeview.cpp beos_throbber.cpp \ beos_window.cpp @@ -102,9 +103,9 @@ S_AMIGA := $(addprefix amiga/,$(S_AMIGA)) # S_FRAMEBUFFER are sources purely for the framebuffer build -S_FRAMEBUFFER := gui.c framebuffer.c tree.c history.c hotlist.c \ - save.c schedule.c thumbnail.c misc.c bitmap.c filetype.c \ - login.c findfile.c localhistory.c +S_FRAMEBUFFER := gui.c framebuffer.c tree.c save.c schedule.c \ + thumbnail.c misc.c bitmap.c filetype.c login.c findfile.c \ + localhistory.c S_FRAMEBUFFER_FBTK := fbtk.c event.c fill.c bitmap.c user.c window.c \ text.c scroll.c osk.c diff --git a/amiga/cookies.c b/amiga/cookies.c index cffa52337..76e2173f2 100755 --- a/amiga/cookies.c +++ b/amiga/cookies.c @@ -1,6 +1,5 @@ /* - * Copyright 2006 Richard Wilson - * Copyright 2008 Chris Young + * Copyright 2008, 2009 Chris Young * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -17,151 +16,23 @@ * along with this program. If not, see . */ -/** \file - * Cookies (implementation). - */ - -#include -#include "content/urldb.h" -#include "desktop/cookies.h" -#include "desktop/tree.h" -#include "utils/messages.h" -#include "utils/log.h" -#include "amiga/cookies.h" #include -#include -#include "utils/utils.h" +#include "amiga/cookies.h" +#include "desktop/cookies.h" +#include "amiga/tree.h" -static bool cookies_init; - -struct node *ami_cookies_find(const char *url); - -/** - * Initialise cookies tree - */ void ami_cookies_initialise(void) { - if(cookies_tree) return; + cookies_window = ami_tree_create(cookies_get_tree_flags(), NULL); - /* Create an empty tree */ - cookies_tree = AllocVec(sizeof(struct tree),MEMF_CLEAR | MEMF_PRIVATE); - if (!cookies_tree) { - warn_user("NoMemory", 0); - return; - } - cookies_tree->root = tree_create_folder_node(NULL, "Root"); - if (!cookies_tree->root) { - warn_user("NoMemory", 0); - FreeVec(cookies_tree); - cookies_tree = NULL; - } - cookies_tree->root->expanded = true; - cookies_tree->movable = false; - cookies_tree->no_drag = true; + if(!cookies_window) return; - cookies_init = true; - urldb_iterate_cookies(cookies_update); - cookies_init = false; - tree_initialise(cookies_tree); -} - -/** - * Perform cookie addition - * - * \param data Cookie data for a domain, or NULL - * \return true (for urldb_iterate_entries) - */ -bool cookies_update(const char *domain, const struct cookie_data *data) -{ - struct node *parent; - struct node *node = NULL; - struct node *child; - struct node *add; - const struct cookie_data *cookie = NULL; - bool expanded; - - assert(domain); - - /* check if we're a domain, and add get the first cookie */ - if (data) - for (cookie = data; cookie->prev; cookie = cookie->prev); - - if (!cookies_init) { - node = ami_cookies_find(domain); - if (node) { - /* mark as deleted so we don't remove the cookies */ - expanded = node->expanded; - for (child = node->child; child; child = child->next) - child->deleted = true; - if (node->child) - tree_delete_node(cookies_tree, node->child, - true); - /* deleting will have contracted our node */ - node->expanded = expanded; - } - if (!data) { - if (!node) - return true; - tree_delete_node(cookies_tree, node, false); - tree_handle_node_changed(cookies_tree, - cookies_tree->root, true, false); - return true; - } - } - - if (!node) { - for (parent = cookies_tree->root->child; parent; - parent = parent->next) { - if (strcmp(domain, parent->data.text) == 0) - break; - } - if (!parent) { - node = tree_create_folder_node(cookies_tree->root, - domain); - } else { - node = parent; - } - } - if (!node) - return true; - node->editable = false; - - for (; cookie; cookie = cookie->next) { - add = tree_create_cookie_node(node, cookie); - if (add && !cookies_init) - tree_handle_node_changed(cookies_tree, add, - true, false); - } - if (!cookies_init) { - tree_handle_node_changed(cookies_tree, node, - true, false); -/* - tree_redraw_area(cookies_tree, - node->box.x - NODE_INSTEP, - 0, NODE_INSTEP, 16384); -*/ - } - return true; -} - -/** - * Find an entry in the cookie tree - * - * \param url The URL to find - * \return Pointer to node, or NULL if not found - */ -struct node *ami_cookies_find(const char *url) -{ - struct node *node; - - for (node = cookies_tree->root->child; node; node = node->next) { - if (!strcmp(url, node->data.text)) - return node; - } - return NULL; + cookies_initialise(ami_tree_get_tree(cookies_window)); } void ami_cookies_free() { - FreeVec(cookies_tree); + cookies_cleanup(); + ami_tree_destroy(cookies_window); + cookies_window = NULL; } diff --git a/amiga/cookies.h b/amiga/cookies.h index 4d376434c..d6922750c 100755 --- a/amiga/cookies.h +++ b/amiga/cookies.h @@ -1,5 +1,5 @@ /* - * Copyright 2008 Chris Young + * Copyright 2008, 2009 Chris Young * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -19,9 +19,10 @@ #ifndef AMIGA_COOKIES_H #define AMIGA_COOKIES_H #include "desktop/tree.h" +#include "amiga/tree.h" void ami_cookies_initialise(void); void ami_cookies_free(void); -struct tree *cookies_tree; +struct treeview_window *cookies_window; #endif diff --git a/amiga/gui.c b/amiga/gui.c index 6372a435a..759b4f932 100755 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -143,6 +143,8 @@ BOOL screen_closed = FALSE; struct MsgPort *applibport = NULL; ULONG applibsig = 0; +const char tree_directory_icon_name[100]; +const char tree_content_icon_name[100]; extern colour scroll_widget_fg_colour; extern colour scroll_widget_bg_colour; extern colour scroll_widget_arrow_colour; @@ -324,9 +326,6 @@ void ami_set_options(void) if((!option_url_file) || (option_url_file[0] == '\0')) option_url_file = (char *)strdup("PROGDIR:Resources/URLs"); - if((!option_recent_file) || (option_recent_file[0] == '\0')) - option_recent_file = (char *)strdup("PROGDIR:Resources/Recent"); - /* if((!option_cookie_jar) || (option_cookie_jar[0] == '\0')) option_cookie_jar = (char *)strdup("PROGDIR:Resources/CookieJar"); @@ -453,7 +452,6 @@ void gui_init(int argc, char** argv) plot=amiplot; - ami_init_menulabs(); if(option_context_menu) ami_context_menu_init(); schedule_list = NewObjList(); @@ -462,15 +460,6 @@ void gui_init(int argc, char** argv) urldb_load(option_url_file); urldb_load_cookies(option_cookie_file); - if(lock = Lock(option_hotlist_file,SHARED_LOCK)) - { - UnLock(lock); - hotlist = options_load_tree(option_hotlist_file); - } - - if(!hotlist) ami_hotlist_init(&hotlist); - ami_global_history_initialise(); - ami_cookies_initialise(); save_complete_init(); ami_theme_init(); ami_init_mouse_pointers(); @@ -567,6 +556,18 @@ static void gui_init2(int argc, char** argv) notalreadyrunning = ami_arexx_init(); + /* Treeview init code ends up calling a font function which needs this */ + browserglob.scale = 1.0; + glob = &browserglob; + /**/ + + ami_get_theme_filename(&tree_directory_icon_name,"theme_list_folder",true); + ami_get_theme_filename(&tree_content_icon_name,"theme_list_content",true); + ami_hotlist_initialise(option_hotlist_file); + ami_cookies_initialise(); + ami_global_history_initialise(); + sslcert_init(); + search_web_provider_details(option_search_provider); if(argc) // argc==0 is started from wb @@ -1331,7 +1332,7 @@ void ami_handle_msg(void) case 'h': if((option_kiosk_mode == false) && (gwin->bw->browser_window_type == BROWSER_WINDOW_NORMAL)) - ami_open_tree(hotlist,AMI_TREE_HOTLIST); + ami_tree_open(hotlist_window, AMI_TREE_HOTLIST); break; /* The following aren't available from the menu at the moment */ @@ -2002,11 +2003,10 @@ void gui_quit(void) urldb_save(option_url_file); urldb_save_cookies(option_cookie_file); - options_save_tree(hotlist,option_hotlist_file,messages_get("TreeHotlist")); - void ami_global_history_save(); - + ami_hotlist_free(option_hotlist_file); ami_cookies_free(); ami_global_history_free(); + sslcert_cleanup(); hubbub_finalise(ns_realloc,NULL); @@ -2033,7 +2033,10 @@ void gui_quit(void) FreeVec(nsscreentitle); if(option_context_menu) ami_context_menu_free(); - ami_free_menulabs(); + +/* fixme: need newmenu struct propd to this function - should this be freed here? + ami_free_menulabs(menu); +*/ ami_mouse_pointers_free(); ami_clipboard_free(); @@ -2187,7 +2190,6 @@ void ami_toggletabbar(struct gui_window_2 *gwin, bool show) struct gui_window *gui_create_browser_window(struct browser_window *bw, struct browser_window *clone, bool new_tab) { - struct NewMenu *menu; struct gui_window *gwin = NULL; bool closegadg=TRUE; struct Node *node; @@ -2357,7 +2359,7 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, { ULONG addtabclosegadget = TAG_IGNORE; - menu = ami_create_menu(bw->browser_window_type); + ami_create_menu(bw->browser_window_type, gwin->shared); NewList(&gwin->shared->tab_list); gwin->tab_node = AllocClickTabNode(TNA_Text,messages_get("NetSurf"), @@ -2389,28 +2391,28 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, gwin->shared->helphints[GID_ADDTAB] = remove_escape_chars(messages_get("HelpAddTab"), true); - ami_get_theme_filename(nav_west,"theme_nav_west"); - ami_get_theme_filename(nav_west_s,"theme_nav_west_s"); - ami_get_theme_filename(nav_west_g,"theme_nav_west_g"); - ami_get_theme_filename(nav_east,"theme_nav_east"); - ami_get_theme_filename(nav_east_s,"theme_nav_east_s"); - ami_get_theme_filename(nav_east_g,"theme_nav_east_g"); - ami_get_theme_filename(stop,"theme_stop"); - ami_get_theme_filename(stop_s,"theme_stop_s"); - ami_get_theme_filename(stop_g,"theme_stop_g"); - ami_get_theme_filename(reload,"theme_reload"); - ami_get_theme_filename(reload_s,"theme_reload_s"); - ami_get_theme_filename(reload_g,"theme_reload_g"); - ami_get_theme_filename(home,"theme_home"); - ami_get_theme_filename(home_s,"theme_home_s"); - ami_get_theme_filename(home_g,"theme_home_g"); - ami_get_theme_filename(closetab,"theme_closetab"); - ami_get_theme_filename(closetab_s,"theme_closetab_s"); - ami_get_theme_filename(closetab_g,"theme_closetab_g"); - ami_get_theme_filename(addtab,"theme_addtab"); - ami_get_theme_filename(addtab_s,"theme_addtab_s"); - ami_get_theme_filename(addtab_g,"theme_addtab_g"); - ami_get_theme_filename(tabthrobber,"theme_tab_loading"); + ami_get_theme_filename(nav_west,"theme_nav_west",false); + ami_get_theme_filename(nav_west_s,"theme_nav_west_s",false); + ami_get_theme_filename(nav_west_g,"theme_nav_west_g",false); + ami_get_theme_filename(nav_east,"theme_nav_east",false); + ami_get_theme_filename(nav_east_s,"theme_nav_east_s",false); + ami_get_theme_filename(nav_east_g,"theme_nav_east_g",false); + ami_get_theme_filename(stop,"theme_stop",false); + ami_get_theme_filename(stop_s,"theme_stop_s",false); + ami_get_theme_filename(stop_g,"theme_stop_g",false); + ami_get_theme_filename(reload,"theme_reload",false); + ami_get_theme_filename(reload_s,"theme_reload_s",false); + ami_get_theme_filename(reload_g,"theme_reload_g",false); + ami_get_theme_filename(home,"theme_home",false); + ami_get_theme_filename(home_s,"theme_home_s",false); + ami_get_theme_filename(home_g,"theme_home_g",false); + ami_get_theme_filename(closetab,"theme_closetab",false); + ami_get_theme_filename(closetab_s,"theme_closetab_s",false); + ami_get_theme_filename(closetab_g,"theme_closetab_g",false); + ami_get_theme_filename(addtab,"theme_addtab",false); + ami_get_theme_filename(addtab_s,"theme_addtab_s",false); + ami_get_theme_filename(addtab_g,"theme_addtab_g",false); + ami_get_theme_filename(tabthrobber,"theme_tab_loading",false); gwin->shared->objects[GID_ADDTAB_BM] = BitMapObject, BITMAP_SourceFile, addtab, @@ -2482,7 +2484,7 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, IDCMP_GADGETUP | IDCMP_IDCMPUPDATE | IDCMP_ACTIVEWINDOW | IDCMP_INTUITICKS | IDCMP_EXTENDEDMOUSE | IDCMP_GADGETDOWN, - WINDOW_NewMenu,menu, + WINDOW_NewMenu, gwin->shared->menu, WINDOW_VertProp,1, WINDOW_IDCMPHook,&gwin->shared->scrollerhook, WINDOW_IDCMPHookBits,IDCMP_IDCMPUPDATE | @@ -2934,6 +2936,7 @@ void gui_window_destroy(struct gui_window *g) DisposeObject(g->shared->objects[OID_MAIN]); + ami_free_menulabs(g->shared); free(g->shared->wintitle); ami_utf8_free(g->shared->status); FreeVec(g->shared->svbuffer); diff --git a/amiga/gui.h b/amiga/gui.h index dce118b89..70c1d2db3 100755 --- a/amiga/gui.h +++ b/amiga/gui.h @@ -23,8 +23,10 @@ #include #include "desktop/browser.h" #include +#include #include "desktop/gui.h" #include "amiga/plotters.h" +#include "amiga/menu.h" enum { @@ -56,11 +58,7 @@ enum GID_PASS, GID_LOGIN, GID_CANCEL, - GID_TREEBROWSER, GID_OPEN, - GID_LEFT, - GID_UP, - GID_DOWN, GID_NEWF, GID_NEWB, GID_DEL, @@ -98,6 +96,11 @@ struct gui_window_2 { ULONG oldv; bool redraw_scroll; bool new_content; + char *menulab[AMI_MENU_AREXX_MAX + 1]; + char menukey[AMI_MENU_AREXX_MAX + 1]; + UBYTE *menutype; + struct NewMenu *menu; + ULONG hotlist_items; char *svbuffer; char *status; char *wintitle; @@ -127,6 +130,7 @@ void ami_close_all_tabs(struct gui_window_2 *gwin); void ami_quit_netsurf(void); void ami_do_redraw(struct gui_window_2 *g); STRPTR ami_locale_langs(void); +int ami_key_to_nskey(ULONG keycode, struct InputEvent *ie); struct box *ami_text_box_at_point(struct gui_window_2 *gwin, ULONG *x, ULONG *y); struct gui_window_2 *ami_window_at_pointer(void); diff --git a/amiga/history.c b/amiga/history.c index 5e685b76a..19ba9aff9 100755 --- a/amiga/history.c +++ b/amiga/history.c @@ -1,6 +1,5 @@ /* - * Copyright 2005 Richard Wilson - * Copyright 2008 Chris Young + * Copyright 2008, 2009 Chris Young * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -17,362 +16,24 @@ * along with this program. If not, see . */ -#include "desktop/browser.h" #include "amiga/history.h" #include "amiga/tree.h" -#include "content/urldb.h" -#include -#include "amiga/options.h" +#include "desktop/history_global_core.h" #include -#include -#include - -#define MAXIMUM_URL_LENGTH 1024 -#define MAXIMUM_BASE_NODES 16 - -static struct node *global_history_base_node[MAXIMUM_BASE_NODES]; -static int global_history_base_node_time[MAXIMUM_BASE_NODES]; -static int global_history_base_node_count = 0; - -static char *global_history_recent_url[GLOBAL_HISTORY_RECENT_URLS]; -static int global_history_recent_count = 0; - -static bool global_history_init; - -static struct node *ami_global_history_find(const char *url); -static bool global_history_add_internal(const char *url, - const struct url_data *data); -void ami_global_history_initialise_node(const char *title, - time_t base, int days_back); -void ami_global_history_initialise_nodes(void); +#include "amiga/tree.h" void ami_global_history_initialise(void) { - char s[MAXIMUM_URL_LENGTH]; - BPTR *fp; + global_history_window = ami_tree_create(history_global_get_tree_flags(), NULL); -// if(global_history_tree) return; + if(!global_history_window) return; - /* Create an empty tree */ - global_history_tree = AllocVec(sizeof(struct tree), MEMF_CLEAR | MEMF_PRIVATE); - if (!global_history_tree) { - warn_user("NoMemory", 0); - return; - } - global_history_tree->root = tree_create_folder_node(NULL, "Root"); - if (!global_history_tree->root) { - warn_user("NoMemory", 0); - FreeVec(global_history_tree); - global_history_tree = NULL; - } - global_history_tree->root->expanded = true; - ami_global_history_initialise_nodes(); - global_history_tree->movable = false; - - /* load recent URLs */ - fp = FOpen(option_recent_file, MODE_OLDFILE,0); - if (!fp) - LOG(("Failed to open file '%s' for reading", - option_recent_file)); - else { - while (FGets(fp,s, MAXIMUM_URL_LENGTH)) { - if (s[strlen(s) - 1] == '\n') - s[strlen(s) - 1] = '\0'; - global_history_add_recent(s); - } - FClose(fp); - } - - global_history_init = true; - urldb_iterate_entries(global_history_add_internal); - global_history_init = false; - tree_initialise(global_history_tree); - -} - -void global_history_add(const char *url) -{ - const struct url_data *data; - - data = urldb_get_url_data(url); - if (!data) - return; - - global_history_add_internal(url, data); -} - -/** - * Internal routine to actually perform global history addition - * - * \param url The URL to add - * \param data URL data associated with URL - * \return true (for urldb_iterate_entries) - */ -bool global_history_add_internal(const char *url, - const struct url_data *data) -{ - int i, j; - struct node *parent = NULL; - struct node *link; - struct node *node; - bool before = false; - int visit_date; - - assert(url && data); - - visit_date = data->last_visit; - - /* find parent node */ - for (i = 0; i < global_history_base_node_count; i++) { - if (global_history_base_node_time[i] <= visit_date) { - parent = global_history_base_node[i]; - break; - } - } - - /* the entry is too old to care about */ - if (!parent) - return true; - - if (parent->deleted) { - /* parent was deleted, so find place to insert it */ - link = global_history_tree->root; - - for (j = global_history_base_node_count - 1; j >= 0; j--) { - if (!global_history_base_node[j]->deleted && - global_history_base_node_time[j] > - global_history_base_node_time[i]) { - link = global_history_base_node[j]; - before = true; - break; - } - } - - tree_set_node_selected(global_history_tree, - parent, false); - tree_set_node_expanded(global_history_tree, - parent, false); - tree_link_node(link, parent, before); -/* - if (!global_history_init) { - tree_recalculate_node(global_history_tree, parent, true); - tree_recalculate_node_positions(global_history_tree, - global_history_tree->root); - tree_redraw_area(global_history_tree, - 0, 0, 16384, 16384); - } -*/ - } - - /* find any previous occurance */ - - if (!global_history_init) { - node = ami_global_history_find(url); - if (node) { - /* \todo: calculate old/new positions and redraw - * only the relevant portion */ -/* - tree_redraw_area(global_history_tree, - 0, 0, 16384, 16384); -*/ - tree_update_URL_node(node, url, data); - tree_delink_node(node); - tree_link_node(parent, node, false); - tree_handle_node_changed(global_history_tree, - node, false, true); - return true; - } - } - - /* Add the node at the bottom */ - node = tree_create_URL_node_shared(parent, url, data); - if ((!global_history_init) && (node)) { -/* - tree_redraw_area(global_history_tree, - node->box.x - NODE_INSTEP, - 0, NODE_INSTEP, 16384); -*/ - tree_handle_node_changed(global_history_tree, node, - true, false); - } - - return true; -} - -/** - * Find an entry in the global history - * - * \param url The URL to find - * \return Pointer to node, or NULL if not found - */ -struct node *ami_global_history_find(const char *url) -{ - int i; - struct node *node; - struct node_element *element; - - for (i = 0; i < global_history_base_node_count; i++) { - if (!global_history_base_node[i]->deleted) { - for (node = global_history_base_node[i]->child; - node; node = node->next) { - element = tree_find_element(node, - TREE_ELEMENT_URL); - if ((element) && !strcmp(url, element->text)) - return node; - } - } - } - return NULL; -} - -/** - * Saves the global history's recent URL data. - */ -void ami_global_history_save(void) -{ - BPTR *fp; - int i; - - /* save recent URLs */ - fp = fopen(option_recent_file, "w"); - if (!fp) - LOG(("Failed to open file '%s' for writing", - option_recent_file)); - else { - for (i = global_history_recent_count - 1; i >= 0; i--) - if (strlen(global_history_recent_url[i]) < - MAXIMUM_URL_LENGTH) - fprintf(fp, "%s\n", - global_history_recent_url[i]); - fclose(fp); - } -} - -void global_history_add_recent(const char *url) -{ - int i; - int j = -1; - char *current; - - /* try to find a string already there */ - for (i = 0; i < global_history_recent_count; i++) - if (global_history_recent_url[i] && - !strcmp(global_history_recent_url[i], url)) - j = i; - - /* already at head of list */ - if (j == 0) - return; - - if (j < 0) { - /* add to head of list */ - free(global_history_recent_url[ - GLOBAL_HISTORY_RECENT_URLS - 1]); - memmove(&global_history_recent_url[1], - &global_history_recent_url[0], - (GLOBAL_HISTORY_RECENT_URLS - 1) * - sizeof(char *)); - global_history_recent_url[0] = strdup(url); - global_history_recent_count++; - if (global_history_recent_count > GLOBAL_HISTORY_RECENT_URLS) - global_history_recent_count = - GLOBAL_HISTORY_RECENT_URLS; -/* - if (global_history_recent_count == 1) - ro_gui_window_prepare_navigate_all(); -*/ - } else { - /* move to head of list */ - current = global_history_recent_url[j]; - for (i = j; i > 0; i--) - global_history_recent_url[i] = - global_history_recent_url[i - 1]; - global_history_recent_url[0] = current; - } -} - -/** - * Gets details of the currently used URL list. - * - * \param count set to the current number of entries in the URL array on exit - * \return the current URL array - */ -char **global_history_get_recent(int *count) -{ - *count = global_history_recent_count; - return global_history_recent_url; + history_global_initialise(ami_tree_get_tree(global_history_window)); } void ami_global_history_free() { - FreeVec(global_history_tree); + history_global_cleanup(); + ami_tree_destroy(global_history_window); + global_history_window = NULL; } - -/** - * Initialises the base nodes - */ -void ami_global_history_initialise_nodes(void) -{ - struct tm *full_time; - time_t t; - int weekday; - int i; - - /* get the current time */ - t = time(NULL); - if (t == -1) - return; - - /* get the time at the start of today */ - full_time = localtime(&t); - weekday = full_time->tm_wday; - full_time->tm_sec = 0; - full_time->tm_min = 0; - full_time->tm_hour = 0; - t = mktime(full_time); - if (t == -1) - return; - - ami_global_history_initialise_node((char *)messages_get("DateToday"), t, 0); - if (weekday > 0) - ami_global_history_initialise_node( - (char *)messages_get("DateYesterday"), t, -1); - for (i = 2; i <= weekday; i++) - ami_global_history_initialise_node(NULL, t, -i); - ami_global_history_initialise_node((char *)messages_get("Date1Week"), - t, -weekday - 7); - ami_global_history_initialise_node((char *)messages_get("Date2Week"), - t, -weekday - 14); - ami_global_history_initialise_node((char *)messages_get("Date3Week"), - t, -weekday - 21); -} - -/** - * Create and initialise a node - */ -void ami_global_history_initialise_node(const char *title, - time_t base, int days_back) -{ - struct tm *full_time; - char buffer[64]; - struct node *node; - - base += days_back * 60 * 60 * 24; - if (!title) { - full_time = localtime(&base); - strftime((char *)&buffer, (size_t)64, "%A", full_time); - node = tree_create_folder_node(NULL, buffer); - } else - node = tree_create_folder_node(NULL, title); - - if (!node) - return; - - node->retain_in_memory = true; - node->deleted = true; - node->editable = false; - global_history_base_node[global_history_base_node_count] = node; - global_history_base_node_time[global_history_base_node_count] = base; - global_history_base_node_count++; -} - diff --git a/amiga/history.h b/amiga/history.h index c9f8254dc..b69d46c6a 100755 --- a/amiga/history.h +++ b/amiga/history.h @@ -19,11 +19,12 @@ #ifndef AMIGA_HISTORY_H #define AMIGA_HISTORY_H #include "desktop/tree.h" +#include "desktop/history_global_core.h" #define GLOBAL_HISTORY_RECENT_URLS 16 void ami_global_history_initialise(void); void ami_global_history_free(void); -struct tree *global_history_tree; +struct treeview_window *global_history_window; #endif diff --git a/amiga/hotlist.c b/amiga/hotlist.c index 71c5ddbba..f90f3645e 100755 --- a/amiga/hotlist.c +++ b/amiga/hotlist.c @@ -1,5 +1,4 @@ /* - * Copyright 2004, 2005 Richard Wilson * Copyright 2008, 2009 Chris Young * * This file is part of NetSurf, http://www.netsurf-browser.org/ @@ -17,137 +16,24 @@ * along with this program. If not, see . */ -#include "desktop/browser.h" -#include "desktop/tree.h" #include -#include "content/urldb.h" #include "amiga/hotlist.h" +#include "desktop/hotlist.h" #include "amiga/tree.h" -void ami_gui_hotlist_visited(hlcache_handle *content, struct tree *tree, - struct node *node); - -static const struct { - const char *url; - const char *msg_key; -} default_entries[] = { - { "http://www.netsurf-browser.org/", "HotlistHomepage" }, - { "http://www.netsurf-browser.org/downloads/amiga/", "HotlistTestBuild" }, - { "http://www.netsurf-browser.org/documentation/", "HotlistDocumentation" }, - { "http://sourceforge.net/tracker/?atid=464312&group_id=51719", - "HotlistBugTracker" }, - { "http://sourceforge.net/tracker/?atid=464315&group_id=51719", - "HotlistFeatureRequest" }, - { "http://www.unsatisfactorysoftware.co.uk/", - "Unsatisfactory Software" } -}; -#define ENTRIES_COUNT (sizeof(default_entries) / sizeof(default_entries[0])) - -void hotlist_visited(hlcache_handle *c) +void ami_hotlist_initialise(const char *hotlist_file) { - if ((!c) || (!content_get_url(c)) || (!hotlist)) - return; - ami_gui_hotlist_visited(c, hotlist, hotlist->root); + hotlist_window = ami_tree_create(hotlist_get_tree_flags(), NULL); + + if(!hotlist_window) return; + + hotlist_initialise(ami_tree_get_tree(hotlist_window), + hotlist_file); } -/** - * Informs the hotlist that some content has been visited - * - * \param content the content visited - * \param tree the tree to find the URL data from - * \param node the node to update siblings and children of - */ -void ami_gui_hotlist_visited(hlcache_handle *content, struct tree *tree, - struct node *node) +void ami_hotlist_free(const char *hotlist_file) { - struct node_element *element; - - for (; node; node = node->next) { - if (!node->folder) { - element = tree_find_element(node, TREE_ELEMENT_URL); - if ((element) && (!strcmp(element->text, - content_get_url(content)))) { - tree_update_URL_node(node, content_get_url(content), NULL); - tree_handle_node_changed(tree, node, true, - false); - } - } - if (node->child) - ami_gui_hotlist_visited(content, tree, node->child); - } -} - -void ami_hotlist_init(struct tree **hotlist) -{ - struct tree *hotlist_tree; - struct node *node; - int i; - const struct url_data *data; - - *hotlist = AllocVec(sizeof(struct tree),MEMF_PRIVATE | MEMF_CLEAR); - hotlist_tree = *hotlist; - - if (!hotlist_tree) { - warn_user("NoMemory", 0); - return; - } - - hotlist_tree->root = tree_create_folder_node(NULL, "Root"); - if (!hotlist_tree->root) { - warn_user("NoMemory", 0); - FreeVec(hotlist_tree); - hotlist_tree = NULL; - } - - hotlist_tree->root->expanded = true; - - node = tree_create_folder_node(hotlist_tree->root, "Menu"); - if (!node) - node = hotlist_tree->root; - - node = tree_create_folder_node(node, "NetSurf"); - if (!node) - node = hotlist_tree->root; - - for (i = 0; i != ENTRIES_COUNT; i++) { - data = urldb_get_url_data(default_entries[i].url); - if (!data) { - urldb_add_url(default_entries[i].url); - urldb_set_url_persistence( - default_entries[i].url, - true); - data = urldb_get_url_data( - default_entries[i].url); - } - if (data) { - tree_create_URL_node(node, - default_entries[i].url, data, - messages_get(default_entries[i].msg_key)); - } - } - - tree_initialise(hotlist_tree); -} - -void ami_hotlist_add(struct node *node, struct hlcache_handle *c) -{ - const struct url_data *data; - - data = urldb_get_url_data(content_get_url(c)); - if (!data) - { - urldb_add_url(content_get_url(c)); - urldb_set_url_persistence(content_get_url(c),true); - data = urldb_get_url_data(content_get_url(c)); - } - - if (data) - { - tree_create_URL_node(node,content_get_url(c),data,content_get_title(c)); - } - - tree_handle_node_changed(hotlist,node,false,true); - - if(hotlist->handle) - ami_recreate_listbrowser((struct treeview_window *)hotlist->handle); + hotlist_cleanup(hotlist_file); + ami_tree_destroy(hotlist_window); + hotlist_window = NULL; } diff --git a/amiga/hotlist.h b/amiga/hotlist.h index eed5b0eed..ee258af7b 100755 --- a/amiga/hotlist.h +++ b/amiga/hotlist.h @@ -1,5 +1,5 @@ /* - * Copyright 2008 Chris Young + * Copyright 2008, 2009 Chris Young * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -19,9 +19,10 @@ #ifndef AMIGA_HOTLIST_H #define AMIGA_HOTLIST_H #include "desktop/tree.h" +#include "amiga/tree.h" -void ami_hotlist_init(struct tree **hotlist); -void ami_hotlist_add(struct node *node, struct hlcache_handle *c); +void ami_hotlist_initialise(const char *hotlist_file); +void ami_hotlist_free(const char *hotlist_file); -struct tree *hotlist; +struct treeview_window *hotlist_window; #endif diff --git a/amiga/menu.c b/amiga/menu.c index 9f5aab757..081b1e568 100755 --- a/amiga/menu.c +++ b/amiga/menu.c @@ -41,6 +41,11 @@ #include "amiga/iff_dr2d.h" #include "amiga/clipboard.h" #include "amiga/gui_options.h" +#include "desktop/tree_url_node.h" +#include +#include +#include "desktop/hotlist.h" +#include #include "amiga/print.h" #include "amiga/download.h" @@ -61,226 +66,221 @@ const char * const versvn; const char * const verdate; static struct Hook aslhookfunc; -void ami_menu_scan(struct tree *tree,struct NewMenu *menu); -void ami_menu_scan_2(struct tree *tree,struct node *root,WORD *gen,ULONG *item,struct NewMenu *menu); -void ami_menu_arexx_scan(struct NewMenu *menu); +ULONG ami_menu_scan(struct tree *tree, bool count, struct gui_window_2 *gwin); +void ami_menu_scan_2(struct tree *tree, struct node *root, WORD *gen, + ULONG *item, bool count, struct gui_window_2 *gwin); +void ami_menu_arexx_scan(struct gui_window_2 *gwin); static const ULONG ami_asl_mime_hook(struct Hook *mh,struct FileRequester *fr,struct AnchorPathOld *ap); -void ami_free_menulabs(void) +void ami_free_menulabs(struct gui_window_2 *gwin) { int i; - for(i=0;i<=AMI_MENU_MAX;i++) + for(i=0;i<=AMI_MENU_AREXX_MAX;i++) { - if(menulab[i] && (menulab[i] != NM_BARLABEL)) ami_utf8_free(menulab[i]); + if(gwin->menulab[i] && (gwin->menulab[i] != NM_BARLABEL)) + ami_utf8_free(gwin->menulab[i]); + + gwin->menulab[i] = NULL; + gwin->menukey[i] = 0; } - for(i=AMI_MENU_MAX+1;i<=AMI_MENU_AREXX_MAX;i++) - { - if(menulab[i] && (menulab[i] != NM_BARLABEL)) free(menulab[i]); - } + FreeVec(gwin->menutype); + FreeVec(gwin->menu); + + gwin->menutype = NULL; + gwin->menu = NULL; } -void ami_init_menulabs(void) +void ami_init_menulabs(struct gui_window_2 *gwin) { - menulab[0] = ami_utf8_easy((char *)messages_get("Project")); - menulab[1] = ami_utf8_easy((char *)messages_get("NewWindowNS")); - menulab[2] = ami_utf8_easy((char *)messages_get("NewTab")); - menulab[3] = NM_BARLABEL; - menulab[4] = ami_utf8_easy((char *)messages_get("OpenFile")); - menulab[5] = ami_utf8_easy((char *)messages_get("SaveAsNS")); - menulab[6] = ami_utf8_easy((char *)messages_get("Source")); - menulab[7] = ami_utf8_easy((char *)messages_get("TextNS")); - menulab[8] = ami_utf8_easy((char *)messages_get("SaveCompNS")); - menulab[9] = ami_utf8_easy((char *)messages_get("PDFNS")); - menulab[10] = ami_utf8_easy((char *)messages_get("IFF")); - menulab[11] = NM_BARLABEL; - menulab[12] = ami_utf8_easy((char *)messages_get("CloseTab")); - menulab[13] = ami_utf8_easy((char *)messages_get("CloseWindow")); - menulab[14] = NM_BARLABEL; - menulab[15] = ami_utf8_easy((char *)messages_get("PrintNS")); - menulab[16] = NM_BARLABEL; - menulab[17] = ami_utf8_easy((char *)messages_get("About")); - menulab[18] = ami_utf8_easy((char *)messages_get("Quit")); - menulab[19] = ami_utf8_easy((char *)messages_get("Edit")); - menulab[20] = ami_utf8_easy((char *)messages_get("CutNS")); - menulab[21] = ami_utf8_easy((char *)messages_get("CopyNS")); - menulab[22] = ami_utf8_easy((char *)messages_get("PasteNS")); - menulab[23] = NM_BARLABEL; - menulab[24] = ami_utf8_easy((char *)messages_get("SelectAllNS")); - menulab[25] = ami_utf8_easy((char *)messages_get("ClearNS")); - menulab[26] = ami_utf8_easy((char *)messages_get("Browser")); - menulab[27] = ami_utf8_easy((char *)messages_get("FindTextNS")); - menulab[28] = NM_BARLABEL; - menulab[29] = ami_utf8_easy((char *)messages_get("HistLocalNS")); - menulab[30] = ami_utf8_easy((char *)messages_get("HistGlobalNS")); - menulab[31] = NM_BARLABEL; - menulab[32] = ami_utf8_easy((char *)messages_get("ShowCookies")); - menulab[33] = NM_BARLABEL; - menulab[34] = ami_utf8_easy((char *)messages_get("ScaleNS")); - menulab[35] = ami_utf8_easy((char *)messages_get("ScaleDec")); - menulab[36] = ami_utf8_easy((char *)messages_get("ScaleNorm")); - menulab[37] = ami_utf8_easy((char *)messages_get("ScaleInc")); - menulab[38] = ami_utf8_easy((char *)messages_get("Redraw")); - menulab[39] = ami_utf8_easy((char *)messages_get("Hotlist")); - menulab[40] = ami_utf8_easy((char *)messages_get("HotlistAdd")); - menulab[41] = ami_utf8_easy((char *)messages_get("HotlistShowNS")); - menulab[42] = NM_BARLABEL; + int i; - menulab[AMI_MENU_HOTLIST_MAX] = ami_utf8_easy((char *)messages_get("Settings")); - menulab[AMI_MENU_HOTLIST_MAX+1] = ami_utf8_easy((char *)messages_get("SettingsEdit")); - menulab[AMI_MENU_HOTLIST_MAX+2] = NM_BARLABEL; - menulab[AMI_MENU_HOTLIST_MAX+3] = ami_utf8_easy((char *)messages_get("SnapshotWindow")); - menulab[AMI_MENU_HOTLIST_MAX+4] = ami_utf8_easy((char *)messages_get("SettingsSave")); - menulab[AMI_MENU_HOTLIST_MAX+5] = ami_utf8_easy((char *)messages_get("ARexx")); - menulab[AMI_MENU_HOTLIST_MAX+6] = ami_utf8_easy((char *)messages_get("ARexxExecute")); - menulab[AMI_MENU_HOTLIST_MAX+7] = NM_BARLABEL; + gwin->menutype = AllocVec(AMI_MENU_AREXX_MAX + 1, MEMF_PRIVATE | MEMF_CLEAR); + + for(i=0;i <= AMI_MENU_AREXX_MAX;i++) + { + gwin->menutype[i] = NM_IGNORE; + gwin->menulab[i] = NULL; + } + + gwin->menutype[0] = NM_TITLE; + gwin->menulab[0] = ami_utf8_easy((char *)messages_get("Project")); + gwin->menutype[1] = NM_ITEM; + gwin->menulab[1] = ami_utf8_easy((char *)messages_get("NewWindowNS")); + gwin->menukey[1] = 'N'; + gwin->menutype[2] = NM_ITEM; + gwin->menulab[2] = ami_utf8_easy((char *)messages_get("NewTab")); + gwin->menukey[1] = 'T'; + gwin->menutype[3] = NM_ITEM; + gwin->menulab[3] = NM_BARLABEL; + gwin->menutype[4] = NM_ITEM; + gwin->menulab[4] = ami_utf8_easy((char *)messages_get("OpenFile")); + gwin->menukey[4] = 'O'; + gwin->menutype[5] = NM_ITEM; + gwin->menulab[5] = ami_utf8_easy((char *)messages_get("SaveAsNS")); + gwin->menukey[5] = 'S'; + gwin->menutype[6] = NM_SUB; + gwin->menulab[6] = ami_utf8_easy((char *)messages_get("Source")); + gwin->menutype[7] = NM_SUB; + gwin->menulab[7] = ami_utf8_easy((char *)messages_get("TextNS")); + gwin->menutype[8] = NM_SUB; + gwin->menulab[8] = ami_utf8_easy((char *)messages_get("SaveCompNS")); + gwin->menutype[9] = NM_SUB; + gwin->menulab[9] = ami_utf8_easy((char *)messages_get("PDFNS")); + gwin->menutype[10] = NM_SUB; + gwin->menulab[10] = ami_utf8_easy((char *)messages_get("IFF")); + gwin->menutype[11] = NM_ITEM; + gwin->menulab[11] = NM_BARLABEL; + gwin->menutype[12] = NM_ITEM; + gwin->menulab[12] = ami_utf8_easy((char *)messages_get("CloseTab")); + gwin->menukey[12] = 'K'; + gwin->menutype[13] = NM_ITEM; + gwin->menulab[13] = ami_utf8_easy((char *)messages_get("CloseWindow")); + gwin->menutype[14] = NM_ITEM; + gwin->menulab[14] = NM_BARLABEL; + gwin->menutype[15] = NM_ITEM; + gwin->menulab[15] = ami_utf8_easy((char *)messages_get("PrintNS")); + gwin->menukey[15] = 'P'; + gwin->menutype[16] = NM_ITEM; + gwin->menulab[16] = NM_BARLABEL; + gwin->menutype[17] = NM_ITEM; + gwin->menulab[17] = ami_utf8_easy((char *)messages_get("About")); + gwin->menukey[17] = '?'; + gwin->menutype[18] = NM_ITEM; + gwin->menulab[18] = ami_utf8_easy((char *)messages_get("Quit")); + gwin->menukey[18] = 'Q'; + gwin->menutype[19] = NM_TITLE; + gwin->menulab[19] = ami_utf8_easy((char *)messages_get("Edit")); + gwin->menutype[20] = NM_ITEM; + gwin->menulab[20] = ami_utf8_easy((char *)messages_get("CutNS")); + gwin->menukey[20] = 'X'; + gwin->menutype[21] = NM_ITEM; + gwin->menulab[21] = ami_utf8_easy((char *)messages_get("CopyNS")); + gwin->menukey[21] = 'C'; + gwin->menutype[22] = NM_ITEM; + gwin->menulab[22] = ami_utf8_easy((char *)messages_get("PasteNS")); + gwin->menukey[22] = 'V'; + gwin->menutype[23] = NM_ITEM; + gwin->menulab[23] = NM_BARLABEL; + gwin->menutype[24] = NM_ITEM; + gwin->menulab[24] = ami_utf8_easy((char *)messages_get("SelectAllNS")); + gwin->menukey[24] = 'A'; + gwin->menutype[25] = NM_ITEM; + gwin->menulab[25] = ami_utf8_easy((char *)messages_get("ClearNS")); + gwin->menukey[25] = 'Z'; + gwin->menutype[26] = NM_TITLE; + gwin->menulab[26] = ami_utf8_easy((char *)messages_get("Browser")); + gwin->menutype[27] = NM_ITEM; + gwin->menulab[27] = ami_utf8_easy((char *)messages_get("FindTextNS")); + gwin->menukey[27] = 'F'; + gwin->menutype[28] = NM_ITEM; + gwin->menulab[28] = NM_BARLABEL; + gwin->menutype[29] = NM_ITEM; + gwin->menulab[29] = ami_utf8_easy((char *)messages_get("HistLocalNS")); + gwin->menutype[30] = NM_ITEM; + gwin->menulab[30] = ami_utf8_easy((char *)messages_get("HistGlobalNS")); + gwin->menutype[31] = NM_ITEM; + gwin->menulab[31] = NM_BARLABEL; + gwin->menutype[32] = NM_ITEM; + gwin->menulab[32] = ami_utf8_easy((char *)messages_get("ShowCookies")); + gwin->menutype[33] = NM_ITEM; + gwin->menulab[33] = NM_BARLABEL; + gwin->menutype[34] = NM_ITEM; + gwin->menulab[34] = ami_utf8_easy((char *)messages_get("ScaleNS")); + gwin->menutype[35] = NM_SUB; + gwin->menulab[35] = ami_utf8_easy((char *)messages_get("ScaleDec")); + gwin->menukey[35] = '-'; + gwin->menutype[36] = NM_SUB; + gwin->menulab[36] = ami_utf8_easy((char *)messages_get("ScaleNorm")); + gwin->menukey[36] = '='; + gwin->menutype[37] = NM_SUB; + gwin->menulab[37] = ami_utf8_easy((char *)messages_get("ScaleInc")); + gwin->menukey[37] = '+'; + gwin->menutype[38] = NM_ITEM; + gwin->menulab[38] = ami_utf8_easy((char *)messages_get("Redraw")); + gwin->menutype[39] = NM_TITLE; + gwin->menulab[39] = ami_utf8_easy((char *)messages_get("Hotlist")); + gwin->menukey[39] = 'H'; + gwin->menutype[40] = NM_ITEM; + gwin->menulab[40] = ami_utf8_easy((char *)messages_get("HotlistAdd")); + gwin->menutype[41] = NM_ITEM; + gwin->menulab[41] = ami_utf8_easy((char *)messages_get("HotlistShowNS")); + gwin->menutype[42] = NM_ITEM; + gwin->menulab[42] = NM_BARLABEL; + + gwin->menutype[AMI_MENU_HOTLIST_MAX + 1] = NM_TITLE; + gwin->menulab[AMI_MENU_HOTLIST_MAX + 1] = ami_utf8_easy((char *)messages_get("Settings")); + gwin->menutype[AMI_MENU_HOTLIST_MAX + 2] = NM_ITEM; + gwin->menulab[AMI_MENU_HOTLIST_MAX + 2] = ami_utf8_easy((char *)messages_get("SettingsEdit")); + gwin->menutype[AMI_MENU_HOTLIST_MAX + 3] = NM_ITEM; + gwin->menulab[AMI_MENU_HOTLIST_MAX + 3] = NM_BARLABEL; + gwin->menutype[AMI_MENU_HOTLIST_MAX + 4] = NM_ITEM; + gwin->menulab[AMI_MENU_HOTLIST_MAX + 4] = ami_utf8_easy((char *)messages_get("SnapshotWindow")); + gwin->menutype[AMI_MENU_HOTLIST_MAX + 5] = NM_ITEM; + gwin->menulab[AMI_MENU_HOTLIST_MAX + 5] = ami_utf8_easy((char *)messages_get("SettingsSave")); + gwin->menutype[AMI_MENU_HOTLIST_MAX + 6] = NM_TITLE; + gwin->menulab[AMI_MENU_HOTLIST_MAX + 6] = ami_utf8_easy((char *)messages_get("ARexx")); + gwin->menutype[AMI_MENU_HOTLIST_MAX + 7] = NM_ITEM; + gwin->menulab[AMI_MENU_HOTLIST_MAX + 7] = ami_utf8_easy((char *)messages_get("ARexxExecute")); + gwin->menutype[AMI_MENU_HOTLIST_MAX + 8] = NM_ITEM; + gwin->menulab[AMI_MENU_HOTLIST_MAX + 8] = NM_BARLABEL; + + gwin->menutype[AMI_MENU_AREXX_MAX] = NM_END; } -struct NewMenu *ami_create_menu(ULONG type) +void ami_menu_refresh(struct gui_window_2 *gwin) +{ + SetAttrs(gwin->objects[OID_MAIN], + WINDOW_NewMenu, NULL, + TAG_DONE); + + ami_free_menulabs(gwin); + ami_create_menu(BROWSER_WINDOW_NORMAL, gwin); + + SetAttrs(gwin->objects[OID_MAIN], + WINDOW_NewMenu, gwin->menu, + TAG_DONE); + + schedule(6000,(void *)ami_menu_refresh,gwin); +} + +struct NewMenu *ami_create_menu(ULONG type, struct gui_window_2 *gwin) { int i; ULONG menuflags = 0; - STATIC struct NewMenu menu[] = { - {NM_TITLE,0,0,0,0,0,}, // project - { NM_ITEM,0,"N",0,0,0,}, // new window - { NM_ITEM,0,"T",0,0,0,}, // new tab - { NM_ITEM,NM_BARLABEL,0,0,0,0,}, - { NM_ITEM,0,"O",0,0,0,}, // open local file - { NM_ITEM,0,0,0,0,0,}, // save - { NM_SUB,0,"S",0,0,0,}, // save as source - { NM_SUB,0,0,0,0,0,}, // save as text - { NM_SUB,0,0,0,0,0,}, // save as complete - { NM_SUB,0,0,0,0,0,}, // save as pdf - { NM_SUB,0,0,0,0,0,}, // save as iff - { NM_ITEM,NM_BARLABEL,0,0,0,0,}, - { NM_ITEM,0,"K",0,0,0,}, // close tab - { NM_ITEM,0,0,0,0,0,}, // close window - { NM_ITEM,NM_BARLABEL,0,0,0,0,}, - { NM_ITEM,0,"P",0,0,0,}, // print - { NM_ITEM,NM_BARLABEL,0,0,0,0,}, - { NM_ITEM,0,"?",0,0,0,}, // about - { NM_ITEM,0,"Q",0,0,0,}, // quit - {NM_TITLE,0,0,0,0,0,}, // edit - { NM_ITEM,0,"X",0,0,0,}, // cut - { NM_ITEM,0,"C",0,0,0,}, // copy - { NM_ITEM,0,"V",0,0,0,}, // paste - { NM_ITEM,NM_BARLABEL,0,0,0,0,}, - { NM_ITEM,0,"A",0,0,0,}, // select all - { NM_ITEM,0,"Z",0,0,0,}, // clear selection - {NM_TITLE,0,0,0,0,0,}, // browser - { NM_ITEM,0,"F",0,0,0,}, // find in page - { NM_ITEM,NM_BARLABEL,0,0,0,0,}, - { NM_ITEM,0,0,0,0,0,}, // local history - { NM_ITEM,0,0,0,0,0,}, // global history - { NM_ITEM,NM_BARLABEL,0,0,0,0,}, - { NM_ITEM,0,0,0,0,0,}, // cookies - { NM_ITEM,NM_BARLABEL,0,0,0,0,}, - { NM_ITEM,0,0,0,0,0,}, // scale - { NM_SUB,0,"-",0,0,0,}, // decrease - { NM_SUB,0,"=",0,0,0,}, // normal - { NM_SUB,0,"+",0,0,0,}, // increase - { NM_ITEM,0,0,0,0,0,}, // redraw - {NM_TITLE,0,0,0,0,0,}, // hotlist - { NM_ITEM,0,0,0,0,0,}, // add to hotlist - { NM_ITEM,0,"H",0,0,0,}, // show hotlist (treeview) - { NM_ITEM,NM_BARLABEL,0,0,0,0,}, - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** - {NM_TITLE,0,0,0,0,0,}, // settings - { NM_ITEM,0,0,0,0,0,}, // edit prefs - { NM_ITEM,NM_BARLABEL,0,0,0,0,}, - { NM_ITEM,0,0,0,0,0,}, // snapshot window - { NM_ITEM,0,0,0,0,0,}, // save settings - {NM_TITLE,0,0,0,0,0,}, // arexx - { NM_ITEM,0,0,0,0,0,}, // execute arexx - { NM_ITEM,NM_BARLABEL,0,0,0,0,}, - { NM_IGNORE,0,0,0,0,0,}, // ** arexx entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** arexx entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** arexx entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** arexx entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** arexx entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** arexx entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** arexx entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** arexx entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** arexx entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** arexx entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** arexx entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** arexx entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** arexx entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** arexx entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** arexx entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** arexx entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** arexx entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** arexx entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** arexx entry ** - { NM_IGNORE,0,0,0,0,0,}, // ** arexx entry ** - { NM_END,0,0,0,0,0,}, - }; + + ami_init_menulabs(gwin); + gwin->menu = AllocVec(sizeof(struct NewMenu) * (AMI_MENU_AREXX_MAX + 1), MEMF_CLEAR); if(type != BROWSER_WINDOW_NORMAL) { menuflags = NM_ITEMDISABLED; } - for(i=0;i<=AMI_MENU_MAX;i++) + for(i=0;i<=AMI_MENU_AREXX_MAX;i++) { - menu[i].nm_Label = menulab[i]; + gwin->menu[i].nm_Type = gwin->menutype[i]; + gwin->menu[i].nm_Label = gwin->menulab[i]; + if(gwin->menukey[i]) gwin->menu[i].nm_CommKey = &gwin->menukey[i]; + gwin->menu[i].nm_Flags = 0; } - menu[1].nm_Flags = menuflags; - menu[2].nm_Flags = menuflags; - menu[12].nm_Flags = menuflags; - menu[13].nm_Flags = menuflags; + gwin->menu[1].nm_Flags = menuflags; + gwin->menu[2].nm_Flags = menuflags; + gwin->menu[12].nm_Flags = menuflags; + gwin->menu[13].nm_Flags = menuflags; #ifndef WITH_PDF_EXPORT - menu[9].nm_Flags = NM_ITEMDISABLED; + gwin->menu[9].nm_Flags = NM_ITEMDISABLED; #endif + ami_menu_scan(ami_tree_get_tree(hotlist_window), false, gwin); + ami_menu_arexx_scan(gwin); + if(!menualreadyinit) { - ami_menu_scan(hotlist,menu); - ami_menu_arexx_scan(&menu); - aslhookfunc.h_Entry = (void *)&ami_asl_mime_hook; aslhookfunc.h_SubEntry = NULL; aslhookfunc.h_Data = NULL; @@ -288,10 +288,16 @@ struct NewMenu *ami_create_menu(ULONG type) menualreadyinit = TRUE; } - return(menu); +/* Set up scheduler to refresh the hotlist menu + Disabled as it causes everything to slow down to a halt after + several iterations + schedule(6000,(void *)ami_menu_refresh,gwin); +*/ + + return(gwin->menu); } -void ami_menu_arexx_scan(struct NewMenu *menu) +void ami_menu_arexx_scan(struct gui_window_2 *gwin) { int item = AMI_MENU_AREXX; BPTR lock = 0; @@ -323,23 +329,20 @@ void ami_menu_arexx_scan(struct NewMenu *menu) for(ead = (struct ExAllData *)buffer; ead; ead = ead->ed_Next) { if(item >= AMI_MENU_AREXX_MAX) continue; - if(!strcasecmp(ead->ed_Name, option_arexx_startup)) continue; - if(!strcasecmp(ead->ed_Name, option_arexx_shutdown)) continue; - if(EAD_IS_FILE(ead)) { - menu[item].nm_Type = NM_ITEM; + gwin->menu[item].nm_Type = NM_ITEM; if(ead->ed_Comment[0] != '\0') { - menulab[item] = (char *)strdup(ead->ed_Comment); + gwin->menulab[item] = (char *)strdup(ead->ed_Comment); } else { - menulab[item] = (char *)strdup(ead->ed_Name); + gwin->menulab[item] = (char *)strdup(ead->ed_Name); } - menu[item].nm_Label = menulab[item]; - menu[item].nm_UserData = (char *)strdup(ead->ed_Name); + gwin->menu[item].nm_Label = gwin->menulab[item]; + gwin->menu[item].nm_UserData = (char *)strdup(ead->ed_Name); item++; } @@ -351,31 +354,37 @@ void ami_menu_arexx_scan(struct NewMenu *menu) } UnLock(lock); } + + gwin->menu[item].nm_Type = NM_END; + gwin->menu[item].nm_Label = NULL; } -void ami_menu_scan(struct tree *tree,struct NewMenu *menu) +ULONG ami_menu_scan(struct tree *tree, bool count, struct gui_window_2 *gwin) { - struct node *root = tree->root->child; - struct node_element *element=NULL; + struct node *root = tree_node_get_child(tree_get_root(tree)); struct node *node; + struct node_element *element; static WORD gen = 0; static ULONG item; item = AMI_MENU_HOTLIST; - for (node = root; node; node = node->next) + for (node = root; node; node = tree_node_get_next(node)) { - element = tree_find_element(node, TREE_ELEMENT_NAME); - if(!element) element = tree_find_element(node, TREE_ELEMENT_TITLE); - if(element && (strcmp(element->text,"Menu")==0)) + element = tree_node_find_element(node, TREE_ELEMENT_TITLE, NULL); + if(!element) element = tree_node_find_element(node, TREE_ELEMENT_TITLE, NULL); + if(element && (strcmp(tree_node_element_get_text(element),"Menu")==0)) { // found menu - ami_menu_scan_2(tree,node->child,&gen,&item,menu); + ami_menu_scan_2(tree,tree_node_get_child(node),&gen,&item,count,gwin); } } + + return(item - AMI_MENU_HOTLIST); } -void ami_menu_scan_2(struct tree *tree,struct node *root,WORD *gen,ULONG *item,struct NewMenu *menu) +void ami_menu_scan_2(struct tree *tree,struct node *root,WORD *gen, + ULONG *item, bool count, struct gui_window_2 *gwin) { struct node *tempnode; struct node_element *element=NULL; @@ -383,38 +392,39 @@ void ami_menu_scan_2(struct tree *tree,struct node *root,WORD *gen,ULONG *item,s *gen = *gen + 1; - for (node = root; node; node = node->next) + for (node = root; node; node = tree_node_get_next(node)) { - element = tree_find_element(node, TREE_ELEMENT_TITLE); - if((*gen > 0) && (*gen < 3)) { - if(*item >= AMI_MENU_HOTLIST_MAX) return; +// if(*item >= AMI_MENU_HOTLIST_MAX) return; - if(*gen == 1) menu[*item].nm_Type = NM_ITEM; - if(*gen == 2) menu[*item].nm_Type = NM_SUB; - - if(strcmp(element->text,"--")) + if(!count) { - menulab[*item] = ami_utf8_easy((char *)element->text); - } - else - { - menulab[*item] = NM_BARLABEL; - } + if(*gen == 1) gwin->menu[*item].nm_Type = NM_ITEM; + if(*gen == 2) gwin->menu[*item].nm_Type = NM_SUB; - menu[*item].nm_Label = menulab[*item]; + if(strcmp(tree_url_node_get_title(node),"--")) + { + gwin->menulab[*item] = ami_utf8_easy((char *)tree_url_node_get_title(node)); + } + else + { + gwin->menulab[*item] = NM_BARLABEL; + } - element = tree_find_element(node, TREE_ELEMENT_URL); - if(element && element->text) menu[*item].nm_UserData = (void *)element->text; - if(node->folder && (!node->child)) menu[*item].nm_Flags = NM_ITEMDISABLED; + gwin->menu[*item].nm_Label = gwin->menulab[*item]; + + gwin->menu[*item].nm_UserData = (void *)tree_url_node_get_url(node); + if(tree_node_is_folder(node) && (!tree_node_get_child(node))) + gwin->menu[*item].nm_Flags = NM_ITEMDISABLED; + } *item = *item + 1; } - if (node->child) + if (tree_node_get_child(node)) { - ami_menu_scan_2(tree,node->child,gen,item,menu); + ami_menu_scan_2(tree,tree_node_get_child(node),gen,item,count,gwin); } } @@ -698,11 +708,11 @@ void ami_menupick(ULONG code,struct gui_window_2 *gwin,struct MenuItem *item) break; case 3: // global history - ami_open_tree(global_history_tree,AMI_TREE_HISTORY); + ami_tree_open(global_history_window,AMI_TREE_HISTORY); break; case 5: // cookies tree - ami_open_tree(cookies_tree,AMI_TREE_COOKIES); + ami_tree_open(cookies_window,AMI_TREE_COOKIES); break; case 7: // size @@ -736,12 +746,18 @@ void ami_menupick(ULONG code,struct gui_window_2 *gwin,struct MenuItem *item) switch(itemnum) { case 0: // add - ami_hotlist_add(hotlist->root,gwin->bw->current_content); - options_save_tree(hotlist,option_hotlist_file,messages_get("TreeHotlist")); + if (bw == NULL || + bw->current_content + == NULL || + content_get_url(bw->current_content) + == NULL) + break; + hotlist_add_page(content_get_url(gwin->bw-> + current_content)); break; case 1: // show - ami_open_tree(hotlist,AMI_TREE_HOTLIST); + ami_tree_open(hotlist_window, AMI_TREE_HOTLIST); break; default: // bookmarks diff --git a/amiga/menu.h b/amiga/menu.h index 8f925411a..5a739d616 100755 --- a/amiga/menu.h +++ b/amiga/menu.h @@ -19,12 +19,14 @@ #ifndef AMIGA_MENU_H #define AMIGA_MENU_H #include -#include "amiga/gui.h" #include +#include +#include "content/hlcache.h" /* Number of hotlist items, menu structure needs to be changed in ami_create_menu() * if this value is changed. */ -#define AMI_HOTLIST_ITEMS 40 +#define AMI_HOTLIST_ITEMS 60 +//gwin->hotlist_items /* Maximum number of menu items - first value is number of static items * (ie. everything not intially defined as NM_IGNORE) */ @@ -61,11 +63,12 @@ #define AMI_MENU_CLEAR FULLMENUNUM(1,5,0) #define AMI_MENU_FIND FULLMENUNUM(2,0,0) -char *menulab[AMI_MENU_AREXX_MAX+1]; +struct gui_window; +struct gui_window_2; -struct NewMenu *ami_create_menu(ULONG type); -void ami_init_menulabs(void); -void ami_free_menulabs(void); +void ami_free_menulabs(struct gui_window_2 *gwin); +struct NewMenu *ami_create_menu(ULONG type, struct gui_window_2 *gwin); +void ami_menu_refresh(struct gui_window_2 *gwin); void ami_menupick(ULONG code,struct gui_window_2 *gwin,struct MenuItem *item); void ami_menu_update_disabled(struct gui_window *g, hlcache_handle *c); #endif diff --git a/amiga/object.c b/amiga/object.c index a51be81c1..93094cbda 100755 --- a/amiga/object.c +++ b/amiga/object.c @@ -48,14 +48,24 @@ struct nsObject *AddObject(struct MinList *objlist,ULONG otype) return(dtzo); } -void DelObject(struct nsObject *dtzo) +void DelObjectInternal(struct nsObject *dtzo, BOOL free_obj) { Remove((struct Node *)dtzo); - if(dtzo->objstruct) FreeVec(dtzo->objstruct); + if(dtzo->objstruct && free_obj) FreeVec(dtzo->objstruct); FreeVec(dtzo); dtzo = NULL; } +void DelObject(struct nsObject *dtzo) +{ + DelObjectInternal(dtzo, TRUE); +} + +void DelObjectNoFree(struct nsObject *dtzo) +{ + DelObjectInternal(dtzo, FALSE); +} + void FreeObjList(struct MinList *objlist) { struct nsObject *node; diff --git a/amiga/object.h b/amiga/object.h index 82d01098d..db7869df8 100755 --- a/amiga/object.h +++ b/amiga/object.h @@ -48,6 +48,7 @@ struct nsObject struct MinList *NewObjList(void); struct nsObject *AddObject(struct MinList *objlist,ULONG otype); void DelObject(struct nsObject *dtzo); +void DelObjectNoFree(struct nsObject *dtzo); void FreeObjList(struct MinList *objlist); #endif diff --git a/amiga/options.h b/amiga/options.h index 7e4e6cc15..f32938969 100644 --- a/amiga/options.h +++ b/amiga/options.h @@ -34,7 +34,6 @@ extern bool option_truecolour_mouse_pointers; extern bool option_use_os_pointers; extern bool option_new_tab_active; extern bool option_kiosk_mode; -extern char *option_recent_file; extern char *option_search_engines_file; extern char *option_search_ico_file; extern char *option_arexx_dir; @@ -68,7 +67,6 @@ bool option_truecolour_mouse_pointers = false; \ bool option_use_os_pointers = true; \ bool option_new_tab_active = false; \ bool option_kiosk_mode = false; \ -char *option_recent_file = 0; \ char *option_search_engines_file = 0; \ char *option_search_ico_file = 0; \ char *option_arexx_dir = 0; \ @@ -102,7 +100,6 @@ bool option_drag_save_icons = true; \ { "os_mouse_pointers", OPTION_BOOL, &option_use_os_pointers}, \ { "new_tab_is_active", OPTION_BOOL, &option_new_tab_active}, \ { "kiosk_mode", OPTION_BOOL, &option_kiosk_mode}, \ -{ "recent_file", OPTION_STRING, &option_recent_file }, \ { "search_engines_file", OPTION_STRING, &option_search_engines_file }, \ { "search_ico_file", OPTION_STRING, &option_search_ico_file }, \ { "arexx_dir", OPTION_STRING, &option_arexx_dir }, \ diff --git a/amiga/plotters.c b/amiga/plotters.c index de60b9518..5bd34d2bc 100755 --- a/amiga/plotters.c +++ b/amiga/plotters.c @@ -91,7 +91,7 @@ void ami_cairo_set_colour(cairo_t *cr,colour c) void ami_cairo_set_solid(cairo_t *cr) { double dashes = 0; - + cairo_set_dash(glob->cr, &dashes, 0, 0); } @@ -240,7 +240,7 @@ bool ami_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style) glob->rp.LinePtrn = PATT_DASH; break; } - + SetRPAttrs(&glob->rp, RPTAG_APenColor, p96EncodeColor(RGBFB_A8B8G8R8, style->stroke_colour), @@ -272,7 +272,7 @@ bool ami_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style) break; } - if (style->stroke_width == 0) + if (style->stroke_width == 0) cairo_set_line_width(glob->cr, 1); else cairo_set_line_width(glob->cr, style->stroke_width); @@ -337,13 +337,17 @@ bool ami_line(int x0, int y0, int x1, int y1, const plot_style_t *style) break; } - if (style->stroke_width == 0) + if (style->stroke_width == 0) cairo_set_line_width(glob->cr, 1); else cairo_set_line_width(glob->cr, style->stroke_width); - cairo_move_to(glob->cr, x0 + 0.5, y0 + 0.5); - cairo_line_to(glob->cr, x1 + 0.5, y1 + 0.5); + /* core expects horizontal and vertical lines to be on pixels, not + * between pixels */ + cairo_move_to(current_cr, (x0 == x1) ? x0 + 0.5 : x0, + (y0 == y1) ? y0 + 0.5 : y0); + cairo_line_to(current_cr, (x0 == x1) ? x1 + 0.5 : x1, + (y0 == y1) ? y1 + 0.5 : y1); cairo_stroke(glob->cr); #endif return true; @@ -426,7 +430,7 @@ bool ami_clip(int x0, int y0, int x1, int y1) return true; } -bool ami_text(int x, int y, const char *text, size_t length, +bool ami_text(int x, int y, const char *text, size_t length, const plot_font_style_t *fstyle) { #ifdef AMI_PLOTTER_DEBUG @@ -459,7 +463,7 @@ bool ami_disc(int x, int y, int radius, const plot_style_t *style) p96EncodeColor(RGBFB_A8B8G8R8, style->stroke_colour), TAG_DONE); - DrawEllipse(&glob->rp,x,y,radius,radius); + DrawEllipse(&glob->rp,x,y,radius,radius); } #else if (style->fill_type != PLOT_OP_TYPE_NONE) { diff --git a/amiga/resources/Themes/AISS/Theme b/amiga/resources/Themes/AISS/Theme index 8f3dd8aec..8dfa1d3a7 100755 --- a/amiga/resources/Themes/AISS/Theme +++ b/amiga/resources/Themes/AISS/Theme @@ -24,12 +24,8 @@ theme_closetab_g:*TBImages:list_cancel theme_addtab:*TBImages:list_add theme_addtab_s:*TBImages:list_add theme_addtab_g:*TBImages:list_add -theme_list_folder_closed:*TBImages:list_folderfold -theme_list_folder_open:*TBImages:list_folderunfold -theme_list_bookmark:*TBImages:list_bookmark -theme_list_cookie:*TBImages:list_abstract -theme_list_history:*TBImages:list_archive -theme_list_sslcert:*TBImages:list_crypt +theme_list_folder:*TBImages:list_drawer +theme_list_content:*TBImages:list_abstract theme_throbber:Throbber theme_throbber_frames:13 theme_throbber_delay:100 diff --git a/amiga/resources/Themes/Default/Theme b/amiga/resources/Themes/Default/Theme index eb6b9c3ce..2497af467 100755 --- a/amiga/resources/Themes/Default/Theme +++ b/amiga/resources/Themes/Default/Theme @@ -37,12 +37,8 @@ theme_closetab_g:closetab_g.png theme_addtab: theme_addtab_s: theme_addtab_g: -theme_list_folder_closed: -theme_list_folder_open: -theme_list_bookmark: -theme_list_cookie: -theme_list_history: -theme_list_sslcert: +theme_list_folder:directory.png +theme_list_content:content.png theme_throbber:Throbber theme_throbber_frames:9 theme_throbber_delay:100 diff --git a/amiga/resources/Themes/Default/content.png b/amiga/resources/Themes/Default/content.png new file mode 120000 index 000000000..4b8c13c1c --- /dev/null +++ b/amiga/resources/Themes/Default/content.png @@ -0,0 +1 @@ +../../../../!NetSurf/Resources/Icons/content.png \ No newline at end of file diff --git a/amiga/resources/Themes/Default/directory.png b/amiga/resources/Themes/Default/directory.png new file mode 120000 index 000000000..0e6ce854d --- /dev/null +++ b/amiga/resources/Themes/Default/directory.png @@ -0,0 +1 @@ +../../../../!NetSurf/Resources/Icons/directory.png \ No newline at end of file diff --git a/amiga/sslcert.c b/amiga/sslcert.c index c02329449..8eede70f2 100644 --- a/amiga/sslcert.c +++ b/amiga/sslcert.c @@ -16,224 +16,28 @@ * along with this program. If not, see . */ -#include -#include -#include #include -#include -#include "utils/errors.h" -#include "utils/utils.h" -#include "utils/messages.h" -#include "content/urldb.h" -#include "content/fetch.h" -#include "desktop/tree.h" #include "amiga/tree.h" -#include "amiga/gui.h" - -struct session_data { - struct session_cert *certs; - unsigned long num; - nserror (*cb)(bool proceed, void *pw); - void *cbpw; - char *url; - struct tree *tree; -}; -struct session_cert { - char version[16], valid_from[32], valid_to[32], type[8], serial[32]; - char *issuer_t; - char *subject_t; - uintptr_t issuer; - uintptr_t subject; -}; - -void ami_gui_cert_close(struct session_data *data); -bool ami_gui_cert_apply(struct session_data *session); +#include "amiga/sslcert.h" void gui_cert_verify(const char *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw) { - const struct ssl_cert_info *from; - struct session_cert *to; - struct session_data *data; - struct tree *tree; - struct node *node; - long i; - STRPTR yesorno,reqcontents; - int res = 0; - struct treeview_window *twin; + struct sslcert_session_data *data; + struct treeview_window *ssl_window; - assert(certs); + data = sslcert_create_session_data(num, url, cb, cbpw); - /* copy the certificate information */ - data = calloc(1, sizeof(struct session_data)); - if (!data) { - warn_user("NoMemory", 0); - return; - } - data->url = strdup(url); - if (!data->url) { - free(data); - warn_user("NoMemory", 0); - return; - } - data->cb = cb; - data->cbpw = cbpw; - data->num = num; - data->certs = calloc(num, sizeof(struct session_cert)); - if (!data->certs) { - free(data->url); - free(data); - warn_user("NoMemory", 0); - return; - } - for (i = 0; i < (long)num; i++) { - to = &data->certs[i]; - from = &certs[i]; - to->subject_t = strdup(from->subject); - to->issuer_t = strdup(from->issuer); - if ((!to->subject_t) || (!to->issuer_t)) { - for (; i >= 0; i--) { - to = &data->certs[i]; - free(to->subject_t); - free(to->issuer_t); - } - free(data->certs); - free(data->url); - free(data); - warn_user("NoMemory", 0); - return; - } - snprintf(to->version, sizeof data->certs->version, "%ld", - from->version); - snprintf(to->valid_from, sizeof data->certs->valid_from, "%s", - from->not_before); - snprintf(to->type, sizeof data->certs->type, "%d", - from->cert_type); - snprintf(to->valid_to, sizeof data->certs->valid_to, "%s", - from->not_after); - snprintf(to->serial, sizeof data->certs->serial, "%ld", - from->serial); - } + ssl_window = ami_tree_create(sslcert_get_tree_flags(), data); + if(!ssl_window) return; - tree = calloc(sizeof(struct tree), 1); - if (!tree) { - //ro_gui_cert_close(ssl_w); - warn_user("NoMemory", 0); - return; - } - tree->root = tree_create_folder_node(NULL, "Root"); - if (!tree->root) { -// ro_gui_cert_close(ssl_w); - warn_user("NoMemory", 0); - free(tree); - tree = NULL; - return; - } - tree->root->expanded = true; - tree->handle = 0; - tree->movable = false; - tree->no_drag = true; - tree->no_vscroll = true; - tree->no_furniture = true; - tree->single_selection = true; - data->tree = tree; - - /* put the SSL names in the tree */ - for (i = 0; i < (long)num; i++) { - node = tree_create_leaf_node(tree->root, certs[i].subject); - if (node) { - node->data.data = TREE_ELEMENT_SSL; - tree_set_node_sprite(node, "small_xxx", "small_xxx"); - } - } - tree_initialise(tree); - - ami_open_tree(tree,AMI_TREE_SSLCERT); - twin = (struct treeview_window *)data->tree->handle; - - if(yesorno = ASPrintf("%s|%s",messages_get("Accept"),messages_get("Reject"))) - { - if(reqcontents = ASPrintf("%s\n\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s", - messages_get("SSLError"), - messages_get("Subject"), - to->subject_t, - messages_get("Issuer"), - to->issuer_t, - messages_get("Version"), - to->version, - messages_get("ValidFrom"), - to->valid_from, - messages_get("ValidTo"), - to->valid_to)) - { - res = TimedDosRequesterTags(TDR_ImageType,TDRIMAGE_QUESTION, - TDR_Window,twin->win, - TDR_TitleString,messages_get("NetSurf"), - TDR_GadgetString,yesorno, - TDR_FormatString,reqcontents, - TAG_DONE); - - FreeVec(reqcontents); - } - - FreeVec(yesorno); - } - - if(res == 1) - { - ami_gui_cert_apply(data); - } - ami_gui_cert_close(data); + sslcert_load_tree(ami_tree_get_tree(ssl_window), certs, data); + ami_tree_open(ssl_window, AMI_TREE_SSLCERT); } -void ami_gui_cert_close(struct session_data *data) +void ami_ssl_free(struct treeview_window *twin) { - unsigned long i; - - if(data->tree->handle) - { - ami_tree_close((struct treeview_window *)data->tree->handle); - win_destroyed = true; - } - - assert(data); - -/* - for (i = 0; i < data->num; i++) { - if (data->certs[i].subject) - textarea_destroy(data->certs[i].subject); - if (data->certs[i].issuer) - textarea_destroy(data->certs[i].issuer); - } -*/ - - /* Send failure if callback exists */ - if (data->cb != NULL) - data->cb(false, data->cbpw); - - if (data->tree) { - tree_delete_node(data->tree, data->tree->root, false); - free(data->tree); - } - - free(data->certs); - free(data->url); - free(data); -} - -bool ami_gui_cert_apply(struct session_data *session) -{ - assert(session); - - urldb_set_cert_permissions(session->url, true); - - session->cb(true, session->cbpw); - - /* Invalidate callback */ - session->cb = NULL; - session->cbpw = NULL; - - return true; + ami_tree_destroy(twin); } diff --git a/windows/hotlist.c b/amiga/sslcert.h similarity index 76% rename from windows/hotlist.c rename to amiga/sslcert.h index dab18d11c..10078d9bb 100644 --- a/windows/hotlist.c +++ b/amiga/sslcert.h @@ -1,5 +1,5 @@ /* - * Copyright 2008 Vincent Sanders + * Copyright 2009 Chris Young * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -16,9 +16,9 @@ * along with this program. If not, see . */ -#include "desktop/browser.h" -#include "content/hlcache.h" +#ifndef AMIGA_SSLCERT_H +#define AMIGA_SSLCERT_H +#include "desktop/sslcert.h" -void hotlist_visited(hlcache_handle *content) -{ -} +void ami_ssl_free(struct treeview_window *twin); +#endif diff --git a/amiga/theme.c b/amiga/theme.c index cf9148581..7b10e139b 100644 --- a/amiga/theme.c +++ b/amiga/theme.c @@ -121,7 +121,7 @@ void ami_theme_throbber_setup(void) char throbberfile[1024]; Object *dto; - ami_get_theme_filename(throbberfile,"theme_throbber"); + ami_get_theme_filename(throbberfile,"theme_throbber",false); throbber_frames=atoi(messages_get("theme_throbber_frames")); throbber_update_interval = atoi(messages_get("theme_throbber_delay")); if(throbber_update_interval == 0) throbber_update_interval = 100; @@ -170,15 +170,20 @@ void ami_theme_throbber_free(void) p96FreeBitMap(throbber); } -void ami_get_theme_filename(char *filename, char *themestring) +void ami_get_theme_filename(char *filename, char *themestring, bool protocol) { + if(protocol) + strcpy(filename,"file:///"); + else + strcpy(filename,""); + if(messages_get(themestring)[0] == '*') { - strncpy(filename, messages_get(themestring) + 1, 100); + strncat(filename,messages_get(themestring)+1,100); } else { - strcpy(filename, option_theme); + strcat(filename, option_theme); AddPart(filename, messages_get(themestring), 100); } } @@ -273,7 +278,7 @@ void ami_init_mouse_pointers(void) if(option_truecolour_mouse_pointers) { - ami_get_theme_filename(&ptrfname,ptrs32[i]); + ami_get_theme_filename(&ptrfname,ptrs32[i], false); if(dobj = GetIconTags(ptrfname,ICONGETA_UseFriendBitMap,TRUE,TAG_DONE)) { if(IconControl(dobj, ICONCTRLA_GetImageDataFormat, &format, TAG_DONE)) @@ -325,7 +330,7 @@ void ami_init_mouse_pointers(void) if(!mouseptrobj[i]) { - ami_get_theme_filename(ptrfname,ptrs[i]); + ami_get_theme_filename(ptrfname,ptrs[i], false); if(ptrfile = Open(ptrfname,MODE_OLDFILE)) { int mx,my; diff --git a/amiga/theme.h b/amiga/theme.h index 3a396fdb1..ba1295d61 100644 --- a/amiga/theme.h +++ b/amiga/theme.h @@ -27,7 +27,7 @@ ULONG throbber_width, throbber_height; void ami_theme_init(void); -void ami_get_theme_filename(char *filename, char *themestring); +void ami_get_theme_filename(char *filename, char *themestring, bool protocol); void ami_theme_throbber_setup(void); void ami_theme_throbber_free(void); diff --git a/amiga/tree.c b/amiga/tree.c index 7000fb76c..f01805314 100755 --- a/amiga/tree.c +++ b/amiga/tree.c @@ -1,5 +1,5 @@ /* - * Copyright 2008,2009 Chris Young + * Copyright 2008, 2009 Chris Young * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -16,13 +16,16 @@ * along with this program. If not, see . */ -#include "desktop/tree.h" -#include #include #include +#include +#include +#include #include -#include +#include +#include #include +#include #include #include "amiga/gui.h" #include "content/urldb.h" @@ -36,222 +39,395 @@ #include "utils/messages.h" #include #include +#include +#include +#include +#include +#include +#include +#include "amiga/utf8.h" +#include "desktop/cookies.h" +#include "desktop/history_global_core.h" +#include "desktop/hotlist.h" +#include "amiga/sslcert.h" +#include "utils/utils.h" -struct Node *selectednode; -struct node *selectednode2; +#define AMI_TREE_MENU_ITEMS 19 -void ami_add_elements(struct treeview_window *twin,struct node *root,WORD *gen); -bool ami_tree_launch_node(struct tree *tree, struct node *node); -void free_browserlist(struct List *list); -void ami_move_node(struct treeview_window *twin,int move); -void ami_new_bookmark(struct treeview_window *twin); -void ami_recreate_listbrowser(struct treeview_window *twin); +struct treeview_window { + struct Window *win; + Object *objects[OID_LAST]; + struct Gadget *gadgets[GID_LAST]; + struct nsObject *node; + ULONG pad[5]; + int type; + struct NewMenu *menu; + char *menu_name[AMI_TREE_MENU_ITEMS]; + struct tree *tree; + struct Hook scrollerhook; + uint32 key_state; + uint32 mouse_state; + int drag_x; + int drag_y; + struct timeval lastclick; + int max_width; + int max_height; + struct gui_globals globals; + struct sslcert_session_data *ssl_data; +}; -void tree_initialise_redraw(struct tree *tree) -{ -} +void ami_tree_draw(struct treeview_window *twin); +static void ami_tree_redraw_request(int x, int y, int width, int height, + void *data); +static void ami_tree_resized(struct tree *tree, int width, + int height, void *data); +static void ami_tree_scroll_visible(int y, int height, void *data); +static void ami_tree_get_window_dimensions(int *width, int *height, void *data); -void tree_redraw_area(struct tree *tree, int x, int y, int width, int height) -{ -} +const struct treeview_table ami_tree_callbacks = { + .redraw_request = ami_tree_redraw_request, + .resized = ami_tree_resized, + .scroll_visible = ami_tree_scroll_visible, + .get_window_dimensions = ami_tree_get_window_dimensions +}; -void tree_draw_line(int x, int y, int width, int height) -{ -} - -void tree_draw_node_element(struct tree *tree, struct node_element *element) -{ - return; -#if 0 -/* add element to listbrowser list */ - - struct Node *lbnode; - struct treeview_window *twin = tree->handle; - struct node *tempnode; - int generation=1; - BOOL edit = FALSE; - - tempnode = element->parent; - edit = tempnode->editable; - - while(tempnode) - { - tempnode = tempnode->parent; - generation++; - } - - switch (element->type) { - case NODE_ELEMENT_TEXT_PLUS_SPRITE: - case NODE_ELEMENT_TEXT: - if (lbnode = AllocListBrowserNode(3, -// LBNA_UserData,nodetime, - LBNA_Generation,1, - LBNA_Column, 0, - LBNCA_CopyText,TRUE, - LBNCA_Text, element->text, - LBNCA_Editable,edit, - LBNA_Column, 1, - LBNCA_CopyText,TRUE, - LBNCA_Text, "", - LBNA_Column, 2, - LBNCA_CopyText,TRUE, - LBNCA_Text, "", - TAG_DONE)) - { - AddTail(twin->listbrowser_list, lbnode); - } - break; - } -#endif -} - -void tree_draw_node_expansion(struct tree *tree, struct node *node) -{ - DebugPrintF("tree_draw_node_expansion\n"); -} - -void tree_recalculate_node_element(struct node_element *element) -{ -} - -void tree_update_URL_node(struct node *node, const char *url, - const struct url_data *data) -{ - struct node_element *element; - char buffer[256]; - - assert(node); - - element = tree_find_element(node, TREE_ELEMENT_URL); - - if (!element) - return; - if (data) { - /* node is linked, update */ - assert(!node->editable); - if (!data->title) - urldb_set_url_title(url, url); - - if (!data->title) - return; - - node->data.text = data->title; - } else { - /* node is not linked, find data */ - assert(node->editable); - data = urldb_get_url_data(element->text); - if (!data) - return; - } - -/* not implemented yet - if (element) { - sprintf(buffer, "small_%.3x", ro_content_filetype_from_type(data->type)); - if (ro_gui_wimp_sprite_exists(buffer)) - tree_set_node_sprite(node, buffer, buffer); - else - tree_set_node_sprite(node, "small_xxx", "small_xxx"); - } -*/ - - element = tree_find_element(node, TREE_ELEMENT_LAST_VISIT); - if (element) { - snprintf(buffer, 256, (char *)messages_get("TreeLast"), - (data->last_visit > 0) ? - ctime((time_t *)&data->last_visit) : - (char *)messages_get("TreeUnknown")); - if (data->last_visit > 0) - buffer[strlen(buffer) - 1] = '\0'; - free((void *)element->text); - element->text = (char *)strdup(buffer); - } - - element = tree_find_element(node, TREE_ELEMENT_VISITS); - if (element) { - snprintf(buffer, 256, (char *)messages_get("TreeVisits"), - data->visits); - free((void *)element->text); - element->text = (char *)strdup(buffer); - } -} - -void tree_resized(struct tree *tree) -{ -} - -void tree_set_node_sprite_folder(struct node *node) -{ -} - -void tree_set_node_sprite(struct node *node, const char *sprite, - const char *expanded) -{ -} - -void ami_open_tree(struct tree *tree,int type) +struct treeview_window *ami_tree_create(uint8 flags, + struct sslcert_session_data *ssl_data) { struct treeview_window *twin; + + twin = AllocVec(sizeof(struct treeview_window), + MEMF_PRIVATE | MEMF_CLEAR); + + if(!twin) + { + warn_user("NoMemory", 0); + return NULL; + } + + twin->ssl_data = ssl_data; + + twin->tree = tree_create(flags, &ami_tree_callbacks, twin); + return twin; +} + +void ami_tree_destroy(struct treeview_window *twin) +{ + tree_delete(twin->tree); + FreeVec(twin); +} + +struct tree *ami_tree_get_tree(struct treeview_window *twin) +{ + return twin->tree; +} + +void ami_tree_resized(struct tree *tree, int width, int height, void *data) +{ + struct treeview_window *twin = data; + struct IBox *bbox; + + twin->max_height = height; + twin->max_width = width; + + if(twin->win) + { + GetAttr(SPACE_AreaBox,twin->gadgets[GID_BROWSER],(ULONG *)&bbox); + + RefreshSetGadgetAttrs((APTR)twin->objects[OID_VSCROLL], twin->win, NULL, + SCROLLER_Total, height, + SCROLLER_Visible, bbox->Height, + TAG_DONE); + + RefreshSetGadgetAttrs((APTR)twin->objects[OID_HSCROLL], twin->win, NULL, + SCROLLER_Total, width, + SCROLLER_Visible, bbox->Width, + TAG_DONE); + } +} + +/** + * Retrieves the dimensions of the window with the tree + * + * \param data user data assigned to the tree on tree creation + * \param width will be updated to window width if not NULL + * \param height will be updated to window height if not NULL + */ +void ami_tree_get_window_dimensions(int *width, int *height, void *data) +{ + struct treeview_window *twin = data; + struct IBox *bbox; + + GetAttr(SPACE_AreaBox,twin->gadgets[GID_BROWSER],(ULONG *)&bbox); + + if(width) *width = bbox->Width; + if(height) *height = bbox->Height; +} + +/** + * Translates a content_type to the name of a respective icon + * + * \param content_type content type + * \param buffer buffer for the icon name + */ +void tree_icon_name_from_content_type(char *buffer, content_type type) +{ + // TODO: design/acquire icons + switch (type) { + case CONTENT_HTML: + case CONTENT_TEXTPLAIN: + case CONTENT_CSS: +#if defined(WITH_MNG) || defined(WITH_PNG) + case CONTENT_PNG: +#endif +#ifdef WITH_MNG + case CONTENT_JNG: + case CONTENT_MNG: +#endif +#ifdef WITH_JPEG + case CONTENT_JPEG: +#endif +#ifdef WITH_GIF + case CONTENT_GIF: +#endif +#ifdef WITH_BMP + case CONTENT_BMP: + case CONTENT_ICO: +#endif +#ifdef WITH_NSSPRITE + case CONTENT_SPRITE: +#endif +#ifdef WITH_NS_SVG + case CONTENT_SVG: +#endif + default: + ami_get_theme_filename(buffer,"theme_list_content",true); + break; + } +} + +/** + * Scrolls the tree to make an element visible + * + * \param y Y coordinate of the element + * \param height height of the element + * \param data user data assigned to the tree on tree creation + */ +void ami_tree_scroll_visible(int y, int height, void *data) +{ + ULONG sy, scrollset; + struct IBox *bbox; + struct treeview_window *twin = data; + + GetAttr(SCROLLER_Top, twin->objects[OID_VSCROLL], (ULONG *)&sy); + GetAttr(SPACE_AreaBox,twin->gadgets[GID_BROWSER],(ULONG *)&bbox); + + if((y > sy) && ((y + height) < (sy + bbox->Height))) return; + + if((y <= sy) || (height > bbox->Height)) scrollset = (ULONG)y; + else scrollset = sy + (y + height) - (sy + bbox->Height); + + RefreshSetGadgetAttrs((APTR)twin->objects[OID_VSCROLL], twin->win, NULL, + SCROLLER_Top, scrollset, + TAG_DONE); + + ami_tree_draw(twin); +} + +void ami_tree_scroll(struct treeview_window *twin, int sx, int sy) +{ + int x, y; + + if(!twin) return; + if(sx<0) sx=0; + if(sy<0) sy=0; + + GetAttr(SCROLLER_Top, twin->objects[OID_HSCROLL], (ULONG *)&x); + GetAttr(SCROLLER_Top, twin->objects[OID_VSCROLL], (ULONG *)&y); + + RefreshSetGadgetAttrs((APTR)twin->objects[OID_VSCROLL], twin->win, NULL, + SCROLLER_Top, y + sy, + TAG_DONE); + + RefreshSetGadgetAttrs((APTR)twin->objects[OID_HSCROLL], twin->win, NULL, + SCROLLER_Top, x + sx, + TAG_DONE); + + ami_tree_draw(twin); +} + + +void ami_tree_scroller_hook(struct Hook *hook,Object *object,struct IntuiMessage *msg) +{ + ULONG gid,x,y; + struct treeview_window *twin = hook->h_Data; + struct IntuiWheelData *wheel; + + switch(msg->Class) + { + case IDCMP_IDCMPUPDATE: + gid = GetTagData( GA_ID, 0, msg->IAddress ); + + switch( gid ) + { + case OID_HSCROLL: + case OID_VSCROLL: + ami_tree_draw(twin); + break; + } + break; + + case IDCMP_EXTENDEDMOUSE: + if(msg->Code == IMSGCODE_INTUIWHEELDATA) + { + wheel = (struct IntuiWheelData *)msg->IAddress; + + ami_tree_scroll(twin, (wheel->WheelX * 20), (wheel->WheelY * 20)); + } + break; + } +} + +void ami_tree_menu(struct treeview_window *twin) +{ + if(twin->menu) return; + + if(twin->menu = AllocVec(sizeof(struct NewMenu) * AMI_TREE_MENU_ITEMS, MEMF_CLEAR)) + { + twin->menu[0].nm_Type = NM_TITLE; + twin->menu_name[0] = ami_utf8_easy((char *)messages_get("Tree")); + twin->menu[0].nm_Label = twin->menu_name[0]; + + twin->menu[1].nm_Type = NM_ITEM; + twin->menu_name[1] = ami_utf8_easy((char *)messages_get("TreeExport")); + twin->menu[1].nm_Label = twin->menu_name[1]; + if(twin->type == AMI_TREE_COOKIES) + twin->menu[1].nm_Flags = NM_ITEMDISABLED; + twin->menu[1].nm_CommKey = "S"; + + twin->menu[2].nm_Type = NM_ITEM; + twin->menu[2].nm_Label = NM_BARLABEL; + + twin->menu[3].nm_Type = NM_ITEM; + twin->menu_name[3] = ami_utf8_easy((char *)messages_get("Expand")); + twin->menu[3].nm_Label = twin->menu_name[3]; + + twin->menu[4].nm_Type = NM_SUB; + twin->menu_name[4] = ami_utf8_easy((char *)messages_get("All")); + twin->menu[4].nm_Label = twin->menu_name[4]; + twin->menu[4].nm_CommKey = "+"; + + if(twin->type == AMI_TREE_COOKIES) + { + twin->menu_name[5] = ami_utf8_easy((char *)messages_get("Domains")); + twin->menu_name[6] = ami_utf8_easy((char *)messages_get("Cookies")); + } + else + { + twin->menu_name[5] = ami_utf8_easy((char *)messages_get("Folders")); + twin->menu_name[6] = ami_utf8_easy((char *)messages_get("Links")); + } + + twin->menu[5].nm_Type = NM_SUB; + twin->menu[5].nm_Label = twin->menu_name[5]; // tree-specific title + + twin->menu[6].nm_Type = NM_SUB; + twin->menu[6].nm_Label = twin->menu_name[6]; // tree-specific title + + twin->menu[7].nm_Type = NM_ITEM; + twin->menu_name[7] = ami_utf8_easy((char *)messages_get("Collapse")); + twin->menu[7].nm_Label = twin->menu_name[7]; + + twin->menu[8].nm_Type = NM_SUB; + twin->menu[8].nm_Label = twin->menu_name[4]; + twin->menu[8].nm_CommKey = "-"; + + twin->menu[9].nm_Type = NM_SUB; + twin->menu[9].nm_Label = twin->menu_name[5]; // tree-specific title + + twin->menu[10].nm_Type = NM_SUB; + twin->menu[10].nm_Label = twin->menu_name[6]; // tree-specific title + + twin->menu[11].nm_Type = NM_ITEM; + twin->menu[11].nm_Label = NM_BARLABEL; + + twin->menu[12].nm_Type = NM_ITEM; + twin->menu_name[12] = ami_utf8_easy((char *)messages_get("CloseWindow")); + twin->menu[12].nm_Label = twin->menu_name[12]; + twin->menu[12].nm_CommKey = "K"; + + twin->menu[13].nm_Type = NM_TITLE; + twin->menu_name[13] = ami_utf8_easy((char *)messages_get("Edit")); + twin->menu[13].nm_Label = twin->menu_name[13]; + + twin->menu[14].nm_Type = NM_ITEM; + twin->menu_name[14] = ami_utf8_easy((char *)messages_get("TreeDelete")); + twin->menu[14].nm_Label = twin->menu_name[14]; + twin->menu[14].nm_CommKey = "D"; + + twin->menu[15].nm_Type = NM_ITEM; + twin->menu[15].nm_Label = NM_BARLABEL; + + twin->menu[16].nm_Type = NM_ITEM; + twin->menu_name[16] = ami_utf8_easy((char *)messages_get("SelectAllNS")); + twin->menu[16].nm_Label = twin->menu_name[16]; + twin->menu[16].nm_CommKey = "A"; + + twin->menu[17].nm_Type = NM_ITEM; + twin->menu_name[17] = ami_utf8_easy((char *)messages_get("ClearNS")); + twin->menu[17].nm_Label = twin->menu_name[17]; + twin->menu[17].nm_CommKey = "Z"; + + twin->menu[18].nm_Type = NM_END; + } +} + +void ami_tree_open(struct treeview_window *twin,int type) +{ BOOL msel = TRUE,nothl = TRUE,launchdisable=FALSE; static WORD gen=0; char *wintitle; char folderclosed[100],folderopen[100],item[100]; - if(tree->handle) + if(twin->win) { - twin = (struct treeview_window *)tree->handle; WindowToFront(twin->win); ActivateWindow(twin->win); return; } - twin = AllocVec(sizeof(struct treeview_window),MEMF_PRIVATE | MEMF_CLEAR); - twin->listbrowser_list = AllocVec(sizeof(struct List),MEMF_PRIVATE | MEMF_CLEAR); + twin->type = type; - static struct ColumnInfo columninfo[] = - { - { 80,"Name", CIF_DRAGGABLE | CIF_SORTABLE}, - { 20,"URL", CIF_DRAGGABLE }, -// { 5,"Visits", CIF_DRAGGABLE }, - { -1, (STRPTR)~0, -1 } - }; - - if(tree->single_selection) msel = FALSE; - - ami_get_theme_filename(&folderclosed,"theme_list_folder_closed"); - ami_get_theme_filename(&folderopen,"theme_list_folder_open"); - - switch(type) + switch(twin->type) { case AMI_TREE_HOTLIST: nothl = FALSE; wintitle = (char *)messages_get("Hotlist"); - ami_get_theme_filename(&item,"theme_list_bookmark"); break; case AMI_TREE_COOKIES: nothl = TRUE; launchdisable=TRUE; wintitle = (char *)messages_get("Cookies"); - ami_get_theme_filename(&item,"theme_list_cookie"); break; case AMI_TREE_HISTORY: nothl = TRUE; wintitle = (char *)messages_get("GlobalHistory"); - ami_get_theme_filename(&item,"theme_list_history"); break; case AMI_TREE_SSLCERT: nothl = TRUE; wintitle = (char *)messages_get("SSLCerts"); - ami_get_theme_filename(&item,"theme_list_sslcert"); break; } - NewList(twin->listbrowser_list); + twin->scrollerhook.h_Entry = (void *)ami_tree_scroller_hook; + twin->scrollerhook.h_Data = twin; - tree->handle = (void *)twin; - twin->tree = tree; - ami_add_elements(twin,twin->tree->root,&gen); + ami_init_layers(&twin->globals, scrn->Width, scrn->Height); + ami_tree_menu(twin); - twin->objects[OID_MAIN] = WindowObject, + if(type == AMI_TREE_SSLCERT) + { + twin->objects[OID_MAIN] = WindowObject, WA_ScreenTitle,nsscreentitle, WA_Title,wintitle, WA_Activate, TRUE, @@ -259,43 +435,77 @@ void ami_open_tree(struct tree *tree,int type) WA_DragBar, TRUE, WA_CloseGadget, TRUE, WA_SizeGadget, TRUE, + WA_Height, scrn->Height / 2, WA_CustomScreen,scrn, + WA_ReportMouse,TRUE, + WA_IDCMP,IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS | IDCMP_NEWSIZE | + IDCMP_RAWKEY | IDCMP_GADGETUP | IDCMP_IDCMPUPDATE | + IDCMP_EXTENDEDMOUSE, + WINDOW_HorizProp,1, + WINDOW_VertProp,1, + WINDOW_IDCMPHook,&twin->scrollerhook, + WINDOW_IDCMPHookBits,IDCMP_IDCMPUPDATE | IDCMP_EXTENDEDMOUSE, WINDOW_SharedPort,sport, WINDOW_UserData,twin, - WINDOW_IconifyGadget, TRUE, + /* WINDOW_NewMenu, twin->menu, -> No menu for SSL Cert */ + WINDOW_IconifyGadget, FALSE, WINDOW_Position, WPOS_CENTERSCREEN, WINDOW_ParentGroup, twin->gadgets[GID_MAIN] = VGroupObject, - LAYOUT_AddChild, twin->gadgets[GID_TREEBROWSER] = ListBrowserObject, - GA_ID, GID_TREEBROWSER, - GA_RelVerify, TRUE, - GA_ReadOnly,FALSE, - LISTBROWSER_ColumnInfo, &columninfo, -// LISTBROWSER_ColumnTitles, TRUE, - LISTBROWSER_Hierarchical,TRUE, - LISTBROWSER_Editable,TRUE, -// LISTBROWSER_TitleClickable,TRUE, - LISTBROWSER_AutoFit, TRUE, - LISTBROWSER_HorizontalProp, TRUE, - LISTBROWSER_Labels, twin->listbrowser_list, -// LISTBROWSER_MultiSelect,msel, - LISTBROWSER_ShowSelected,TRUE, - LISTBROWSER_ShowImage,BitMapObject, - BITMAP_SourceFile,folderclosed, - BITMAP_Screen,scrn, - BITMAP_Masking,TRUE, - BitMapEnd, - LISTBROWSER_HideImage,BitMapObject, - BITMAP_SourceFile,folderopen, - BITMAP_Screen,scrn, - BITMAP_Masking,TRUE, - BitMapEnd, - LISTBROWSER_LeafImage,BitMapObject, - BITMAP_SourceFile,item, - BITMAP_Screen,scrn, - BITMAP_Masking,TRUE, - BitMapEnd, - ListBrowserEnd, - CHILD_NominalSize,TRUE, + LAYOUT_AddImage, LabelObject, + LABEL_Text, messages_get("SSLError"), + LabelEnd, + LAYOUT_AddChild, twin->gadgets[GID_BROWSER] = SpaceObject, + GA_ID, GID_BROWSER, + SPACE_Transparent,TRUE, + SPACE_BevelStyle, BVS_DISPLAY, + SpaceEnd, + LAYOUT_AddChild, HGroupObject, + LAYOUT_AddChild, twin->gadgets[GID_OPEN] = ButtonObject, + GA_ID,GID_OPEN, + GA_Text,messages_get("Accept"), + GA_RelVerify,TRUE, + ButtonEnd, + LAYOUT_AddChild, twin->gadgets[GID_CANCEL] = ButtonObject, + GA_ID,GID_CANCEL, + GA_Text,messages_get("Reject"), + GA_RelVerify,TRUE, + ButtonEnd, + EndGroup, + CHILD_WeightedHeight,0, + EndGroup, + EndWindow; + } + else + { + twin->objects[OID_MAIN] = WindowObject, + WA_ScreenTitle,nsscreentitle, + WA_Title,wintitle, + WA_Activate, TRUE, + WA_DepthGadget, TRUE, + WA_DragBar, TRUE, + WA_CloseGadget, TRUE, + WA_SizeGadget, TRUE, + WA_Height, scrn->Height / 2, + WA_CustomScreen,scrn, + WA_ReportMouse,TRUE, + WA_IDCMP,IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS | IDCMP_NEWSIZE | + IDCMP_RAWKEY | IDCMP_GADGETUP | IDCMP_IDCMPUPDATE | + IDCMP_EXTENDEDMOUSE, + WINDOW_HorizProp,1, + WINDOW_VertProp,1, + WINDOW_IDCMPHook,&twin->scrollerhook, + WINDOW_IDCMPHookBits,IDCMP_IDCMPUPDATE | IDCMP_EXTENDEDMOUSE, + WINDOW_SharedPort,sport, + WINDOW_UserData,twin, + WINDOW_NewMenu, twin->menu, + WINDOW_IconifyGadget, FALSE, + WINDOW_Position, WPOS_CENTERSCREEN, + WINDOW_ParentGroup, twin->gadgets[GID_MAIN] = VGroupObject, + LAYOUT_AddChild, twin->gadgets[GID_BROWSER] = SpaceObject, + GA_ID, GID_BROWSER, + SPACE_Transparent,TRUE, + SPACE_BevelStyle, BVS_DISPLAY, + SpaceEnd, LAYOUT_AddChild, HGroupObject, LAYOUT_AddChild, twin->gadgets[GID_OPEN] = ButtonObject, GA_ID,GID_OPEN, @@ -315,24 +525,6 @@ void ami_open_tree(struct tree *tree,int type) GA_RelVerify,TRUE, GA_Disabled,nothl, ButtonEnd, - LAYOUT_AddChild, twin->gadgets[GID_LEFT] = ButtonObject, - GA_ID,GID_LEFT, - BUTTON_AutoButton,BAG_LFARROW, - GA_RelVerify,TRUE, - GA_Disabled,nothl, //(!tree->movable), - ButtonEnd, - LAYOUT_AddChild, twin->gadgets[GID_UP] = ButtonObject, - GA_ID,GID_UP, - BUTTON_AutoButton,BAG_UPARROW, - GA_RelVerify,TRUE, - GA_Disabled,nothl, //(!tree->movable), - ButtonEnd, - LAYOUT_AddChild, twin->gadgets[GID_DOWN] = ButtonObject, - GA_ID,GID_DOWN, - BUTTON_AutoButton,BAG_DNARROW, - GA_RelVerify,TRUE, - GA_Disabled,nothl, //(!tree->movable), - ButtonEnd, LAYOUT_AddChild, twin->gadgets[GID_DEL] = ButtonObject, GA_ID,GID_DEL, GA_Text,messages_get("TreeDelete"), @@ -342,161 +534,89 @@ void ami_open_tree(struct tree *tree,int type) CHILD_WeightedHeight,0, EndGroup, EndWindow; + } twin->win = (struct Window *)RA_OpenWindow(twin->objects[OID_MAIN]); + GetAttr(WINDOW_HorizObject, twin->objects[OID_MAIN], + (ULONG *)&twin->objects[OID_HSCROLL]); + GetAttr(WINDOW_VertObject, twin->objects[OID_MAIN], + (ULONG *)&twin->objects[OID_VSCROLL]); + + RefreshSetGadgetAttrs((APTR)twin->objects[OID_VSCROLL], twin->win, NULL, + GA_ID,OID_VSCROLL, + ICA_TARGET,ICTARGET_IDCMP, + TAG_DONE); + + RefreshSetGadgetAttrs((APTR)twin->objects[OID_HSCROLL], twin->win, NULL, + GA_ID,OID_HSCROLL, + ICA_TARGET,ICTARGET_IDCMP, + TAG_DONE); + twin->node = AddObject(window_list,AMINS_TVWINDOW); twin->node->objstruct = twin; -} -/** - * Launches a node using all known methods. - * - * \param node the node to launch - * \return whether the node could be launched - */ -bool ami_tree_launch_node(struct tree *tree, struct node *node) -{ - struct node_element *element; - - assert(node); - - element = tree_find_element(node, TREE_ELEMENT_URL); - if (element) { - browser_window_create(element->text, NULL, 0, true, false); - return true; - } - -/* not implemented yet - element = tree_find_element(node, TREE_ELEMENT_SSL); - if (element) { - ro_gui_cert_open(tree, node); - return true; - } -*/ - - return false; + ami_tree_resized(twin->tree, twin->max_width, twin->max_height, twin); + tree_set_redraw(twin->tree, true); + ami_tree_draw(twin); } void ami_tree_close(struct treeview_window *twin) { - twin->tree->handle = 0; + int i; + + tree_set_redraw(twin->tree, false); + twin->win = NULL; DisposeObject(twin->objects[OID_MAIN]); - FreeListBrowserList(twin->listbrowser_list); - FreeVec(twin->listbrowser_list); - //free_browserlist(twin->listbrowser_list); - DelObject(twin->node); -} + DelObjectNoFree(twin->node); + ami_free_layers(&twin->globals); -void free_browserlist(struct List *list) -{ - struct Node *node, *nextnode; - - if(IsListEmpty(list)) return; - - node = GetHead(list); - - do - { - nextnode = GetSucc(node); -// FreeVec(node->ln_Name); - FreeListBrowserNode(node); - } while(node = nextnode); -} - -void ami_add_elements(struct treeview_window *twin,struct node *root,WORD *gen) -{ - struct Node *lbnode; - struct tree *tree = twin->tree; - struct node *tempnode; - int generation=1; - BOOL edit = FALSE; - struct node_element *element=NULL,*element2=NULL,*element3=NULL; - struct node *node; - ULONG flags = 0; - STRPTR text1 = "",text2 = "",text3 = ""; - - *gen = *gen + 1; - for (node = root; node; node = node->next) + for(i=0;itext) - { - text1 = (char *)element->text; - } - -/* Really, the second column needs axing - relevant data should appear in an -area below the listview when items are selected */ - - element2 = tree_find_element(node, TREE_ELEMENT_URL); - if(!element2) element2 = tree_find_element(node, TREE_ELEMENT_VALUE); - if(!element2) element2 = tree_find_element(node, TREE_ELEMENT_COMMENT); - - if(element2 && element2->text) - { - text2 = (char *)element2->text; - } - else - { - text2 = ""; - } - -// element = tree_find_element(node, TREE_ELEMENT_VISITS); - - flags = 0; - /*if(node->expanded) */ flags = LBFLG_SHOWCHILDREN; - if(node->folder) flags |= LBFLG_HASCHILDREN; - if(!node->parent) flags |= LBFLG_HIDDEN; - - switch (element->type) { - case NODE_ELEMENT_TEXT_PLUS_SPRITE: - case NODE_ELEMENT_TEXT: - if (lbnode = AllocListBrowserNode(3, - LBNA_UserData,node, - LBNA_Generation,*gen - 1, - LBNA_Selected,node->selected, - LBNA_Flags,flags, - LBNA_Column, 0, - LBNCA_CopyText,TRUE, - LBNCA_MaxChars,256, - LBNCA_Text, text1, - LBNCA_Editable,node->editable, - LBNA_Column, 1, - LBNCA_CopyText,TRUE, - LBNCA_MaxChars,256, - LBNCA_Text, text2, - LBNCA_Editable,FALSE, - TAG_DONE)) - { - AddTail(twin->listbrowser_list, lbnode); - if(node == selectednode2) selectednode = lbnode; - } - break; - } - - if (node->child) - { - ami_add_elements(twin,node->child,gen); - } + if(twin->menu_name[i] && (twin->menu_name[i] != NM_BARLABEL)) ami_utf8_free(twin->menu_name[i]); + } + FreeVec(twin->menu); + twin->menu = NULL; + if(twin->type == AMI_TREE_SSLCERT) ami_ssl_free(twin); +} + +void ami_tree_update_quals(struct treeview_window *twin) +{ + uint32 quals = 0; + + GetAttr(WINDOW_Qualifier, twin->objects[OID_MAIN], (uint32 *)&quals); + + twin->key_state = 0; + + if((quals & IEQUALIFIER_LSHIFT) || (quals & IEQUALIFIER_RSHIFT)) + { + twin->key_state |= BROWSER_MOUSE_MOD_1; + } + + if(quals & IEQUALIFIER_CONTROL) + { + twin->key_state |= BROWSER_MOUSE_MOD_2; + } + + if((quals & IEQUALIFIER_LALT) || (quals & IEQUALIFIER_RALT)) + { + twin->key_state |= BROWSER_MOUSE_MOD_3; } - *gen = *gen - 1; } BOOL ami_tree_event(struct treeview_window *twin) { /* return TRUE if window destroyed */ - ULONG class,result,relevent = 0; - ULONG column; + ULONG class,result,storage = 0; uint16 code; struct MenuItem *item; - struct node *treenode; - struct Node *lbnode; - struct node_element *element; - char *text; -// ULONG editcols[] = {TREE_ELEMENT_TITLE,TREE_ELEMENT_URL}; - static WORD gen=0; + ULONG menunum=0,itemnum=0,subnum=0; + int xs, ys, x, y; + struct IBox *bbox; + struct timeval curtime; + struct InputEvent *ie; + int nskey; + char fname[1024]; while((result = RA_HandleInput(twin->objects[OID_MAIN],&code)) != WMHI_LASTMSG) { @@ -505,126 +625,386 @@ BOOL ami_tree_event(struct treeview_window *twin) case WMHI_GADGETUP: switch(result & WMHI_GADGETMASK) { - case GID_TREEBROWSER: - GetAttrs(twin->gadgets[GID_TREEBROWSER], - LISTBROWSER_RelEvent,&relevent, - TAG_DONE); - - switch(relevent) + case GID_OPEN: + if(twin->type == AMI_TREE_SSLCERT) { - case LBRE_DOUBLECLICK: - GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode); - GetListBrowserNodeAttrs(lbnode, - LBNA_UserData,(ULONG *)&treenode, - TAG_DONE); - ami_tree_launch_node(twin->tree,treenode); - break; - - case LBRE_EDIT: - GetAttrs(twin->gadgets[GID_TREEBROWSER], - LISTBROWSER_SelectedNode,(ULONG *)&lbnode, -// LISTBROWSER_RelColumn,(ULONG *)&column, - TAG_DONE); - - GetListBrowserNodeAttrs(lbnode, - LBNA_UserData,(ULONG *)&treenode, - TAG_DONE); - - element = tree_find_element(treenode,TREE_ELEMENT_TITLE); - GetListBrowserNodeAttrs(lbnode, - LBNA_Column,column, - LBNCA_Text,(ULONG *)&text, - TAG_DONE); - element->text = (char *)strdup(text); - tree_handle_node_element_changed(twin->tree, element); - break; - - case LBRE_HIDECHILDREN: - GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode); - GetListBrowserNodeAttrs(lbnode, - LBNA_UserData,(ULONG *)&treenode, - TAG_DONE); - tree_set_node_expanded(twin->tree, treenode, false); - break; - - case LBRE_SHOWCHILDREN: - GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode); - GetListBrowserNodeAttrs(lbnode, - LBNA_UserData,(ULONG *)&treenode, - TAG_DONE); - tree_set_node_expanded(twin->tree, treenode, true); - break; + sslcert_accept(twin->ssl_data); + ami_tree_close(twin); + return TRUE; } + else tree_launch_selected(twin->tree); break; - case GID_OPEN: - GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode); - GetListBrowserNodeAttrs(lbnode, - LBNA_UserData,(ULONG *)&treenode, - TAG_DONE); - ami_tree_launch_node(twin->tree,treenode); + case GID_CANCEL: + sslcert_reject(twin->ssl_data); + ami_tree_close(twin); + return TRUE; break; case GID_NEWF: - GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode); - if(lbnode) - { - GetListBrowserNodeAttrs(lbnode, - LBNA_UserData,(ULONG *)&treenode, - TAG_DONE); - } - else - { - treenode = twin->tree->root; - } - - tree_create_folder_node(treenode,(char *)messages_get("TreeNewFolder")); - - ami_recreate_listbrowser(twin); + hotlist_add_folder(); break; case GID_NEWB: - ami_new_bookmark(twin); - break; - - case GID_UP: - ami_move_node(twin,AMI_MOVE_UP); - break; - - case GID_DOWN: - ami_move_node(twin,AMI_MOVE_DOWN); - break; - - case GID_LEFT: - ami_move_node(twin,AMI_MOVE_OUT); + hotlist_add_entry(); break; case GID_DEL: - GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode); - GetListBrowserNodeAttrs(lbnode, - LBNA_UserData,(ULONG *)&treenode, - TAG_DONE); - tree_delete_node(twin->tree, treenode, false); -/* We are recreating the list from scratch as there is no obvious easy way - to delete children from a listbrowser list */ - ami_recreate_listbrowser(twin); + switch(twin->type) + { + case AMI_TREE_HISTORY: + history_global_delete_selected(); + break; + case AMI_TREE_COOKIES: + cookies_delete_selected(); + break; + case AMI_TREE_HOTLIST: + hotlist_delete_selected(); + break; + } break; } break; -/* no menus yet, copied in as will probably need it later + case WMHI_MOUSEMOVE: + GetAttr(SPACE_AreaBox, twin->gadgets[GID_BROWSER], (ULONG *)&bbox); + + GetAttr(SCROLLER_Top, twin->objects[OID_HSCROLL], (ULONG *)&xs); + x = twin->win->MouseX - bbox->Left + xs; + + GetAttr(SCROLLER_Top, twin->objects[OID_VSCROLL], (ULONG *)&ys); + y = twin->win->MouseY - bbox->Top + ys; + + if((x >= xs) && (y >= ys) && (x < bbox->Width + xs) && + (y < bbox->Height + ys)) + { + ami_tree_update_quals(twin); + + if(twin->mouse_state & BROWSER_MOUSE_PRESS_1) + { + tree_mouse_action(twin->tree, + BROWSER_MOUSE_DRAG_1 | twin->key_state, x, y); + twin->mouse_state = BROWSER_MOUSE_HOLDING_1 | + BROWSER_MOUSE_DRAG_ON; + if(twin->drag_x == 0) twin->drag_x = x; + if(twin->drag_y == 0) twin->drag_y = y; + + } + else if(twin->mouse_state & BROWSER_MOUSE_PRESS_2) + { + tree_mouse_action(twin->tree, + BROWSER_MOUSE_DRAG_2 | twin->key_state, x, y); + twin->mouse_state = BROWSER_MOUSE_HOLDING_2 | + BROWSER_MOUSE_DRAG_ON; + if(twin->drag_x == 0) twin->drag_x = x; + if(twin->drag_y == 0) twin->drag_y = y; + } + else + { + tree_mouse_action(twin->tree, + twin->mouse_state | twin->key_state, x, y); + } + } + twin->lastclick.tv_sec = 0; + twin->lastclick.tv_usec = 0; + break; + + case WMHI_MOUSEBUTTONS: + GetAttr(SPACE_AreaBox, twin->gadgets[GID_BROWSER], (ULONG *)&bbox); + GetAttr(SCROLLER_Top, twin->objects[OID_HSCROLL], (ULONG *)&xs); + x = twin->win->MouseX - bbox->Left + xs; + GetAttr(SCROLLER_Top, twin->objects[OID_VSCROLL], (ULONG *)&ys); + y = twin->win->MouseY - bbox->Top + ys; + + ami_tree_update_quals(twin); + + if((x >= xs) && (y >= ys) && (x < bbox->Width + xs) && + (y < bbox->Height + ys)) + { + switch(code) + { + case SELECTDOWN: + twin->mouse_state = BROWSER_MOUSE_PRESS_1; + break; + case MIDDLEDOWN: + twin->mouse_state = BROWSER_MOUSE_PRESS_2; + break; + } + tree_mouse_action(twin->tree, + twin->mouse_state | twin->key_state, x, y); + } + + if(x < xs) x = xs; + if(y < ys) y = ys; + if(x >= bbox->Width + xs) x = bbox->Width + xs - 1; + if(y >= bbox->Height + ys) y = bbox->Height + ys - 1; + + switch(code) + { + case SELECTUP: + if(twin->mouse_state & BROWSER_MOUSE_PRESS_1) + { + CurrentTime(&curtime.tv_sec,&curtime.tv_usec); + + twin->mouse_state = BROWSER_MOUSE_CLICK_1; + + if(twin->lastclick.tv_sec) + { + if(DoubleClick(twin->lastclick.tv_sec, + twin->lastclick.tv_usec, + curtime.tv_sec, curtime.tv_usec)) + twin->mouse_state |= BROWSER_MOUSE_DOUBLE_CLICK; + } + tree_mouse_action(twin->tree, + twin->mouse_state | twin->key_state, x, y); + + if(twin->mouse_state & BROWSER_MOUSE_DOUBLE_CLICK) + { + twin->lastclick.tv_sec = 0; + twin->lastclick.tv_usec = 0; + } + else + { + twin->lastclick.tv_sec = curtime.tv_sec; + twin->lastclick.tv_usec = curtime.tv_usec; + } + } + else + { + tree_drag_end(twin->tree, twin->mouse_state, + twin->drag_x, twin->drag_y, x, y); + } + twin->mouse_state=0; + twin->drag_x = 0; + twin->drag_y = 0; + break; + case MIDDLEUP: + if(twin->mouse_state & BROWSER_MOUSE_PRESS_2) + { + tree_mouse_action(twin->tree, + BROWSER_MOUSE_CLICK_2 | twin->key_state, x, y); + } + else + { + tree_drag_end(twin->tree, twin->mouse_state, + twin->drag_x, twin->drag_y, x, y); + } + twin->mouse_state=0; + twin->drag_x = 0; + twin->drag_y = 0; + break; + } + break; + + case WMHI_RAWKEY: + storage = result & WMHI_GADGETMASK; + + GetAttr(WINDOW_InputEvent,twin->objects[OID_MAIN],(ULONG *)&ie); + nskey = ami_key_to_nskey(storage, ie); + tree_keypress(twin->tree, nskey); + break; + case WMHI_MENUPICK: - item = ItemAddress(gwin->win->MenuStrip,code); + item = ItemAddress(twin->win->MenuStrip,code); while (code != MENUNULL) { - ami_menupick(code,gwin); + menunum = MENUNUM(code); + itemnum = ITEMNUM(code); + subnum = SUBNUM(code); + + switch(menunum) + { + case 0: // tree + switch(itemnum) + { + case 0: // export + if(AslRequestTags(savereq, + ASLFR_TitleText,messages_get("NetSurf"), + ASLFR_Screen,scrn, + ASLFR_InitialFile,"tree_export.html", + TAG_DONE)) + { + strlcpy(&fname,savereq->fr_Drawer,1024); + AddPart(fname,savereq->fr_File,1024); + ami_update_pointer(twin->win,GUI_POINTER_WAIT); + if(twin->type == AMI_TREE_HISTORY) + history_global_export(fname); + else if(twin->type == AMI_TREE_HOTLIST) + hotlist_export(fname); + ami_update_pointer(twin->win,GUI_POINTER_DEFAULT); + } + break; + + case 2: // expand + switch(subnum) + { + case 0: // all + switch(twin->type) + { + case AMI_TREE_HISTORY: + history_global_expand_all(); + break; + case AMI_TREE_COOKIES: + cookies_expand_all(); + break; + case AMI_TREE_HOTLIST: + hotlist_expand_all(); + break; + } + break; + + case 1: // lev 1 + switch(twin->type) + { + case AMI_TREE_HISTORY: + history_global_expand_directories(); + break; + case AMI_TREE_COOKIES: + cookies_expand_domains(); + break; + case AMI_TREE_HOTLIST: + hotlist_expand_directories(); + break; + } + break; + + case 2: // lev 2 + switch(twin->type) + { + case AMI_TREE_HISTORY: + history_global_expand_addresses(); + break; + case AMI_TREE_COOKIES: + cookies_expand_cookies(); + break; + case AMI_TREE_HOTLIST: + hotlist_expand_addresses(); + break; + } + break; + } + break; + + case 3: // collapse + switch(subnum) + { + case 0: // all + switch(twin->type) + { + case AMI_TREE_HISTORY: + history_global_collapse_all(); + break; + case AMI_TREE_COOKIES: + cookies_collapse_all(); + break; + case AMI_TREE_HOTLIST: + hotlist_collapse_all(); + break; + } + break; + + case 1: // lev 1 + switch(twin->type) + { + case AMI_TREE_HISTORY: + history_global_collapse_directories(); + break; + case AMI_TREE_COOKIES: + cookies_collapse_domains(); + break; + case AMI_TREE_HOTLIST: + hotlist_collapse_directories(); + break; + } + break; + + case 2: // lev 2 + switch(twin->type) + { + case AMI_TREE_HISTORY: + history_global_collapse_addresses(); + break; + case AMI_TREE_COOKIES: + cookies_collapse_cookies(); + break; + case AMI_TREE_HOTLIST: + hotlist_collapse_addresses(); + break; + } + break; + } + break; + + case 5: // close + ami_tree_close(twin); + return TRUE; + break; + } + break; + + case 1: // edit + switch(itemnum) + { + case 0: // delete + switch(twin->type) + { + case AMI_TREE_HISTORY: + history_global_delete_selected(); + break; + case AMI_TREE_COOKIES: + cookies_delete_selected(); + break; + case AMI_TREE_HOTLIST: + hotlist_delete_selected(); + break; + } + break; + + case 2: // select all + switch(twin->type) + { + case AMI_TREE_HISTORY: + history_global_select_all(); + break; + case AMI_TREE_COOKIES: + cookies_select_all(); + break; + case AMI_TREE_HOTLIST: + hotlist_select_all(); + break; + } + break; + + case 3: // clear + switch(twin->type) + { + case AMI_TREE_HISTORY: + history_global_clear_selection(); + break; + case AMI_TREE_COOKIES: + cookies_clear_selection(); + break; + case AMI_TREE_HOTLIST: + hotlist_clear_selection(); + break; + } + break; + } + break; + } + if(win_destroyed) break; code = item->NextSelect; } break; -*/ + + case WMHI_NEWSIZE: + ami_tree_draw(twin); + break; case WMHI_CLOSEWINDOW: + if(twin->type == AMI_TREE_SSLCERT) + sslcert_reject(twin->ssl_data); ami_tree_close(twin); return TRUE; break; @@ -633,103 +1013,44 @@ BOOL ami_tree_event(struct treeview_window *twin) return FALSE; } -void ami_move_node(struct treeview_window *twin,int move) +void ami_tree_draw(struct treeview_window *twin) { - struct Node *lbnode = NULL; - struct node *treenode,*moveto; - bool before; + struct IBox *bbox; + int x, y; - GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode); + if(!twin) return; - if(!lbnode) return; + GetAttr(SCROLLER_Top, twin->objects[OID_HSCROLL], (ULONG *)&x); + GetAttr(SCROLLER_Top, twin->objects[OID_VSCROLL], (ULONG *)&y); + GetAttr(SPACE_AreaBox,twin->gadgets[GID_BROWSER],(ULONG *)&bbox); - GetListBrowserNodeAttrs(lbnode, - LBNA_UserData,(ULONG *)&treenode, -// for multiselects? LBNA_Selected,(BOOL *)&sel, - TAG_DONE); - - selectednode2 = treenode; - - tree_set_node_selected(twin->tree,twin->tree->root,false); - tree_set_node_selected(twin->tree,treenode,true); - - switch(move) - { - case AMI_MOVE_UP: - moveto = treenode->previous; - before = true; - break; - - case AMI_MOVE_DOWN: - moveto = treenode->next; - before = false; - break; - - case AMI_MOVE_OUT: - moveto = treenode->parent->previous; - before = false; - break; - } - - if(!moveto) return; - - tree_delink_node(treenode); - //tree_move_selected_nodes(twin->tree,moveto,before); - tree_link_node(moveto,treenode,before); - ami_recreate_listbrowser(twin); - selectednode2 = NULL; + ami_tree_redraw_request(x, y, bbox->Width, bbox->Height, twin); } -void ami_new_bookmark(struct treeview_window *twin) +void ami_tree_redraw_request(int x, int y, int width, int height, void *data) { - const struct url_data *data; - struct Node *lbnode; - struct node *treenode; - char *url,*title; + struct treeview_window *twin = data; + struct IBox *bbox; + int pos_x, pos_y; - GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode); - if(lbnode) - { - GetListBrowserNodeAttrs(lbnode, - LBNA_UserData,(ULONG *)&treenode, - TAG_DONE); - } - else - { - treenode = twin->tree->root; - } + if(!twin->win) return; +// if(tree_get_redraw(twin->tree) == false) return; - url = (char *)strdup("http://www.netsurf-browser.org"); + ami_update_pointer(twin->win, GUI_POINTER_WAIT); + glob = &twin->globals; - data = urldb_get_url_data(url); - if (!data) - { - urldb_add_url(url); - urldb_set_url_persistence(url,true); - data = urldb_get_url_data(url); - } + GetAttr(SPACE_AreaBox,twin->gadgets[GID_BROWSER],(ULONG *)&bbox); + GetAttr(SCROLLER_Top, twin->objects[OID_HSCROLL], (ULONG *)&pos_x); + GetAttr(SCROLLER_Top, twin->objects[OID_VSCROLL], (ULONG *)&pos_y); - if (data) - { - title = data->title; - tree_create_URL_node(treenode,url,data,title); - ami_recreate_listbrowser(twin); - } -} - -void ami_recreate_listbrowser(struct treeview_window *twin) -{ - static WORD gen=0; - - SetGadgetAttrs(twin->gadgets[GID_TREEBROWSER],twin->win,NULL, - LISTBROWSER_Labels,~0, - TAG_DONE); - - FreeListBrowserList(twin->listbrowser_list); - ami_add_elements(twin,twin->tree->root,&gen); - - RefreshSetGadgetAttrs(twin->gadgets[GID_TREEBROWSER],twin->win,NULL, - LISTBROWSER_Labels,twin->listbrowser_list, - LISTBROWSER_SelectedNode,selectednode, - TAG_DONE); + if(x - pos_x + width > bbox->Width) width = bbox->Width - (x - pos_x); + if(y - pos_y + height > bbox->Height) height = bbox->Height - (y - pos_y); + + tree_draw(twin->tree, -pos_x, -pos_y, x, y, width, height); + + BltBitMapRastPort(twin->globals.bm, x - pos_x, y - pos_y, twin->win->RPort, + bbox->Left + x - pos_x, bbox->Top + y - pos_y, width, height, 0x0C0); + + ami_update_pointer(twin->win, GUI_POINTER_DEFAULT); + glob = &browserglob; } diff --git a/amiga/tree.h b/amiga/tree.h index 4129df1d2..315938d0d 100755 --- a/amiga/tree.h +++ b/amiga/tree.h @@ -1,5 +1,5 @@ /* - * Copyright 2008 Chris Young + * Copyright 2008, 2009 Chris Young * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -22,15 +22,10 @@ #include #include #include "amiga/gui.h" +#include "desktop/tree.h" +#include "desktop/sslcert.h" -struct treeview_window { - struct nsObject *node; - struct Window *win; - Object *objects[OID_LAST]; - struct Gadget *gadgets[GID_LAST]; - struct tree *tree; - struct List *listbrowser_list; -}; +struct treeview_window; enum { @@ -40,15 +35,15 @@ enum AMI_TREE_SSLCERT }; -enum -{ - AMI_MOVE_UP, - AMI_MOVE_DOWN, - AMI_MOVE_OUT -}; +struct treeview_window *ami_tree_create(uint8 flags, + struct sslcert_session_data *ssl_data); +void ami_tree_destroy(struct treeview_window *twin); +struct tree *ami_tree_get_tree(struct treeview_window *twin); -void ami_open_tree(struct tree *tree,int type); +void ami_tree_open(struct treeview_window *twin,int type); void ami_tree_close(struct treeview_window *twin); BOOL ami_tree_event(struct treeview_window *twin); -void ami_recreate_listbrowser(struct treeview_window *twin); + +extern const struct treeview_table ami_tree_callbacks; + #endif diff --git a/beos/beos_bitmap.cpp b/beos/beos_bitmap.cpp index 881ffe727..5df1fce38 100644 --- a/beos/beos_bitmap.cpp +++ b/beos/beos_bitmap.cpp @@ -312,6 +312,16 @@ void bitmap_set_suspendable(void *vbitmap, void *private_word, struct bitmap *bitmap = (struct bitmap *)vbitmap; } +int bitmap_get_width(void *vbitmap){ + struct bitmap *bitmap = (struct bitmap *)vbitmap; + return bitmap->primary->Bounds().Width() + 1; +} + +int bitmap_get_height(void *vbitmap){ + struct bitmap *bitmap = (struct bitmap *)vbitmap; + return bitmap->primary->Bounds().Height() + 1; +} + static BBitmap * nsbeos_bitmap_generate_pretile(BBitmap *primary, int repeat_x, int repeat_y) { diff --git a/beos/beos_gui.cpp b/beos/beos_gui.cpp index d8cb4bbb2..c06b0c7fc 100644 --- a/beos/beos_gui.cpp +++ b/beos/beos_gui.cpp @@ -74,7 +74,6 @@ extern "C" { #include "beos/beos_window.h" #include "beos/options.h" #include "beos/beos_throbber.h" -#include "beos/beos_history.h" #include "beos/beos_filetype.h" //#include "beos/beos_download.h" #include "beos/beos_schedule.h" @@ -641,7 +640,6 @@ void gui_init(int argc, char** argv) urldb_load(option_url_file); urldb_load_cookies(option_cookie_file); - nsbeos_history_init(); //nsbeos_download_initialise(); if (!replicated) @@ -1059,11 +1057,6 @@ void die(const char * const error) exit(EXIT_FAILURE); } - -void hotlist_visited(hlcache_handle *content) -{ -} - void gui_cert_verify(const char *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw) diff --git a/beos/beos_history.cpp b/beos/beos_history.cpp deleted file mode 100644 index b35d6d075..000000000 --- a/beos/beos_history.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright 2008 François Revol - * Copyright 2006 Rob Kendrick - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * NetSurf is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * NetSurf is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#define __STDBOOL_H__ 1 -extern "C" { -#include "utils/log.h" -#include "content/urldb.h" -} - -#include "beos/beos_history.h" -#include "beos/beos_gui.h" -#include "beos/beos_window.h" - -#include -#include - - -enum -{ - COL_TITLE = 0, - COL_ADDRESS, - COL_LASTVISIT, - COL_TOTALVISITS, - COL_THUMBNAIL, - COL_NCOLS -}; - -BWindow *wndHistory; -#warning XXX -#if 0 /* GTK */ -static GtkTreeView *treeview; -static GtkTreeStore *history_tree; -static GtkTreeSelection *selection; - -static bool nsgtk_history_add_internal(const char *, const struct url_data *); -static void nsgtk_history_selection_changed(GtkTreeSelection *, gpointer); -#endif - -void nsbeos_history_init(void) -{ -#warning XXX -#if 0 /* GTK */ - GtkCellRenderer *renderer; - - wndHistory = GTK_WINDOW(glade_xml_get_widget(gladeWindows, - "wndHistory")); - treeview = GTK_TREE_VIEW(glade_xml_get_widget(gladeWindows, - "treeHistory")); - history_tree = gtk_tree_store_new(COL_NCOLS, - G_TYPE_STRING, /* title */ - G_TYPE_STRING, /* address */ - G_TYPE_STRING, /* last visit */ - G_TYPE_INT, /* nr. visits */ - GDK_TYPE_PIXBUF); /* thumbnail */ - - selection = gtk_tree_view_get_selection(treeview); - gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); - g_signal_connect(G_OBJECT(selection), "changed", - G_CALLBACK(nsgtk_history_selection_changed), NULL); - - renderer = gtk_cell_renderer_text_new(); - gtk_tree_view_insert_column_with_attributes(treeview, -1, "Title", - renderer, - "text", - COL_TITLE, - NULL); - - gtk_tree_view_set_model(treeview, GTK_TREE_MODEL(history_tree)); - -#endif - nsbeos_history_update(); -} - -void nsbeos_history_update(void) -{ -#warning XXX -#if 0 /* GTK */ - gtk_tree_store_clear(history_tree); - urldb_iterate_entries(nsgtk_history_add_internal); -#endif -} - -bool nsbeos_history_add_internal(const char *url, const struct url_data *data) -{ -#warning XXX -#if 0 /* GTK */ - GtkTreeIter iter; - - if (data->visits > 0) - { - gtk_tree_store_append(history_tree, &iter, NULL); - gtk_tree_store_set(history_tree, &iter, - COL_TITLE, data->title, - COL_ADDRESS, url, - COL_LASTVISIT, "Unknown", - COL_TOTALVISITS, data->visits, - -1); - } - -#endif - return true; -} - -#warning XXX -#if 0 /* GTK */ -void nsgtk_history_selection_changed(GtkTreeSelection *treesel, gpointer g) -{ - GtkTreeIter iter; - GtkTreeModel *model = GTK_TREE_MODEL(history_tree); - if (gtk_tree_selection_get_selected(treesel, &model, &iter)) - { - gchar *b; - gint i; - char buf[20]; - - gtk_tree_model_get(model, &iter, COL_ADDRESS, &b, -1); - gtk_label_set_text(GTK_LABEL(glade_xml_get_widget(gladeWindows, - "labelHistoryAddress")), b); - - gtk_tree_model_get(model, &iter, COL_LASTVISIT, &b, -1); - gtk_label_set_text(GTK_LABEL(glade_xml_get_widget(gladeWindows, - "labelHistoryLastVisit")), b); - - gtk_tree_model_get(model, &iter, COL_TOTALVISITS, - &i, -1); - snprintf(buf, 20, "%d", i); - gtk_label_set_text(GTK_LABEL(glade_xml_get_widget(gladeWindows, - "labelHistoryVisits")), buf); - - - - } - else - { - - } -} - -void nsgtk_history_row_activated(GtkTreeView *tv, GtkTreePath *path, - GtkTreeViewColumn *column, gpointer g) -{ - GtkTreeModel *model; - GtkTreeIter iter; - - model = gtk_tree_view_get_model(tv); - if (gtk_tree_model_get_iter(model, &iter, path)) - { - gchar *b; - - gtk_tree_model_get(model, &iter, COL_ADDRESS, &b, -1); - - browser_window_create((const char *)b, NULL, NULL, true); - } -} -#endif - -void global_history_add(const char *url) -{ - const struct url_data *data; - - data = urldb_get_url_data(url); - if (!data) - return; - - nsbeos_history_add_internal(url, data); - -} diff --git a/beos/beos_scaffolding.cpp b/beos/beos_scaffolding.cpp index a5cc832a7..3fb147f1f 100644 --- a/beos/beos_scaffolding.cpp +++ b/beos/beos_scaffolding.cpp @@ -63,7 +63,6 @@ extern "C" { #include "beos/beos_options.h" //#include "beos/beos_completion.h" #include "beos/beos_throbber.h" -//#include "beos/beos_history.h" #include "beos/beos_window.h" //#include "beos/beos_schedule.h" //#include "beos/beos_download.h" diff --git a/beos/beos_treeview.cpp b/beos/beos_treeview.cpp index 1688a95fa..6763c25b8 100644 --- a/beos/beos_treeview.cpp +++ b/beos/beos_treeview.cpp @@ -26,107 +26,59 @@ extern "C" { #include "utils/config.h" #include "desktop/tree.h" +#include "desktop/tree_url_node.h" } +const char tree_directory_icon_name[] = "directory.png"; +const char tree_content_icon_name[] = "content.png"; + + + /** - * Sets the origin variables to the correct values for a specified tree + * Translates a content_type to the name of a respective icon * - * \param tree the tree to set the origin for + * \param content_type content type + * \param buffer buffer for the icon name */ -void tree_initialise_redraw(struct tree *tree) { -} - - -/** - * Informs the current window manager that an area requires updating. - * - * \param tree the tree that is requesting a redraw - * \param x the x co-ordinate of the redraw area - * \param y the y co-ordinate of the redraw area - * \param width the width of the redraw area - * \param height the height of the redraw area - */ -void tree_redraw_area(struct tree *tree, int x, int y, int width, int height) { -} - - -/** - * Draws a line. - * - * \param x the x co-ordinate - * \param x the y co-ordinate - * \param x the width of the line - * \param x the height of the line - */ -void tree_draw_line(int x, int y, int width, int height) { -} - - -/** - * Draws an element, including any expansion icons - * - * \param tree the tree to draw an element for - * \param element the element to draw - */ -void tree_draw_node_element(struct tree *tree, struct node_element *element) { -} - - -/** - * Draws an elements expansion icon - * - * \param tree the tree to draw the expansion for - * \param element the element to draw the expansion for - */ -void tree_draw_node_expansion(struct tree *tree, struct node *node) { -} - - -/** - * Recalculates the dimensions of a node element. - * - * \param element the element to recalculate - */ -void tree_recalculate_node_element(struct node_element *element) { -} - -/** - * Sets a node element as having a specific sprite. - * - * \param node the node to update - * \param sprite the sprite to use - * \param selected the expanded sprite name to use - */ -void tree_set_node_sprite(struct node *node, const char *sprite, - const char *expanded) { - -} - -/** - * Sets a node element as having a folder sprite - * - * \param node the node to update - */ -void tree_set_node_sprite_folder(struct node *node) { - -} - -/** - * Updates the node details for a URL node. - * The internal node dimensions are not updated. - * - * \param node the node to update - */ -void tree_update_URL_node(struct node *node, const char *url, - const struct url_data *data) { -} - - -/** - * Updates the tree owner following a tree resize - * - * \param tree the tree to update the owner of - */ -void tree_resized(struct tree *tree) { +void tree_icon_name_from_content_type(char *buffer, content_type type) +{ + // TODO: design/acquire icons + switch (type) { + case CONTENT_HTML: + case CONTENT_TEXTPLAIN: + case CONTENT_CSS: +#if defined(WITH_MNG) || defined(WITH_PNG) + case CONTENT_PNG: +#endif +#ifdef WITH_MNG + case CONTENT_JNG: + case CONTENT_MNG: +#endif +#ifdef WITH_JPEG + case CONTENT_JPEG: +#endif +#ifdef WITH_GIF + case CONTENT_GIF: +#endif +#ifdef WITH_BMP + case CONTENT_BMP: + case CONTENT_ICO: +#endif +#ifdef WITH_SPRITE + case CONTENT_SPRITE: +#endif +#ifdef WITH_DRAW + case CONTENT_DRAW: +#endif +#ifdef WITH_ARTWORKS + case CONTENT_ARTWORKS: +#endif +#ifdef WITH_NS_SVG + case CONTENT_SVG: +#endif + default: + sprintf(buffer, tree_content_icon_name); + break; + } } diff --git a/content/urldb.c b/content/urldb.c index e4a163738..ee550503f 100644 --- a/content/urldb.c +++ b/content/urldb.c @@ -245,13 +245,11 @@ static bool urldb_iterate_partial_path(const struct path_data *parent, static bool urldb_iterate_entries_host(struct search_node *parent, bool (*url_callback)(const char *url, const struct url_data *data), - bool (*cookie_callback)(const char *domain, - const struct cookie_data *data)); + bool (*cookie_callback)(const struct cookie_data *data)); static bool urldb_iterate_entries_path(const struct path_data *parent, bool (*url_callback)(const char *url, const struct url_data *data), - bool (*cookie_callback)(const char *domain, - const struct cookie_data *data)); + bool (*cookie_callback)(const struct cookie_data *data)); /* Insertion */ static struct host_part *urldb_add_host_node(const char *part, @@ -1390,8 +1388,7 @@ void urldb_iterate_entries(bool (*callback)(const char *url, * * \param callback Function to callback for each entry */ -void urldb_iterate_cookies(bool (*callback)(const char *domain, - const struct cookie_data *data)) +void urldb_iterate_cookies(bool (*callback)(const struct cookie_data *data)) { int i; @@ -1415,8 +1412,7 @@ void urldb_iterate_cookies(bool (*callback)(const char *domain, bool urldb_iterate_entries_host(struct search_node *parent, bool (*url_callback)(const char *url, const struct url_data *data), - bool (*cookie_callback)(const char *domain, - const struct cookie_data *data)) + bool (*cookie_callback)(const struct cookie_data *data)) { if (parent == &empty) return true; @@ -1452,11 +1448,11 @@ bool urldb_iterate_entries_host(struct search_node *parent, bool urldb_iterate_entries_path(const struct path_data *parent, bool (*url_callback)(const char *url, const struct url_data *data), - bool (*cookie_callback)(const char *domain, - const struct cookie_data *data)) + bool (*cookie_callback)(const struct cookie_data *data)) { const struct path_data *p = parent; - + const struct cookie_data *c; + do { if (p->children != NULL) { /* Drill down into children */ @@ -1478,11 +1474,10 @@ bool urldb_iterate_entries_path(const struct path_data *parent, (const struct url_data *) u)) return false; } else { - if (p->cookies && !cookie_callback( - p->cookies->domain, - (const struct cookie_data *) - p->cookies)) - return false; + c = (const struct cookie_data *)p->cookies; + for (; c != NULL; c = c->next) + if (!cookie_callback(c)) + return false; } /* Now, find next node to process. */ @@ -2447,9 +2442,7 @@ char *urldb_get_cookie(const char *url) url_func_result res; int i; - assert(url); - -// LOG(("%s", url)); + assert(url != NULL); urldb_add_url(url); @@ -2529,14 +2522,11 @@ char *urldb_get_cookie(const char *url) version = c->version; c->last_used = now; - cookies_update(c->domain, - (struct cookie_data *)c); + cookies_schedule_update((struct cookie_data *)c); } } } -// LOG(("%s", ret)); - /* Now consider cookies whose paths prefix-match ours */ for (p = p->parent; p; p = p->parent) { /* Find directory's path entry(ies) */ @@ -2546,7 +2536,6 @@ char *urldb_get_cookie(const char *url) continue; for (c = q->cookies; c; c = c->next) { -// LOG(("%p: %s=%s", c, c->name, c->value)); if (c->expires != 1 && c->expires < now) /* cookie has expired => ignore */ continue; @@ -2565,8 +2554,7 @@ char *urldb_get_cookie(const char *url) version = c->version; c->last_used = now; - cookies_update(c->domain, - (struct cookie_data *)c); + cookies_schedule_update((struct cookie_data *)c); } } @@ -2606,13 +2594,11 @@ char *urldb_get_cookie(const char *url) version = c->version; c->last_used = now; - cookies_update(c->domain, (struct cookie_data *)c); + cookies_schedule_update((struct cookie_data *)c); } } -// LOG(("%s", ret)); - /* Finally consider domain cookies for hosts which domain match ours */ for (h = (const struct host_part *)p; h && h != &db_root; h = h->parent) { @@ -2638,12 +2624,10 @@ char *urldb_get_cookie(const char *url) version = c->version; c->last_used = now; - cookies_update(c->domain, (struct cookie_data *)c); + cookies_schedule_update((struct cookie_data *)c); } } -// LOG(("%s", ret)); - if (count == 0) { /* No cookies found */ free(path); @@ -2712,8 +2696,6 @@ bool urldb_set_cookie(const char *header, const char *url, assert(url && header); -// LOG(("'%s' : '%s'", url, header)); - /* strip fragment */ urlt = strdup(url); if (!urlt) @@ -2928,7 +2910,7 @@ bool urldb_set_cookie(const char *header, const char *url, /* Now insert into database */ if (!urldb_insert_cookie(c, scheme, urlt)) goto error; - cookies_update(c->domain, (struct cookie_data *)c); + cookies_schedule_update((struct cookie_data *)c); } while (cur < end); free(host); @@ -3378,6 +3360,8 @@ bool urldb_insert_cookie(struct cookie_internal_data *c, const char *scheme, d->prev->next = d->next; else p->cookies = d->next; + + cookies_remove((struct cookie_data *)d); urldb_free_cookie(d); urldb_free_cookie(c); } else { @@ -3392,8 +3376,11 @@ bool urldb_insert_cookie(struct cookie_internal_data *c, const char *scheme, c->prev->next = c; else p->cookies = c; + + cookies_remove((struct cookie_data *)d); urldb_free_cookie(d); -// LOG(("%p: %s=%s", c, c->name, c->value)); + + cookies_schedule_update((struct cookie_data *)c); } } else { c->prev = p->cookies_end; @@ -3403,7 +3390,6 @@ bool urldb_insert_cookie(struct cookie_internal_data *c, const char *scheme, else p->cookies = c; p->cookies_end = c; -// LOG(("%p: %s=%s", c, c->name, c->value)); } return true; @@ -3771,9 +3757,7 @@ void urldb_delete_cookie_paths(const char *domain, const char *path, else p->cookies_end = c->prev; - if (p->cookies == NULL) - cookies_update(domain, NULL); - + cookies_remove((struct cookie_data *)c); urldb_free_cookie(c); return; diff --git a/content/urldb.h b/content/urldb.h index 5080dc52d..bbf378332 100644 --- a/content/urldb.h +++ b/content/urldb.h @@ -108,8 +108,7 @@ void urldb_iterate_partial(const char *prefix, /* Iteration */ void urldb_iterate_entries(bool (*callback)(const char *url, const struct url_data *data)); -void urldb_iterate_cookies(bool (*callback)(const char *domain, - const struct cookie_data *cookie)); +void urldb_iterate_cookies(bool (*callback)(const struct cookie_data *cookie)); /* Debug */ void urldb_dump(void); diff --git a/desktop/browser.c b/desktop/browser.c index 8c53813a6..b301b5fa3 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -46,6 +46,7 @@ #include "desktop/download.h" #include "desktop/frames.h" #include "desktop/history_core.h" +#include "desktop/hotlist.h" #include "desktop/gui.h" #include "desktop/options.h" #include "desktop/selection.h" diff --git a/desktop/cookies.c b/desktop/cookies.c new file mode 100644 index 000000000..c5dac5101 --- /dev/null +++ b/desktop/cookies.c @@ -0,0 +1,531 @@ +/* + * Copyright 2006 Richard Wilson + * Copyright 2009 Paul Blokus + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** \file + * Cookies (implementation). + */ + +#include +#include +#include +#include +#include +#include +#include "content/content.h" +#include "content/hlcache.h" +#include "content/urldb.h" +#include "desktop/cookies.h" +#include "desktop/options.h" +#include "desktop/tree.h" +#include "utils/messages.h" +#include "utils/log.h" +#include "utils/url.h" +#include "utils/utils.h" + +/** Flags for each type of cookie tree node. */ +enum tree_element_cookie { + TREE_ELEMENT_PERSISTENT = 0x01, + TREE_ELEMENT_VERSION = 0x02, + TREE_ELEMENT_SECURE = 0x03, + TREE_ELEMENT_LAST_USED = 0x04, + TREE_ELEMENT_EXPIRES = 0x05, + TREE_ELEMENT_PATH = 0x06, + TREE_ELEMENT_DOMAIN = 0x07, + TREE_ELEMENT_COMMENT = 0x08, + TREE_ELEMENT_VALUE = 0x09, +}; + +static struct tree *cookies_tree; +static struct node *cookies_tree_root; +static bool user_delete; +static hlcache_handle *folder_icon; +static hlcache_handle *cookie_icon; + + +/** + * Find an entry in the cookie tree + * + * \param node the node to check the children of + * \param title The title to find + * \return Pointer to node, or NULL if not found + */ +static struct node *cookies_find(struct node *node, const char *title) +{ + struct node *search; + struct node_element *element; + + for (search = tree_node_get_child(node); search; + search = tree_node_get_next(search)) { + element = tree_node_find_element(search, TREE_ELEMENT_TITLE, + NULL); + if (strcmp(title, tree_node_element_get_text(element)) == 0) + return search; + } + return NULL; +} + +/** + * Callback for all cookie tree nodes. + */ +static node_callback_resp cookies_node_callback(void *user_data, struct node_msg_data *msg_data) +{ + struct node *node = msg_data->node; + struct node_element *domain, *path; + const char *domain_t, *path_t, *name_t; + char *space; + bool is_folder = tree_node_is_folder(node); + + /* we don't remove any icons here */ + if (msg_data->msg == NODE_DELETE_ELEMENT_IMG) + return NODE_CALLBACK_HANDLED; + + /* let the tree handle events other than text data removal */ + if (msg_data->msg != NODE_DELETE_ELEMENT_TXT) + return NODE_CALLBACK_NOT_HANDLED; + + /* check if it's a domain folder */ + if (is_folder) + return NODE_CALLBACK_NOT_HANDLED; + + switch (msg_data->flag) { + case TREE_ELEMENT_TITLE: + if (!user_delete) + break; + /* get the rest of the cookie data */ + domain = tree_node_find_element(node, + TREE_ELEMENT_DOMAIN, NULL); + path = tree_node_find_element(node, TREE_ELEMENT_PATH, + NULL); + + if ((domain != NULL) && + (path != NULL)) { + domain_t = tree_node_element_get_text(domain) + + strlen(messages_get( + "TreeDomain")) - 4; + space = strchr(domain_t, ' '); + if (space != NULL) + *space = '\0'; + path_t = tree_node_element_get_text(path) + + strlen(messages_get("TreePath")) + - 4; + space = strchr(path_t, ' '); + if (space != NULL) + *space = '\0'; + name_t = msg_data->data.text; + urldb_delete_cookie(domain_t, path_t, name_t); + } + break; + default: + break; + } + + free(msg_data->data.text); + + return NODE_CALLBACK_HANDLED; +} + + +/** + * Updates a tree entry for a cookie. + * + * All information is copied from the cookie_data, and as such can + * be edited and should be freed. + * + * \param node The node to update + * \param data The cookie data to use + * \return true if node updated, or false for failure + */ +static bool cookies_update_cookie_node(struct node *node, + const struct cookie_data *data) +{ + struct node_element *element; + char buffer[32]; + + assert(data != NULL); + + /* update the value text */ + element = tree_node_find_element(node, TREE_ELEMENT_VALUE, NULL); + tree_update_element_text(cookies_tree, + element, + messages_get_buff("TreeValue", + data->value != NULL ? + data->value : + messages_get("TreeUnused"))); + + + /* update the comment text */ + if ((data->comment != NULL) && + (strcmp(data->comment, "") != 0)) { + element = tree_node_find_element(node, TREE_ELEMENT_COMMENT, NULL); + tree_update_element_text(cookies_tree, + element, + messages_get_buff("TreeComment", + data->comment)); + } + + /* update domain text */ + element = tree_node_find_element(node, TREE_ELEMENT_DOMAIN, element); + tree_update_element_text(cookies_tree, + element, + messages_get_buff("TreeDomain", + data->domain, + data->domain_from_set ? + messages_get("TreeHeaders") : + "")); + + /* update path text */ + element = tree_node_find_element(node, TREE_ELEMENT_PATH, element); + tree_update_element_text(cookies_tree, + element, + messages_get_buff("TreePath", data->path, + data->path_from_set ? + messages_get("TreeHeaders") : + "")); + + /* update expiry text */ + element = tree_node_find_element(node, TREE_ELEMENT_EXPIRES, element); + tree_update_element_text(cookies_tree, + element, + messages_get_buff("TreeExpires", + (data->expires > 0) + ? (data->expires == 1) + ? messages_get("TreeSession") + : ctime(&data->expires) + : messages_get("TreeUnknown"))); + + /* update last used text */ + element = tree_node_find_element(node, TREE_ELEMENT_LAST_USED, element); + tree_update_element_text(cookies_tree, + element, + messages_get_buff("TreeLastUsed", + (data->last_used > 0) ? + ctime(&data->last_used) : + messages_get("TreeUnknown"))); + + /* update secure text */ + element = tree_node_find_element(node, TREE_ELEMENT_SECURE, element); + tree_update_element_text(cookies_tree, + element, + messages_get_buff("TreeSecure", + data->secure ? + messages_get("Yes") : + messages_get("No"))); + + /* update version text */ + element = tree_node_find_element(node, TREE_ELEMENT_VERSION, element); + snprintf(buffer, sizeof(buffer), "TreeVersion%i", data->version); + tree_update_element_text(cookies_tree, + element, + messages_get_buff("TreeVersion", + messages_get(buffer))); + + /* update persistant text */ + element = tree_node_find_element(node, TREE_ELEMENT_PERSISTENT, element); + tree_update_element_text(cookies_tree, + element, + messages_get_buff("TreePersistent", + data->no_destroy ? + messages_get("Yes") : + messages_get("No"))); + + return node; +} + +/** + * Creates an empty tree entry for a cookie, and links it into the tree. + * + * All information is copied from the cookie_data, and as such can + * be edited and should be freed. + * + * \param parent the node to link to + * \param data the cookie data to use + * \return the node created, or NULL for failure + */ +static struct node *cookies_create_cookie_node(struct node *parent, + const struct cookie_data *data) +{ + struct node *node; + char *name; + + name = strdup(data->name); + if (name == NULL) { + LOG(("malloc failed")); + warn_user("NoMemory", 0); + return NULL; + } + + node = tree_create_leaf_node(cookies_tree, NULL, name, + false, false, false); + if (node == NULL) { + free(name); + return NULL; + } + + tree_set_node_user_callback(node, cookies_node_callback, NULL); + + tree_create_node_element(node, NODE_ELEMENT_TEXT, + TREE_ELEMENT_PERSISTENT, false); + + tree_create_node_element(node, NODE_ELEMENT_TEXT, + TREE_ELEMENT_VERSION, false); + + tree_create_node_element(node, NODE_ELEMENT_TEXT, + TREE_ELEMENT_SECURE, false); + + tree_create_node_element(node, NODE_ELEMENT_TEXT, + TREE_ELEMENT_LAST_USED, false); + + tree_create_node_element(node, NODE_ELEMENT_TEXT, + TREE_ELEMENT_EXPIRES, false); + + tree_create_node_element(node, NODE_ELEMENT_TEXT, + TREE_ELEMENT_PATH, false); + + tree_create_node_element(node, NODE_ELEMENT_TEXT, + TREE_ELEMENT_DOMAIN, false); + + if ((data->comment) && (strcmp(data->comment, ""))) + tree_create_node_element(node, NODE_ELEMENT_TEXT, + TREE_ELEMENT_COMMENT, false); + tree_create_node_element(node, NODE_ELEMENT_TEXT, + TREE_ELEMENT_VALUE, false); + tree_set_node_icon(cookies_tree, node, cookie_icon); + + if (!cookies_update_cookie_node(node, data)) + { + tree_delete_node(NULL, node, false); + return NULL; + } + + tree_link_node(cookies_tree, parent, node, false); + return node; +} + + +/** + * Called when scheduled event gets fired. Actually performs the update. + */ +static void cookies_schedule_callback(void *scheduled_data) +{ + const struct cookie_data *data = scheduled_data; + struct node *node = NULL; + struct node *cookie_node = NULL; + char *domain_cp; + + assert(data != NULL); + + node = cookies_find(cookies_tree_root, data->domain); + + if (node == NULL) { + domain_cp = strdup(data->domain); + if (domain_cp == NULL) { + LOG(("malloc failed")); + warn_user("NoMemory", 0); + return; + } + node = tree_create_folder_node(cookies_tree, + cookies_tree_root, domain_cp, + false, false, false); + if (node != NULL) { + tree_set_node_user_callback(node, cookies_node_callback, + NULL); + tree_set_node_icon(cookies_tree, node, folder_icon); + } + } + + if (node == NULL) + return; + + cookie_node = cookies_find(node, data->name); + if (cookie_node == NULL) + cookies_create_cookie_node(node, data); + else + cookies_update_cookie_node(cookie_node, data); + + return; +} + +/** + * Initialises cookies tree. + * + * \param data user data for the callbacks + * \param start_redraw callback function called before every redraw + * \param end_redraw callback function called after every redraw + * \return true on success, false on memory exhaustion + */ +bool cookies_initialise(struct tree *tree) +{ + + if (tree == NULL) + return false; + + folder_icon = tree_load_icon(tree_directory_icon_name); + cookie_icon = tree_load_icon(tree_content_icon_name); + + /* Create an empty tree */ + cookies_tree = tree; + cookies_tree_root = tree_get_root(cookies_tree); + + user_delete = false; + urldb_iterate_cookies(cookies_schedule_update); + tree_set_node_expanded(cookies_tree, cookies_tree_root, + true, true, true); + + return true; +} + + +/** + * Get flags with which the cookies tree should be created; + * + * \return the flags + */ +unsigned int cookies_get_tree_flags(void) +{ + return TREE_DELETE_EMPTY_DIRS; +} + + +/* exported interface documented in cookies.h */ +bool cookies_schedule_update(const struct cookie_data *data) +{ + assert(data != NULL); + assert(user_delete == false); + + schedule(100, cookies_schedule_callback, (void *)data); + + return true; +} + + +/* exported interface documented in cookies.h */ +void cookies_remove(const struct cookie_data *data) +{ + assert(data != NULL); + + schedule_remove(cookies_schedule_callback, (void *)data); +} + + +/** + * Free memory and release all other resources. + */ +void cookies_cleanup(void) +{ +} + +/* Actions to be connected to front end specific toolbars */ + +/** + * Delete nodes which are currently selected. + */ +void cookies_delete_selected(void) +{ + user_delete = true; + tree_delete_selected_nodes(cookies_tree, cookies_tree_root); + user_delete = false; +} + +/** + * Delete all nodes. + */ +void cookies_delete_all(void) +{ + bool needs_redraw = tree_get_redraw(cookies_tree); + if (needs_redraw) + tree_set_redraw(cookies_tree, false); + + user_delete = true; + tree_set_node_selected(cookies_tree, cookies_tree_root, true, true); + tree_delete_selected_nodes(cookies_tree, cookies_tree_root); + user_delete = false; + + if (needs_redraw) + tree_set_redraw(cookies_tree, true); +} + +/** + * Select all nodes in the tree. + */ +void cookies_select_all(void) +{ + tree_set_node_selected(cookies_tree, cookies_tree_root, true, true); +} + +/** + * Unselect all nodes. + */ +void cookies_clear_selection(void) +{ + tree_set_node_selected(cookies_tree, cookies_tree_root, true, false); +} + +/** + * Expand both domain and cookie nodes. + */ +void cookies_expand_all(void) +{ + tree_set_node_expanded(cookies_tree, cookies_tree_root, + true, true, true); +} + +/** + * Expand domain nodes only. + */ +void cookies_expand_domains(void) +{ + tree_set_node_expanded(cookies_tree, cookies_tree_root, + true, true, false); +} + +/** + * Expand cookie nodes only. + */ +void cookies_expand_cookies(void) +{ + tree_set_node_expanded(cookies_tree, cookies_tree_root, + true, false, true); +} + +/** + * Collapse both domain and cookie nodes. + */ +void cookies_collapse_all(void) +{ + tree_set_node_expanded(cookies_tree, cookies_tree_root, + false, true, true); +} + +/** + * Collapse domain nodes only. + */ +void cookies_collapse_domains(void) +{ + tree_set_node_expanded(cookies_tree, cookies_tree_root, + false, true, false); +} + +/** + * Collapse cookie nodes only. + */ +void cookies_collapse_cookies(void) +{ + tree_set_node_expanded(cookies_tree, cookies_tree_root, + false, false, true); +} diff --git a/desktop/cookies.h b/desktop/cookies.h index 4311957df..06278c006 100644 --- a/desktop/cookies.h +++ b/desktop/cookies.h @@ -25,8 +25,42 @@ #include +#include "desktop/tree.h" + struct cookie_data; -bool cookies_update(const char *domain, const struct cookie_data *data); +bool cookies_initialise(struct tree *tree); +unsigned int cookies_get_tree_flags(void); + +/** + * Perform cookie updates and addition. The update is only scheduled here. + * The actual update is performed in the callback function. + * + * \param data Data of cookie being updated. + * \return true (for urldb_iterate_entries) + */ +bool cookies_schedule_update(const struct cookie_data *data); + +/** + * Remove a cookie from the active set. + * The cookie is to be removed from the active set and no futher + * references made to the cookie data. + * + * \param data Data of cookie being removed. + */ +void cookies_remove(const struct cookie_data *data); + +void cookies_cleanup(void); + +void cookies_delete_selected(void); +void cookies_delete_all(void); +void cookies_select_all(void); +void cookies_clear_selection(void); +void cookies_expand_all(void); +void cookies_expand_domains(void); +void cookies_expand_cookies(void); +void cookies_collapse_all(void); +void cookies_collapse_domains(void); +void cookies_collapse_cookies(void); #endif diff --git a/desktop/history_global_core.c b/desktop/history_global_core.c new file mode 100644 index 000000000..b8cd9a5b0 --- /dev/null +++ b/desktop/history_global_core.c @@ -0,0 +1,464 @@ +/* + * Copyright 2005 Richard Wilson + * Copyright 2009 Paul Blokus + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include + +#include "content/content.h" +#include "content/hlcache.h" +#include "content/urldb.h" +#include "desktop/browser.h" +#include "desktop/history_global_core.h" +#include "desktop/plotters.h" +#include "desktop/tree.h" +#include "desktop/tree_url_node.h" + +#ifdef riscos +#include "riscos/gui.h" +#endif +#include "utils/messages.h" +#include "utils/utils.h" +#include "utils/log.h" + +#define MAXIMUM_BASE_NODES 16 +#define GLOBAL_HISTORY_RECENT_URLS 16 +#define URL_CHUNK_LENGTH 512 + +static struct node *global_history_base_node[MAXIMUM_BASE_NODES]; +static int global_history_base_node_time[MAXIMUM_BASE_NODES]; +static int global_history_base_node_count = 0; + +static bool global_history_initialised; + +static struct tree *global_history_tree; +static struct node *global_history_tree_root; + +static hlcache_handle *folder_icon; + +static const char *const weekday_msg_name [] = +{ + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday" +}; + +/** + * Find an entry in the global history + * + * \param url The URL to find + * \return Pointer to node, or NULL if not found + */ +static struct node *history_global_find(const char *url) +{ + int i; + struct node *node; + const char *text; + + for (i = 0; i < global_history_base_node_count; i++) { + if (!tree_node_is_deleted(global_history_base_node[i])) { + node = tree_node_get_child(global_history_base_node[i]); + for (; node != NULL; node = tree_node_get_next(node)) { + text = tree_url_node_get_url(node); + if ((text != NULL) && !strcmp(url, text)) + return node; + } + } + } + return NULL; +} + +/** + * Internal routine to actually perform global history addition + * + * \param url The URL to add + * \param data URL data associated with URL + * \return true (for urldb_iterate_entries) + */ +static bool global_history_add_internal(const char *url, + const struct url_data *data) +{ + int i, j; + struct node *parent = NULL; + struct node *link; + struct node *node; + bool before = false; + int visit_date; + + assert((url != NULL) && (data != NULL)); + + visit_date = data->last_visit; + + /* find parent node */ + for (i = 0; i < global_history_base_node_count; i++) { + if (global_history_base_node_time[i] <= visit_date) { + parent = global_history_base_node[i]; + break; + } + } + + /* the entry is too old to care about */ + if (parent == NULL) + return true; + + if (tree_node_is_deleted(parent)) { + /* parent was deleted, so find place to insert it */ + link = global_history_tree_root; + + for (j = global_history_base_node_count - 1; j >= 0; j--) { + if (!tree_node_is_deleted(global_history_base_node[j]) && + global_history_base_node_time[j] > + global_history_base_node_time[i]) { + link = global_history_base_node[j]; + before = true; + break; + } + } + + tree_set_node_selected(global_history_tree, + parent, true, false); + tree_set_node_expanded(global_history_tree, + parent, false, true, true); + tree_link_node(global_history_tree, link, parent, before); + } + + /* find any previous occurance */ + if (global_history_initialised == false) { + node = history_global_find(url); + if (node != NULL) { + tree_update_URL_node(global_history_tree, + node, url, data, true); + tree_delink_node(global_history_tree, node); + tree_link_node(global_history_tree, parent, node, + false); + return true; + } + } + + /* Add the node at the bottom */ + node = tree_create_URL_node_shared(global_history_tree, + parent, url, data, + tree_url_node_callback, NULL); + + return true; +} + +static node_callback_resp +history_global_node_callback(void *user_data, + struct node_msg_data *msg_data) +{ + if (msg_data->msg == NODE_DELETE_ELEMENT_IMG) + return NODE_CALLBACK_HANDLED; + return NODE_CALLBACK_NOT_HANDLED; +} + +/** + * Initialises a single grouping node for the global history tree. + * + * \return false on memory exhaustion, true otherwise + */ +static bool history_global_initialise_node(const char *title, + time_t base, int days_back) +{ + struct tm *full_time; + char *buffer; + struct node *node; + + base += days_back * 60 * 60 * 24; + if (title == NULL) { + full_time = localtime(&base); + buffer = strdup(messages_get(weekday_msg_name[full_time->tm_wday])); + } else { + buffer = strdup(title); + } + + if (buffer == NULL) { + LOG(("malloc failed")); + warn_user("NoMemory", 0); + return false; + } + + node = tree_create_folder_node(NULL, NULL, buffer, + false, true, true); + if (node == NULL) { + LOG(("malloc failed")); + warn_user("NoMemory", 0); + free(buffer); + return false; + } + if (folder_icon != NULL) + tree_set_node_icon(global_history_tree, node, folder_icon); + tree_set_node_user_callback(node, history_global_node_callback, NULL); + + global_history_base_node[global_history_base_node_count] = node; + global_history_base_node_time[global_history_base_node_count] = base; + global_history_base_node_count++; + + return true; +} + +/** + * Initialises the grouping nodes(Today, Yesterday etc.) for the global history + * tree. + * + * \return false on memory exhaustion, true otherwise + */ +static bool history_global_initialise_nodes(void) +{ + struct tm *full_time; + time_t t; + int weekday; + int i; + + /* get the current time */ + t = time(NULL); + if (t == -1) { + LOG(("time info unaviable")); + return false; + } + + /* get the time at the start of today */ + full_time = localtime(&t); + weekday = full_time->tm_wday; + full_time->tm_sec = 0; + full_time->tm_min = 0; + full_time->tm_hour = 0; + t = mktime(full_time); + if (t == -1) { + LOG(("mktime failed")); + return false; + } + + history_global_initialise_node(messages_get("DateToday"), t, 0); + if (weekday > 0) + if (!history_global_initialise_node( + messages_get("DateYesterday"), t, -1)) + return false; + for (i = 2; i <= weekday; i++) + if (!history_global_initialise_node(NULL, t, -i)) + return false; + + if (!history_global_initialise_node(messages_get("Date1Week"), + t, -weekday - 7)) + return false; + if (!history_global_initialise_node(messages_get("Date2Week"), + t, -weekday - 14)) + return false; + if (!history_global_initialise_node(messages_get("Date3Week"), + t, -weekday - 21)) + return false; + + return true; +} + +/** + * Initialises the global history tree. + * + * \param data user data for the callbacks + * \param start_redraw callback function called before every redraw + * \param end_redraw callback function called after every redraw + * \return true on success, false on memory exhaustion + */ +bool history_global_initialise(struct tree *tree) +{ + struct node *first; + + folder_icon = tree_load_icon(tree_directory_icon_name); + tree_url_node_init(); + + if (tree == NULL) + return false; + + global_history_tree = tree; + global_history_tree_root = tree_get_root(global_history_tree); + + if (!history_global_initialise_nodes()) + return false; + + global_history_initialised = true; + urldb_iterate_entries(global_history_add_internal); + global_history_initialised = false; + tree_set_node_expanded(global_history_tree, global_history_tree_root, + false, true, true); + first = tree_node_get_child(global_history_tree_root); + if (first != NULL) + tree_set_node_expanded(global_history_tree, first, + true, false, false); + + return true; +} + + +/** + * Get flags with which the global history tree should be created; + * + * \return the flags + */ +unsigned int history_global_get_tree_flags(void) +{ + return TREE_NO_FLAGS; +} + + +/** + * Deletes the global history tree. + */ +void history_global_cleanup(void) +{ +} + + +/** + * Adds a url to the global history. + * + * \param url the url to be added + */ +void global_history_add(const char *url) +{ + const struct url_data *data; + + data = urldb_get_url_data(url); + if (data == NULL) + return; + + global_history_add_internal(url, data); +} + + +/* Actions to be connected to front end specific toolbars */ + +/** + * Save the global history in a human-readable form under the given location. + * + * \param path the path where the history will be saved + */ +bool history_global_export(const char *path) +{ + return tree_urlfile_save(global_history_tree, path, "NetSurf history"); +} + +/** + * Delete nodes which are currently selected. + */ +void history_global_delete_selected(void) +{ + tree_delete_selected_nodes(global_history_tree, + global_history_tree_root); +} + +/** + * Delete all nodes. + */ +void history_global_delete_all(void) +{ + bool redraw_needed = tree_get_redraw(global_history_tree); + if (redraw_needed) + tree_set_redraw(global_history_tree, false); + + tree_set_node_selected(global_history_tree, global_history_tree_root, + true, true); + tree_delete_selected_nodes(global_history_tree, + global_history_tree_root); + + if (redraw_needed) + tree_set_redraw(global_history_tree, true); +} + +/** + * Select all nodes in the tree. + */ +void history_global_select_all(void) +{ + tree_set_node_selected(global_history_tree, global_history_tree_root, + true, true); +} + +/** + * Unselect all nodes. + */ +void history_global_clear_selection(void) +{ + tree_set_node_selected(global_history_tree, global_history_tree_root, + true, false); +} + +/** + * Expand grouping folders and history entries. + */ +void history_global_expand_all(void) +{ + tree_set_node_expanded(global_history_tree, global_history_tree_root, + true, true, true); +} + +/** + * Expand grouping folders only. + */ +void history_global_expand_directories(void) +{ + tree_set_node_expanded(global_history_tree, global_history_tree_root, + true, true, false); +} + +/** + * Expand history entries only. + */ +void history_global_expand_addresses(void) +{ + tree_set_node_expanded(global_history_tree, global_history_tree_root, + true, false, true); +} + +/** + * Collapse grouping folders and history entries. + */ +void history_global_collapse_all(void) +{ + tree_set_node_expanded(global_history_tree, global_history_tree_root, + false, true, true); +} + +/** + * Collapse grouping folders only. + */ +void history_global_collapse_directories(void) +{ + tree_set_node_expanded(global_history_tree, global_history_tree_root, + false, true, false); +} + +/** + * Collapse history entries only. + */ +void history_global_collapse_addresses(void) +{ + tree_set_node_expanded(global_history_tree, global_history_tree_root, + false, false, true); +} + +/** + * Open the selected entries in seperate browser windows. + */ +void history_global_launch_selected(void) +{ + tree_launch_selected(global_history_tree); +} diff --git a/desktop/history_global_core.h b/desktop/history_global_core.h new file mode 100644 index 000000000..97c578f3d --- /dev/null +++ b/desktop/history_global_core.h @@ -0,0 +1,44 @@ +/* + * Copyright 2005 Richard Wilson + * Copyright 2009 Paul Blokus + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _NETSURF_DESKTOP_HISTORY_GLOBAL_H_ +#define _NETSURF_DESKTOP_HISTORY_GLOBAL_H_ + +#include + +#include "desktop/tree.h" + +bool history_global_initialise(struct tree *tree); +unsigned int history_global_get_tree_flags(void); +void history_global_cleanup(void); + +bool history_global_export(const char *path); +void history_global_delete_selected(void); +void history_global_delete_all(void); +void history_global_select_all(void); +void history_global_clear_selection(void); +void history_global_expand_all(void); +void history_global_expand_directories(void); +void history_global_expand_addresses(void); +void history_global_collapse_all(void); +void history_global_collapse_directories(void); +void history_global_collapse_addresses(void); +void history_global_launch_selected(void); + +#endif diff --git a/desktop/hotlist.c b/desktop/hotlist.c new file mode 100644 index 000000000..09be05709 --- /dev/null +++ b/desktop/hotlist.c @@ -0,0 +1,457 @@ +/* + * Copyright 2004, 2005 Richard Wilson + * Copyright 2009 Paul Blokus + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include "content/content.h" +#include "content/hlcache.h" +#include "content/urldb.h" +#include "desktop/browser.h" +#include "desktop/hotlist.h" +#include "desktop/plotters.h" +#include "desktop/tree.h" +#include "desktop/tree_url_node.h" + +#include "utils/messages.h" +#include "utils/utils.h" +#include "utils/log.h" + +#define URL_CHUNK_LENGTH 512 + +static struct tree *hotlist_tree; +static struct node *hotlist_tree_root; + +static bool creating_node; +static hlcache_handle *folder_icon; + +static const struct { + const char *url; + const char *msg_key; +} hotlist_default_entries[] = { + { "http://www.netsurf-browser.org/", "HotlistHomepage" }, + { "http://www.netsurf-browser.org/downloads/riscos/testbuilds", + "HotlistTestBuild" }, + { "http://www.netsurf-browser.org/documentation", + "HotlistDocumentation" }, + { "http://sourceforge.net/tracker/?atid=464312&group_id=51719", + "HotlistBugTracker" }, + { "http://sourceforge.net/tracker/?atid=464315&group_id=51719", + "HotlistFeatureRequest" } +}; +#define HOTLIST_ENTRIES_COUNT (sizeof(hotlist_default_entries) / sizeof(hotlist_default_entries[0])) + +static node_callback_resp hotlist_node_callback(void *user_data, + struct node_msg_data *msg_data) +{ + struct node *node = msg_data->node; + const char *text; + char *norm_text; + bool is_folder = tree_node_is_folder(node); + + switch (msg_data->msg) { + case NODE_ELEMENT_EDIT_FINISHED: + if (creating_node && + (is_folder == false) && + (msg_data->flag == TREE_ELEMENT_TITLE)) { + tree_url_node_edit_url(hotlist_tree, node); + } else { + creating_node = false; + } + return NODE_CALLBACK_HANDLED; + + case NODE_ELEMENT_EDIT_FINISHING: + if (creating_node && (is_folder == false)) + return tree_url_node_callback(hotlist_tree, msg_data); + + if (is_folder == true) { + text = msg_data->data.text; + while (isspace(*text)) + text++; + norm_text = strdup(text); + if (norm_text == NULL) { + LOG(("malloc failed")); + warn_user("NoMemory", 0); + return NODE_CALLBACK_REJECT; + } + /* don't allow zero length entry text, return false */ + if (norm_text[0] == '\0') { + warn_user("NoNameError", 0); + msg_data->data.text = NULL; + return NODE_CALLBACK_CONTINUE; + } + msg_data->data.text = norm_text; + } + break; + + case NODE_DELETE_ELEMENT_IMG: + return NODE_CALLBACK_HANDLED; + + default: + if (is_folder == false) + return tree_url_node_callback(hotlist_tree, msg_data); + } + + return NODE_CALLBACK_NOT_HANDLED; +} + + +bool hotlist_initialise(struct tree *tree, const char *hotlist_path) +{ + struct node *node; + const struct url_data *url_data; + char *name; + int hlst_loop; + + /* Either load or create a hotlist */ + + creating_node = false; + + folder_icon = tree_load_icon(tree_directory_icon_name); + + tree_url_node_init(); + + if (tree == NULL) + return false; + + hotlist_tree = tree; + hotlist_tree_root = tree_get_root(hotlist_tree); + + if (tree_urlfile_load(hotlist_path, + hotlist_tree, + hotlist_node_callback, + NULL)) { + return true; + } + + + /* failed to load hotlist file, use default list */ + name = strdup("NetSurf"); + if (name == NULL) { + LOG(("malloc failed")); + warn_user("NoMemory", 0); + return false; + } + node = tree_create_folder_node(hotlist_tree, hotlist_tree_root, + name, true, false, false); + if (node == NULL) { + free(name); + return false; + } + + tree_set_node_user_callback(node, hotlist_node_callback, NULL); + tree_set_node_icon(hotlist_tree, node, folder_icon); + + for (hlst_loop = 0; hlst_loop != HOTLIST_ENTRIES_COUNT; hlst_loop++) { + url_data = urldb_get_url_data(hotlist_default_entries[hlst_loop].url); + if (url_data == NULL) { + urldb_add_url(hotlist_default_entries[hlst_loop].url); + urldb_set_url_persistence( + hotlist_default_entries[hlst_loop].url, + true); + url_data = urldb_get_url_data( + hotlist_default_entries[hlst_loop].url); + } + if (url_data != NULL) { + tree_create_URL_node(hotlist_tree, node, + hotlist_default_entries[hlst_loop].url, + messages_get(hotlist_default_entries[hlst_loop].msg_key), + hotlist_node_callback, NULL); + tree_update_URL_node(hotlist_tree, node, + hotlist_default_entries[hlst_loop].url, + url_data, false); + } + } + + + + return true; +} + + +/** + * Get flags with which the hotlist tree should be created; + * + * \return the flags + */ +unsigned int hotlist_get_tree_flags(void) +{ + return TREE_MOVABLE; +} + + +/** + * Deletes the global history tree and saves the hotlist. + * \param hotlist_path the path where the hotlist should be saved + */ +void hotlist_cleanup(const char *hotlist_path) +{ + hotlist_export(hotlist_path); +} + + +/** + * Informs the hotlist that some content has been visited. Internal procedure. + * + * \param content the content visited + * \param node the node to update siblings and children of + */ +static void hotlist_visited_internal(hlcache_handle *content, struct node *node) +{ + struct node *child; + const char *text; + const char *url; + + if (content == NULL || + content_get_url(content) == NULL || + hotlist_tree == NULL) + return; + + url = content_get_url(content); + + for (; node; node = tree_node_get_next(node)) { + if (!tree_node_is_folder(node)) { + text = tree_url_node_get_url(node); + if (strcmp(text, url) == 0) { + tree_update_URL_node(hotlist_tree, node, + url, NULL, false); + } + } + child = tree_node_get_child(node); + if (child != NULL) { + hotlist_visited_internal(content, child); + } + } +} + +/** + * Informs the hotlist that some content has been visited + * + * \param content the content visited + */ +void hotlist_visited(hlcache_handle *content) +{ + if (hotlist_tree != NULL) { + hotlist_visited_internal(content, tree_get_root(hotlist_tree)); + } +} + +/** + * Save the hotlist in a human-readable form under the given location. + * + * \param path the path where the hotlist will be saved + */ +bool hotlist_export(const char *path) +{ + return tree_urlfile_save(hotlist_tree, path, "NetSurf hotlist"); +} + +/** + * Edit the node which is currently selected. Works only if one node is + * selected. + */ +void hotlist_edit_selected(void) +{ + struct node *node; + struct node_element *element; + + node = tree_get_selected_node(hotlist_tree_root); + + if (node != NULL) { + creating_node = true; + element = tree_node_find_element(node, TREE_ELEMENT_TITLE, NULL); + tree_start_edit(hotlist_tree, element); + } +} + +/** + * Delete nodes which are currently selected. + */ +void hotlist_delete_selected(void) +{ + tree_delete_selected_nodes(hotlist_tree, hotlist_tree_root); +} + +/** + * Select all nodes in the tree. + */ +void hotlist_select_all(void) +{ + tree_set_node_selected(hotlist_tree, hotlist_tree_root, + true, true); +} + +/** + * Unselect all nodes. + */ +void hotlist_clear_selection(void) +{ + tree_set_node_selected(hotlist_tree, hotlist_tree_root, + true, false); +} + +/** + * Expand grouping folders and history entries. + */ +void hotlist_expand_all(void) +{ + tree_set_node_expanded(hotlist_tree, hotlist_tree_root, + true, true, true); +} + +/** + * Expand grouping folders only. + */ +void hotlist_expand_directories(void) +{ + tree_set_node_expanded(hotlist_tree, hotlist_tree_root, + true, true, false); +} + +/** + * Expand history entries only. + */ +void hotlist_expand_addresses(void) +{ + tree_set_node_expanded(hotlist_tree, hotlist_tree_root, + true, false, true); +} + +/** + * Collapse grouping folders and history entries. + */ +void hotlist_collapse_all(void) +{ + tree_set_node_expanded(hotlist_tree, hotlist_tree_root, + false, true, true); +} + +/** + * Collapse grouping folders only. + */ +void hotlist_collapse_directories(void) +{ + tree_set_node_expanded(hotlist_tree, hotlist_tree_root, + false, true, false); +} + +/** + * Collapse history entries only. + */ +void hotlist_collapse_addresses(void) +{ + tree_set_node_expanded(hotlist_tree, + hotlist_tree_root, false, false, true); +} + +/** + * Add a folder node. + */ +void hotlist_add_folder(void) +{ + struct node *node; + struct node_element *element; + char *title = strdup("Untitled"); + + if (title == NULL) { + LOG(("malloc failed")); + warn_user("NoMemory", 0); + return; + } + creating_node = true; + node = tree_create_folder_node(hotlist_tree, hotlist_tree_root, title, + true, false, false); + if (node == NULL) { + free(title); + return; + } + tree_set_node_user_callback(node, hotlist_node_callback, NULL); + tree_set_node_icon(hotlist_tree, node, folder_icon); + element = tree_node_find_element(node, TREE_ELEMENT_TITLE, NULL); + tree_start_edit(hotlist_tree, element); +} + +/** + * Add an entry node. + */ +void hotlist_add_entry(void) +{ + struct node *node; + creating_node = true; + node = tree_create_URL_node(hotlist_tree, hotlist_tree_root, "Address", + "Untitled", hotlist_node_callback, NULL); + + if (node == NULL) + return; + tree_set_node_user_callback(node, hotlist_node_callback, NULL); + tree_url_node_edit_title(hotlist_tree, node); +} + +/** + * Adds the currently viewed page to the hotlist + */ +void hotlist_add_page(const char *url) +{ + const struct url_data *data; + struct node *node; + + if (url == NULL) + return; + data = urldb_get_url_data(url); + if (data == NULL) + return; + + node = tree_create_URL_node(hotlist_tree, hotlist_tree_root, url, NULL, + hotlist_node_callback, NULL); + tree_update_URL_node(hotlist_tree, node, url, data, false); +} + +/** + * Adds the currently viewed page to the hotlist at the given cooridinates + * \param url url of the page + * \param x X cooridinate with respect to tree origin + * \param y Y cooridinate with respect to tree origin + */ +void hotlist_add_page_xy(const char *url, int x, int y) +{ + const struct url_data *data; + struct node *link, *node; + bool before; + + data = urldb_get_url_data(url); + if (data == NULL) { + urldb_add_url(url); + urldb_set_url_persistence(url, true); + data = urldb_get_url_data(url); + } + if (data != NULL) { + link = tree_get_link_details(hotlist_tree, x, y, &before); + node = tree_create_URL_node(NULL, NULL, url, + NULL, hotlist_node_callback, NULL); + tree_link_node(hotlist_tree, link, node, before); + } +} + +/** + * Open the selected entries in separate browser windows. + */ +void hotlist_launch_selected(void) +{ + tree_launch_selected(hotlist_tree); +} diff --git a/desktop/hotlist.h b/desktop/hotlist.h new file mode 100644 index 000000000..84f573a90 --- /dev/null +++ b/desktop/hotlist.h @@ -0,0 +1,54 @@ +/* + * Copyright 2004, 2005 Richard Wilson + * Copyright 2009 Paul Blokus + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + + +/** \file + * Hotlist (interface). + */ + +#ifndef _NETSURF_DESKTOP_HOTLIST_H_ +#define _NETSURF_DESKTOP_HOTLIST_H_ + +#include + +#include "desktop/tree.h" + +bool hotlist_initialise(struct tree *tree, const char *hotlist_path); +unsigned int hotlist_get_tree_flags(void); +void hotlist_cleanup(const char *hotlist_path); + +bool hotlist_export(const char *path); +void hotlist_edit_selected(void); +void hotlist_delete_selected(void); +void hotlist_select_all(void); +void hotlist_clear_selection(void); +void hotlist_expand_all(void); +void hotlist_expand_directories(void); +void hotlist_expand_addresses(void); +void hotlist_collapse_all(void); +void hotlist_collapse_directories(void); +void hotlist_collapse_addresses(void); +void hotlist_add_folder(void); +void hotlist_add_entry(void); +void hotlist_add_page(const char *url); +void hotlist_add_page_xy(const char *url, int x, int y); +void hotlist_launch_selected(void); + +#endif diff --git a/desktop/options.c b/desktop/options.c index 9ed8b192c..47b42dc3b 100644 --- a/desktop/options.c +++ b/desktop/options.c @@ -31,16 +31,10 @@ #include #include #include -#include -#include -#include "content/urldb.h" #include "css/css.h" #include "desktop/options.h" #include "desktop/plot_style.h" -#include "desktop/tree.h" #include "utils/log.h" -#include "utils/messages.h" -#include "utils/url.h" #include "utils/utils.h" #if defined(riscos) @@ -145,6 +139,7 @@ unsigned int option_min_reflow_period = 100; /* time in cs */ #else unsigned int option_min_reflow_period = 25; /* time in cs */ #endif +char *option_tree_icons_dir = NULL; bool option_core_select_menu = false; /** top margin of exported page*/ int option_margin_top = DEFAULT_MARGIN_TOP_MM; @@ -247,6 +242,7 @@ struct { { "scale", OPTION_INTEGER, &option_scale }, { "incremental_reflow", OPTION_BOOL, &option_incremental_reflow }, { "min_reflow_period", OPTION_INTEGER, &option_min_reflow_period }, + { "tree_icons_dir", OPTION_STRING, &option_tree_icons_dir }, { "core_select_menu", OPTION_BOOL, &option_core_select_menu }, /* Fetcher options */ { "max_fetchers", OPTION_INTEGER, &option_max_fetchers }, @@ -276,13 +272,6 @@ struct { #define option_table_entries (sizeof option_table / sizeof option_table[0]) -static void options_load_tree_directory(xmlNode *ul, struct node *directory); -static void options_load_tree_entry(xmlNode *li, struct node *directory); -xmlNode *options_find_tree_element(xmlNode *node, const char *name); -bool options_save_tree_directory(struct node *directory, xmlNode *node); -bool options_save_tree_entry(struct node *entry, xmlNode *node); - - /** * Read options from a file. * @@ -429,351 +418,3 @@ void options_dump(void) fprintf(stderr, "\n"); } } - -/** - * Loads a hotlist as a tree from a specified file. - * - * \param filename name of file to read - * \return the hotlist file represented as a tree, or NULL on failure - */ -struct tree *options_load_tree(const char *filename) { - xmlDoc *doc; - xmlNode *html, *body, *ul; - struct tree *tree; - - doc = htmlParseFile(filename, "iso-8859-1"); - if (!doc) { - warn_user("HotlistLoadError", messages_get("ParsingFail")); - return NULL; - } - - html = options_find_tree_element((xmlNode *) doc, "html"); - body = options_find_tree_element(html, "body"); - ul = options_find_tree_element(body, "ul"); - if (!ul) { - xmlFreeDoc(doc); - warn_user("HotlistLoadError", - "(......