Make Open URL dialogue allocate memory for the URL field.

Add global constant for URL length, to manage both URL Bar and Open URL.
This commit is contained in:
Steve Fryatt 2014-01-26 14:35:57 +00:00
parent 89992958d2
commit def97156d3
7 changed files with 76 additions and 15 deletions

View File

@ -85,6 +85,7 @@ static struct {
} persistent_dialog[MAX_PERSISTENT];
static bool ro_gui_dialog_open_url_init(void);
static bool ro_gui_dialog_openurl_apply(wimp_w w);
static bool ro_gui_dialog_open_url_menu_prepare(wimp_w w, wimp_i i,
wimp_menu *menu, wimp_pointer *pointer);
@ -161,15 +162,7 @@ void ro_gui_dialog_init(void)
ro_gui_wimp_event_set_help_prefix(dialog_url_complete, "HelpAutoURL");
/* open URL */
dialog_openurl = ro_gui_dialog_create("open_url");
ro_gui_wimp_event_register_menu_gright(dialog_openurl, ICON_OPENURL_URL,
ICON_OPENURL_MENU, ro_gui_url_suggest_menu);
ro_gui_wimp_event_register_cancel(dialog_openurl, ICON_OPENURL_CANCEL);
ro_gui_wimp_event_register_ok(dialog_openurl, ICON_OPENURL_OPEN,
ro_gui_dialog_openurl_apply);
ro_gui_wimp_event_register_menu_prepare(dialog_openurl,
ro_gui_dialog_open_url_menu_prepare);
ro_gui_wimp_event_set_help_prefix(dialog_openurl, "HelpOpenURL");
ro_gui_dialog_open_url_init();
/* scale view */
dialog_zoom = ro_gui_dialog_create("zoom");
@ -702,6 +695,70 @@ void ro_gui_dialog_update_zoom(struct gui_window *g) {
}
/**
* Create the Open URL dialogue, allocating storage for the URL field icon
* as we go.
*
* \return true on success; false on failure (although errors with
* the templates or memory allocation will exit via die()).
*/
static bool ro_gui_dialog_open_url_init(void)
{
wimp_window *definition;
char *buffer;
os_error *error;
definition = ro_gui_dialog_load_template("open_url");
/* _load_template() should die on any error, so we trust its data. */
assert(definition != NULL);
/* Create the dialogue, with modifications. */
if ((definition->icons[ICON_OPENURL_URL].flags & wimp_ICON_INDIRECTED)
== 0) {
LOG(("open_url URL icon not indirected"));
xwimp_close_template();
die("Template");
}
buffer = malloc(RO_GUI_MAX_URL_SIZE);
if (buffer == NULL) {
xwimp_close_template();
die("NoMemory");
}
definition->icons[ICON_OPENURL_URL].data.indirected_text.text = buffer;
definition->icons[ICON_OPENURL_URL].data.indirected_text.size =
RO_GUI_MAX_URL_SIZE;
definition->sprite_area = gui_sprites;
error = xwimp_create_window(definition, &dialog_openurl);
if (error != NULL) {
LOG(("xwimp_create_window: 0x%x: %s",
error->errnum, error->errmess));
xwimp_close_template();
die(error->errmess);
}
free(definition);
ro_gui_wimp_event_register_menu_gright(dialog_openurl, ICON_OPENURL_URL,
ICON_OPENURL_MENU, ro_gui_url_suggest_menu);
ro_gui_wimp_event_register_cancel(dialog_openurl, ICON_OPENURL_CANCEL);
ro_gui_wimp_event_register_ok(dialog_openurl, ICON_OPENURL_OPEN,
ro_gui_dialog_openurl_apply);
ro_gui_wimp_event_register_menu_prepare(dialog_openurl,
ro_gui_dialog_open_url_menu_prepare);
ro_gui_wimp_event_set_help_prefix(dialog_openurl, "HelpOpenURL");
return true;
}
bool ro_gui_dialog_openurl_apply(wimp_w w) {
const char *urltxt;
char *url2;

View File

@ -35,6 +35,10 @@
#define THUMBNAIL_WIDTH 100
#define THUMBNAIL_HEIGHT 86
/* The maximum size for user-editable URLs in the RISC OS GUI. */
#define RO_GUI_MAX_URL_SIZE 2048
extern int os_version;
extern const char * NETSURF_DIR;

View File

@ -30,6 +30,7 @@
#include "oslib/os.h"
#include "oslib/osspriteop.h"
#include "oslib/wimp.h"
#include "riscos/gui.h"
#include "riscos/hotlist.h"
#include "riscos/gui/url_bar.h"
#include "riscos/theme.h"
@ -50,7 +51,6 @@
#define URLBAR_MIN_WIDTH 52
#define URLBAR_GRIGHT_GUTTER 8
#define URLBAR_FAVICON_NAME_LENGTH 12
#define URLBAR_URL_LENGTH 2048
struct url_bar {
/** The applied theme (or NULL to use the default) */
@ -167,7 +167,7 @@ struct url_bar *ro_gui_url_bar_create(struct theme_descriptor *theme)
url_bar->hotlist.extent.x1 = 0;
url_bar->hotlist.extent.y1 = 0;
url_bar->text_size = URLBAR_URL_LENGTH;
url_bar->text_size = RO_GUI_MAX_URL_SIZE;
url_bar->text_buffer = malloc(url_bar->text_size);
strncpy(url_bar->text_buffer, "", url_bar->text_size);

View File

@ -1683,7 +1683,7 @@ wimp_window {
icon_fg:wimp_COLOUR_BLACK
icon_bg:wimp_COLOUR_WHITE
text.text:""
text.size:128
text.size:1
text.validation:"Pptr_write;Kta"
}
wimp_icon {

View File

@ -1891,7 +1891,7 @@ wimp_window {
icon_fg:wimp_COLOUR_BLACK
icon_bg:wimp_COLOUR_WHITE
text.text:""
text.size:128
text.size:1
text.validation:"Pptr_write;Kta"
}
wimp_icon {

View File

@ -1695,7 +1695,7 @@ wimp_window {
icon_fg:wimp_COLOUR_BLACK
icon_bg:wimp_COLOUR_WHITE
text.text:""
text.size:128
text.size:1
text.validation:"Pptr_write;Kta"
}
wimp_icon {

View File

@ -1895,7 +1895,7 @@ wimp_window {
icon_fg:wimp_COLOUR_BLACK
icon_bg:wimp_COLOUR_WHITE
text.text:""
text.size:128
text.size:1
text.validation:"Pptr_write;Kta"
}
wimp_icon {