[project @ 2004-07-08 22:05:35 by rjw]

Lose compiler warnings. Fix for dragging hotlist item to itself failing. Initial work on adding/editing entries.

svn path=/import/netsurf/; revision=1061
This commit is contained in:
Richard Wilson 2004-07-08 22:05:35 +00:00
parent 4d3423003e
commit e387d5e34a
8 changed files with 173 additions and 42 deletions

Binary file not shown.

Binary file not shown.

View File

@ -36,7 +36,8 @@ wimp_w dialog_info, dialog_saveas, dialog_config, dialog_config_br,
dialog_401li,
#endif
dialog_zoom, dialog_pageinfo, dialog_objinfo, dialog_tooltip,
dialog_warning, dialog_config_th_pane, dialog_debug;
dialog_warning, dialog_config_th_pane, dialog_debug,
dialog_folder, dialog_entry;
static int font_size;
static int font_min_size;
@ -90,6 +91,8 @@ void ro_gui_dialog_init(void)
dialog_tooltip = ro_gui_dialog_create("tooltip");
dialog_warning = ro_gui_dialog_create("warning");
dialog_debug = ro_gui_dialog_create("debug");
dialog_folder = ro_gui_dialog_create("new_folder");
dialog_entry = ro_gui_dialog_create("new_entry");
set_browser_choices();
set_proxy_choices();

View File

@ -24,7 +24,7 @@
extern wimp_w dialog_info, dialog_saveas, dialog_config, dialog_config_br,
dialog_config_prox, dialog_config_th, dialog_zoom, dialog_pageinfo,
dialog_objinfo, dialog_tooltip, dialog_warning, dialog_config_th_pane,
dialog_debug;
dialog_debug, dialog_folder, dialog_entry;
extern wimp_w history_window;
extern wimp_w hotlist_window;
extern wimp_menu *iconbar_menu, *browser_menu, *combo_menu, *hotlist_menu;
@ -38,6 +38,7 @@ extern gui_window *current_gui;
extern gui_window *ro_gui_current_redraw_gui;
extern osspriteop_area *gui_sprites;
extern struct toolbar *hotlist_toolbar;
extern bool dialog_folder_add, dialog_entry_add, hotlist_insert;
typedef enum { GUI_BROWSER_WINDOW } gui_window_type;
typedef enum { GUI_SAVE_SOURCE, GUI_SAVE_DRAW, GUI_SAVE_TEXT,
@ -198,6 +199,8 @@ void ro_gui_hotlist_set_selected(bool selected);
void ro_gui_hotlist_set_expanded(bool expand, bool folders, bool links);
void ro_gui_hotlist_delete_selected(void);
void ro_gui_hotlist_save_as(const char *file);
void ro_gui_hotlist_prepare_folder_dialog(bool selected);
void ro_gui_hotlist_prepare_entry_dialog(bool selected);
/* in save.c */
void ro_gui_save_click(wimp_pointer *pointer);

View File

@ -193,10 +193,19 @@ wimp_mouse_state drag_buttons;
bool menu_selection = false;
bool menu_open = false;
/* Whether the editing facilities are for add so that we know how
to reset the dialog boxes on a adjust-cancel and the action to
perform on ok.
*/
bool dialog_folder_add = false;
bool dialog_entry_add = false;
bool hotlist_insert = false;
/* Hotlist loading buffer
*/
char *load_buf;
static bool ro_gui_hotlist_initialise_sprite(const char *name, int number);
static bool ro_gui_hotlist_load(void);
static bool ro_gui_hotlist_save_entry(FILE *fp, struct hotlist_entry *entry);
static bool ro_gui_hotlist_load_entry(FILE *fp, struct hotlist_entry *entry);
@ -242,37 +251,16 @@ void ro_gui_hotlist_init(void) {
return;
}
/* Get our sprite ids for faster plotting. This could be done in a
far more elegant manner, but it's late and my girlfriend will
kill me if I don't go to bed soon. Sorry.
/* Get our sprite ids for faster plotting.
*/
error = xosspriteop_select_sprite(osspriteop_USER_AREA, gui_sprites,
(osspriteop_id)"tr_expand",
(osspriteop_header **)&sprite[HOTLIST_EXPAND]);
if (!error)
error = xosspriteop_select_sprite(osspriteop_USER_AREA, gui_sprites,
(osspriteop_id)"tr_collapse",
(osspriteop_header **)&sprite[HOTLIST_COLLAPSE]);
if (!error)
error = xosspriteop_select_sprite(osspriteop_USER_AREA, gui_sprites,
(osspriteop_id)"tr_entry",
(osspriteop_header **)&sprite[HOTLIST_ENTRY]);
if (!error)
error = xosspriteop_select_sprite(osspriteop_USER_AREA, gui_sprites,
(osspriteop_id)"tr_line",
(osspriteop_header **)&sprite[HOTLIST_LINE]);
if (!error)
error = xosspriteop_select_sprite(osspriteop_USER_AREA, gui_sprites,
(osspriteop_id)"tr_halflinet",
(osspriteop_header **)&sprite[HOTLIST_TLINE]);
if (!error)
error = xosspriteop_select_sprite(osspriteop_USER_AREA, gui_sprites,
(osspriteop_id)"tr_halflineb",
(osspriteop_header **)&sprite[HOTLIST_BLINE]);
if (error) {
warn_user("MiscError", error->errmess);
if (ro_gui_hotlist_initialise_sprite("expand", HOTLIST_EXPAND) ||
ro_gui_hotlist_initialise_sprite("collapse", HOTLIST_COLLAPSE) ||
ro_gui_hotlist_initialise_sprite("entry", HOTLIST_ENTRY) ||
ro_gui_hotlist_initialise_sprite("line", HOTLIST_LINE) ||
ro_gui_hotlist_initialise_sprite("halflinet", HOTLIST_TLINE) ||
ro_gui_hotlist_initialise_sprite("halflineb", HOTLIST_BLINE)) {
return;
}
}
/* Update our text icon
*/
@ -308,6 +296,27 @@ void ro_gui_hotlist_init(void) {
}
}
/**
* Initialise a hotlist sprite
*
* \param name the name of the sprite
* \param number the sprite cache number
* \return whether an error occurred
*/
bool ro_gui_hotlist_initialise_sprite(const char *name, int number) {
os_error *error;
sprintf(icon_name, "tr_%s", name);
error = xosspriteop_select_sprite(osspriteop_USER_AREA, gui_sprites,
(osspriteop_id)icon_name,
(osspriteop_header **)&sprite[number]);
if (error) {
warn_user("MiscError", error->errmess);
LOG(("Failed to load hotlist sprite 'tr_%s'", name));
return true;
}
return false;
}
/**
* Shows the hotlist window.
@ -374,6 +383,7 @@ void ro_gui_hotlist_show(void) {
-100, 32, -1);
}
bool ro_gui_hotlist_load(void) {
FILE *fp;
fileswitch_object_type obj_type = 0;
@ -824,7 +834,7 @@ struct hotlist_entry *ro_gui_hotlist_create(const char *title, const char *url,
void ro_gui_hotlist_link_entry(struct hotlist_entry *link, struct hotlist_entry *entry, bool before) {
struct hotlist_entry *link_entry;
if (!link || !entry) return;
if ((!link || !entry) || (link == entry)) return;
/* Check if the parent is a folder or an entry
*/
@ -2083,7 +2093,6 @@ void ro_gui_hotlist_move_drag_end(wimp_dragged *drag) {
/* No parent of the destination can be processed
*/
test_entry = entry;
if (entry->children == -1) test_entry = entry->parent_entry;
while (test_entry != NULL) {
if (test_entry->process) return;
test_entry = test_entry->parent_entry;
@ -2222,6 +2231,16 @@ void ro_gui_hotlist_toolbar_click(wimp_pointer* pointer) {
/* Handle the buttons appropriately
*/
switch (pointer->i) {
case ICON_TOOLBAR_CREATE:
hotlist_insert = false;
if (pointer->buttons == wimp_CLICK_SELECT) {
ro_gui_hotlist_prepare_folder_dialog(false);
ro_gui_dialog_open_persistant(hotlist_window, dialog_folder);
} else {
ro_gui_hotlist_prepare_entry_dialog(false);
ro_gui_dialog_open_persistant(hotlist_window, dialog_entry);
}
break;
case ICON_TOOLBAR_OPEN:
selection = ro_gui_hotlist_get_selected(true);
ro_gui_hotlist_update_expansion(root.child_entry, (selection != 0), true, false,
@ -2244,6 +2263,51 @@ void ro_gui_hotlist_toolbar_click(wimp_pointer* pointer) {
}
void ro_gui_hotlist_prepare_folder_dialog(bool selected) {
struct hotlist_entry *entry = NULL;
if (selected) entry = ro_gui_hotlist_first_selection(root.child_entry);
/* Update the title
*/
dialog_folder_add = selected;
if (selected) {
ro_gui_set_window_title(dialog_folder, messages_get("EditFolder"));
} else {
ro_gui_set_window_title(dialog_folder, messages_get("NewFolder"));
}
/* Update the icons
*/
if (entry == NULL) {
ro_gui_set_icon_string(dialog_folder, 1, messages_get("Folder"));
} else {
ro_gui_set_icon_string(dialog_folder, 1, entry->title);
}
}
void ro_gui_hotlist_prepare_entry_dialog(bool selected) {
struct hotlist_entry *entry = NULL;
if (selected) entry = ro_gui_hotlist_first_selection(root.child_entry);
/* Update the title
*/
dialog_entry_add = selected;
if (selected) {
ro_gui_set_window_title(dialog_entry, messages_get("EditLink"));
} else {
ro_gui_set_window_title(dialog_entry, messages_get("NewLink"));
}
/* Update the icons
*/
if (entry == NULL) {
ro_gui_set_icon_string(dialog_entry, 1, messages_get("Link"));
ro_gui_set_icon_string(dialog_entry, 3, "");
} else {
ro_gui_set_icon_string(dialog_entry, 1, entry->title);
ro_gui_set_icon_string(dialog_entry, 3, entry->url);
}
}
/**

View File

@ -280,8 +280,8 @@ wimp_menu *browser_menu = (wimp_menu *) &menu;
static wimp_MENU(2) hotlist_new = {
{ "New" }, 7,2,7,0, 300, 44, 0,
{
{ 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Folder" } },
{ wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Link" } },
{ wimp_MENU_GIVE_WARNING, (wimp_menu *)1, DEFAULT_FLAGS, { "Folder" } },
{ wimp_MENU_LAST | wimp_MENU_GIVE_WARNING, (wimp_menu *)1, DEFAULT_FLAGS, { "Link" } },
}
};
@ -324,7 +324,7 @@ static wimp_MENU(4) hotlist_save = {
static wimp_MENU(5) hotlist_file = {
{ "Hotlist" }, 7,2,7,0, 300, 44, 0,
{
{ wimp_MENU_GIVE_WARNING, (wimp_menu *)&hotlist_new, DEFAULT_FLAGS, { "New" } },
{ 0, (wimp_menu *)&hotlist_new, DEFAULT_FLAGS, { "New" } },
{ wimp_MENU_GIVE_WARNING, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Save" } },
{ wimp_MENU_GIVE_WARNING | wimp_MENU_SEPARATE, (wimp_menu *)1, DEFAULT_FLAGS, { "Export" } },
{ 0, (wimp_menu *)&hotlist_expand, DEFAULT_FLAGS, { "Expand" } },
@ -977,6 +977,18 @@ void ro_gui_menu_hotlist_warning(wimp_message_menu_warning *warning) {
case 0: /* Hotlist-> */
switch (warning->selection.items[1]) {
case 0: /* New-> */
hotlist_insert = true;
switch (warning->selection.items[2]) {
case 0: /* Folder */
ro_gui_hotlist_prepare_folder_dialog(false);
error = xwimp_create_sub_menu((wimp_menu *) dialog_folder,
warning->pos.x, warning->pos.y);
break;
case 1: /* Entry */
ro_gui_hotlist_prepare_entry_dialog(false);
error = xwimp_create_sub_menu((wimp_menu *) dialog_entry,
warning->pos.x, warning->pos.y);
}
break;
case 2: /* Export-> */
gui_current_save_type = GUI_HOTLIST_EXPORT_HTML;
@ -995,7 +1007,17 @@ void ro_gui_menu_hotlist_warning(wimp_message_menu_warning *warning) {
break;
case 0: /* Save-> */
break;
case 1: /* Edit title-> */
case 1: /* Edit-> */
hotlist_insert = true;
if (ro_gui_hotlist_get_selected(false) == 0) {
ro_gui_hotlist_prepare_folder_dialog(true);
error = xwimp_create_sub_menu((wimp_menu *) dialog_folder,
warning->pos.x, warning->pos.y);
} else {
ro_gui_hotlist_prepare_entry_dialog(true);
error = xwimp_create_sub_menu((wimp_menu *) dialog_entry,
warning->pos.x, warning->pos.y);
}
break;
}
break;
@ -1305,24 +1327,33 @@ void ro_gui_menu_prepare_scale(void) {
*/
void ro_gui_menu_prepare_hotlist(void) {
int selection;
int selection_full;
selection = ro_gui_hotlist_get_selected(false);
if (selection == 0) {
selection_full = ro_gui_hotlist_get_selected(true);
if (selection_full == 0) {
hotlist_menu->entries[1].icon_flags |= wimp_ICON_SHADED;
hotlist_menu->entries[3].icon_flags |= wimp_ICON_SHADED;
hotlist_select_menu->entries[2].icon_flags |= wimp_ICON_SHADED;
hotlist_select_menu->entries[4].icon_flags |= wimp_ICON_SHADED;
} else {
hotlist_menu->entries[1].icon_flags &= ~wimp_ICON_SHADED;
hotlist_menu->entries[3].icon_flags &= ~wimp_ICON_SHADED;
}
if (selection == 0) {
hotlist_select_menu->entries[2].icon_flags |= wimp_ICON_SHADED;
hotlist_select_menu->entries[4].icon_flags |= wimp_ICON_SHADED;
} else {
hotlist_select_menu->entries[2].icon_flags &= ~wimp_ICON_SHADED;
hotlist_select_menu->entries[4].icon_flags &= ~wimp_ICON_SHADED;
}
if (selection != 1) {
if (selection_full != 1) {
hotlist_select_menu->entries[1].icon_flags |= wimp_ICON_SHADED;
} else {
hotlist_select_menu->entries[1].icon_flags &= ~wimp_ICON_SHADED;
}
if (selection != 1) {
hotlist_save_menu->entries[0].icon_flags |= wimp_ICON_SHADED;
hotlist_save_menu->entries[1].icon_flags |= wimp_ICON_SHADED;
} else {
hotlist_select_menu->entries[1].icon_flags &= ~wimp_ICON_SHADED;
hotlist_save_menu->entries[0].icon_flags &= ~wimp_ICON_SHADED;
hotlist_save_menu->entries[1].icon_flags &= ~wimp_ICON_SHADED;
}

View File

@ -239,6 +239,35 @@ int ro_gui_get_icon_selected_state(wimp_w w, wimp_i i) {
#define ro_gui_set_icon_shaded_state(w, i, state) xwimp_set_icon_state(w, i, (state ? wimp_ICON_SHADED : 0), wimp_ICON_SHADED)
/**
* Set a window title (does *not* redraw the title)
*
* \param w window handle
* \param text new title (copied)
*/
void ro_gui_set_window_title(wimp_w w, const char *text) {
wimp_window_info_base window;
os_error *error;
/* Get the window details
*/
window.w = w;
error = xwimp_get_window_info_header_only((wimp_window_info *)&window);
if (error) {
LOG(("xwimp_get_window_info: 0x%x: %s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
return;
}
/* Set the title string
*/
strncpy(window.title_data.indirected_text.text, text,
(unsigned int)window.title_data.indirected_text.size - 1);
window.title_data.indirected_text.text[window.title_data.indirected_text.size - 1] = '\0';
}
/**
* Load a sprite file into memory.
*

View File

@ -39,6 +39,7 @@ void ro_gui_set_icon_integer(wimp_w w, wimp_i i, int value);
#define ro_gui_set_icon_selected_state(w, i, state) xwimp_set_icon_state(w, i, (state ? wimp_ICON_SELECTED : 0), wimp_ICON_SELECTED)
int ro_gui_get_icon_selected_state(wimp_w w, wimp_i i);
#define ro_gui_set_icon_shaded_state(w, i, state) xwimp_set_icon_state(w, i, (state ? wimp_ICON_SHADED : 0), wimp_ICON_SHADED)
void ro_gui_set_window_title(wimp_w w, const char *title);
osspriteop_area *ro_gui_load_sprite_file(const char *pathname);