diff options
author | James Bursa <james@netsurf-browser.org> | 2004-05-08 20:44:00 +0000 |
---|---|---|
committer | James Bursa <james@netsurf-browser.org> | 2004-05-08 20:44:00 +0000 |
commit | 29340cf8c8e2fe2f0fe8155e45940da29c37b79e (patch) | |
tree | 8cfc858e6e92268eab8da3e5ed8bcf04e2199b8f /riscos | |
parent | 7356aa96c9c2332b9d3fe35f8e48b2c403620b08 (diff) | |
download | netsurf-29340cf8c8e2fe2f0fe8155e45940da29c37b79e.tar.gz netsurf-29340cf8c8e2fe2f0fe8155e45940da29c37b79e.tar.bz2 |
[project @ 2004-05-08 20:44:00 by bursa]
Break out ro_gui_dialog_load_template(). Replace xcalloc() with malloc() and add some error handling.
svn path=/import/netsurf/; revision=844
Diffstat (limited to 'riscos')
-rw-r--r-- | riscos/401login.c | 22 | ||||
-rw-r--r-- | riscos/dialog.c | 85 | ||||
-rw-r--r-- | riscos/download.c | 16 | ||||
-rw-r--r-- | riscos/gui.h | 1 |
4 files changed, 75 insertions, 49 deletions
diff --git a/riscos/401login.c b/riscos/401login.c index c96fcd2c1..c6927355e 100644 --- a/riscos/401login.c +++ b/riscos/401login.c @@ -34,33 +34,17 @@ static char* url; static char *pwd; static struct browser_window *bwin; + /** * Load the 401 login window template. */ void ro_gui_401login_init(void) { - char name[20] = "login"; - int context, window_size, data_size; - char *data; - os_error *e; - - /* find required buffer sizes */ - e = xwimp_load_template(wimp_GET_SIZE, 0, 0, wimp_NO_FONTS, - name, 0, &window_size, &data_size, &context); - if (e) { - die(e->errmess); - } - assert(context != 0); - - dialog_401_template = xcalloc((unsigned int) window_size, 1); - data = xcalloc((unsigned int) data_size, 1); - - /* load */ - wimp_load_template(dialog_401_template, data, data + data_size, - wimp_NO_FONTS, name, 0, 0, 0); + dialog_401_template = ro_gui_dialog_load_template("login"); } + void gui_401login_open(struct browser_window *bw, struct content *c, char *realm) { char *murl, *host; diff --git a/riscos/dialog.c b/riscos/dialog.c index 1b74ceefb..dbb1687ca 100644 --- a/riscos/dialog.c +++ b/riscos/dialog.c @@ -89,36 +89,91 @@ void ro_gui_dialog_init(void) /** * Create a window from a template. + * + * \param template_name name of template to load + * \return window handle + * + * Exits through die() on error. */ wimp_w ro_gui_dialog_create(const char *template_name) { + wimp_window *window; + wimp_w w; + os_error *error; + + window = ro_gui_dialog_load_template(template_name); + + /* create window */ + error = xwimp_create_window(window, &w); + if (error) { + LOG(("xwimp_create_window: 0x%x: %s", + error->errnum, error->errmess)); + xwimp_close_template(); + die(error->errmess); + } + + /* the window definition is copied by the wimp and may be freed */ + free(window); + + return w; +} + + +/** + * Load a template without creating a window. + * + * \param template_name name of template to load + * \return window block + * + * Exits through die() on error. + */ + +wimp_window * ro_gui_dialog_load_template(const char *template_name) +{ char name[20]; int context, window_size, data_size; char *data; wimp_window *window; - wimp_w w; + os_error *error; /* wimp_load_template won't accept a const char * */ - strncpy(name, template_name, 20); + strncpy(name, template_name, sizeof name); /* find required buffer sizes */ - context = wimp_load_template(wimp_GET_SIZE, 0, 0, wimp_NO_FONTS, - name, 0, &window_size, &data_size); - assert(context != 0); - - window = xcalloc((unsigned int) window_size, 1); - data = xcalloc((unsigned int) data_size, 1); + error = xwimp_load_template(wimp_GET_SIZE, 0, 0, wimp_NO_FONTS, + name, 0, &window_size, &data_size, &context); + if (error) { + LOG(("xwimp_load_template: 0x%x: %s", + error->errnum, error->errmess)); + xwimp_close_template(); + die(error->errmess); + } + if (!context) { + LOG(("template '%s' missing", template_name)); + xwimp_close_template(); + die("Template"); + } - /* load and create */ - wimp_load_template(window, data, data + data_size, wimp_NO_FONTS, - name, 0, 0, 0); - w = wimp_create_window(window); + /* allocate space for indirected data and temporary window buffer */ + data = malloc(data_size); + window = malloc(window_size); + if (!data || !window) { + xwimp_close_template(); + die("NoMemory"); + } - /* the window definition is copied by the wimp and may be freed */ - xfree(window); + /* load template */ + error = xwimp_load_template(window, data, data + data_size, + wimp_NO_FONTS, name, 0, 0, 0, 0); + if (error) { + LOG(("xwimp_load_template: 0x%x: %s", + error->errnum, error->errmess)); + xwimp_close_template(); + die(error->errmess); + } - return w; + return window; } diff --git a/riscos/download.c b/riscos/download.c index 6dedaa59e..6ddc0bcaf 100644 --- a/riscos/download.c +++ b/riscos/download.c @@ -31,21 +31,7 @@ static void ro_gui_download_leaf(const char *url, char *leaf); void ro_gui_download_init(void) { - char name[] = "download"; - int context, window_size, data_size; - char *data; - - /* find required buffer sizes */ - context = wimp_load_template(wimp_GET_SIZE, 0, 0, wimp_NO_FONTS, - name, 0, &window_size, &data_size); - assert(context != 0); - - download_template = xcalloc((unsigned int) window_size, 1); - data = xcalloc((unsigned int) data_size, 1); - - /* load */ - wimp_load_template(download_template, data, data + data_size, - wimp_NO_FONTS, name, 0, 0, 0); + download_template = ro_gui_dialog_load_template("download"); } diff --git a/riscos/gui.h b/riscos/gui.h index de23ac3d1..fb9dcb307 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -117,6 +117,7 @@ void ro_gui_menu_prepare_scale(void); /* in dialog.c */ void ro_gui_dialog_init(void); wimp_w ro_gui_dialog_create(const char *template_name); +wimp_window * ro_gui_dialog_load_template(const char *template_name); void ro_gui_dialog_open(wimp_w w); void ro_gui_dialog_click(wimp_pointer *pointer); bool ro_gui_dialog_keypress(wimp_key *key); |