2004-06-30 21:44:11 +04:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
|
|
|
* Copyright 2004 Richard Wilson <not_ginger_matt@users.sourceforge.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Hotlist (implementation).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
2004-07-03 20:28:09 +04:00
|
|
|
#include <time.h>
|
2004-07-09 21:03:35 +04:00
|
|
|
#include <swis.h>
|
2004-07-16 03:58:08 +04:00
|
|
|
#include "libxml/parserInternals.h"
|
2004-06-30 21:44:11 +04:00
|
|
|
#include "oslib/colourtrans.h"
|
2004-07-07 04:31:57 +04:00
|
|
|
#include "oslib/dragasprite.h"
|
2004-07-04 18:59:29 +04:00
|
|
|
#include "oslib/osfile.h"
|
2004-06-30 21:44:11 +04:00
|
|
|
#include "oslib/wimp.h"
|
|
|
|
#include "oslib/wimpspriteop.h"
|
2004-07-02 02:56:26 +04:00
|
|
|
#include "netsurf/content/content.h"
|
2004-06-30 21:44:11 +04:00
|
|
|
#include "netsurf/riscos/gui.h"
|
2004-07-08 02:09:26 +04:00
|
|
|
#include "netsurf/riscos/theme.h"
|
2004-07-09 21:03:35 +04:00
|
|
|
#include "netsurf/riscos/tinct.h"
|
2004-07-17 17:00:38 +04:00
|
|
|
#include "netsurf/riscos/toolbar.h"
|
2004-06-30 21:44:11 +04:00
|
|
|
#include "netsurf/riscos/wimp.h"
|
|
|
|
#include "netsurf/utils/log.h"
|
2004-07-03 21:30:28 +04:00
|
|
|
#include "netsurf/utils/messages.h"
|
2004-06-30 21:44:11 +04:00
|
|
|
#include "netsurf/utils/utils.h"
|
2004-07-09 21:03:35 +04:00
|
|
|
#include "netsurf/utils/url.h"
|
2004-06-30 21:44:11 +04:00
|
|
|
|
|
|
|
#define HOTLIST_EXPAND 0
|
|
|
|
#define HOTLIST_COLLAPSE 1
|
|
|
|
#define HOTLIST_ENTRY 2
|
|
|
|
#define HOTLIST_LINE 3
|
|
|
|
#define HOTLIST_TLINE 4
|
|
|
|
#define HOTLIST_BLINE 5
|
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
#define HOTLIST_TEXT_BUFFER 256
|
2004-07-03 20:28:09 +04:00
|
|
|
|
2004-07-04 22:44:51 +04:00
|
|
|
#define HOTLIST_LEAF_INSET 32
|
|
|
|
#define HOTLIST_ICON_WIDTH 36
|
|
|
|
#define HOTLIST_LINE_HEIGHT 44
|
|
|
|
#define HOTLIST_TEXT_PADDING 16
|
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
struct hotlist_entry {
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/** The next hotlist entry at this level, or NULL for no more
|
|
|
|
*/
|
|
|
|
struct hotlist_entry *next_entry;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/** The child hotlist entry (NULL for no children).
|
|
|
|
The children value must be set for this value to take effect.
|
|
|
|
*/
|
|
|
|
struct hotlist_entry *child_entry;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
/** The hotlist entry that has this entry as its next entry
|
|
|
|
*/
|
|
|
|
struct hotlist_entry *previous_entry;
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
/** The hotlist entry that this is a child of
|
|
|
|
*/
|
|
|
|
struct hotlist_entry *parent_entry;
|
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/** The number of children (-1 for non-folders, >=0 for folders)
|
|
|
|
*/
|
|
|
|
int children;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/** The title of the hotlist entry/folder
|
|
|
|
*/
|
|
|
|
char *title;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/** The URL of the hotlist entry (NULL for folders)
|
|
|
|
*/
|
|
|
|
char *url;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/** Whether this entry is expanded
|
|
|
|
*/
|
|
|
|
bool expanded;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/** Whether this entry is selected
|
|
|
|
*/
|
|
|
|
bool selected;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-02 02:56:26 +04:00
|
|
|
/** The content filetype (not for folders)
|
|
|
|
*/
|
|
|
|
int filetype;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-02 02:56:26 +04:00
|
|
|
/** The number of visits
|
|
|
|
*/
|
|
|
|
int visits;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
/** Add/last visit dates
|
2004-07-02 02:56:26 +04:00
|
|
|
*/
|
2004-07-03 20:28:09 +04:00
|
|
|
time_t add_date;
|
|
|
|
time_t last_date;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/** Position on last reformat (relative to window origin)
|
|
|
|
*/
|
|
|
|
int x0;
|
|
|
|
int y0;
|
|
|
|
int width;
|
|
|
|
int height;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/** Cached values
|
|
|
|
*/
|
|
|
|
int collapsed_width;
|
|
|
|
int expanded_width;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
/** The width of the various lines sub-text
|
|
|
|
*/
|
|
|
|
int widths[4];
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
/** Whether the item is awaiting processing
|
|
|
|
*/
|
|
|
|
bool process;
|
2004-06-30 21:44:11 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* A basic window for the toolbar and status
|
|
|
|
*/
|
|
|
|
static wimp_window hotlist_window_definition = {
|
|
|
|
{0, 0, 600, 800},
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
wimp_TOP,
|
|
|
|
wimp_WINDOW_NEW_FORMAT | wimp_WINDOW_MOVEABLE | wimp_WINDOW_BACK_ICON |
|
|
|
|
wimp_WINDOW_CLOSE_ICON | wimp_WINDOW_TITLE_ICON |
|
|
|
|
wimp_WINDOW_TOGGLE_ICON | wimp_WINDOW_SIZE_ICON |wimp_WINDOW_VSCROLL,
|
|
|
|
wimp_COLOUR_BLACK,
|
|
|
|
wimp_COLOUR_LIGHT_GREY,
|
|
|
|
wimp_COLOUR_LIGHT_GREY,
|
2004-07-08 02:09:26 +04:00
|
|
|
wimp_COLOUR_WHITE,
|
2004-06-30 21:44:11 +04:00
|
|
|
wimp_COLOUR_DARK_GREY,
|
|
|
|
wimp_COLOUR_MID_LIGHT_GREY,
|
|
|
|
wimp_COLOUR_CREAM,
|
|
|
|
0,
|
|
|
|
{0, -800, 16384, 0},
|
2004-07-09 21:03:35 +04:00
|
|
|
wimp_ICON_TEXT | wimp_ICON_INDIRECTED | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED,
|
2004-06-30 21:44:11 +04:00
|
|
|
(wimp_BUTTON_DOUBLE_CLICK_DRAG << wimp_ICON_BUTTON_TYPE_SHIFT),
|
|
|
|
wimpspriteop_AREA,
|
|
|
|
1,
|
2004-07-08 02:09:26 +04:00
|
|
|
256,
|
2004-07-09 21:03:35 +04:00
|
|
|
{""},
|
2004-07-04 22:44:51 +04:00
|
|
|
0
|
2004-06-30 21:44:11 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* An icon to plot text with
|
|
|
|
*/
|
|
|
|
static wimp_icon text_icon;
|
|
|
|
static wimp_icon sprite_icon;
|
|
|
|
static char null_text_string[] = "\0";
|
|
|
|
|
2004-07-02 02:56:26 +04:00
|
|
|
/* Temporary workspace for plotting
|
|
|
|
*/
|
2004-07-07 04:31:57 +04:00
|
|
|
static char drag_name[12];
|
2004-07-02 02:56:26 +04:00
|
|
|
static char icon_name[12];
|
2004-07-03 21:30:28 +04:00
|
|
|
static char extended_text[HOTLIST_TEXT_BUFFER];
|
2004-07-02 02:56:26 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/* Whether a reformat is pending
|
|
|
|
*/
|
2004-07-02 02:56:26 +04:00
|
|
|
static bool reformat_pending = false;
|
|
|
|
static int max_width = 0;
|
|
|
|
static int max_height = 0;
|
2004-06-30 21:44:11 +04:00
|
|
|
|
2004-07-08 02:09:26 +04:00
|
|
|
/* The hotlist window, toolbar and plot origins
|
2004-06-30 21:44:11 +04:00
|
|
|
*/
|
|
|
|
wimp_w hotlist_window;
|
2004-07-08 02:09:26 +04:00
|
|
|
struct toolbar *hotlist_toolbar = NULL;
|
2004-07-02 02:56:26 +04:00
|
|
|
static int origin_x, origin_y;
|
|
|
|
|
|
|
|
/* The current redraw rectangle
|
|
|
|
*/
|
|
|
|
static int clip_x0, clip_y0, clip_x1, clip_y1;
|
2004-06-30 21:44:11 +04:00
|
|
|
|
|
|
|
/* The root entry
|
|
|
|
*/
|
2004-07-02 02:56:26 +04:00
|
|
|
static struct hotlist_entry root;
|
2004-06-30 21:44:11 +04:00
|
|
|
|
2004-07-09 21:03:35 +04:00
|
|
|
/* The sprite header addresses for Tinct
|
2004-06-30 21:44:11 +04:00
|
|
|
*/
|
2004-07-09 21:03:35 +04:00
|
|
|
static char *sprite[6];
|
2004-06-30 21:44:11 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
/* The drag buttons
|
|
|
|
*/
|
2004-07-16 20:33:45 +04:00
|
|
|
bool dragging;
|
2004-07-03 21:30:28 +04:00
|
|
|
wimp_mouse_state drag_buttons;
|
|
|
|
|
2004-07-04 22:44:51 +04:00
|
|
|
/* Whether the current selection was from a menu click
|
|
|
|
*/
|
|
|
|
bool menu_selection = false;
|
2004-07-06 02:17:59 +04:00
|
|
|
bool menu_open = false;
|
2004-07-04 22:44:51 +04:00
|
|
|
|
2004-07-09 02:05:35 +04:00
|
|
|
/* Whether the editing facilities are for add so that we know how
|
|
|
|
to reset the dialog boxes on a adjust-cancel and the action to
|
|
|
|
perform on ok.
|
|
|
|
*/
|
|
|
|
bool dialog_folder_add = false;
|
|
|
|
bool dialog_entry_add = false;
|
|
|
|
bool hotlist_insert = false;
|
|
|
|
|
2004-07-16 03:58:08 +04:00
|
|
|
/* Hotlist loading buffers
|
2004-07-04 22:44:51 +04:00
|
|
|
*/
|
2004-07-16 03:58:08 +04:00
|
|
|
static char *load_title = NULL;
|
|
|
|
static char *load_url = NULL;
|
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
|
2004-07-09 02:05:35 +04:00
|
|
|
static bool ro_gui_hotlist_initialise_sprite(const char *name, int number);
|
2004-07-04 18:59:29 +04:00
|
|
|
static bool ro_gui_hotlist_load(void);
|
2004-07-26 01:45:37 +04:00
|
|
|
static void ro_gui_hotlist_load_entry(xmlNode *cur, struct hotlist_entry *entry, bool allow_add);
|
2004-07-04 22:44:51 +04:00
|
|
|
static bool ro_gui_hotlist_save_entry(FILE *fp, struct hotlist_entry *entry);
|
2004-07-07 04:31:57 +04:00
|
|
|
static void ro_gui_hotlist_link_entry(struct hotlist_entry *link, struct hotlist_entry *entry, bool before);
|
|
|
|
static void ro_gui_hotlist_delink_entry(struct hotlist_entry *entry);
|
|
|
|
static void ro_gui_hotlist_delete_entry(struct hotlist_entry *entry, bool siblings);
|
2004-07-10 01:03:26 +04:00
|
|
|
static void ro_gui_hotlist_visited_update(struct content *content, struct hotlist_entry *entry);
|
2004-06-30 21:44:11 +04:00
|
|
|
static int ro_gui_hotlist_redraw_tree(struct hotlist_entry *entry, int level, int x0, int y0);
|
|
|
|
static int ro_gui_hotlist_redraw_item(struct hotlist_entry *entry, int level, int x0, int y0);
|
2004-07-09 21:03:35 +04:00
|
|
|
static struct hotlist_entry *ro_gui_hotlist_create_entry(const char *title, const char *url,
|
2004-07-02 02:56:26 +04:00
|
|
|
int filetype, struct hotlist_entry *folder);
|
2004-06-30 21:44:11 +04:00
|
|
|
static void ro_gui_hotlist_update_entry_size(struct hotlist_entry *entry);
|
|
|
|
static struct hotlist_entry *ro_gui_hotlist_find_entry(int x, int y, struct hotlist_entry *entry);
|
2004-07-01 03:11:11 +04:00
|
|
|
static int ro_gui_hotlist_selection_state(struct hotlist_entry *entry, bool selected, bool redraw);
|
2004-07-03 21:30:28 +04:00
|
|
|
static void ro_gui_hotlist_selection_drag(struct hotlist_entry *entry,
|
|
|
|
int x0, int y0, int x1, int y1,
|
|
|
|
bool toggle, bool redraw);
|
2004-07-06 02:17:59 +04:00
|
|
|
static int ro_gui_hotlist_selection_count(struct hotlist_entry *entry, bool folders);
|
2004-07-04 18:59:29 +04:00
|
|
|
static void ro_gui_hotlist_update_expansion(struct hotlist_entry *entry, bool only_selected,
|
2004-07-04 22:44:51 +04:00
|
|
|
bool folders, bool links, bool expand, bool contract);
|
|
|
|
static void ro_gui_hotlist_launch_selection(struct hotlist_entry *entry);
|
2004-07-10 01:03:26 +04:00
|
|
|
static void ro_gui_hotlist_invalidate_statistics(struct hotlist_entry *entry);
|
2004-07-07 04:31:57 +04:00
|
|
|
static struct hotlist_entry *ro_gui_hotlist_first_selection(struct hotlist_entry *entry);
|
|
|
|
static void ro_gui_hotlist_selection_to_process(struct hotlist_entry *entry);
|
|
|
|
static bool ro_gui_hotlist_move_processing(struct hotlist_entry *entry, struct hotlist_entry *destination, bool before);
|
|
|
|
|
|
|
|
#define hotlist_ensure_sprite(buffer, fallback) if (xwimpspriteop_read_sprite_info(buffer, 0, 0, 0, 0)) sprintf(buffer, fallback)
|
2004-07-10 01:03:26 +04:00
|
|
|
#define hotlist_redraw_entry(entry, full) xwimp_force_redraw(hotlist_window, full ? 0 : entry->x0, \
|
|
|
|
full ? -16384 : entry->y0, full ? 16384 : entry->x0 + entry->expanded_width, entry->y0 + entry->height);
|
|
|
|
#define hotlist_redraw_entry_title(entry) xwimp_force_redraw(hotlist_window, entry->x0, \
|
|
|
|
entry->y0 + entry->height - HOTLIST_LINE_HEIGHT, entry->x0 + entry->width, entry->y0 + entry->height);
|
|
|
|
|
2004-07-04 18:59:29 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
|
|
|
|
void ro_gui_hotlist_init(void) {
|
2004-07-10 01:03:26 +04:00
|
|
|
const char *title;
|
|
|
|
char *new_title;
|
2004-07-08 02:09:26 +04:00
|
|
|
os_box extent = {0, 0, 0, 0};;
|
2004-06-30 21:44:11 +04:00
|
|
|
os_error *error;
|
2004-07-04 16:42:54 +04:00
|
|
|
|
2004-07-04 18:59:29 +04:00
|
|
|
/* Set the initial root options
|
|
|
|
*/
|
|
|
|
root.next_entry = NULL;
|
|
|
|
root.child_entry = NULL;
|
|
|
|
root.children = 0;
|
|
|
|
root.expanded = true;
|
|
|
|
|
|
|
|
/* Load the hotlist
|
|
|
|
*/
|
2004-07-09 21:03:35 +04:00
|
|
|
if (!ro_gui_hotlist_load()) return;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-09 02:05:35 +04:00
|
|
|
/* Get our sprite ids for faster plotting.
|
2004-06-30 21:44:11 +04:00
|
|
|
*/
|
2004-07-09 02:05:35 +04:00
|
|
|
if (ro_gui_hotlist_initialise_sprite("expand", HOTLIST_EXPAND) ||
|
2004-07-17 17:00:38 +04:00
|
|
|
ro_gui_hotlist_initialise_sprite("collapse", HOTLIST_COLLAPSE) ||
|
|
|
|
ro_gui_hotlist_initialise_sprite("entry", HOTLIST_ENTRY) ||
|
|
|
|
ro_gui_hotlist_initialise_sprite("line", HOTLIST_LINE) ||
|
|
|
|
ro_gui_hotlist_initialise_sprite("halflinet", HOTLIST_TLINE) ||
|
2004-07-09 02:05:35 +04:00
|
|
|
ro_gui_hotlist_initialise_sprite("halflineb", HOTLIST_BLINE)) {
|
2004-06-30 21:44:11 +04:00
|
|
|
return;
|
2004-07-17 17:00:38 +04:00
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/* Update our text icon
|
|
|
|
*/
|
|
|
|
text_icon.data.indirected_text.validation = null_text_string;
|
|
|
|
text_icon.data.indirected_text.size = 256;
|
|
|
|
sprite_icon.flags = wimp_ICON_SPRITE | wimp_ICON_INDIRECTED |
|
2004-07-02 03:20:40 +04:00
|
|
|
wimp_ICON_HCENTRED | wimp_ICON_VCENTRED |
|
|
|
|
(wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) |
|
|
|
|
(wimp_COLOUR_VERY_LIGHT_GREY << wimp_ICON_BG_COLOUR_SHIFT);
|
2004-06-30 21:44:11 +04:00
|
|
|
sprite_icon.data.indirected_sprite.area = wimpspriteop_AREA;
|
|
|
|
sprite_icon.data.indirected_text.size = 12;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/* Create our window
|
|
|
|
*/
|
2004-07-09 21:03:35 +04:00
|
|
|
title = messages_get("Hotlist");
|
2004-07-10 01:03:26 +04:00
|
|
|
new_title = malloc(strlen(title + 1));
|
2004-07-12 03:14:24 +04:00
|
|
|
if (!new_title) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return;
|
|
|
|
}
|
2004-07-10 01:03:26 +04:00
|
|
|
strcpy(new_title, title);
|
|
|
|
hotlist_window_definition.title_data.indirected_text.text = new_title;
|
2004-07-09 21:03:35 +04:00
|
|
|
hotlist_window_definition.title_data.indirected_text.validation = null_text_string;
|
|
|
|
hotlist_window_definition.title_data.indirected_text.size = strlen(title);
|
2004-06-30 21:44:11 +04:00
|
|
|
error = xwimp_create_window(&hotlist_window_definition, &hotlist_window);
|
|
|
|
if (error) {
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
return;
|
|
|
|
}
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-08 02:09:26 +04:00
|
|
|
/* Create our toolbar
|
|
|
|
*/
|
|
|
|
ro_theme_create_hotlist_toolbar();
|
|
|
|
|
|
|
|
/* Update the extent
|
|
|
|
*/
|
|
|
|
if (hotlist_toolbar) {
|
|
|
|
extent.x1 = 16384;
|
|
|
|
extent.y1 = hotlist_toolbar->height;
|
|
|
|
extent.y0 = -16384;
|
|
|
|
xwimp_set_extent(hotlist_window, &extent);
|
|
|
|
reformat_pending = true;
|
|
|
|
}
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
|
|
|
|
2004-07-09 02:05:35 +04:00
|
|
|
/**
|
2004-07-09 21:03:35 +04:00
|
|
|
* Initialise a hotlist sprite for use with Tinct
|
2004-07-09 02:05:35 +04:00
|
|
|
*
|
|
|
|
* \param name the name of the sprite
|
|
|
|
* \param number the sprite cache number
|
|
|
|
* \return whether an error occurred
|
|
|
|
*/
|
|
|
|
bool ro_gui_hotlist_initialise_sprite(const char *name, int number) {
|
|
|
|
os_error *error;
|
|
|
|
sprintf(icon_name, "tr_%s", name);
|
|
|
|
error = xosspriteop_select_sprite(osspriteop_USER_AREA, gui_sprites,
|
|
|
|
(osspriteop_id)icon_name,
|
|
|
|
(osspriteop_header **)&sprite[number]);
|
|
|
|
if (error) {
|
|
|
|
warn_user("MiscError", error->errmess);
|
|
|
|
LOG(("Failed to load hotlist sprite 'tr_%s'", name));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the hotlist window.
|
2004-07-04 23:27:42 +04:00
|
|
|
*/
|
2004-06-30 21:44:11 +04:00
|
|
|
void ro_gui_hotlist_show(void) {
|
|
|
|
os_error *error;
|
|
|
|
int screen_width, screen_height;
|
|
|
|
wimp_window_state state;
|
|
|
|
int dimension;
|
|
|
|
int scroll_width;
|
|
|
|
|
|
|
|
/* We may have failed to initialise
|
|
|
|
*/
|
|
|
|
if (!hotlist_window) return;
|
|
|
|
|
|
|
|
/* Get the window state
|
|
|
|
*/
|
|
|
|
state.w = hotlist_window;
|
|
|
|
error = xwimp_get_window_state(&state);
|
|
|
|
if (error) {
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we're open we jump to the top of the stack, if not then we
|
|
|
|
open in the centre of the screen.
|
|
|
|
*/
|
|
|
|
if (!(state.flags & wimp_WINDOW_OPEN)) {
|
2004-07-04 18:59:29 +04:00
|
|
|
/* Clear the selection/expansion states
|
2004-07-03 21:30:28 +04:00
|
|
|
*/
|
2004-07-04 22:44:51 +04:00
|
|
|
ro_gui_hotlist_update_expansion(root.child_entry, false, true, true, false, true);
|
2004-07-03 21:30:28 +04:00
|
|
|
ro_gui_hotlist_selection_state(root.child_entry, false, false);
|
2004-07-01 03:11:11 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/* Get the current screen size
|
|
|
|
*/
|
|
|
|
ro_gui_screen_size(&screen_width, &screen_height);
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/* Move to the centre
|
|
|
|
*/
|
|
|
|
dimension = state.visible.x1 - state.visible.x0;
|
|
|
|
scroll_width = ro_get_vscroll_width(hotlist_window);
|
|
|
|
state.visible.x0 = (screen_width - (dimension + scroll_width)) / 2;
|
|
|
|
state.visible.x1 = state.visible.x0 + dimension;
|
|
|
|
dimension = state.visible.y1 - state.visible.y0;
|
|
|
|
state.visible.y0 = (screen_height - dimension) / 2;
|
|
|
|
state.visible.y1 = state.visible.y0 + dimension;
|
2004-07-08 02:09:26 +04:00
|
|
|
state.xscroll = 0;
|
|
|
|
state.yscroll = 0;
|
|
|
|
if (hotlist_toolbar) state.yscroll = hotlist_toolbar->height;
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Open the window at the top of the stack
|
|
|
|
*/
|
|
|
|
state.next = wimp_TOP;
|
|
|
|
error = xwimp_open_window((wimp_open*)&state);
|
|
|
|
if (error) {
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
return;
|
|
|
|
}
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
/* Set the caret position
|
|
|
|
*/
|
|
|
|
xwimp_set_caret_position(state.w, -1, -100,
|
|
|
|
-100, 32, -1);
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
|
|
|
|
2004-07-09 02:05:35 +04:00
|
|
|
|
2004-07-04 18:59:29 +04:00
|
|
|
bool ro_gui_hotlist_load(void) {
|
2004-07-16 03:58:08 +04:00
|
|
|
htmlDocPtr doc;
|
2004-07-16 20:33:45 +04:00
|
|
|
const char *encoding;
|
2004-07-04 18:59:29 +04:00
|
|
|
fileswitch_object_type obj_type = 0;
|
2004-06-30 21:44:11 +04:00
|
|
|
struct hotlist_entry *netsurf;
|
2004-07-16 03:58:08 +04:00
|
|
|
struct hotlist_entry *entry = &root;
|
2004-07-04 16:42:54 +04:00
|
|
|
|
2004-07-04 18:59:29 +04:00
|
|
|
/* Check if we have an initial hotlist. OS_File does funny things relating to errors,
|
|
|
|
so we use the object type to determine success
|
2004-06-30 21:44:11 +04:00
|
|
|
*/
|
2004-07-04 18:59:29 +04:00
|
|
|
xosfile_read_stamped_no_path("<Choices$Write>.WWW.NetSurf.Hotlist", &obj_type,
|
2004-07-16 03:58:08 +04:00
|
|
|
(bits)0, (bits)0, (int *)0, (fileswitch_attr)0, (bits)0);
|
2004-07-17 17:00:38 +04:00
|
|
|
if (obj_type != 0) {
|
2004-07-16 03:58:08 +04:00
|
|
|
/* Read our file
|
2004-07-04 18:59:29 +04:00
|
|
|
*/
|
2004-07-16 20:33:45 +04:00
|
|
|
encoding = xmlGetCharEncodingName(XML_CHAR_ENCODING_8859_1);
|
|
|
|
doc = htmlParseFile("<Choices$Write>.WWW.NetSurf.Hotlist", encoding);
|
2004-07-16 03:58:08 +04:00
|
|
|
if ((!doc) || (!(doc->children))) {
|
|
|
|
xmlFreeDoc(doc);
|
2004-07-04 18:59:29 +04:00
|
|
|
warn_user("HotlistLoadError", 0);
|
|
|
|
return false;
|
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-16 03:58:08 +04:00
|
|
|
/* Perform our recursive load
|
2004-07-04 22:44:51 +04:00
|
|
|
*/
|
2004-07-26 01:45:37 +04:00
|
|
|
ro_gui_hotlist_load_entry(doc->children, &root, true);
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-16 03:58:08 +04:00
|
|
|
/* Exit cleanly
|
2004-07-04 18:59:29 +04:00
|
|
|
*/
|
2004-07-16 03:58:08 +04:00
|
|
|
xmlFreeDoc(doc);
|
|
|
|
return true;
|
2004-07-04 18:59:29 +04:00
|
|
|
} else {
|
|
|
|
/* Create a folder
|
|
|
|
*/
|
2004-07-09 21:03:35 +04:00
|
|
|
netsurf = ro_gui_hotlist_create_entry("NetSurf", NULL, 0, &root);
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-04 18:59:29 +04:00
|
|
|
/* Add some content
|
|
|
|
*/
|
2004-07-10 01:03:26 +04:00
|
|
|
entry = ro_gui_hotlist_create_entry("NetSurf homepage", "http://netsurf.sourceforge.net/",
|
2004-07-04 18:59:29 +04:00
|
|
|
0xfaf, netsurf);
|
|
|
|
entry->add_date = (time_t)-1;
|
2004-07-09 21:03:35 +04:00
|
|
|
entry = ro_gui_hotlist_create_entry("NetSurf test builds", "http://netsurf.strcprstskrzkrk.co.uk/",
|
2004-07-04 18:59:29 +04:00
|
|
|
0xfaf, netsurf);
|
|
|
|
entry->add_date = (time_t)-1;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-04 18:59:29 +04:00
|
|
|
/* We succeeded
|
|
|
|
*/
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2004-07-04 16:42:54 +04:00
|
|
|
|
2004-07-06 02:17:59 +04:00
|
|
|
|
2004-07-26 01:45:37 +04:00
|
|
|
void ro_gui_hotlist_load_entry(xmlNode *cur, struct hotlist_entry *entry, bool allow_add) {
|
2004-07-16 03:58:08 +04:00
|
|
|
struct hotlist_entry *last_entry = entry;
|
|
|
|
char *xml_comment = NULL;
|
|
|
|
char *comment = comment;
|
|
|
|
int filetype = 0xfaf;
|
|
|
|
int add_date = -1;
|
|
|
|
int last_date = -1;
|
|
|
|
int visits = 0;
|
2004-07-26 01:45:37 +04:00
|
|
|
bool add_entry;
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-26 02:47:54 +04:00
|
|
|
while (true) {
|
2004-07-16 03:58:08 +04:00
|
|
|
/* Add any items that have had all the data they can have
|
|
|
|
*/
|
2004-07-26 01:45:37 +04:00
|
|
|
if ((allow_add) && (load_title != NULL)) {
|
2004-07-26 02:47:54 +04:00
|
|
|
if ((cur == NULL) || ((cur->type == XML_ELEMENT_NODE) &&
|
2004-07-16 03:58:08 +04:00
|
|
|
((!(strcmp(cur->name, "li"))) || (!(strcmp(cur->name, "h4"))) ||
|
2004-07-26 01:45:37 +04:00
|
|
|
(!(strcmp(cur->name, "ul")))))) {
|
|
|
|
|
|
|
|
/* Add the entry
|
|
|
|
*/
|
|
|
|
last_entry = ro_gui_hotlist_create_entry(load_title, load_url, filetype, entry);
|
|
|
|
last_entry->add_date = add_date;
|
|
|
|
if (last_entry->url) {
|
|
|
|
last_entry->last_date = last_date;
|
|
|
|
last_entry->visits = visits;
|
|
|
|
last_entry->filetype = filetype;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset our variables
|
|
|
|
*/
|
|
|
|
if (load_title) xmlFree(load_title);
|
|
|
|
load_title = NULL;
|
|
|
|
if (load_url) xmlFree(load_url);
|
|
|
|
load_url = NULL;
|
|
|
|
filetype = 0xfaf;
|
|
|
|
add_date = -1;
|
|
|
|
last_date = -1;
|
|
|
|
visits = 0;
|
2004-07-16 03:58:08 +04:00
|
|
|
}
|
|
|
|
}
|
2004-07-26 02:47:54 +04:00
|
|
|
|
|
|
|
/* Abort if we've ran out of content
|
|
|
|
*/
|
|
|
|
if (cur == NULL) return;
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-16 03:58:08 +04:00
|
|
|
/* Gather further information and recurse
|
|
|
|
*/
|
|
|
|
if (cur->type == XML_ELEMENT_NODE) {
|
2004-07-26 01:45:37 +04:00
|
|
|
add_entry = allow_add;
|
2004-07-16 03:58:08 +04:00
|
|
|
if (!(strcmp(cur->name, "h4"))) {
|
2004-07-26 01:45:37 +04:00
|
|
|
add_entry = false;
|
2004-07-16 03:58:08 +04:00
|
|
|
if (!load_title) load_title = xmlNodeGetContent(cur);
|
|
|
|
} else if (!(strcmp(cur->name, "a"))) {
|
2004-07-26 01:45:37 +04:00
|
|
|
add_entry = false;
|
2004-07-16 03:58:08 +04:00
|
|
|
load_url = (char *)xmlGetProp(cur, (const xmlChar *)"href");
|
2004-07-26 01:45:37 +04:00
|
|
|
} else if (!(strcmp(cur->name, "li"))) {
|
|
|
|
add_entry = false;
|
2004-07-16 03:58:08 +04:00
|
|
|
}
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-16 03:58:08 +04:00
|
|
|
if ((cur->children) && (strcmp(cur->name, "h4"))) {
|
2004-07-26 01:45:37 +04:00
|
|
|
ro_gui_hotlist_load_entry(cur->children, last_entry, add_entry);
|
2004-07-16 03:58:08 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Check for comment data
|
|
|
|
*/
|
|
|
|
if (!(strcmp(cur->name, "comment"))) {
|
|
|
|
xml_comment = xmlNodeGetContent(cur);
|
|
|
|
comment = xml_comment;
|
2004-07-17 17:00:38 +04:00
|
|
|
while (comment[0] == ' ') comment++;
|
2004-07-16 03:58:08 +04:00
|
|
|
if (strncmp("Added:", comment, 6) == 0) {
|
|
|
|
add_date = atoi(comment + 6);
|
|
|
|
} else if (strncmp("LastVisit:", comment, 10) == 0) {
|
|
|
|
last_date = atoi(comment + 10);
|
|
|
|
} else if (strncmp("Visits:", comment, 7) == 0) {
|
|
|
|
visits = atoi(comment + 7);
|
|
|
|
} else if (strncmp("Type:", comment, 5) == 0) {
|
|
|
|
filetype = atoi(comment + 5);
|
|
|
|
}
|
|
|
|
xmlFree(xml_comment);
|
|
|
|
} else if (!(strcmp(cur->name, "text"))) {
|
|
|
|
if ((!(strcmp(cur->parent->name, "li"))) || (!(strcmp(cur->parent->name, "a")))) {
|
|
|
|
if (!load_title) load_title = xmlNodeGetContent(cur);
|
|
|
|
if ((load_title[0] == 13) || (load_title[0] == 10)) {
|
|
|
|
xmlFree(load_title);
|
|
|
|
load_title = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-06 02:17:59 +04:00
|
|
|
/**
|
|
|
|
* Perform a save to the default file
|
|
|
|
*/
|
2004-07-04 23:27:42 +04:00
|
|
|
void ro_gui_hotlist_save(void) {
|
2004-07-04 22:44:51 +04:00
|
|
|
/* Don't save if we didn't load
|
|
|
|
*/
|
|
|
|
if (!hotlist_window) return;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-04 22:44:51 +04:00
|
|
|
/* Ensure we have a directory to save to later.
|
|
|
|
*/
|
|
|
|
xosfile_create_dir("<Choices$Write>.WWW", 0);
|
|
|
|
xosfile_create_dir("<Choices$Write>.WWW.NetSurf", 0);
|
|
|
|
|
2004-07-06 02:17:59 +04:00
|
|
|
/* Save to our file
|
|
|
|
*/
|
|
|
|
ro_gui_hotlist_save_as("<Choices$Write>.WWW.NetSurf.Hotlist");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform a save to a specified file
|
|
|
|
*
|
|
|
|
* /param file the file to save to
|
|
|
|
*/
|
|
|
|
void ro_gui_hotlist_save_as(const char *file) {
|
|
|
|
FILE *fp;
|
|
|
|
|
2004-07-04 18:59:29 +04:00
|
|
|
/* Open our file
|
|
|
|
*/
|
2004-07-06 02:17:59 +04:00
|
|
|
fp = fopen(file, "w");
|
2004-07-04 18:59:29 +04:00
|
|
|
if (!fp) {
|
|
|
|
warn_user("HotlistSaveError", 0);
|
|
|
|
return;
|
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-04 22:44:51 +04:00
|
|
|
/* HTML header
|
|
|
|
*/
|
2004-07-16 20:33:45 +04:00
|
|
|
fprintf(fp, "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");
|
|
|
|
fprintf(fp, "<title>Hotlist</title>\n</head>\n<body>\n");
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-04 18:59:29 +04:00
|
|
|
/* Start our recursive save
|
2004-06-30 21:44:11 +04:00
|
|
|
*/
|
2004-07-04 22:44:51 +04:00
|
|
|
if (!ro_gui_hotlist_save_entry(fp, root.child_entry)) {
|
2004-07-04 18:59:29 +04:00
|
|
|
warn_user("HotlistSaveError", 0);
|
|
|
|
}
|
2004-07-04 22:44:51 +04:00
|
|
|
|
|
|
|
/* HTML footer
|
|
|
|
*/
|
|
|
|
fprintf(fp, "</body>\n</html>\n");
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-04 18:59:29 +04:00
|
|
|
/* Close our file
|
|
|
|
*/
|
|
|
|
fclose(fp);
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-04 22:44:51 +04:00
|
|
|
/* Set the filetype to HTML
|
|
|
|
*/
|
2004-07-06 02:17:59 +04:00
|
|
|
xosfile_set_type(file, 0xfaf);
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
|
|
|
|
2004-07-04 22:44:51 +04:00
|
|
|
bool ro_gui_hotlist_save_entry(FILE *fp, struct hotlist_entry *entry) {
|
|
|
|
if (!entry) return true;
|
|
|
|
|
|
|
|
/* We're starting a new child
|
|
|
|
*/
|
|
|
|
fprintf(fp, "<ul>\n");
|
|
|
|
|
|
|
|
/* Work through the entries
|
|
|
|
*/
|
|
|
|
while (entry) {
|
|
|
|
/* Save this entry
|
|
|
|
*/
|
2004-07-16 20:33:45 +04:00
|
|
|
if (entry->children >= 0) {
|
|
|
|
fprintf(fp, "<h4>%s</h4>\n", entry->title);
|
|
|
|
if (entry->child_entry) ro_gui_hotlist_save_entry(fp, entry->child_entry);
|
2004-07-04 22:44:51 +04:00
|
|
|
} else {
|
2004-07-16 20:33:45 +04:00
|
|
|
fprintf(fp, "<li><a href=\"%s\">%s</a>\n", entry->url, entry->title);
|
|
|
|
if (entry->filetype != 0xfaf) fprintf(fp, "<!-- Type:%i -->\n", entry->filetype);
|
|
|
|
if (entry->add_date != -1) fprintf(fp, "<!--Added:%i-->\n", (int)entry->add_date);
|
|
|
|
if (entry->last_date != -1) fprintf(fp, "<!--LastVisit:%i-->\n", (int)entry->last_date);
|
|
|
|
if (entry->visits != 0) fprintf(fp, "<!--Visits:%i-->\n", entry->visits);
|
2004-07-04 22:44:51 +04:00
|
|
|
}
|
|
|
|
entry = entry->next_entry;
|
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-04 22:44:51 +04:00
|
|
|
/* We're starting a new child
|
|
|
|
*/
|
2004-07-04 23:27:42 +04:00
|
|
|
fprintf(fp, "</ul>\n");
|
|
|
|
return true;
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a hotlist entry to the root of the tree.
|
|
|
|
*
|
2004-07-03 21:30:28 +04:00
|
|
|
* \param title the entry title
|
2004-07-02 02:56:26 +04:00
|
|
|
* \param content the content to add
|
2004-07-04 23:27:42 +04:00
|
|
|
*/
|
2004-07-02 02:56:26 +04:00
|
|
|
void ro_gui_hotlist_add(char *title, struct content *content) {
|
2004-07-09 21:03:35 +04:00
|
|
|
ro_gui_hotlist_create_entry(title, content->url, ro_content_filetype(content), &root);
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
2004-07-02 02:56:26 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Informs the hotlist that some content has been visited
|
|
|
|
*
|
|
|
|
* \param content the content visited
|
|
|
|
*/
|
2004-07-03 21:30:28 +04:00
|
|
|
void hotlist_visited(struct content *content) {
|
2004-07-02 02:56:26 +04:00
|
|
|
if ((!content) || (!content->url)) return;
|
2004-07-10 01:03:26 +04:00
|
|
|
ro_gui_hotlist_visited_update(content, root.child_entry);
|
2004-07-02 02:56:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Informs the hotlist that some content has been visited (internal)
|
|
|
|
*
|
|
|
|
* \param content the content visited
|
2004-07-03 21:30:28 +04:00
|
|
|
* \param entry the entry to check siblings and children of
|
2004-07-02 02:56:26 +04:00
|
|
|
*/
|
2004-07-10 01:03:26 +04:00
|
|
|
void ro_gui_hotlist_visited_update(struct content *content, struct hotlist_entry *entry) {
|
|
|
|
char *url;
|
2004-07-03 21:30:28 +04:00
|
|
|
bool full = false;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-02 02:56:26 +04:00
|
|
|
/* Update the hotlist
|
|
|
|
*/
|
2004-07-10 01:03:26 +04:00
|
|
|
url = content->url;
|
2004-07-02 02:56:26 +04:00
|
|
|
while (entry) {
|
2004-07-09 21:03:35 +04:00
|
|
|
if ((entry->url) && (strcmp(url, entry->url) == 0)) {
|
|
|
|
/* Check if we're going to need a full redraw downwards
|
|
|
|
*/
|
|
|
|
full = ((entry->visits == 0) || (entry->last_date == -1));
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-09 21:03:35 +04:00
|
|
|
/* Update our values
|
|
|
|
*/
|
2004-07-10 01:22:03 +04:00
|
|
|
if (entry->children == -1) entry->filetype = ro_content_filetype(content);
|
2004-07-09 21:03:35 +04:00
|
|
|
entry->visits++;
|
|
|
|
entry->last_date = time(NULL);
|
|
|
|
ro_gui_hotlist_update_entry_size(entry);
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-09 21:03:35 +04:00
|
|
|
/* Redraw the least we can get away with
|
|
|
|
*/
|
2004-07-10 01:03:26 +04:00
|
|
|
if (entry->expanded) hotlist_redraw_entry(entry, full);
|
2004-07-02 02:56:26 +04:00
|
|
|
}
|
2004-07-10 01:03:26 +04:00
|
|
|
if (entry->child_entry) ro_gui_hotlist_visited_update(content, entry->child_entry);
|
2004-07-02 02:56:26 +04:00
|
|
|
entry = entry->next_entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a hotlist entry to the root of the tree (internal).
|
|
|
|
*
|
|
|
|
* \param title the entry title
|
|
|
|
* \param url the entry url (NULL to create a folder)
|
|
|
|
* \param folder the folder to add the entry into
|
2004-07-04 23:27:42 +04:00
|
|
|
*/
|
2004-07-09 21:03:35 +04:00
|
|
|
struct hotlist_entry *ro_gui_hotlist_create_entry(const char *title, const char *url,
|
2004-07-02 02:56:26 +04:00
|
|
|
int filetype, struct hotlist_entry *folder) {
|
2004-06-30 21:44:11 +04:00
|
|
|
struct hotlist_entry *entry;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/* Check we have a title or a URL
|
|
|
|
*/
|
|
|
|
if (!title && !url) return NULL;
|
|
|
|
|
|
|
|
/* Allocate some memory
|
|
|
|
*/
|
|
|
|
entry = (struct hotlist_entry *)calloc(1, sizeof(struct hotlist_entry));
|
|
|
|
if (!entry) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-09 21:03:35 +04:00
|
|
|
/* Normalise the URL and add the title if we have one, or
|
|
|
|
use the URL instead
|
2004-06-30 21:44:11 +04:00
|
|
|
*/
|
2004-07-09 21:03:35 +04:00
|
|
|
if ((url) && ((entry->url = url_normalize(url)) == 0)) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
free(entry->url);
|
|
|
|
return NULL;
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
|
|
|
if (title) {
|
|
|
|
entry->title = malloc(strlen(title) + 1);
|
|
|
|
if (!entry->title) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
free(entry->url);
|
|
|
|
free(entry);
|
2004-07-04 23:27:42 +04:00
|
|
|
return NULL;
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
|
|
|
strcpy(entry->title, title);
|
2004-07-05 03:16:12 +04:00
|
|
|
entry->title = strip(entry->title);
|
2004-06-30 21:44:11 +04:00
|
|
|
} else {
|
2004-07-04 23:27:42 +04:00
|
|
|
entry->title = entry->url;
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-09 21:03:35 +04:00
|
|
|
/* Set the other values
|
2004-07-02 02:56:26 +04:00
|
|
|
*/
|
2004-07-09 21:03:35 +04:00
|
|
|
entry->children = (url == NULL) ? 0 : -1;
|
2004-07-02 02:56:26 +04:00
|
|
|
entry->filetype = filetype;
|
|
|
|
entry->visits = 0;
|
2004-07-03 20:28:09 +04:00
|
|
|
entry->add_date = time(NULL);
|
2004-07-03 21:30:28 +04:00
|
|
|
entry->last_date = (time_t)-1;
|
2004-06-30 21:44:11 +04:00
|
|
|
ro_gui_hotlist_update_entry_size(entry);
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
/* Link into the tree
|
2004-06-30 21:44:11 +04:00
|
|
|
*/
|
2004-07-07 04:31:57 +04:00
|
|
|
ro_gui_hotlist_link_entry(folder, entry, false);
|
2004-06-30 21:44:11 +04:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Links a hotlist entry into the tree.
|
|
|
|
*
|
2004-07-07 04:31:57 +04:00
|
|
|
* \param link the entry to link as a child (folders) or before/after (link)
|
2004-06-30 21:44:11 +04:00
|
|
|
* \param entry the entry to link
|
2004-07-07 04:31:57 +04:00
|
|
|
* \param before whether to link siblings before or after the supplied link
|
2004-07-04 23:27:42 +04:00
|
|
|
*/
|
2004-07-07 04:31:57 +04:00
|
|
|
void ro_gui_hotlist_link_entry(struct hotlist_entry *link, struct hotlist_entry *entry, bool before) {
|
2004-06-30 21:44:11 +04:00
|
|
|
struct hotlist_entry *link_entry;
|
|
|
|
|
2004-07-09 02:05:35 +04:00
|
|
|
if ((!link || !entry) || (link == entry)) return;
|
2004-07-07 04:31:57 +04:00
|
|
|
|
|
|
|
/* Check if the parent is a folder or an entry
|
|
|
|
*/
|
|
|
|
if (link->children == -1) {
|
|
|
|
entry->parent_entry = link->parent_entry;
|
|
|
|
entry->parent_entry->children++;
|
|
|
|
if (before) {
|
|
|
|
entry->next_entry = link;
|
|
|
|
entry->previous_entry = link->previous_entry;
|
|
|
|
if (link->previous_entry) link->previous_entry->next_entry = entry;
|
|
|
|
link->previous_entry = entry;
|
|
|
|
if (link->parent_entry) {
|
|
|
|
if (link->parent_entry->child_entry == link) {
|
|
|
|
link->parent_entry->child_entry = entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
entry->previous_entry = link;
|
|
|
|
entry->next_entry = link->next_entry;
|
|
|
|
if (link->next_entry) link->next_entry->previous_entry = entry;
|
|
|
|
link->next_entry = entry;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
link_entry = link->child_entry;
|
|
|
|
|
|
|
|
/* Link into the tree as a child at the end
|
|
|
|
*/
|
|
|
|
if (!link_entry) {
|
|
|
|
link->child_entry = entry;
|
|
|
|
entry->previous_entry = NULL;
|
|
|
|
} else {
|
|
|
|
while (link_entry->next_entry) link_entry = link_entry->next_entry;
|
|
|
|
link_entry->next_entry = entry;
|
|
|
|
entry->previous_entry = link_entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the links
|
|
|
|
*/
|
|
|
|
entry->parent_entry = link;
|
|
|
|
entry->next_entry = NULL;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
/* Increment the number of children
|
|
|
|
*/
|
|
|
|
link->children += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Force a redraw
|
2004-06-30 21:44:11 +04:00
|
|
|
*/
|
2004-07-07 04:31:57 +04:00
|
|
|
reformat_pending = true;
|
|
|
|
xwimp_force_redraw(hotlist_window, 0, -16384, 16384, 0);
|
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* De-links a hotlist entry from the tree.
|
|
|
|
*
|
|
|
|
* \param entry the entry to de-link
|
|
|
|
*/
|
|
|
|
void ro_gui_hotlist_delink_entry(struct hotlist_entry *entry) {
|
|
|
|
if (!entry) return;
|
|
|
|
|
|
|
|
/* Sort out if the entry was the initial child reference
|
2004-06-30 21:44:11 +04:00
|
|
|
*/
|
2004-07-07 04:31:57 +04:00
|
|
|
if (entry->parent_entry) {
|
|
|
|
entry->parent_entry->children -= 1;
|
2004-07-08 02:09:26 +04:00
|
|
|
if (entry->parent_entry->children == 0) entry->parent_entry->expanded = false;
|
2004-07-07 04:31:57 +04:00
|
|
|
if (entry->parent_entry->child_entry == entry) {
|
|
|
|
entry->parent_entry->child_entry = entry->next_entry;
|
|
|
|
}
|
|
|
|
entry->parent_entry = NULL;
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
/* Remove the entry from siblings
|
2004-06-30 21:44:11 +04:00
|
|
|
*/
|
2004-07-07 04:31:57 +04:00
|
|
|
if (entry->previous_entry) {
|
|
|
|
entry->previous_entry->next_entry = entry->next_entry;
|
|
|
|
}
|
|
|
|
if (entry->next_entry) {
|
|
|
|
entry->next_entry->previous_entry = entry->previous_entry;
|
|
|
|
}
|
|
|
|
entry->previous_entry = NULL;
|
|
|
|
entry->next_entry = NULL;
|
2004-06-30 21:44:11 +04:00
|
|
|
|
|
|
|
/* Force a redraw
|
|
|
|
*/
|
|
|
|
reformat_pending = true;
|
|
|
|
xwimp_force_redraw(hotlist_window, 0, -16384, 16384, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
/**
|
|
|
|
* Delete an entry and all children
|
|
|
|
* This function also performs any necessary delinking
|
|
|
|
*
|
|
|
|
* \param entry the entry to delete
|
|
|
|
* \param siblings delete all following siblings
|
|
|
|
*/
|
|
|
|
void ro_gui_hotlist_delete_entry(struct hotlist_entry *entry, bool siblings) {
|
|
|
|
struct hotlist_entry *next_entry = NULL;
|
|
|
|
while (entry) {
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
/* Recurse to children first
|
|
|
|
*/
|
|
|
|
if (entry->child_entry) ro_gui_hotlist_delete_entry(entry->child_entry, true);
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
/* Free our memory
|
|
|
|
*/
|
|
|
|
if (entry->url) {
|
|
|
|
free(entry->url);
|
|
|
|
entry->url = NULL;
|
|
|
|
}
|
|
|
|
if (entry->title) {
|
|
|
|
free(entry->title);
|
|
|
|
entry->title = NULL;
|
|
|
|
}
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
/* Get the next entry before we de-link and delete
|
|
|
|
*/
|
|
|
|
if (siblings) next_entry = entry->next_entry;
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
/* Delink and delete our entry and move on
|
|
|
|
*/
|
|
|
|
ro_gui_hotlist_delink_entry(entry);
|
|
|
|
free(entry);
|
|
|
|
entry = next_entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/**
|
|
|
|
* Updates and entrys size
|
|
|
|
*/
|
|
|
|
void ro_gui_hotlist_update_entry_size(struct hotlist_entry *entry) {
|
|
|
|
int width;
|
2004-07-03 21:30:28 +04:00
|
|
|
int max_width;
|
|
|
|
int line_number = 0;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/* Get the width of the title
|
2004-07-04 23:27:42 +04:00
|
|
|
*/
|
2004-06-30 21:44:11 +04:00
|
|
|
xwimptextop_string_width(entry->title,
|
|
|
|
strlen(entry->title) > 256 ? 256 : strlen(entry->title),
|
|
|
|
&width);
|
2004-07-03 21:30:28 +04:00
|
|
|
entry->collapsed_width = width;
|
|
|
|
max_width = width;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/* Get the width of the URL
|
|
|
|
*/
|
|
|
|
if (entry->url) {
|
2004-07-03 21:30:28 +04:00
|
|
|
snprintf(extended_text, HOTLIST_TEXT_BUFFER,
|
|
|
|
messages_get("HotlistURL"), entry->url);
|
|
|
|
if (strlen(extended_text) >= 255) {
|
|
|
|
extended_text[252] = '.';
|
|
|
|
extended_text[253] = '.';
|
|
|
|
extended_text[254] = '.';
|
|
|
|
extended_text[255] = '\0';
|
|
|
|
}
|
|
|
|
xwimptextop_string_width(extended_text,
|
|
|
|
strlen(extended_text) > 256 ? 256 : strlen(extended_text),
|
2004-06-30 21:44:11 +04:00
|
|
|
&width);
|
2004-07-03 21:30:28 +04:00
|
|
|
if (width > max_width) max_width = width;
|
|
|
|
entry->widths[line_number++] = width;
|
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
/* Get the width of the add date
|
|
|
|
*/
|
|
|
|
if (entry->add_date != -1) {
|
|
|
|
snprintf(extended_text, HOTLIST_TEXT_BUFFER,
|
2004-07-04 23:27:42 +04:00
|
|
|
messages_get("HotlistAdded"), ctime(&entry->add_date));
|
2004-07-03 21:30:28 +04:00
|
|
|
xwimptextop_string_width(extended_text,
|
|
|
|
strlen(extended_text) > 256 ? 256 : strlen(extended_text),
|
|
|
|
&width);
|
|
|
|
if (width > max_width) max_width = width;
|
|
|
|
entry->widths[line_number++] = width;
|
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
/* Get the width of the last visit
|
|
|
|
*/
|
|
|
|
if (entry->last_date != -1) {
|
|
|
|
snprintf(extended_text, HOTLIST_TEXT_BUFFER,
|
|
|
|
messages_get("HotlistLast"), ctime(&entry->last_date));
|
|
|
|
xwimptextop_string_width(extended_text,
|
|
|
|
strlen(extended_text) > 256 ? 256 : strlen(extended_text),
|
|
|
|
&width);
|
|
|
|
if (width > max_width) max_width = width;
|
|
|
|
entry->widths[line_number++] = width;
|
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
/* Get the width of the visit count
|
|
|
|
*/
|
|
|
|
if (entry->visits > 0) {
|
|
|
|
snprintf(extended_text, HOTLIST_TEXT_BUFFER,
|
|
|
|
messages_get("HotlistVisits"), entry->visits);
|
|
|
|
xwimptextop_string_width(extended_text,
|
|
|
|
strlen(extended_text) > 256 ? 256 : strlen(extended_text),
|
|
|
|
&width);
|
|
|
|
if (width > max_width) max_width = width;
|
|
|
|
entry->widths[line_number++] = width;
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
/* Increase the text width by the borders
|
|
|
|
*/
|
2004-07-04 22:44:51 +04:00
|
|
|
entry->expanded_width = max_width + HOTLIST_LEAF_INSET + HOTLIST_ICON_WIDTH + HOTLIST_TEXT_PADDING;
|
|
|
|
entry->collapsed_width += HOTLIST_LEAF_INSET + HOTLIST_ICON_WIDTH + HOTLIST_TEXT_PADDING;
|
2004-07-03 21:30:28 +04:00
|
|
|
reformat_pending = true;
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redraws a section of the hotlist window
|
2004-07-04 23:27:42 +04:00
|
|
|
*
|
2004-07-02 02:56:26 +04:00
|
|
|
* \param redraw the area to redraw
|
2004-06-30 21:44:11 +04:00
|
|
|
*/
|
|
|
|
void ro_gui_hotlist_redraw(wimp_draw *redraw) {
|
2004-06-30 21:59:18 +04:00
|
|
|
wimp_window_state state;
|
2004-06-30 21:44:11 +04:00
|
|
|
osbool more;
|
|
|
|
os_box extent = {0, 0, 0, 0};;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/* Reset our min/max sizes
|
|
|
|
*/
|
|
|
|
max_width = 0;
|
|
|
|
max_height = 0;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/* Redraw each rectangle
|
|
|
|
*/
|
|
|
|
more = wimp_redraw_window(redraw);
|
|
|
|
while (more) {
|
2004-07-03 21:30:28 +04:00
|
|
|
clip_x0 = redraw->clip.x0;
|
|
|
|
clip_y0 = redraw->clip.y0;
|
|
|
|
clip_x1 = redraw->clip.x1;
|
|
|
|
clip_y1 = redraw->clip.y1;
|
2004-06-30 21:44:11 +04:00
|
|
|
origin_x = redraw->box.x0 - redraw->xscroll;
|
|
|
|
origin_y = redraw->box.y1 - redraw->yscroll;
|
|
|
|
ro_gui_hotlist_redraw_tree(root.child_entry, 0,
|
|
|
|
origin_x + 8, origin_y - 4);
|
|
|
|
more = wimp_get_rectangle(redraw);
|
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/* Check if we should reformat
|
|
|
|
*/
|
|
|
|
if (reformat_pending) {
|
2004-07-01 03:11:11 +04:00
|
|
|
max_width += 8;
|
|
|
|
max_height -= 4;
|
|
|
|
if (max_width < 600) max_width = 600;
|
|
|
|
if (max_height > -800) max_height = -800;
|
|
|
|
extent.x1 = max_width;
|
|
|
|
extent.y0 = max_height;
|
2004-07-08 02:09:26 +04:00
|
|
|
if (hotlist_toolbar) {
|
|
|
|
extent.y1 += hotlist_toolbar->height;
|
|
|
|
}
|
2004-06-30 21:44:11 +04:00
|
|
|
xwimp_set_extent(hotlist_window, &extent);
|
2004-06-30 21:59:18 +04:00
|
|
|
state.w = hotlist_window;
|
|
|
|
wimp_get_window_state(&state);
|
|
|
|
wimp_open_window((wimp_open *) &state);
|
2004-06-30 21:44:11 +04:00
|
|
|
reformat_pending = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redraws a section of the hotlist window (non-WIMP interface)
|
2004-07-02 02:56:26 +04:00
|
|
|
*
|
|
|
|
* \param entry the entry to draw descendants and siblings of
|
|
|
|
* \param level the tree level of the entry
|
2004-07-03 21:30:28 +04:00
|
|
|
* \param x0 the x co-ordinate to plot from
|
|
|
|
* \param y0 the y co-ordinate to plot from
|
2004-07-02 02:56:26 +04:00
|
|
|
* \returns the height of the tree
|
2004-06-30 21:44:11 +04:00
|
|
|
*/
|
|
|
|
int ro_gui_hotlist_redraw_tree(struct hotlist_entry *entry, int level, int x0, int y0) {
|
|
|
|
bool first = true;
|
|
|
|
int cumulative = 0;
|
|
|
|
int height = 0;
|
|
|
|
int box_y0;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
if (!entry) return 0;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/* Repeatedly draw our entries
|
|
|
|
*/
|
|
|
|
while (entry) {
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-01 03:11:11 +04:00
|
|
|
/* Redraw the item
|
|
|
|
*/
|
2004-07-04 22:44:51 +04:00
|
|
|
height = ro_gui_hotlist_redraw_item(entry, level, x0 + HOTLIST_LEAF_INSET, y0);
|
2004-07-01 03:11:11 +04:00
|
|
|
box_y0 = y0;
|
|
|
|
cumulative += height;
|
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/* Update the entry position
|
|
|
|
*/
|
2004-07-01 03:11:11 +04:00
|
|
|
if (entry->children == -1) {
|
|
|
|
entry->height = height;
|
|
|
|
} else {
|
2004-07-04 22:44:51 +04:00
|
|
|
entry->height = HOTLIST_LINE_HEIGHT;
|
2004-07-01 03:11:11 +04:00
|
|
|
}
|
2004-06-30 21:44:11 +04:00
|
|
|
entry->x0 = x0 - origin_x;
|
2004-07-01 03:11:11 +04:00
|
|
|
entry->y0 = y0 - origin_y - entry->height;
|
2004-06-30 21:44:11 +04:00
|
|
|
if (entry->expanded) {
|
|
|
|
entry->width = entry->expanded_width;
|
|
|
|
} else {
|
|
|
|
entry->width = entry->collapsed_width;
|
|
|
|
}
|
|
|
|
|
2004-06-30 21:59:18 +04:00
|
|
|
/* Get the maximum extents
|
|
|
|
*/
|
|
|
|
if ((x0 + entry->width) > (max_width + origin_x))
|
|
|
|
max_width = x0 + entry->width - origin_x;
|
|
|
|
if ((y0 - height) < (max_height + origin_y))
|
|
|
|
max_height = y0 - height - origin_y;
|
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/* Draw the vertical links
|
|
|
|
*/
|
|
|
|
if (entry->next_entry) {
|
|
|
|
/* Draw a half-line for the first entry in the top tree
|
|
|
|
*/
|
|
|
|
if (first && (level == 0)) {
|
2004-07-09 21:03:35 +04:00
|
|
|
_swix(Tinct_Plot, _IN(2) | _IN(3) | _IN(4) | _IN(7),
|
|
|
|
sprite[HOTLIST_BLINE], x0 + 8, y0 - HOTLIST_LINE_HEIGHT, 0);
|
2004-07-04 22:44:51 +04:00
|
|
|
y0 -= HOTLIST_LINE_HEIGHT;
|
|
|
|
height -= HOTLIST_LINE_HEIGHT;
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/* Draw the rest of the lines
|
|
|
|
*/
|
|
|
|
while (height > 0) {
|
2004-07-09 21:03:35 +04:00
|
|
|
_swix(Tinct_Plot, _IN(2) | _IN(3) | _IN(4) | _IN(7),
|
|
|
|
sprite[HOTLIST_LINE], x0 + 8, y0 - HOTLIST_LINE_HEIGHT, 0);
|
2004-07-04 22:44:51 +04:00
|
|
|
y0 -= HOTLIST_LINE_HEIGHT;
|
|
|
|
height -= HOTLIST_LINE_HEIGHT;
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
} else {
|
|
|
|
/* Draw a half-line for the last entry
|
|
|
|
*/
|
|
|
|
if (!first || (level != 0)) {
|
2004-07-09 21:03:35 +04:00
|
|
|
_swix(Tinct_Plot, _IN(2) | _IN(3) | _IN(4) | _IN(7),
|
|
|
|
sprite[HOTLIST_TLINE], x0 + 8, y0 - 22, 0);
|
2004-07-04 22:44:51 +04:00
|
|
|
height -= HOTLIST_LINE_HEIGHT;
|
|
|
|
y0 -= HOTLIST_LINE_HEIGHT;
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw the expansion type
|
|
|
|
*/
|
|
|
|
if (entry->children == 0) {
|
2004-07-09 21:03:35 +04:00
|
|
|
_swix(Tinct_Plot, _IN(2) | _IN(3) | _IN(4) | _IN(7),
|
|
|
|
sprite[HOTLIST_ENTRY], x0, box_y0 - 23, 0);
|
2004-06-30 21:44:11 +04:00
|
|
|
} else {
|
|
|
|
if (entry->expanded) {
|
2004-07-09 21:03:35 +04:00
|
|
|
_swix(Tinct_Plot, _IN(2) | _IN(3) | _IN(4) | _IN(7),
|
|
|
|
sprite[HOTLIST_COLLAPSE], x0, box_y0 - 31, 0);
|
2004-06-30 21:44:11 +04:00
|
|
|
} else {
|
2004-07-09 21:03:35 +04:00
|
|
|
_swix(Tinct_Plot, _IN(2) | _IN(3) | _IN(4) | _IN(7),
|
|
|
|
sprite[HOTLIST_EXPAND], x0, box_y0 - 31, 0);
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move to the next entry
|
|
|
|
*/
|
|
|
|
entry = entry->next_entry;
|
|
|
|
first = false;
|
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/* Return our height
|
|
|
|
*/
|
|
|
|
return cumulative;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-02 02:56:26 +04:00
|
|
|
/**
|
|
|
|
* Redraws an entry in the tree and any children
|
|
|
|
*
|
|
|
|
* \param entry the entry to redraw
|
|
|
|
* \param level the level of the entry
|
2004-07-03 21:30:28 +04:00
|
|
|
* \param x0 the x co-ordinate to plot at
|
|
|
|
* \param y0 the y co-ordinate to plot at
|
2004-07-02 02:56:26 +04:00
|
|
|
* \return the height of the entry
|
|
|
|
*/
|
2004-06-30 21:44:11 +04:00
|
|
|
int ro_gui_hotlist_redraw_item(struct hotlist_entry *entry, int level, int x0, int y0) {
|
2004-07-04 22:44:51 +04:00
|
|
|
int height = HOTLIST_LINE_HEIGHT;
|
2004-07-03 21:30:28 +04:00
|
|
|
int line_y0;
|
|
|
|
int line_height;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-02 02:56:26 +04:00
|
|
|
/* Set the correct height
|
2004-06-30 21:44:11 +04:00
|
|
|
*/
|
2004-07-02 02:56:26 +04:00
|
|
|
if ((entry->children == -1) && (entry->expanded)) {
|
2004-07-04 22:44:51 +04:00
|
|
|
if (entry->url) height += HOTLIST_LINE_HEIGHT;
|
|
|
|
if (entry->visits > 0) height += HOTLIST_LINE_HEIGHT;
|
|
|
|
if (entry->add_date != -1) height += HOTLIST_LINE_HEIGHT;
|
|
|
|
if (entry->last_date != -1) height += HOTLIST_LINE_HEIGHT;
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-02 02:56:26 +04:00
|
|
|
/* Check whether we need to redraw
|
2004-06-30 21:44:11 +04:00
|
|
|
*/
|
2004-07-02 02:56:26 +04:00
|
|
|
if ((x0 < clip_x1) && (y0 > clip_y0) && ((x0 + entry->width) > clip_x0) &&
|
|
|
|
((y0 - height) < clip_y1)) {
|
2004-07-04 23:27:42 +04:00
|
|
|
|
|
|
|
|
2004-07-02 02:56:26 +04:00
|
|
|
/* Update the selection state
|
|
|
|
*/
|
|
|
|
text_icon.flags = wimp_ICON_TEXT | (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) |
|
2004-07-02 03:20:40 +04:00
|
|
|
(wimp_COLOUR_VERY_LIGHT_GREY << wimp_ICON_BG_COLOUR_SHIFT) |
|
2004-07-02 02:56:26 +04:00
|
|
|
wimp_ICON_INDIRECTED | wimp_ICON_VCENTRED;
|
|
|
|
if (entry->selected) {
|
|
|
|
sprite_icon.flags |= wimp_ICON_SELECTED;
|
|
|
|
text_icon.flags |= wimp_ICON_SELECTED;
|
|
|
|
text_icon.flags |= wimp_ICON_FILLED;
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
|
|
|
|
2004-07-02 02:56:26 +04:00
|
|
|
/* Draw our icon type
|
|
|
|
*/
|
|
|
|
sprite_icon.extent.x0 = x0 - origin_x;
|
2004-07-04 22:44:51 +04:00
|
|
|
sprite_icon.extent.x1 = x0 - origin_x + HOTLIST_ICON_WIDTH;
|
|
|
|
sprite_icon.extent.y0 = y0 - origin_y - HOTLIST_LINE_HEIGHT;
|
2004-07-02 02:56:26 +04:00
|
|
|
sprite_icon.extent.y1 = y0 - origin_y;
|
|
|
|
sprite_icon.data.indirected_sprite.id = (osspriteop_id)icon_name;
|
|
|
|
if (entry->children != -1) {
|
|
|
|
if ((entry->expanded) && (entry->children > 0)) {
|
|
|
|
sprintf(icon_name, "small_diro");
|
2004-07-07 04:31:57 +04:00
|
|
|
hotlist_ensure_sprite(icon_name, "small_dir");
|
2004-07-02 02:56:26 +04:00
|
|
|
} else {
|
|
|
|
sprintf(icon_name, "small_dir");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Get the icon sprite
|
|
|
|
*/
|
|
|
|
sprintf(icon_name, "small_%x", entry->filetype);
|
2004-07-07 04:31:57 +04:00
|
|
|
hotlist_ensure_sprite(icon_name, "small_xxx");
|
2004-07-02 02:56:26 +04:00
|
|
|
}
|
|
|
|
xwimp_plot_icon(&sprite_icon);
|
2004-06-30 21:44:11 +04:00
|
|
|
|
2004-07-02 02:56:26 +04:00
|
|
|
/* Draw our textual information
|
|
|
|
*/
|
|
|
|
text_icon.data.indirected_text.text = entry->title;
|
2004-07-04 22:44:51 +04:00
|
|
|
text_icon.extent.x0 = x0 - origin_x + HOTLIST_ICON_WIDTH;
|
|
|
|
text_icon.extent.x1 = x0 - origin_x + entry->collapsed_width - HOTLIST_LEAF_INSET;
|
|
|
|
text_icon.extent.y0 = y0 - origin_y - HOTLIST_LINE_HEIGHT + 2;
|
2004-07-03 21:30:28 +04:00
|
|
|
text_icon.extent.y1 = y0 - origin_y - 2;
|
2004-07-02 02:56:26 +04:00
|
|
|
xwimp_plot_icon(&text_icon);
|
2004-06-30 21:44:11 +04:00
|
|
|
|
2004-07-02 02:56:26 +04:00
|
|
|
/* Clear the selection state
|
2004-07-01 03:11:11 +04:00
|
|
|
*/
|
2004-07-02 02:56:26 +04:00
|
|
|
if (entry->selected) {
|
|
|
|
sprite_icon.flags &= ~wimp_ICON_SELECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw our further information if expanded
|
2004-06-30 21:44:11 +04:00
|
|
|
*/
|
2004-07-04 22:44:51 +04:00
|
|
|
if ((entry->children == -1) && (entry->expanded) && (height > HOTLIST_LINE_HEIGHT)) {
|
2004-07-02 02:56:26 +04:00
|
|
|
text_icon.flags = wimp_ICON_TEXT | (wimp_COLOUR_DARK_GREY << wimp_ICON_FG_COLOUR_SHIFT) |
|
|
|
|
wimp_ICON_INDIRECTED | wimp_ICON_VCENTRED;
|
2004-07-04 22:44:51 +04:00
|
|
|
text_icon.extent.y0 = y0 - origin_y - HOTLIST_LINE_HEIGHT;
|
2004-07-03 21:30:28 +04:00
|
|
|
text_icon.extent.y1 = y0 - origin_y;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-02 02:56:26 +04:00
|
|
|
/* Draw the lines
|
|
|
|
*/
|
2004-07-04 22:44:51 +04:00
|
|
|
y0 -= HOTLIST_LINE_HEIGHT;
|
2004-07-03 21:30:28 +04:00
|
|
|
line_y0 = y0;
|
2004-07-04 22:44:51 +04:00
|
|
|
line_height = height - HOTLIST_LINE_HEIGHT;
|
2004-07-03 21:30:28 +04:00
|
|
|
while (line_height > 0) {
|
2004-07-04 22:44:51 +04:00
|
|
|
if (line_height == HOTLIST_LINE_HEIGHT) {
|
2004-07-09 21:03:35 +04:00
|
|
|
_swix(Tinct_Plot, _IN(2) | _IN(3) | _IN(4) | _IN(7),
|
|
|
|
sprite[HOTLIST_TLINE], x0 + 16, line_y0 - 22, 0);
|
2004-07-03 21:30:28 +04:00
|
|
|
} else {
|
2004-07-09 21:03:35 +04:00
|
|
|
_swix(Tinct_Plot, _IN(2) | _IN(3) | _IN(4) | _IN(7),
|
|
|
|
sprite[HOTLIST_LINE], x0 + 16, line_y0 - HOTLIST_LINE_HEIGHT, 0);
|
2004-07-03 21:30:28 +04:00
|
|
|
}
|
2004-07-09 21:03:35 +04:00
|
|
|
_swix(Tinct_Plot, _IN(2) | _IN(3) | _IN(4) | _IN(7),
|
|
|
|
sprite[HOTLIST_ENTRY], x0 + 8, line_y0 - 23, 0);
|
2004-07-04 22:44:51 +04:00
|
|
|
line_height -= HOTLIST_LINE_HEIGHT;
|
|
|
|
line_y0 -= HOTLIST_LINE_HEIGHT;
|
2004-07-03 21:30:28 +04:00
|
|
|
}
|
2004-07-02 02:56:26 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
/* Set the right extent of the icon to be big enough for anything
|
2004-07-02 02:56:26 +04:00
|
|
|
*/
|
|
|
|
text_icon.extent.x1 = x0 - origin_x + 4096;
|
2004-07-03 21:30:28 +04:00
|
|
|
|
|
|
|
/* Plot the URL text
|
|
|
|
*/
|
|
|
|
text_icon.data.indirected_text.text = extended_text;
|
|
|
|
if (entry->url) {
|
|
|
|
snprintf(extended_text, HOTLIST_TEXT_BUFFER,
|
|
|
|
messages_get("HotlistURL"), entry->url);
|
|
|
|
if (strlen(extended_text) >= 255) {
|
|
|
|
extended_text[252] = '.';
|
|
|
|
extended_text[253] = '.';
|
|
|
|
extended_text[254] = '.';
|
|
|
|
extended_text[255] = '\0';
|
|
|
|
}
|
2004-07-04 22:44:51 +04:00
|
|
|
text_icon.extent.y0 -= HOTLIST_LINE_HEIGHT;
|
|
|
|
text_icon.extent.y1 -= HOTLIST_LINE_HEIGHT;
|
2004-07-03 21:30:28 +04:00
|
|
|
xwimp_plot_icon(&text_icon);
|
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
/* Plot the date added text
|
|
|
|
*/
|
|
|
|
if (entry->add_date != -1) {
|
|
|
|
snprintf(extended_text, HOTLIST_TEXT_BUFFER,
|
2004-07-04 23:27:42 +04:00
|
|
|
messages_get("HotlistAdded"), ctime(&entry->add_date));
|
2004-07-04 22:44:51 +04:00
|
|
|
text_icon.extent.y0 -= HOTLIST_LINE_HEIGHT;
|
|
|
|
text_icon.extent.y1 -= HOTLIST_LINE_HEIGHT;
|
2004-07-03 21:30:28 +04:00
|
|
|
xwimp_plot_icon(&text_icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Plot the last visited text
|
|
|
|
*/
|
|
|
|
if (entry->last_date != -1) {
|
|
|
|
snprintf(extended_text, HOTLIST_TEXT_BUFFER,
|
|
|
|
messages_get("HotlistLast"), ctime(&entry->last_date));
|
2004-07-04 22:44:51 +04:00
|
|
|
text_icon.extent.y0 -= HOTLIST_LINE_HEIGHT;
|
|
|
|
text_icon.extent.y1 -= HOTLIST_LINE_HEIGHT;
|
2004-07-03 21:30:28 +04:00
|
|
|
xwimp_plot_icon(&text_icon);
|
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
/* Plot the visit count text
|
|
|
|
*/
|
|
|
|
if (entry->visits > 0) {
|
|
|
|
snprintf(extended_text, HOTLIST_TEXT_BUFFER,
|
|
|
|
messages_get("HotlistVisits"), entry->visits);
|
2004-07-04 22:44:51 +04:00
|
|
|
text_icon.extent.y0 -= HOTLIST_LINE_HEIGHT;
|
|
|
|
text_icon.extent.y1 -= HOTLIST_LINE_HEIGHT;
|
2004-07-03 21:30:28 +04:00
|
|
|
xwimp_plot_icon(&text_icon);
|
|
|
|
}
|
2004-07-02 02:56:26 +04:00
|
|
|
}
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw any children
|
|
|
|
*/
|
|
|
|
if ((entry->child_entry) && (entry->expanded)) {
|
|
|
|
height += ro_gui_hotlist_redraw_tree(entry->child_entry, level + 1,
|
2004-07-04 22:44:51 +04:00
|
|
|
x0 + 8, y0 - HOTLIST_LINE_HEIGHT);
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-02 02:56:26 +04:00
|
|
|
/**
|
|
|
|
* Respond to a mouse click
|
|
|
|
*
|
|
|
|
* /param pointer the pointer state
|
|
|
|
*/
|
2004-06-30 21:44:11 +04:00
|
|
|
void ro_gui_hotlist_click(wimp_pointer *pointer) {
|
2004-07-04 18:59:29 +04:00
|
|
|
wimp_caret caret;
|
2004-07-03 21:30:28 +04:00
|
|
|
wimp_drag drag;
|
2004-06-30 21:44:11 +04:00
|
|
|
struct hotlist_entry *entry;
|
|
|
|
wimp_window_state state;
|
|
|
|
wimp_mouse_state buttons;
|
|
|
|
int x, y;
|
|
|
|
int x_offset;
|
2004-07-02 02:56:26 +04:00
|
|
|
int y_offset;
|
|
|
|
bool no_entry = false;
|
2004-07-04 18:59:29 +04:00
|
|
|
os_error *error;
|
2004-07-07 04:31:57 +04:00
|
|
|
os_box box = { pointer->pos.x - 34, pointer->pos.y - 34,
|
|
|
|
pointer->pos.x + 34, pointer->pos.y + 34 };
|
|
|
|
int selection;
|
2004-06-30 21:44:11 +04:00
|
|
|
|
|
|
|
/* Get the button state
|
|
|
|
*/
|
|
|
|
buttons = pointer->buttons;
|
|
|
|
|
|
|
|
/* Get the window state. Quite why the Wimp can't give relative
|
|
|
|
positions is beyond me.
|
|
|
|
*/
|
|
|
|
state.w = hotlist_window;
|
|
|
|
wimp_get_window_state(&state);
|
|
|
|
|
|
|
|
/* Translate by the origin/scroll values
|
|
|
|
*/
|
|
|
|
x = (pointer->pos.x - (state.visible.x0 - state.xscroll));
|
|
|
|
y = (pointer->pos.y - (state.visible.y1 - state.yscroll));
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-04 18:59:29 +04:00
|
|
|
/* We want the caret on a click
|
|
|
|
*/
|
|
|
|
error = xwimp_get_caret_position(&caret);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_get_caret_position: 0x%x: %s", error->errnum,
|
|
|
|
error->errmess));
|
|
|
|
}
|
|
|
|
if (((pointer->buttons == (wimp_CLICK_SELECT << 8)) ||
|
|
|
|
(pointer->buttons == (wimp_CLICK_ADJUST << 8))) &&
|
|
|
|
(caret.w != state.w)) {
|
|
|
|
error = xwimp_set_caret_position(state.w, -1, -100,
|
2004-07-07 04:31:57 +04:00
|
|
|
-100, 32, -1);
|
2004-07-04 18:59:29 +04:00
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_set_caret_position: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
}
|
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
/* Find our entry
|
|
|
|
*/
|
|
|
|
entry = ro_gui_hotlist_find_entry(x, y, root.child_entry);
|
|
|
|
if (entry) {
|
|
|
|
/* Check if we clicked on the expanding bit
|
|
|
|
*/
|
|
|
|
x_offset = x - entry->x0;
|
2004-07-02 02:56:26 +04:00
|
|
|
y_offset = y - (entry->y0 + entry->height);
|
2004-07-06 02:17:59 +04:00
|
|
|
if (((x_offset < HOTLIST_LEAF_INSET) && (y_offset > -HOTLIST_LINE_HEIGHT) &&
|
2004-07-10 01:03:26 +04:00
|
|
|
((buttons == wimp_CLICK_SELECT << 8) || (buttons == wimp_CLICK_ADJUST << 8) ||
|
|
|
|
(buttons == wimp_DOUBLE_SELECT) || (buttons == wimp_DOUBLE_ADJUST))) ||
|
2004-07-04 22:44:51 +04:00
|
|
|
((entry->children != -1) &&
|
2004-07-08 02:09:26 +04:00
|
|
|
((buttons == wimp_DOUBLE_SELECT) || (buttons == wimp_DOUBLE_ADJUST)))) {
|
|
|
|
if (entry->children != 0) {
|
|
|
|
ro_gui_hotlist_update_expansion(entry->child_entry, false, true, true, false, true);
|
|
|
|
ro_gui_hotlist_selection_state(entry->child_entry,
|
|
|
|
false, false);
|
|
|
|
entry->expanded = !entry->expanded;
|
|
|
|
if (x_offset >= HOTLIST_LEAF_INSET) entry->selected = false;
|
|
|
|
reformat_pending = true;
|
2004-07-10 01:03:26 +04:00
|
|
|
hotlist_redraw_entry(entry, true);
|
2004-07-08 02:09:26 +04:00
|
|
|
}
|
2004-07-04 22:44:51 +04:00
|
|
|
} else if (x_offset >= HOTLIST_LEAF_INSET) {
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-04 18:59:29 +04:00
|
|
|
/* We treat a menu click as a Select click if we have no selections
|
|
|
|
*/
|
|
|
|
if (buttons == wimp_CLICK_MENU) {
|
2004-07-06 02:17:59 +04:00
|
|
|
if (ro_gui_hotlist_selection_count(root.child_entry, true) == 0) {
|
2004-07-04 22:44:51 +04:00
|
|
|
menu_selection = true;
|
2004-07-04 18:59:29 +04:00
|
|
|
buttons = (wimp_CLICK_SELECT << 8);
|
|
|
|
}
|
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-01 03:11:11 +04:00
|
|
|
/* Check for selection
|
|
|
|
*/
|
|
|
|
if (buttons == (wimp_CLICK_SELECT << 8)) {
|
2004-07-04 18:59:29 +04:00
|
|
|
if (!entry->selected) {
|
2004-07-01 03:11:11 +04:00
|
|
|
ro_gui_hotlist_selection_state(root.child_entry,
|
|
|
|
false, true);
|
|
|
|
entry->selected = true;
|
2004-07-10 01:03:26 +04:00
|
|
|
hotlist_redraw_entry_title(entry);
|
|
|
|
|
2004-07-01 03:11:11 +04:00
|
|
|
}
|
|
|
|
} else if (buttons == (wimp_CLICK_ADJUST << 8)) {
|
|
|
|
entry->selected = !entry->selected;
|
2004-07-10 01:03:26 +04:00
|
|
|
hotlist_redraw_entry_title(entry);
|
2004-07-01 03:11:11 +04:00
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-01 03:11:11 +04:00
|
|
|
/* Check if we should open the URL
|
|
|
|
*/
|
|
|
|
if (((buttons == wimp_DOUBLE_SELECT) || (buttons == wimp_DOUBLE_ADJUST)) &&
|
|
|
|
(entry->children == -1)) {
|
2004-06-30 22:13:31 +04:00
|
|
|
browser_window_create(entry->url, NULL);
|
2004-07-01 03:11:11 +04:00
|
|
|
if (buttons == wimp_DOUBLE_SELECT) {
|
|
|
|
ro_gui_hotlist_selection_state(root.child_entry,
|
|
|
|
false, true);
|
|
|
|
} else {
|
|
|
|
entry->selected = false;
|
2004-07-10 01:03:26 +04:00
|
|
|
ro_gui_dialog_close_persistant(hotlist_window);
|
2004-06-30 22:13:31 +04:00
|
|
|
xwimp_close_window(hotlist_window);
|
|
|
|
}
|
2004-07-01 03:11:11 +04:00
|
|
|
}
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
/* Check if we should start a drag
|
|
|
|
*/
|
|
|
|
if ((buttons == (wimp_CLICK_SELECT <<4)) || (buttons == (wimp_CLICK_ADJUST << 4))) {
|
|
|
|
selection = ro_gui_hotlist_get_selected(true);
|
|
|
|
if (selection > 0) {
|
|
|
|
gui_current_drag_type = GUI_DRAG_HOTLIST_MOVE;
|
|
|
|
if (selection > 1) {
|
|
|
|
sprintf(drag_name, "package");
|
|
|
|
} else {
|
|
|
|
if (entry->children != -1) {
|
|
|
|
if ((entry->expanded) && (entry->children > 0)) {
|
|
|
|
sprintf(drag_name, "directoryo");
|
|
|
|
hotlist_ensure_sprite(drag_name, "directory");
|
|
|
|
} else {
|
|
|
|
sprintf(drag_name, "directory");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sprintf(drag_name, "file_%x", entry->filetype);
|
|
|
|
hotlist_ensure_sprite(drag_name, "file_xxx");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
error = xdragasprite_start(dragasprite_HPOS_CENTRE |
|
|
|
|
dragasprite_VPOS_CENTRE |
|
|
|
|
dragasprite_BOUND_POINTER |
|
|
|
|
dragasprite_DROP_SHADOW,
|
|
|
|
(osspriteop_area *) 1, drag_name, &box, 0);
|
2004-07-16 20:33:45 +04:00
|
|
|
dragging = true;
|
2004-07-07 04:31:57 +04:00
|
|
|
}
|
|
|
|
}
|
2004-07-02 02:56:26 +04:00
|
|
|
} else {
|
2004-07-06 02:17:59 +04:00
|
|
|
if (!((x_offset < HOTLIST_LEAF_INSET) && (y_offset > -HOTLIST_LINE_HEIGHT))) {
|
|
|
|
no_entry = true;
|
|
|
|
}
|
2004-07-01 03:11:11 +04:00
|
|
|
}
|
|
|
|
} else {
|
2004-07-02 02:56:26 +04:00
|
|
|
no_entry = true;
|
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-04 18:59:29 +04:00
|
|
|
/* Get the original button state back
|
|
|
|
*/
|
|
|
|
buttons = pointer->buttons;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-04 18:59:29 +04:00
|
|
|
/* Create a menu if we should
|
|
|
|
*/
|
2004-07-04 22:44:51 +04:00
|
|
|
if (buttons == wimp_CLICK_MENU) {
|
2004-07-18 21:38:01 +04:00
|
|
|
ro_gui_create_menu(hotlist_menu, pointer->pos.x,
|
2004-07-04 22:44:51 +04:00
|
|
|
pointer->pos.y, NULL);
|
2004-07-06 02:17:59 +04:00
|
|
|
menu_open = true;
|
|
|
|
return;
|
2004-07-04 18:59:29 +04:00
|
|
|
}
|
2004-07-04 16:42:54 +04:00
|
|
|
|
2004-07-02 02:56:26 +04:00
|
|
|
/* Handle a click without an entry
|
|
|
|
*/
|
|
|
|
if (no_entry) {
|
2004-07-03 21:30:28 +04:00
|
|
|
/* Deselect everything if we click nowhere
|
|
|
|
*/
|
2004-07-01 03:11:11 +04:00
|
|
|
if (buttons == (wimp_CLICK_SELECT << 8)) {
|
|
|
|
ro_gui_hotlist_selection_state(root.child_entry,
|
|
|
|
false, true);
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
/* Handle the start of a drag
|
|
|
|
*/
|
2004-07-04 23:27:42 +04:00
|
|
|
if (buttons == (wimp_CLICK_SELECT << 4) ||
|
2004-07-03 21:30:28 +04:00
|
|
|
buttons == (wimp_CLICK_ADJUST << 4)) {
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
/* Clear the current selection
|
|
|
|
*/
|
|
|
|
if (buttons == (wimp_CLICK_SELECT << 4)) {
|
|
|
|
ro_gui_hotlist_selection_state(root.child_entry,
|
|
|
|
false, true);
|
|
|
|
}
|
2004-07-03 20:28:09 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
/* Start a drag box
|
|
|
|
*/
|
|
|
|
drag_buttons = buttons;
|
|
|
|
gui_current_drag_type = GUI_DRAG_HOTLIST_SELECT;
|
2004-07-04 18:59:29 +04:00
|
|
|
drag.w = hotlist_window;
|
|
|
|
drag.type = wimp_DRAG_USER_RUBBER;
|
|
|
|
drag.initial.x0 = pointer->pos.x;
|
|
|
|
drag.initial.x1 = pointer->pos.x;
|
|
|
|
drag.initial.y0 = pointer->pos.y;
|
|
|
|
drag.initial.y1 = pointer->pos.y;
|
|
|
|
drag.bbox.x0 = state.visible.x0;
|
|
|
|
drag.bbox.x1 = state.visible.x1;
|
|
|
|
drag.bbox.y0 = state.visible.y0;
|
|
|
|
drag.bbox.y1 = state.visible.y1;
|
2004-07-08 02:09:26 +04:00
|
|
|
if (hotlist_toolbar) drag.bbox.y1 -= hotlist_toolbar->height;
|
2004-07-04 18:59:29 +04:00
|
|
|
xwimp_drag_box(&drag);
|
2004-07-16 20:33:45 +04:00
|
|
|
dragging = true;
|
2004-07-03 21:30:28 +04:00
|
|
|
}
|
|
|
|
}
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-02 02:56:26 +04:00
|
|
|
/**
|
|
|
|
* Find an entry at a particular position
|
|
|
|
*
|
2004-07-03 21:30:28 +04:00
|
|
|
* \param x the x co-ordinate
|
|
|
|
* \param y the y co-ordinate
|
2004-07-02 02:56:26 +04:00
|
|
|
* \param entry the entry to check down from (root->child_entry for the entire tree)
|
|
|
|
* /return the entry occupying the positon
|
|
|
|
*/
|
2004-06-30 21:44:11 +04:00
|
|
|
struct hotlist_entry *ro_gui_hotlist_find_entry(int x, int y, struct hotlist_entry *entry) {
|
|
|
|
struct hotlist_entry *find_entry;
|
2004-07-03 21:30:28 +04:00
|
|
|
int inset_x = 0;
|
|
|
|
int inset_y = 0;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-01 03:11:11 +04:00
|
|
|
/* Check we have an entry (only applies if we have an empty hotlist)
|
2004-06-30 21:44:11 +04:00
|
|
|
*/
|
|
|
|
if (!entry) return NULL;
|
|
|
|
|
|
|
|
/* Get the first child entry
|
|
|
|
*/
|
|
|
|
while (entry) {
|
2004-07-03 21:30:28 +04:00
|
|
|
/* Check if this entry could possibly match
|
2004-07-01 03:11:11 +04:00
|
|
|
*/
|
|
|
|
if ((x > entry->x0) && (y > entry->y0) && (x < (entry->x0 + entry->width)) &&
|
|
|
|
(y < (entry->y0 + entry->height))) {
|
2004-07-03 21:30:28 +04:00
|
|
|
|
|
|
|
/* The top line extends all the way left
|
2004-07-02 02:56:26 +04:00
|
|
|
*/
|
2004-07-04 22:44:51 +04:00
|
|
|
if (y - (entry->y0 + entry->height) > -HOTLIST_LINE_HEIGHT) {
|
2004-07-03 21:30:28 +04:00
|
|
|
if (x < (entry->x0 + entry->collapsed_width)) return entry;
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
/* No other entry can occupy the left edge
|
|
|
|
*/
|
2004-07-04 22:44:51 +04:00
|
|
|
inset_x = x - entry->x0 - HOTLIST_LEAF_INSET - HOTLIST_ICON_WIDTH;
|
2004-07-03 21:30:28 +04:00
|
|
|
if (inset_x < 0) return NULL;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
/* Check the right edge against our various widths
|
|
|
|
*/
|
2004-07-04 22:44:51 +04:00
|
|
|
inset_y = -((y - entry->y0 - entry->height) / HOTLIST_LINE_HEIGHT);
|
|
|
|
if (inset_x < (entry->widths[inset_y - 1] + HOTLIST_TEXT_PADDING)) return entry;
|
2004-07-04 23:27:42 +04:00
|
|
|
return NULL;
|
2004-07-01 03:11:11 +04:00
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-01 03:11:11 +04:00
|
|
|
/* Continue onwards
|
|
|
|
*/
|
|
|
|
if ((entry->child_entry) && (entry->expanded)) {
|
|
|
|
find_entry = ro_gui_hotlist_find_entry(x, y, entry->child_entry);
|
|
|
|
if (find_entry) return find_entry;
|
|
|
|
}
|
2004-06-30 21:44:11 +04:00
|
|
|
entry = entry->next_entry;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-07-01 03:11:11 +04:00
|
|
|
|
2004-07-02 02:56:26 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Updated the selection state of the tree
|
|
|
|
*
|
2004-07-03 21:30:28 +04:00
|
|
|
* \param entry the entry to update all siblings and descendants of
|
2004-07-02 02:56:26 +04:00
|
|
|
* \param selected the selection state to set
|
|
|
|
* \param redraw update the icons in the Wimp
|
|
|
|
* \return the number of entries that have changed
|
|
|
|
*/
|
2004-07-01 03:11:11 +04:00
|
|
|
int ro_gui_hotlist_selection_state(struct hotlist_entry *entry, bool selected, bool redraw) {
|
|
|
|
int changes = 0;
|
|
|
|
|
|
|
|
/* Check we have an entry (only applies if we have an empty hotlist)
|
|
|
|
*/
|
|
|
|
if (!entry) return 0;
|
|
|
|
|
|
|
|
/* Get the first child entry
|
|
|
|
*/
|
|
|
|
while (entry) {
|
|
|
|
/* Check this entry
|
|
|
|
*/
|
|
|
|
if (entry->selected != selected) {
|
|
|
|
/* Update the selection state
|
|
|
|
*/
|
|
|
|
entry->selected = selected;
|
|
|
|
changes++;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
/* Redraw the entrys first line
|
2004-07-01 03:11:11 +04:00
|
|
|
*/
|
2004-07-10 01:03:26 +04:00
|
|
|
if (redraw) hotlist_redraw_entry_title(entry);
|
2004-07-01 03:11:11 +04:00
|
|
|
}
|
2004-07-03 20:28:09 +04:00
|
|
|
|
2004-07-01 03:11:11 +04:00
|
|
|
/* Continue onwards
|
|
|
|
*/
|
2004-07-06 02:17:59 +04:00
|
|
|
if ((entry->child_entry) && ((!selected) || (entry->expanded))) {
|
2004-07-01 03:11:11 +04:00
|
|
|
changes += ro_gui_hotlist_selection_state(entry->child_entry,
|
2004-07-03 21:30:28 +04:00
|
|
|
selected, redraw & (entry->expanded));
|
2004-07-01 03:11:11 +04:00
|
|
|
}
|
|
|
|
entry = entry->next_entry;
|
|
|
|
}
|
|
|
|
return changes;
|
|
|
|
}
|
2004-07-03 20:28:09 +04:00
|
|
|
|
2004-07-06 02:17:59 +04:00
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
/**
|
|
|
|
* Returns the first selected item
|
|
|
|
*
|
|
|
|
* \param entry the search siblings and children of
|
|
|
|
* \return the first selected item
|
|
|
|
*/
|
|
|
|
struct hotlist_entry *ro_gui_hotlist_first_selection(struct hotlist_entry *entry) {
|
|
|
|
struct hotlist_entry *test_entry;
|
|
|
|
|
|
|
|
/* Check we have an entry (only applies if we have an empty hotlist)
|
|
|
|
*/
|
|
|
|
if (!entry) return NULL;
|
|
|
|
|
2004-07-09 21:03:35 +04:00
|
|
|
/* Work through our entries
|
2004-07-07 04:31:57 +04:00
|
|
|
*/
|
|
|
|
while (entry) {
|
|
|
|
if (entry->selected) return entry;
|
|
|
|
if (entry->child_entry) {
|
|
|
|
test_entry = ro_gui_hotlist_first_selection(entry->child_entry);
|
|
|
|
if (test_entry) return test_entry;
|
|
|
|
}
|
|
|
|
entry = entry->next_entry;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-06 02:17:59 +04:00
|
|
|
/**
|
|
|
|
* Return the current number of selected items (internal interface)
|
|
|
|
*
|
|
|
|
* \param entry the entry to count siblings and children of
|
|
|
|
*/
|
|
|
|
int ro_gui_hotlist_selection_count(struct hotlist_entry *entry, bool folders) {
|
2004-07-04 18:59:29 +04:00
|
|
|
int count = 0;
|
|
|
|
if (!entry) return 0;
|
|
|
|
while (entry) {
|
2004-07-06 02:17:59 +04:00
|
|
|
if ((entry->selected) && (folders || (entry->children == -1))) count++;
|
2004-07-09 21:03:35 +04:00
|
|
|
if (entry->child_entry) count += ro_gui_hotlist_selection_count(entry->child_entry, folders);
|
2004-07-04 18:59:29 +04:00
|
|
|
entry = entry->next_entry;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
|
2004-07-09 21:03:35 +04:00
|
|
|
/**
|
|
|
|
* Launch the current selection (internal interface)
|
|
|
|
*
|
|
|
|
* \param entry the entry to launch siblings and children of
|
|
|
|
*/
|
2004-07-04 22:44:51 +04:00
|
|
|
void ro_gui_hotlist_launch_selection(struct hotlist_entry *entry) {
|
|
|
|
if (!entry) return;
|
|
|
|
while (entry) {
|
2004-07-09 21:03:35 +04:00
|
|
|
if ((entry->selected) && (entry->url)) browser_window_create(entry->url, NULL);
|
|
|
|
if (entry->child_entry) ro_gui_hotlist_launch_selection(entry->child_entry);
|
2004-07-04 22:44:51 +04:00
|
|
|
entry = entry->next_entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-04 18:59:29 +04:00
|
|
|
|
2004-07-10 01:03:26 +04:00
|
|
|
/**
|
|
|
|
* Invalidate the statistics for any selected items (internal interface)
|
|
|
|
*
|
|
|
|
* \param entry the entry to update siblings and children of
|
|
|
|
*/
|
|
|
|
void ro_gui_hotlist_invalidate_statistics(struct hotlist_entry *entry) {
|
|
|
|
if (!entry) return;
|
|
|
|
while (entry) {
|
|
|
|
if ((entry->selected) && (entry->children == -1)) {
|
|
|
|
entry->visits = 0;
|
|
|
|
entry->last_date = (time_t)-1;
|
|
|
|
if (entry->expanded) hotlist_redraw_entry(entry, true);
|
|
|
|
}
|
|
|
|
if (entry->child_entry) ro_gui_hotlist_invalidate_statistics(entry->child_entry);
|
|
|
|
entry = entry->next_entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-09 21:03:35 +04:00
|
|
|
/**
|
|
|
|
* Set the process flag for the current selection (internal interface)
|
|
|
|
*
|
|
|
|
* \param entry the entry to modify siblings and children of
|
|
|
|
*/
|
|
|
|
void ro_gui_hotlist_selection_to_process(struct hotlist_entry *entry) {
|
|
|
|
if (!entry) return;
|
|
|
|
while (entry) {
|
|
|
|
entry->process = entry->selected;
|
|
|
|
if (entry->child_entry) ro_gui_hotlist_selection_to_process(entry->child_entry);
|
|
|
|
entry = entry->next_entry;
|
|
|
|
}
|
|
|
|
}
|
2004-07-07 04:31:57 +04:00
|
|
|
|
|
|
|
|
2004-07-04 18:59:29 +04:00
|
|
|
/**
|
|
|
|
* Toggles the expanded state for selected icons
|
|
|
|
* If neither expand not contract are set then the entries are toggled
|
|
|
|
*
|
|
|
|
* \param entry the entry to update all siblings and descendants of
|
|
|
|
* \param only_selected whether to only update selected icons
|
2004-07-04 22:44:51 +04:00
|
|
|
* \param folders whether to update folders
|
|
|
|
* \param links whether to update links
|
2004-07-04 18:59:29 +04:00
|
|
|
* \param expand force all entries to be expanded (dominant)
|
|
|
|
* \param contract force all entries to be contracted (recessive)
|
|
|
|
*/
|
|
|
|
void ro_gui_hotlist_update_expansion(struct hotlist_entry *entry, bool only_selected,
|
2004-07-04 22:44:51 +04:00
|
|
|
bool folders, bool links, bool expand, bool contract) {
|
2004-07-04 18:59:29 +04:00
|
|
|
bool current;
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-06 02:17:59 +04:00
|
|
|
/* Set a reformat to be pending
|
|
|
|
*/
|
|
|
|
reformat_pending = true;
|
|
|
|
|
2004-07-04 18:59:29 +04:00
|
|
|
/* Check we have an entry (only applies if we have an empty hotlist)
|
|
|
|
*/
|
|
|
|
if (!entry) return;
|
|
|
|
|
|
|
|
/* Get the first child entry
|
|
|
|
*/
|
|
|
|
while (entry) {
|
|
|
|
/* Check this entry
|
|
|
|
*/
|
|
|
|
if ((entry->selected) || (!only_selected)) {
|
|
|
|
current = entry->expanded;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-04 22:44:51 +04:00
|
|
|
/* Only update what we should
|
2004-07-04 18:59:29 +04:00
|
|
|
*/
|
2004-07-06 02:17:59 +04:00
|
|
|
if (((links) && (entry->children == -1)) || ((folders) && (entry->children > 0))) {
|
2004-07-04 22:44:51 +04:00
|
|
|
/* Update the expansion state
|
|
|
|
*/
|
|
|
|
if (expand) {
|
|
|
|
entry->expanded = true;
|
|
|
|
} else if (contract) {
|
|
|
|
entry->expanded = false;
|
|
|
|
} else {
|
|
|
|
entry->expanded = !entry->expanded;
|
|
|
|
}
|
2004-07-04 18:59:29 +04:00
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-04 18:59:29 +04:00
|
|
|
/* If we have contracted then we de-select and collapse any children
|
|
|
|
*/
|
|
|
|
if (entry->child_entry && !entry->expanded) {
|
2004-07-04 22:44:51 +04:00
|
|
|
ro_gui_hotlist_update_expansion(entry->child_entry, false, true, true, false, true);
|
2004-07-04 18:59:29 +04:00
|
|
|
ro_gui_hotlist_selection_state(entry->child_entry, false, false);
|
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-04 18:59:29 +04:00
|
|
|
/* Redraw the entrys first line
|
|
|
|
*/
|
2004-07-10 01:03:26 +04:00
|
|
|
if (current != entry->expanded) hotlist_redraw_entry(entry, true);
|
2004-07-04 18:59:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Continue onwards (child entries cannot be selected if the parent is
|
|
|
|
not expanded)
|
|
|
|
*/
|
|
|
|
if (entry->child_entry && entry->expanded) {
|
|
|
|
ro_gui_hotlist_update_expansion(entry->child_entry,
|
2004-07-04 22:44:51 +04:00
|
|
|
only_selected, folders, links, expand, contract);
|
2004-07-04 18:59:29 +04:00
|
|
|
}
|
|
|
|
entry = entry->next_entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Updated the selection state of the tree
|
|
|
|
*
|
|
|
|
* \param entry the entry to update all siblings and descendants of
|
2004-07-04 18:59:29 +04:00
|
|
|
* \param x0 the left edge of the box
|
|
|
|
* \param y0 the top edge of the box
|
|
|
|
* \param x1 the right edge of the box
|
|
|
|
* \param y1 the bottom edge of the box
|
2004-07-03 21:30:28 +04:00
|
|
|
* \param toggle toggle the selection state, otherwise set
|
|
|
|
* \param redraw update the icons in the Wimp
|
|
|
|
*/
|
|
|
|
void ro_gui_hotlist_selection_drag(struct hotlist_entry *entry,
|
|
|
|
int x0, int y0, int x1, int y1,
|
|
|
|
bool toggle, bool redraw) {
|
|
|
|
bool do_update;
|
|
|
|
int line;
|
|
|
|
int test_y;
|
|
|
|
|
|
|
|
/* Check we have an entry (only applies if we have an empty hotlist)
|
|
|
|
*/
|
|
|
|
if (!entry) return;
|
|
|
|
|
|
|
|
/* Get the first child entry
|
|
|
|
*/
|
|
|
|
while (entry) {
|
|
|
|
/* Check if this entry could possibly match
|
|
|
|
*/
|
2004-07-04 22:44:51 +04:00
|
|
|
if ((x1 > (entry->x0 + HOTLIST_LEAF_INSET)) && (y0 > entry->y0) &&
|
|
|
|
(x0 < (entry->x0 + entry->width)) &&
|
2004-07-03 21:30:28 +04:00
|
|
|
(y1 < (entry->y0 + entry->height))) {
|
|
|
|
do_update = false;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
/* Check the exact area of the title line
|
|
|
|
*/
|
2004-07-04 22:44:51 +04:00
|
|
|
if ((x1 > (entry->x0 + HOTLIST_LEAF_INSET)) &&
|
|
|
|
(y0 > entry->y0 + entry->height - HOTLIST_LINE_HEIGHT) &&
|
2004-07-03 21:30:28 +04:00
|
|
|
(x0 < (entry->x0 + entry->collapsed_width)) &&
|
|
|
|
(y1 < (entry->y0 + entry->height))) {
|
|
|
|
do_update = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check the other lines
|
|
|
|
*/
|
|
|
|
line = 1;
|
2004-07-04 22:44:51 +04:00
|
|
|
test_y = entry->y0 + entry->height - HOTLIST_LINE_HEIGHT;
|
|
|
|
while (((line * HOTLIST_LINE_HEIGHT) < entry->height) && (!do_update)) {
|
2004-07-03 21:30:28 +04:00
|
|
|
/* Check this line
|
|
|
|
*/
|
2004-07-04 22:44:51 +04:00
|
|
|
if ((x1 > (entry->x0 + HOTLIST_LEAF_INSET + HOTLIST_ICON_WIDTH)) &&
|
|
|
|
(y1 < test_y) && (y0 > test_y - HOTLIST_LINE_HEIGHT) &&
|
|
|
|
(x0 < (entry->x0 + entry->widths[line - 1] +
|
|
|
|
HOTLIST_LEAF_INSET + HOTLIST_ICON_WIDTH +
|
|
|
|
HOTLIST_TEXT_PADDING))) {
|
2004-07-03 21:30:28 +04:00
|
|
|
do_update = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move to the next line
|
|
|
|
*/
|
|
|
|
line++;
|
2004-07-04 22:44:51 +04:00
|
|
|
test_y -= HOTLIST_LINE_HEIGHT;
|
2004-07-03 21:30:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Redraw the entrys first line
|
|
|
|
*/
|
|
|
|
if (do_update) {
|
|
|
|
if (toggle) {
|
|
|
|
entry->selected = !entry->selected;
|
|
|
|
} else {
|
2004-07-04 18:59:29 +04:00
|
|
|
entry->selected = true;
|
2004-07-03 21:30:28 +04:00
|
|
|
}
|
2004-07-10 01:03:26 +04:00
|
|
|
if (redraw) hotlist_redraw_entry_title(entry);
|
2004-07-03 21:30:28 +04:00
|
|
|
}
|
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
/* Continue onwards
|
|
|
|
*/
|
|
|
|
if ((entry->child_entry) && (entry->expanded)) {
|
|
|
|
ro_gui_hotlist_selection_drag(entry->child_entry,
|
|
|
|
x0, y0, x1, y1, toggle, redraw);
|
|
|
|
}
|
|
|
|
entry = entry->next_entry;
|
|
|
|
do_update = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The end of a selection drag has been reached
|
|
|
|
*
|
|
|
|
* \param drag the final drag co-ordinates
|
|
|
|
*/
|
|
|
|
void ro_gui_hotlist_selection_drag_end(wimp_dragged *drag) {
|
|
|
|
wimp_window_state state;
|
2004-07-04 18:59:29 +04:00
|
|
|
int x0, y0, x1, y1;
|
2004-07-08 02:09:26 +04:00
|
|
|
int toolbar_height = 0;
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-16 20:33:45 +04:00
|
|
|
/* Reset our dragging state
|
|
|
|
*/
|
|
|
|
dragging = false;
|
2004-07-08 02:09:26 +04:00
|
|
|
|
|
|
|
/* Get the toolbar height
|
|
|
|
*/
|
|
|
|
if (hotlist_toolbar) toolbar_height = hotlist_toolbar->height * 2;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
/* Get the window state to make everything relative
|
|
|
|
*/
|
|
|
|
state.w = hotlist_window;
|
|
|
|
wimp_get_window_state(&state);
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
/* Create the relative positions
|
|
|
|
*/
|
|
|
|
x0 = drag->final.x0 - state.visible.x0 - state.xscroll;
|
|
|
|
x1 = drag->final.x1 - state.visible.x0 - state.xscroll;
|
2004-07-08 02:09:26 +04:00
|
|
|
y0 = drag->final.y0 - state.visible.y1 - state.yscroll + toolbar_height;
|
|
|
|
y1 = drag->final.y1 - state.visible.y1 - state.yscroll + toolbar_height;
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
/* Make sure x0 < x1 and y0 > y1
|
|
|
|
*/
|
|
|
|
if (x0 > x1) {
|
|
|
|
x0 ^= x1;
|
|
|
|
x1 ^= x0;
|
|
|
|
x0 ^= x1;
|
|
|
|
}
|
|
|
|
if (y0 < y1) {
|
|
|
|
y0 ^= y1;
|
|
|
|
y1 ^= y0;
|
|
|
|
y0 ^= y1;
|
2004-07-04 18:59:29 +04:00
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-04 18:59:29 +04:00
|
|
|
/* Update the selection state
|
|
|
|
*/
|
|
|
|
if (drag_buttons == (wimp_CLICK_SELECT << 4)) {
|
|
|
|
ro_gui_hotlist_selection_drag(root.child_entry, x0, y0, x1, y1, false, true);
|
|
|
|
} else {
|
|
|
|
ro_gui_hotlist_selection_drag(root.child_entry, x0, y0, x1, y1, true, true);
|
|
|
|
}
|
2004-07-03 21:30:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The end of a item moving drag has been reached
|
|
|
|
*
|
|
|
|
* \param drag the final drag co-ordinates
|
|
|
|
*/
|
|
|
|
void ro_gui_hotlist_move_drag_end(wimp_dragged *drag) {
|
2004-07-08 02:09:26 +04:00
|
|
|
wimp_pointer pointer;
|
|
|
|
int toolbar_height = 0;
|
2004-07-07 04:31:57 +04:00
|
|
|
wimp_window_state state;
|
|
|
|
struct hotlist_entry *test_entry;
|
|
|
|
struct hotlist_entry *entry;
|
|
|
|
int x, y, x0, y0, x1, y1;
|
|
|
|
bool before = false;
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-16 20:33:45 +04:00
|
|
|
/* Reset our dragging state
|
|
|
|
*/
|
|
|
|
dragging = false;
|
2004-07-07 04:31:57 +04:00
|
|
|
|
2004-07-16 20:33:45 +04:00
|
|
|
/* Check we dropped to our window
|
|
|
|
*/
|
2004-07-08 02:09:26 +04:00
|
|
|
xwimp_get_pointer_info(&pointer);
|
|
|
|
if (pointer.w != hotlist_window) return;
|
|
|
|
|
|
|
|
/* Get the toolbar height
|
|
|
|
*/
|
|
|
|
if (hotlist_toolbar) toolbar_height = hotlist_toolbar->height * 2;
|
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
/* Set the process flag for all selected items
|
|
|
|
*/
|
|
|
|
ro_gui_hotlist_selection_to_process(root.child_entry);
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
/* Get the window state to make everything relative
|
|
|
|
*/
|
|
|
|
state.w = hotlist_window;
|
|
|
|
wimp_get_window_state(&state);
|
|
|
|
|
|
|
|
/* Create the relative positions
|
|
|
|
*/
|
|
|
|
x0 = drag->final.x0 - state.visible.x0 - state.xscroll;
|
|
|
|
x1 = drag->final.x1 - state.visible.x0 - state.xscroll;
|
2004-07-08 02:09:26 +04:00
|
|
|
y0 = drag->final.y0 - state.visible.y1 - state.yscroll + toolbar_height;
|
|
|
|
y1 = drag->final.y1 - state.visible.y1 - state.yscroll + toolbar_height;
|
2004-07-07 04:31:57 +04:00
|
|
|
x = (x0 + x1) / 2;
|
|
|
|
y = (y0 + y1) / 2;
|
|
|
|
|
|
|
|
/* Find our entry
|
|
|
|
*/
|
|
|
|
entry = ro_gui_hotlist_find_entry(x, y, root.child_entry);
|
|
|
|
if (!entry) entry = &root;
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
/* No parent of the destination can be processed
|
|
|
|
*/
|
|
|
|
test_entry = entry;
|
|
|
|
while (test_entry != NULL) {
|
|
|
|
if (test_entry->process) return;
|
|
|
|
test_entry = test_entry->parent_entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for before/after
|
|
|
|
*/
|
|
|
|
before = ((y - (entry->y0 + entry->height)) > (-HOTLIST_LINE_HEIGHT / 2));
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
/* Start our recursive moving
|
|
|
|
*/
|
|
|
|
while (ro_gui_hotlist_move_processing(root.child_entry, entry, before));
|
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
|
2004-07-03 21:30:28 +04:00
|
|
|
|
2004-07-07 04:31:57 +04:00
|
|
|
bool ro_gui_hotlist_move_processing(struct hotlist_entry *entry, struct hotlist_entry *destination, bool before) {
|
|
|
|
bool result = false;
|
|
|
|
if (!entry) return false;
|
|
|
|
while (entry) {
|
|
|
|
if (entry->process) {
|
|
|
|
entry->process = false;
|
|
|
|
ro_gui_hotlist_delink_entry(entry);
|
|
|
|
ro_gui_hotlist_link_entry(destination, entry, before);
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
if (entry->child_entry) {
|
|
|
|
result |= ro_gui_hotlist_move_processing(entry->child_entry, destination, before);
|
|
|
|
}
|
|
|
|
entry = entry->next_entry;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2004-07-03 21:30:28 +04:00
|
|
|
|
2004-07-04 22:44:51 +04:00
|
|
|
/**
|
|
|
|
* Handle a menu being closed
|
|
|
|
*/
|
|
|
|
void ro_gui_hotlist_menu_closed(void) {
|
2004-07-06 02:17:59 +04:00
|
|
|
menu_open = false;
|
2004-07-04 22:44:51 +04:00
|
|
|
if (menu_selection) {
|
|
|
|
ro_gui_hotlist_selection_state(root.child_entry, false, true);
|
|
|
|
menu_selection = false;
|
|
|
|
}
|
2004-07-04 23:27:42 +04:00
|
|
|
}
|
2004-07-04 22:44:51 +04:00
|
|
|
|
2004-07-04 18:59:29 +04:00
|
|
|
/**
|
|
|
|
* Handle a keypress
|
|
|
|
*
|
|
|
|
* \param key the key pressed
|
|
|
|
* \return whether the key was processed
|
|
|
|
*/
|
|
|
|
bool ro_gui_hotlist_keypress(int key) {
|
|
|
|
wimp_window_state state;
|
|
|
|
int y;
|
|
|
|
|
|
|
|
/* Handle basic keys
|
|
|
|
*/
|
|
|
|
switch (key) {
|
|
|
|
case 1: /* CTRL+A */
|
|
|
|
ro_gui_hotlist_selection_state(root.child_entry, true, true);
|
2004-07-06 02:17:59 +04:00
|
|
|
if (menu_open) ro_gui_create_menu(hotlist_menu, 0, 0, NULL);
|
2004-07-04 18:59:29 +04:00
|
|
|
return true;
|
|
|
|
case 26: /* CTRL+Z */
|
|
|
|
ro_gui_hotlist_selection_state(root.child_entry, false, true);
|
2004-07-06 02:17:59 +04:00
|
|
|
if (menu_open) ro_gui_create_menu(hotlist_menu, 0, 0, NULL);
|
2004-07-04 18:59:29 +04:00
|
|
|
return true;
|
|
|
|
case 32: /* SPACE */
|
2004-07-04 22:44:51 +04:00
|
|
|
ro_gui_hotlist_update_expansion(root.child_entry, true, true, true, false, false);
|
2004-07-06 02:17:59 +04:00
|
|
|
if (menu_open) ro_gui_create_menu(hotlist_menu, 0, 0, NULL);
|
2004-07-04 22:44:51 +04:00
|
|
|
return true;
|
|
|
|
case wimp_KEY_RETURN:
|
|
|
|
ro_gui_hotlist_launch_selection(root.child_entry);
|
2004-07-04 18:59:29 +04:00
|
|
|
return true;
|
2004-07-06 02:17:59 +04:00
|
|
|
case wimp_KEY_F3:
|
|
|
|
ro_gui_hotlist_save();
|
|
|
|
return true;
|
2004-07-04 18:59:29 +04:00
|
|
|
case wimp_KEY_UP:
|
|
|
|
case wimp_KEY_DOWN:
|
|
|
|
case wimp_KEY_PAGE_UP:
|
|
|
|
case wimp_KEY_PAGE_DOWN:
|
|
|
|
case wimp_KEY_CONTROL | wimp_KEY_UP:
|
|
|
|
case wimp_KEY_CONTROL | wimp_KEY_DOWN:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2004-07-03 21:30:28 +04:00
|
|
|
|
2004-07-04 18:59:29 +04:00
|
|
|
/* Handle keypress scrolling
|
|
|
|
*/
|
|
|
|
state.w = hotlist_window;
|
|
|
|
wimp_get_window_state(&state);
|
2004-07-05 03:16:12 +04:00
|
|
|
y = state.visible.y1 - state.visible.y0 - 32;
|
2004-07-04 18:59:29 +04:00
|
|
|
switch (key) {
|
|
|
|
case wimp_KEY_UP:
|
2004-07-05 03:16:12 +04:00
|
|
|
state.yscroll += 32;
|
2004-07-04 18:59:29 +04:00
|
|
|
break;
|
|
|
|
case wimp_KEY_DOWN:
|
2004-07-05 03:16:12 +04:00
|
|
|
state.yscroll -= 32;
|
2004-07-04 18:59:29 +04:00
|
|
|
break;
|
|
|
|
case wimp_KEY_PAGE_UP:
|
|
|
|
state.yscroll += y;
|
|
|
|
break;
|
|
|
|
case wimp_KEY_PAGE_DOWN:
|
|
|
|
state.yscroll -= y;
|
|
|
|
break;
|
|
|
|
case wimp_KEY_CONTROL | wimp_KEY_UP:
|
|
|
|
state.yscroll = 1000;
|
|
|
|
break;
|
|
|
|
case wimp_KEY_CONTROL | wimp_KEY_DOWN:
|
|
|
|
state.yscroll = -0x10000000;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
xwimp_open_window((wimp_open *) &state);
|
2004-07-04 23:27:42 +04:00
|
|
|
return true;
|
2004-07-04 18:59:29 +04:00
|
|
|
}
|
2004-07-03 21:30:28 +04:00
|
|
|
|
|
|
|
|
2004-07-08 02:09:26 +04:00
|
|
|
void ro_gui_hotlist_toolbar_click(wimp_pointer* pointer) {
|
|
|
|
int selection;
|
|
|
|
|
|
|
|
/* Reject Menu clicks
|
|
|
|
*/
|
|
|
|
if (pointer->buttons == wimp_CLICK_MENU) return;
|
2004-07-03 21:30:28 +04:00
|
|
|
|
2004-07-08 02:09:26 +04:00
|
|
|
/* Handle the buttons appropriately
|
|
|
|
*/
|
|
|
|
switch (pointer->i) {
|
2004-07-09 02:05:35 +04:00
|
|
|
case ICON_TOOLBAR_CREATE:
|
|
|
|
hotlist_insert = false;
|
|
|
|
if (pointer->buttons == wimp_CLICK_SELECT) {
|
|
|
|
ro_gui_hotlist_prepare_folder_dialog(false);
|
2004-07-16 20:45:42 +04:00
|
|
|
ro_gui_dialog_open_persistant(hotlist_window, dialog_folder, true);
|
2004-07-09 02:05:35 +04:00
|
|
|
} else {
|
|
|
|
ro_gui_hotlist_prepare_entry_dialog(false);
|
2004-07-16 20:45:42 +04:00
|
|
|
ro_gui_dialog_open_persistant(hotlist_window, dialog_entry, true);
|
2004-07-09 02:05:35 +04:00
|
|
|
}
|
|
|
|
break;
|
2004-07-08 02:09:26 +04:00
|
|
|
case ICON_TOOLBAR_OPEN:
|
|
|
|
selection = ro_gui_hotlist_get_selected(true);
|
|
|
|
ro_gui_hotlist_update_expansion(root.child_entry, (selection != 0), true, false,
|
|
|
|
(pointer->buttons == wimp_CLICK_SELECT),
|
|
|
|
(pointer->buttons == wimp_CLICK_ADJUST));
|
|
|
|
break;
|
|
|
|
case ICON_TOOLBAR_EXPAND:
|
|
|
|
selection = ro_gui_hotlist_get_selected(true);
|
|
|
|
ro_gui_hotlist_update_expansion(root.child_entry, (selection != 0), false, true,
|
|
|
|
(pointer->buttons == wimp_CLICK_SELECT),
|
|
|
|
(pointer->buttons == wimp_CLICK_ADJUST));
|
|
|
|
break;
|
|
|
|
case ICON_TOOLBAR_DELETE:
|
|
|
|
ro_gui_hotlist_delete_selected();
|
|
|
|
break;
|
|
|
|
case ICON_TOOLBAR_LAUNCH:
|
|
|
|
ro_gui_hotlist_keypress(wimp_KEY_RETURN);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-07-06 02:17:59 +04:00
|
|
|
|
|
|
|
|
2004-07-09 02:05:35 +04:00
|
|
|
void ro_gui_hotlist_prepare_folder_dialog(bool selected) {
|
|
|
|
struct hotlist_entry *entry = NULL;
|
|
|
|
if (selected) entry = ro_gui_hotlist_first_selection(root.child_entry);
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-09 02:05:35 +04:00
|
|
|
/* Update the title
|
|
|
|
*/
|
|
|
|
dialog_folder_add = selected;
|
|
|
|
if (selected) {
|
|
|
|
ro_gui_set_window_title(dialog_folder, messages_get("EditFolder"));
|
|
|
|
} else {
|
|
|
|
ro_gui_set_window_title(dialog_folder, messages_get("NewFolder"));
|
|
|
|
}
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-09 02:05:35 +04:00
|
|
|
/* Update the icons
|
|
|
|
*/
|
|
|
|
if (entry == NULL) {
|
|
|
|
ro_gui_set_icon_string(dialog_folder, 1, messages_get("Folder"));
|
|
|
|
} else {
|
|
|
|
ro_gui_set_icon_string(dialog_folder, 1, entry->title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ro_gui_hotlist_prepare_entry_dialog(bool selected) {
|
|
|
|
struct hotlist_entry *entry = NULL;
|
|
|
|
if (selected) entry = ro_gui_hotlist_first_selection(root.child_entry);
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-09 02:05:35 +04:00
|
|
|
/* Update the title
|
|
|
|
*/
|
|
|
|
dialog_entry_add = selected;
|
|
|
|
if (selected) {
|
|
|
|
ro_gui_set_window_title(dialog_entry, messages_get("EditLink"));
|
|
|
|
} else {
|
|
|
|
ro_gui_set_window_title(dialog_entry, messages_get("NewLink"));
|
|
|
|
}
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-09 02:05:35 +04:00
|
|
|
/* Update the icons
|
|
|
|
*/
|
|
|
|
if (entry == NULL) {
|
|
|
|
ro_gui_set_icon_string(dialog_entry, 1, messages_get("Link"));
|
|
|
|
ro_gui_set_icon_string(dialog_entry, 3, "");
|
|
|
|
} else {
|
|
|
|
ro_gui_set_icon_string(dialog_entry, 1, entry->title);
|
2004-07-17 17:00:38 +04:00
|
|
|
ro_gui_set_icon_string(dialog_entry, 3, entry->url);
|
2004-07-09 02:05:35 +04:00
|
|
|
}
|
|
|
|
}
|
2004-07-06 02:17:59 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set all items to either selected or deselected
|
|
|
|
*
|
|
|
|
* \param selected the state to set all items to
|
|
|
|
*/
|
|
|
|
void ro_gui_hotlist_set_selected(bool selected) {
|
|
|
|
ro_gui_hotlist_selection_state(root.child_entry, selected, true);
|
|
|
|
menu_selection = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-10 01:03:26 +04:00
|
|
|
/**
|
|
|
|
* Reset the statistics for selected entries
|
|
|
|
*/
|
|
|
|
void ro_gui_hotlist_reset_statistics(void) {
|
|
|
|
ro_gui_hotlist_invalidate_statistics(root.child_entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-06 02:17:59 +04:00
|
|
|
/**
|
|
|
|
* Return the current number of selected items
|
|
|
|
*
|
|
|
|
* \param folders include folders in the selection count
|
|
|
|
* \return the number of selected items
|
|
|
|
*/
|
|
|
|
int ro_gui_hotlist_get_selected(bool folders) {
|
|
|
|
return ro_gui_hotlist_selection_count(root.child_entry, folders);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set all items to either selected or deselected
|
|
|
|
*
|
|
|
|
* \param expand whether to expand (collapse otherwise)
|
|
|
|
* \param folders whether to update folders
|
|
|
|
* \param links whether to update links
|
|
|
|
*/
|
|
|
|
void ro_gui_hotlist_set_expanded(bool expand, bool folders, bool links) {
|
|
|
|
ro_gui_hotlist_update_expansion(root.child_entry, false, folders, links, expand, !expand);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-03 20:28:09 +04:00
|
|
|
/**
|
2004-07-07 04:31:57 +04:00
|
|
|
* Deletes any selected items
|
2004-07-03 20:28:09 +04:00
|
|
|
*
|
2004-07-07 04:31:57 +04:00
|
|
|
* \param selected the state to set all items to
|
2004-07-03 20:28:09 +04:00
|
|
|
*/
|
2004-07-07 04:31:57 +04:00
|
|
|
void ro_gui_hotlist_delete_selected(void) {
|
|
|
|
struct hotlist_entry *entry;
|
|
|
|
while ((entry = ro_gui_hotlist_first_selection(root.child_entry)) != NULL) {
|
|
|
|
ro_gui_hotlist_delete_entry(entry, false);
|
2004-07-03 20:28:09 +04:00
|
|
|
}
|
|
|
|
}
|
2004-07-12 03:14:24 +04:00
|
|
|
|
|
|
|
void ro_gui_hotlist_dialog_click(wimp_pointer *pointer) {
|
|
|
|
struct hotlist_entry *entry = NULL;
|
|
|
|
char *title = NULL;
|
|
|
|
char *url = NULL;
|
|
|
|
char *old_value;
|
|
|
|
int icon = pointer->i;
|
|
|
|
int close_icon, ok_icon;
|
|
|
|
bool folder;
|
|
|
|
bool add;
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-12 03:14:24 +04:00
|
|
|
/* Get our data
|
|
|
|
*/
|
|
|
|
if (pointer->w == dialog_entry) {
|
|
|
|
title = strip(ro_gui_get_icon_string(pointer->w, 1));
|
|
|
|
url = strip(ro_gui_get_icon_string(pointer->w, 3));
|
|
|
|
close_icon = 4;
|
|
|
|
ok_icon = 5;
|
|
|
|
folder = false;
|
|
|
|
add = !dialog_entry_add;
|
|
|
|
} else {
|
|
|
|
title = strip(ro_gui_get_icon_string(pointer->w, 1));
|
|
|
|
close_icon = 2;
|
|
|
|
ok_icon = 3;
|
|
|
|
folder = true;
|
|
|
|
add = !dialog_folder_add;
|
2004-07-17 17:00:38 +04:00
|
|
|
}
|
2004-07-12 03:14:24 +04:00
|
|
|
|
|
|
|
/* Check for cancelling
|
|
|
|
*/
|
|
|
|
if (icon == close_icon) {
|
|
|
|
if (pointer->buttons == wimp_CLICK_SELECT) {
|
|
|
|
ro_gui_dialog_close(pointer->w);
|
|
|
|
xwimp_create_menu((wimp_menu *)-1, 0, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (folder) {
|
|
|
|
ro_gui_hotlist_prepare_folder_dialog(dialog_folder_add);
|
|
|
|
} else {
|
|
|
|
ro_gui_hotlist_prepare_entry_dialog(dialog_entry_add);
|
|
|
|
}
|
2004-07-17 17:00:38 +04:00
|
|
|
return;
|
2004-07-12 03:14:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for ok
|
|
|
|
*/
|
|
|
|
if (icon != ok_icon) return;
|
|
|
|
|
|
|
|
/* Check we have valid values
|
|
|
|
*/
|
|
|
|
if ((title != NULL) && (strlen(title) == 0)) {
|
|
|
|
warn_user("NoNameError", 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((url != NULL) && (strlen(url) == 0)) {
|
|
|
|
warn_user("NoURLError", 0);
|
|
|
|
return;
|
|
|
|
}
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-12 03:14:24 +04:00
|
|
|
/* Update/insert our data
|
|
|
|
*/
|
|
|
|
if (add) {
|
|
|
|
/* todo: insert at the selection place if hotlist_insert is set */
|
|
|
|
ro_gui_hotlist_create_entry(title, url, folder ? 0 : 0xfaf, &root);
|
|
|
|
} else {
|
|
|
|
entry = ro_gui_hotlist_first_selection(root.child_entry);
|
|
|
|
if (entry == NULL) return;
|
|
|
|
if (url) {
|
|
|
|
old_value = entry->url;
|
|
|
|
entry->url = url_normalize(url);
|
|
|
|
if (!entry->url) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
entry->url = old_value;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (old_value) free(old_value);
|
|
|
|
}
|
|
|
|
if (title) {
|
|
|
|
old_value = entry->title;
|
|
|
|
entry->title = malloc(strlen(title) + 1);
|
|
|
|
if (!entry->title) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
entry->title = old_value;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
strcpy(entry->title, title);
|
|
|
|
if (old_value) free(old_value);
|
|
|
|
}
|
|
|
|
ro_gui_hotlist_update_entry_size(entry);
|
|
|
|
}
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-12 03:14:24 +04:00
|
|
|
/* Close if we should
|
|
|
|
*/
|
|
|
|
if (pointer->buttons == wimp_CLICK_SELECT) {
|
|
|
|
xwimp_create_menu((wimp_menu *)-1, 0, 0);
|
2004-07-16 20:33:45 +04:00
|
|
|
ro_gui_dialog_close(pointer->w);
|
2004-07-12 03:14:24 +04:00
|
|
|
return;
|
|
|
|
}
|
2004-07-17 17:00:38 +04:00
|
|
|
|
2004-07-12 03:14:24 +04:00
|
|
|
/* Update our display
|
|
|
|
*/
|
|
|
|
if (folder) {
|
|
|
|
ro_gui_hotlist_prepare_folder_dialog(dialog_folder_add);
|
|
|
|
} else {
|
|
|
|
ro_gui_hotlist_prepare_entry_dialog(dialog_entry_add);
|
|
|
|
}
|
|
|
|
}
|
2004-07-16 20:33:45 +04:00
|
|
|
|
|
|
|
|
|
|
|
int ro_gui_hotlist_help(int x, int y) {
|
|
|
|
struct hotlist_entry *entry;
|
|
|
|
wimp_window_state state;
|
|
|
|
int toolbar_height = 0;
|
|
|
|
int x_offset, y_offset;
|
|
|
|
|
|
|
|
/* Return the dragging codes
|
|
|
|
*/
|
|
|
|
if (dragging) {
|
|
|
|
if (gui_current_drag_type == GUI_DRAG_HOTLIST_SELECT) return 6;
|
|
|
|
if (gui_current_drag_type == GUI_DRAG_HOTLIST_MOVE) return 7;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the toolbar height
|
|
|
|
*/
|
|
|
|
if (hotlist_toolbar) toolbar_height = hotlist_toolbar->height * 2;
|
|
|
|
|
|
|
|
/* Get the window state to make everything relative
|
|
|
|
*/
|
|
|
|
state.w = hotlist_window;
|
|
|
|
wimp_get_window_state(&state);
|
|
|
|
|
|
|
|
/* Create the relative positions
|
|
|
|
*/
|
|
|
|
x = x - state.visible.x0 - state.xscroll;
|
|
|
|
y = y - state.visible.y1 - state.yscroll + toolbar_height;
|
|
|
|
|
|
|
|
/* Get the current entry
|
|
|
|
*/
|
|
|
|
entry = ro_gui_hotlist_find_entry(x, y, root.child_entry);
|
|
|
|
if (entry == NULL) return -1;
|
|
|
|
|
|
|
|
/* Return the relevant code
|
|
|
|
*/
|
|
|
|
x_offset = x - entry->x0;
|
|
|
|
y_offset = y - (entry->y0 + entry->height);
|
|
|
|
if ((x_offset < HOTLIST_LEAF_INSET) && (y_offset > -HOTLIST_LINE_HEIGHT)) {
|
|
|
|
if (entry->children == 0) return -1;
|
|
|
|
return (((entry->children == -1) ? 2 : 0) + ((entry->expanded) ? 1 : 0));
|
|
|
|
}
|
|
|
|
return ((entry->children == -1) ? 5 : 4);
|
|
|
|
}
|