make the form select menu API smaller.

By hiding all but the form selection menu option structure from code
outside of render this reduces the API to the absolute minimum to
support this feature.
This commit is contained in:
Vincent Sanders 2014-11-13 21:52:08 +00:00
parent 9fde3502b6
commit 79e501075a
11 changed files with 168 additions and 122 deletions

View File

@ -1280,7 +1280,7 @@ void gui_create_form_select_menu(struct gui_window *g,
*/
struct gui_window *gwin = g;
struct form_option *opt = control->data.select.items;
struct form_option *opt = form_select_get_option(control, 0);
ULONG i = 0;
if(ctxmenuobj) DisposeObject(ctxmenuobj);
@ -1291,7 +1291,7 @@ void gui_create_form_select_menu(struct gui_window *g,
gwin->shared->control = control;
ctxmenuobj = PMMENU(ami_utf8_easy(control->name)),
ctxmenuobj = PMMENU(ami_utf8_easy(form_control_get_name(control))),
PMA_MenuHandler, &ctxmenuhook, End;
while(opt)

View File

@ -65,7 +65,6 @@ extern "C" {
#include "desktop/gui_search.h"
#include "desktop/gui_fetch.h"
#include "desktop/netsurf.h"
#include "render/form.h"
}
@ -102,9 +101,6 @@ BWindow *wndTooltip;
//beosLabel *labelTooltip;
BFilePanel *wndOpenFile;
//static beosWidget *select_menu;
static struct form_control *select_menu_control;
static thread_id sBAppThreadID;
static BMessage *gFirstRefsReceived = NULL;

View File

@ -48,7 +48,8 @@
[menu addItemWithTitle: @"" action: NULL keyEquivalent: @""];
NSInteger currentItemIndex = 0;
for (struct form_option *opt = control->data.select.items; opt != NULL; opt = opt->next) {
struct form_option *opt;
for (opt = form_select_get_option(control, 0); opt != NULL; opt = opt->next) {
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle: [NSString stringWithUTF8String: opt->text]
action: @selector( itemSelected: )
keyEquivalent: @""];

View File

@ -50,7 +50,7 @@
#include "content/fetch.h"
#include "content/hlcache.h"
#include "content/urldb.h"
#include "render/form.h"
#include "render/form_internal.h"
#include "render/html.h"
#include "render/box.h"
#include "curl/curl.h"

View File

@ -1217,8 +1217,7 @@ static void gui_window_start_selection(struct gui_window *g)
static void gui_window_create_form_select_menu(struct gui_window *g,
struct form_control *control)
{
intptr_t i;
intptr_t item;
struct form_option *option;
GtkWidget *menu_item;
@ -1228,23 +1227,29 @@ static void gui_window_create_form_select_menu(struct gui_window *g,
* Yay. \o/
*/
if (select_menu != NULL)
if (select_menu != NULL) {
gtk_widget_destroy(select_menu);
}
select_menu = gtk_menu_new();
select_menu_control = control;
for (i = 0, option = control->data.select.items; option;
i++, option = option->next) {
item = 0;
option = form_select_get_option(control, item);
while (option != NULL) {
LOG(("Item %d option %p text %s", item, option, option->text));
menu_item = gtk_check_menu_item_new_with_label(option->text);
if (option->selected)
gtk_check_menu_item_set_active(
GTK_CHECK_MENU_ITEM(menu_item), TRUE);
g_signal_connect(menu_item, "toggled",
G_CALLBACK(nsgtk_select_menu_clicked), (gpointer)i);
G_CALLBACK(nsgtk_select_menu_clicked), (gpointer)item);
gtk_menu_shell_append(GTK_MENU_SHELL(select_menu), menu_item);
item++;
option = form_select_get_option(control, item);
}
gtk_widget_show_all(select_menu);

View File

@ -1332,6 +1332,26 @@ nserror form_select_process_selection(struct form_control *control, int item)
return form__select_process_selection(control->html, control, item);
}
/* exported interface documented in render/form.h */
struct form_option *
form_select_get_option(struct form_control *control, int item)
{
struct form_option *opt;
opt = control->data.select.items;
while ((opt != NULL) && (item > 0)) {
opt = opt->next;
item--;
}
return opt;
}
/* exported interface documented in render/form.h */
char *form_control_get_name(struct form_control *control)
{
return control->name;
}
/**
* Handle a click on the area of the currently opened select menu.
*

View File

@ -25,49 +25,11 @@
#ifndef _NETSURF_RENDER_FORM_H_
#define _NETSURF_RENDER_FORM_H_
#include <stdbool.h>
struct box;
struct form_control;
struct form_option;
struct form_select_menu;
struct form;
struct html_content;
struct dom_string;
struct content;
struct nsurl;
struct fetch_multipart_data;
struct redraw_context;
struct browser_window;
enum browser_mouse_state;
/** Type of a struct form_control. */
typedef enum {
GADGET_HIDDEN,
GADGET_TEXTBOX,
GADGET_RADIO,
GADGET_CHECKBOX,
GADGET_SELECT,
GADGET_TEXTAREA,
GADGET_IMAGE,
GADGET_PASSWORD,
GADGET_SUBMIT,
GADGET_RESET,
GADGET_FILE,
GADGET_BUTTON
} form_control_type;
/** Data for textarea */
struct form_textarea_data {
struct form_control *gadget;
};
/** Option in a select. */
struct form_option {
void *node; /**< Corresponding DOM node */
void *node; /**< Corresponding DOM node */
bool selected;
bool initial_selected;
char *value;
@ -75,63 +37,29 @@ struct form_option {
struct form_option* next;
};
struct image_input_coords {
int x;
int y;
};
/** Form control. */
struct form_control {
void *node; /**< Corresponding DOM node */
struct html_content *html; /**< HTML content containing control */
form_control_type type; /**< Type of control */
struct form *form; /**< Containing form */
char *name; /**< Control name */
char *value; /**< Current value of control */
char *initial_value; /**< Initial value of control */
bool disabled; /**< Whether control is disabled */
struct box *box; /**< Box for control */
unsigned int length; /**< Number of characters in control */
unsigned int maxlength; /**< Maximum characters permitted */
bool selected; /**< Whether control is selected */
union {
struct {
int mx, my;
} image;
struct {
int num_items;
struct form_option *items, *last_item;
bool multiple;
int num_selected;
/** Currently selected item, if num_selected == 1. */
struct form_option *current;
struct form_select_menu *menu;
} select;
struct {
struct textarea *ta;
struct dom_string *initial;
struct form_textarea_data data;
} text; /**< input type=text or textarea */
} data;
struct form_control *prev; /**< Previous control in this form */
struct form_control *next; /**< Next control in this form. */
};
/**
* Process a selection from a form select menu.
*
* \param control form control with menu
* \param item index of item selected from the menu
* \param control form control with menu.
* \param item index of item selected from the menu.
*/
nserror form_select_process_selection(struct form_control *control, int item);
/**
* get a form select menus option.
*
* \param control The form control.
* \param item The index of the menu entry to return.
* \return The form option at that index.
*/
struct form_option *form_select_get_option(struct form_control *control, int item);
/**
* Get a form control name
*
* \param control The form control
* \return The form control name
*/
char *form_control_get_name(struct form_control *control);
#endif

View File

@ -26,6 +26,94 @@
#include "render/form.h"
#include <stdbool.h>
struct box;
struct form_control;
struct form_option;
struct form_select_menu;
struct form;
struct html_content;
struct dom_string;
struct content;
struct nsurl;
struct fetch_multipart_data;
struct redraw_context;
struct browser_window;
enum browser_mouse_state;
/** Type of a struct form_control. */
typedef enum {
GADGET_HIDDEN,
GADGET_TEXTBOX,
GADGET_RADIO,
GADGET_CHECKBOX,
GADGET_SELECT,
GADGET_TEXTAREA,
GADGET_IMAGE,
GADGET_PASSWORD,
GADGET_SUBMIT,
GADGET_RESET,
GADGET_FILE,
GADGET_BUTTON
} form_control_type;
/** Data for textarea */
struct form_textarea_data {
struct form_control *gadget;
};
struct image_input_coords {
int x;
int y;
};
/** Form control. */
struct form_control {
void *node; /**< Corresponding DOM node */
struct html_content *html; /**< HTML content containing control */
form_control_type type; /**< Type of control */
struct form *form; /**< Containing form */
char *name; /**< Control name */
char *value; /**< Current value of control */
char *initial_value; /**< Initial value of control */
bool disabled; /**< Whether control is disabled */
struct box *box; /**< Box for control */
unsigned int length; /**< Number of characters in control */
unsigned int maxlength; /**< Maximum characters permitted */
bool selected; /**< Whether control is selected */
union {
struct {
int mx, my;
} image;
struct {
int num_items;
struct form_option *items, *last_item;
bool multiple;
int num_selected;
/** Currently selected item, if num_selected == 1. */
struct form_option *current;
struct form_select_menu *menu;
} select;
struct {
struct textarea *ta;
struct dom_string *initial;
struct form_textarea_data data;
} text; /**< input type=text or textarea */
} data;
struct form_control *prev; /**< Previous control in this form */
struct form_control *next; /**< Next control in this form. */
};
/** Form submit method. */
typedef enum {
method_GET, /**< GET, always url encoded. */

View File

@ -56,7 +56,7 @@
#include "render/box.h"
#include "render/font.h"
#include "render/form.h"
#include "render/form_internal.h"
#include "render/html_internal.h"
#include "render/layout.h"
#include "render/table.h"

View File

@ -60,7 +60,6 @@ extern wimp_w current_menu_window;
extern bool current_menu_open;
extern wimp_menu *recent_search_menu; /* search.c */
extern wimp_w history_window;
extern struct form_control *current_gadget;
extern bool gui_redraw_debug;
extern osspriteop_area *gui_sprites;
extern bool dialog_folder_add, dialog_entry_add, hotlist_insert;

View File

@ -4572,7 +4572,7 @@ void ro_gui_window_default_options(struct gui_window *gui)
bool ro_gui_window_prepare_form_select_menu(struct gui_window *g,
struct form_control *control)
{
unsigned int i, entries;
unsigned int item, entries;
char *text_convert, *temp;
struct form_option *option;
bool reopen = true;
@ -4580,19 +4580,26 @@ bool ro_gui_window_prepare_form_select_menu(struct gui_window *g,
assert(control);
for (entries = 0, option = control->data.select.items; option;
option = option->next)
/* enumerate the entries */
entries = 0;
option = form_select_get_option(control, entries);
while (option != NULL) {
entries++;
option = form_select_get_option(control, item);
}
if (entries == 0) {
/* no menu to display */
ro_gui_menu_destroy();
return false;
}
/* free riscos menu if there already is one */
if ((gui_form_select_menu) && (control != gui_form_select_control)) {
for (i = 0; ; i++) {
free(gui_form_select_menu->entries[i].data.
for (item = 0; ; item++) {
free(gui_form_select_menu->entries[item].data.
indirected_text.text);
if (gui_form_select_menu->entries[i].menu_flags &
if (gui_form_select_menu->entries[item].menu_flags &
wimp_MENU_LAST)
break;
}
@ -4601,6 +4608,7 @@ bool ro_gui_window_prepare_form_select_menu(struct gui_window *g,
gui_form_select_menu = 0;
}
/* allocate new riscos menu */
if (!gui_form_select_menu) {
reopen = false;
gui_form_select_menu = malloc(wimp_SIZEOF_MENU(entries));
@ -4624,11 +4632,12 @@ bool ro_gui_window_prepare_form_select_menu(struct gui_window *g,
ro_gui_menu_init_structure(gui_form_select_menu, entries);
}
for (i = 0, option = control->data.select.items; option;
i++, option = option->next) {
gui_form_select_menu->entries[i].menu_flags = 0;
/* initialise menu entries from form control */
for (item = 0; item < entries; item++) {
option = form_select_get_option(control, item);
gui_form_select_menu->entries[item].menu_flags = 0;
if (option->selected)
gui_form_select_menu->entries[i].menu_flags =
gui_form_select_menu->entries[item].menu_flags =
wimp_MENU_TICKED;
if (!reopen) {
@ -4659,17 +4668,17 @@ bool ro_gui_window_prepare_form_select_menu(struct gui_window *g,
free(temp);
gui_form_select_menu->entries[i].data.indirected_text.text =
gui_form_select_menu->entries[item].data.indirected_text.text =
text_convert;
gui_form_select_menu->entries[i].data.indirected_text.size =
strlen(gui_form_select_menu->entries[i].
gui_form_select_menu->entries[item].data.indirected_text.size =
strlen(gui_form_select_menu->entries[item].
data.indirected_text.text) + 1;
}
}
gui_form_select_menu->entries[0].menu_flags |=
wimp_MENU_TITLE_INDIRECTED;
gui_form_select_menu->entries[i - 1].menu_flags |= wimp_MENU_LAST;
gui_form_select_menu->entries[item - 1].menu_flags |= wimp_MENU_LAST;
return true;
}