Function to find out if browser window has a selection. Front ends should use this API. RISC OS front end updated.

svn path=/trunk/netsurf/; revision=12556
This commit is contained in:
Michael Drake 2011-07-02 16:43:20 +00:00
parent 3f485e083d
commit a6d4f9cb30
3 changed files with 31 additions and 9 deletions

View File

@ -257,6 +257,20 @@ struct browser_window * browser_window_get_root(struct browser_window *bw)
}
return bw;
}
/* exported interface, documented in browser.h */
bool browser_window_has_selection(struct browser_window *bw)
{
assert(bw->window);
/* TODO: handle selections in (i)frames */
if (bw->current_content != NULL && bw->sel != NULL &&
selection_defined(bw->sel)) {
return true;
} else {
return false;
}
}
/**
* Create and open a new root browser window with the given page.

View File

@ -339,6 +339,14 @@ void browser_window_set_drag_type(struct browser_window *bw,
*/
struct browser_window * browser_window_get_root(struct browser_window *bw);
/**
* Check whether browser window contains a selection
*
* \param bw The browser window
* \return true if browser window contains a selection
*/
bool browser_window_has_selection(struct browser_window *bw);
/* In platform specific hotlist.c. */
void hotlist_visited(struct hlcache_handle *c);

View File

@ -2577,21 +2577,21 @@ bool ro_gui_window_menu_prepare(wimp_w w, wimp_i i, wimp_menu *menu,
/* make menu available if there's anything that /could/
* be selected */
ro_gui_menu_set_entry_shaded(menu, BROWSER_SELECTION_SAVE, h == NULL ||
bw->sel == NULL || !selection_defined(bw->sel));
ro_gui_menu_set_entry_shaded(menu, BROWSER_SELECTION_SAVE,
!browser_window_has_selection(bw));
ro_gui_menu_set_entry_shaded(menu, BROWSER_SELECTION_COPY, h == NULL ||
bw->sel == NULL || !selection_defined(bw->sel));
ro_gui_menu_set_entry_shaded(menu, BROWSER_SELECTION_COPY,
!browser_window_has_selection(bw));
ro_gui_menu_set_entry_shaded(menu, BROWSER_SELECTION_CUT, h == NULL ||
bw->sel == NULL || !selection_defined(bw->sel) ||
ro_gui_menu_set_entry_shaded(menu, BROWSER_SELECTION_CUT,
!browser_window_has_selection(bw) ||
selection_read_only(bw->sel));
ro_gui_menu_set_entry_shaded(menu, BROWSER_SELECTION_PASTE,
h == NULL || bw->paste_callback == NULL);
ro_gui_menu_set_entry_shaded(menu, BROWSER_SELECTION_CLEAR, h == NULL ||
bw->sel == NULL || !selection_defined(bw->sel));
ro_gui_menu_set_entry_shaded(menu, BROWSER_SELECTION_CLEAR,
!browser_window_has_selection(bw));
/* Navigate Submenu */
@ -2729,7 +2729,7 @@ void ro_gui_window_menu_warning(wimp_w w, wimp_i i, wimp_menu *menu,
break;
case BROWSER_SELECTION_SAVE:
if (bw->sel != NULL && selection_defined(bw->sel))
if (browser_window_has_selection(bw))
ro_gui_save_prepare(GUI_SAVE_TEXT_SELECTION, NULL,
bw->sel, NULL, NULL);
break;