2005-02-07 17:28:43 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2005 Richard Wilson <info@tinct.net>
|
2010-10-05 23:14:46 +04:00
|
|
|
* Copyright 2010 Stephen Fryatt <stevef@netsurf-browser.org>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
2005-02-07 17:28:43 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Global history (implementation).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2005-02-09 02:37:41 +03:00
|
|
|
#include <time.h>
|
2005-02-07 17:28:43 +03:00
|
|
|
#include "oslib/wimp.h"
|
|
|
|
#include "oslib/wimpspriteop.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/urldb.h"
|
2010-10-05 23:14:46 +04:00
|
|
|
#include "desktop/history_global_core.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/tree.h"
|
|
|
|
#include "riscos/dialog.h"
|
|
|
|
#include "riscos/global_history.h"
|
|
|
|
#include "riscos/gui.h"
|
|
|
|
#include "riscos/menus.h"
|
|
|
|
#include "riscos/options.h"
|
2010-10-05 23:14:46 +04:00
|
|
|
#include "riscos/save.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/theme.h"
|
|
|
|
#include "riscos/treeview.h"
|
|
|
|
#include "riscos/wimp.h"
|
|
|
|
#include "riscos/wimp_event.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/url.h"
|
|
|
|
#include "utils/utils.h"
|
2005-02-07 17:28:43 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
/* The RISC OS global history window, toolbar and treeview data */
|
2005-02-09 02:37:41 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
static struct ro_global_history_window {
|
|
|
|
wimp_w window;
|
|
|
|
struct toolbar *toolbar;
|
|
|
|
ro_treeview *tv;
|
|
|
|
wimp_menu *menu;
|
|
|
|
} global_history_window;
|
2005-02-07 17:28:43 +03:00
|
|
|
|
2006-04-10 03:21:13 +04:00
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Pre-Initialise the global history tree. This is called for things that
|
|
|
|
* need to be done at the gui_init() stage, such as loading templates.
|
2006-04-10 03:21:13 +04:00
|
|
|
*/
|
2010-10-05 23:14:46 +04:00
|
|
|
|
|
|
|
void ro_gui_global_history_preinitialise(void)
|
2006-04-10 03:21:13 +04:00
|
|
|
{
|
2010-10-05 23:14:46 +04:00
|
|
|
/* Create our window. */
|
2005-02-07 17:28:43 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
global_history_window.window = ro_gui_dialog_create("tree");
|
|
|
|
ro_gui_set_window_title(global_history_window.window,
|
2006-01-07 00:25:34 +03:00
|
|
|
messages_get("GlobalHistory"));
|
2005-02-07 17:28:43 +03:00
|
|
|
}
|
|
|
|
|
2005-02-09 02:37:41 +03:00
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Initialise global history tree, at the gui_init2() stage.
|
2005-02-09 02:37:41 +03:00
|
|
|
*/
|
2005-04-08 00:46:22 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
void ro_gui_global_history_postinitialise(void)
|
|
|
|
{
|
2005-04-08 00:46:22 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
/* Create our toolbar. */
|
2005-02-09 02:37:41 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
global_history_window.toolbar = ro_gui_theme_create_toolbar(NULL,
|
|
|
|
THEME_HISTORY_TOOLBAR);
|
|
|
|
if (global_history_window.toolbar)
|
|
|
|
ro_gui_theme_attach_toolbar(global_history_window.toolbar,
|
|
|
|
global_history_window.window);
|
|
|
|
|
|
|
|
/* Create the treeview with the window and toolbar. */
|
|
|
|
|
|
|
|
global_history_window.tv =
|
|
|
|
ro_treeview_create(global_history_window.window,
|
|
|
|
global_history_window.toolbar,
|
|
|
|
history_global_get_tree_flags());
|
|
|
|
if (global_history_window.tv == NULL) {
|
|
|
|
LOG(("Failed to allocate treeview"));
|
2005-02-09 02:37:41 +03:00
|
|
|
return;
|
2010-10-05 23:14:46 +04:00
|
|
|
}
|
2005-02-09 02:37:41 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
/* Initialise the global history into the tree. */
|
|
|
|
|
|
|
|
history_global_initialise(
|
2010-12-14 03:18:24 +03:00
|
|
|
ro_treeview_get_tree(global_history_window.tv),
|
|
|
|
tree_directory_icon_name);
|
2010-10-05 23:14:46 +04:00
|
|
|
|
|
|
|
/* Build the global history window menu. */
|
|
|
|
|
|
|
|
static const struct ns_menu global_history_definition = {
|
|
|
|
"History", {
|
|
|
|
{ "History", NO_ACTION, 0 },
|
|
|
|
{ "_History.Export", HISTORY_EXPORT, &dialog_saveas },
|
|
|
|
{ "History.Expand", TREE_EXPAND_ALL, 0 },
|
|
|
|
{ "History.Expand.All", TREE_EXPAND_ALL, 0 },
|
|
|
|
{ "History.Expand.Folders", TREE_EXPAND_FOLDERS, 0 },
|
|
|
|
{ "History.Expand.Links", TREE_EXPAND_LINKS, 0 },
|
|
|
|
{ "History.Collapse", TREE_COLLAPSE_ALL, 0 },
|
|
|
|
{ "History.Collapse.All", TREE_COLLAPSE_ALL, 0 },
|
|
|
|
{ "History.Collapse.Folders", TREE_COLLAPSE_FOLDERS, 0 },
|
|
|
|
{ "History.Collapse.Links", TREE_COLLAPSE_LINKS, 0 },
|
|
|
|
{ "History.Toolbars", NO_ACTION, 0 },
|
|
|
|
{ "_History.Toolbars.ToolButtons", TOOLBAR_BUTTONS, 0 },
|
|
|
|
{ "History.Toolbars.EditToolbar",TOOLBAR_EDIT, 0 },
|
|
|
|
{ "Selection", TREE_SELECTION, 0 },
|
|
|
|
{ "Selection.Launch", TREE_SELECTION_LAUNCH, 0 },
|
|
|
|
{ "Selection.Delete", TREE_SELECTION_DELETE, 0 },
|
|
|
|
{ "SelectAll", TREE_SELECT_ALL, 0 },
|
|
|
|
{ "Clear", TREE_CLEAR_SELECTION, 0 },
|
|
|
|
{NULL, 0, 0}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
global_history_window.menu = ro_gui_menu_define_menu(
|
|
|
|
&global_history_definition);
|
|
|
|
|
|
|
|
ro_gui_wimp_event_register_window_menu(global_history_window.window,
|
|
|
|
global_history_window.menu,
|
|
|
|
ro_gui_global_history_menu_prepare,
|
|
|
|
ro_gui_global_history_menu_select, NULL,
|
|
|
|
ro_gui_global_history_menu_warning, false);
|
2005-02-09 02:37:41 +03:00
|
|
|
}
|
|
|
|
|
2005-02-07 17:28:43 +03:00
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Open the global history window.
|
2005-02-07 17:28:43 +03:00
|
|
|
*/
|
2010-10-05 23:14:46 +04:00
|
|
|
|
|
|
|
void ro_gui_global_history_open(void)
|
2006-04-10 03:21:13 +04:00
|
|
|
{
|
2010-10-05 23:14:46 +04:00
|
|
|
tree_set_redraw(ro_treeview_get_tree(global_history_window.tv), true);
|
|
|
|
|
|
|
|
if (!ro_gui_dialog_open_top(global_history_window.window,
|
|
|
|
global_history_window.toolbar, 600, 800)) {
|
|
|
|
ro_treeview_set_origin(global_history_window.tv, 0,
|
|
|
|
-(ro_gui_theme_toolbar_height(
|
|
|
|
global_history_window.toolbar)));
|
2005-02-07 17:28:43 +03:00
|
|
|
}
|
2005-03-13 01:32:43 +03:00
|
|
|
}
|
|
|
|
|
2010-10-25 00:00:45 +04:00
|
|
|
/**
|
|
|
|
* Handle Mouse Click events on the toolbar.
|
|
|
|
*
|
|
|
|
* \param *pointer Pointer to the Mouse Click Event block.
|
|
|
|
* \return Return true if click handled; else false.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool ro_gui_global_history_toolbar_click(wimp_pointer *pointer)
|
|
|
|
{
|
2010-10-25 03:17:21 +04:00
|
|
|
if (pointer->buttons == wimp_CLICK_MENU)
|
|
|
|
return ro_gui_wimp_event_process_window_menu_click(pointer);
|
|
|
|
|
2010-10-25 01:52:16 +04:00
|
|
|
if (global_history_window.toolbar->editor != NULL) {
|
|
|
|
ro_gui_theme_toolbar_editor_click(global_history_window.toolbar,
|
|
|
|
pointer);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-25 00:00:45 +04:00
|
|
|
switch (pointer->i) {
|
|
|
|
case ICON_TOOLBAR_DELETE:
|
|
|
|
if (pointer->buttons == wimp_CLICK_SELECT) {
|
|
|
|
history_global_delete_selected();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ICON_TOOLBAR_EXPAND:
|
|
|
|
if (pointer->buttons == wimp_CLICK_SELECT) {
|
|
|
|
history_global_expand_addresses();
|
|
|
|
return true;
|
|
|
|
} else if (pointer->buttons == wimp_CLICK_ADJUST) {
|
|
|
|
history_global_collapse_addresses();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ICON_TOOLBAR_OPEN:
|
|
|
|
if (pointer->buttons == wimp_CLICK_SELECT) {
|
|
|
|
history_global_expand_directories();
|
|
|
|
return true;
|
|
|
|
} else if (pointer->buttons == wimp_CLICK_ADJUST) {
|
|
|
|
history_global_collapse_directories();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ICON_TOOLBAR_LAUNCH:
|
|
|
|
if (pointer->buttons == wimp_CLICK_SELECT) {
|
|
|
|
history_global_launch_selected();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-07 17:28:43 +03:00
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Prepare the global history menu for opening
|
2005-02-07 17:28:43 +03:00
|
|
|
*
|
2010-10-05 23:14:46 +04:00
|
|
|
* \param window The window owning the menu.
|
|
|
|
* \param *menu The menu about to be opened.
|
2005-02-07 17:28:43 +03:00
|
|
|
*/
|
2010-10-05 23:14:46 +04:00
|
|
|
|
|
|
|
void ro_gui_global_history_menu_prepare(wimp_w window, wimp_menu *menu)
|
2006-04-10 03:21:13 +04:00
|
|
|
{
|
2010-10-05 23:14:46 +04:00
|
|
|
bool selection;
|
|
|
|
|
2010-10-25 03:17:21 +04:00
|
|
|
if (menu != global_history_window.menu && menu != tree_toolbar_menu)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (menu == global_history_window.menu) {
|
|
|
|
selection = ro_treeview_has_selection(global_history_window.tv);
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2010-10-25 03:17:21 +04:00
|
|
|
ro_gui_menu_set_entry_shaded(global_history_window.menu,
|
|
|
|
TREE_SELECTION, !selection);
|
|
|
|
ro_gui_menu_set_entry_shaded(global_history_window.menu,
|
|
|
|
TREE_CLEAR_SELECTION, !selection);
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2010-10-25 03:17:21 +04:00
|
|
|
ro_gui_save_prepare(GUI_SAVE_HISTORY_EXPORT_HTML,
|
|
|
|
NULL, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
ro_gui_menu_set_entry_shaded(menu, TOOLBAR_BUTTONS,
|
2010-10-05 23:14:46 +04:00
|
|
|
(global_history_window.toolbar == NULL ||
|
|
|
|
global_history_window.toolbar->editor));
|
2010-10-25 03:17:21 +04:00
|
|
|
ro_gui_menu_set_entry_ticked(menu, TOOLBAR_BUTTONS,
|
2010-10-05 23:14:46 +04:00
|
|
|
(global_history_window.toolbar != NULL &&
|
|
|
|
(global_history_window.toolbar->display_buttons ||
|
|
|
|
(global_history_window.toolbar->editor))));
|
|
|
|
|
2010-10-25 03:17:21 +04:00
|
|
|
ro_gui_menu_set_entry_shaded(menu, TOOLBAR_EDIT,
|
2010-10-05 23:14:46 +04:00
|
|
|
global_history_window.toolbar == NULL);
|
2010-10-25 03:17:21 +04:00
|
|
|
ro_gui_menu_set_entry_ticked(menu, TOOLBAR_EDIT,
|
2010-10-05 23:14:46 +04:00
|
|
|
(global_history_window.toolbar != NULL &&
|
|
|
|
global_history_window.toolbar->editor));
|
2005-02-07 17:28:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Handle submenu warnings for the global_hostory menu
|
2006-04-10 03:21:13 +04:00
|
|
|
*
|
2010-10-05 23:14:46 +04:00
|
|
|
* \param window The window owning the menu.
|
|
|
|
* \param *menu The menu to which the warning applies.
|
|
|
|
* \param *selection The wimp menu selection data.
|
|
|
|
* \param action The selected menu action.
|
2005-02-07 17:28:43 +03:00
|
|
|
*/
|
2006-04-11 06:39:55 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
void ro_gui_global_history_menu_warning(wimp_w window, wimp_menu *menu,
|
|
|
|
wimp_selection *selection, menu_action action)
|
|
|
|
{
|
|
|
|
/* Do nothing */
|
2006-04-11 06:39:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Handle selections from the global history menu
|
2006-04-11 06:39:55 +04:00
|
|
|
*
|
2010-10-05 23:14:46 +04:00
|
|
|
* \param window The window owning the menu.
|
|
|
|
* \param *menu The menu from which the selection was made.
|
|
|
|
* \param *selection The wimp menu selection data.
|
|
|
|
* \param action The selected menu action.
|
|
|
|
* \return true if action accepted; else false.
|
2006-04-11 06:39:55 +04:00
|
|
|
*/
|
2005-04-08 00:46:22 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
bool ro_gui_global_history_menu_select(wimp_w window, wimp_menu *menu,
|
|
|
|
wimp_selection *selection, menu_action action)
|
|
|
|
{
|
|
|
|
switch (action) {
|
|
|
|
case HISTORY_EXPORT:
|
|
|
|
ro_gui_dialog_open_persistent(window, dialog_saveas, true);
|
2006-04-11 06:39:55 +04:00
|
|
|
return true;
|
2010-10-05 23:14:46 +04:00
|
|
|
case TREE_EXPAND_ALL:
|
|
|
|
history_global_expand_all();
|
|
|
|
return true;
|
|
|
|
case TREE_EXPAND_FOLDERS:
|
|
|
|
history_global_expand_directories();
|
|
|
|
return true;
|
|
|
|
case TREE_EXPAND_LINKS:
|
|
|
|
history_global_expand_addresses();
|
|
|
|
return true;
|
|
|
|
case TREE_COLLAPSE_ALL:
|
|
|
|
history_global_collapse_all();
|
|
|
|
return true;
|
|
|
|
case TREE_COLLAPSE_FOLDERS:
|
|
|
|
history_global_collapse_directories();
|
|
|
|
return true;
|
|
|
|
case TREE_COLLAPSE_LINKS:
|
|
|
|
history_global_collapse_addresses();
|
|
|
|
return true;
|
|
|
|
case TREE_SELECTION_LAUNCH:
|
|
|
|
history_global_launch_selected();
|
|
|
|
return true;
|
|
|
|
case TREE_SELECTION_DELETE:
|
|
|
|
history_global_delete_selected();
|
|
|
|
return true;
|
|
|
|
case TREE_SELECT_ALL:
|
|
|
|
history_global_select_all();
|
|
|
|
return true;
|
|
|
|
case TREE_CLEAR_SELECTION:
|
|
|
|
history_global_clear_selection();
|
|
|
|
return true;
|
2010-10-25 01:52:16 +04:00
|
|
|
case TOOLBAR_BUTTONS:
|
|
|
|
global_history_window.toolbar->display_buttons =
|
|
|
|
!global_history_window.toolbar->display_buttons;
|
|
|
|
ro_gui_theme_refresh_toolbar(global_history_window.toolbar);
|
|
|
|
return true;
|
|
|
|
case TOOLBAR_EDIT:
|
|
|
|
ro_gui_theme_toggle_edit(global_history_window.toolbar);
|
|
|
|
return true;
|
2010-10-05 23:14:46 +04:00
|
|
|
default:
|
|
|
|
return false;
|
2005-12-31 07:36:24 +03:00
|
|
|
}
|
2006-04-11 06:39:55 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
return false;
|
2005-12-31 07:36:24 +03:00
|
|
|
}
|
|
|
|
|
2006-04-10 03:21:13 +04:00
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Update the theme details of the global history window.
|
2010-10-25 01:52:16 +04:00
|
|
|
*
|
|
|
|
* \param full_update true to force a full theme change; false to
|
|
|
|
* refresh the toolbar size.
|
2006-04-10 03:21:13 +04:00
|
|
|
*/
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2010-10-25 01:52:16 +04:00
|
|
|
void ro_gui_global_history_update_theme(bool full_update)
|
2006-04-10 03:21:13 +04:00
|
|
|
{
|
2010-10-25 01:52:16 +04:00
|
|
|
if (full_update)
|
|
|
|
ro_treeview_update_theme(global_history_window.tv);
|
|
|
|
else
|
|
|
|
ro_treeview_update_toolbar(global_history_window.tv);
|
2005-02-07 17:28:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Check if a particular window handle is the global history window
|
2005-02-07 17:28:43 +03:00
|
|
|
*
|
2010-10-05 23:14:46 +04:00
|
|
|
* \param window the window in question
|
|
|
|
* \return true if this window is the global history
|
2005-02-07 17:28:43 +03:00
|
|
|
*/
|
2005-04-08 00:46:22 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
bool ro_gui_global_history_check_window(wimp_w window)
|
|
|
|
{
|
2010-10-25 01:52:16 +04:00
|
|
|
if (global_history_window.window == window)
|
2010-10-05 23:14:46 +04:00
|
|
|
return true;
|
2010-10-25 01:52:16 +04:00
|
|
|
else
|
2010-10-05 23:14:46 +04:00
|
|
|
return false;
|
2005-02-07 17:28:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Check if a particular menu handle is the global history menu
|
2005-02-07 17:28:43 +03:00
|
|
|
*
|
2010-10-05 23:14:46 +04:00
|
|
|
* \param *menu The menu in question.
|
|
|
|
* \return true if this menu is the global history menu
|
2005-02-07 17:28:43 +03:00
|
|
|
*/
|
2010-10-05 23:14:46 +04:00
|
|
|
|
|
|
|
bool ro_gui_global_history_check_menu(wimp_menu *menu)
|
2006-04-10 03:21:13 +04:00
|
|
|
{
|
2010-10-05 23:14:46 +04:00
|
|
|
if (global_history_window.menu == menu)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
2005-02-07 17:28:43 +03:00
|
|
|
}
|
2010-10-05 23:14:46 +04:00
|
|
|
|