[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
This commit is contained in:
James Bursa 2004-05-08 20:44:00 +00:00
parent 7356aa96c9
commit 29340cf8c8
6 changed files with 77 additions and 49 deletions

View File

@ -85,6 +85,7 @@ MenuError:An error occurred when opening the menu:
DragError:An error occurred when dragging the icon:
TbarError:An error occurred when constructing the toolbar:
WimpError:An unexpected Window Manager error occurred:
Template:A window template is missing from the Templates file. Please reinstall NetSurf.
# Some general purpose words and phrases
Bytes: B

View File

@ -85,6 +85,7 @@ MenuError:An error occurred when opening the menu:
DragError:An error occurred when dragging the icon:
TbarError:An error occurred when constructing the toolbar:
WimpError:An unexpected Window Manager error occurred:
Template:A window template is missing from the Templates file. Please reinstall NetSurf.
Bytes: O
kBytes: kO

View File

@ -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;

View File

@ -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);
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");
}
window = xcalloc((unsigned int) window_size, 1);
data = xcalloc((unsigned int) data_size, 1);
/* 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");
}
/* load and create */
wimp_load_template(window, data, data + data_size, wimp_NO_FONTS,
name, 0, 0, 0);
w = wimp_create_window(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);
}
/* the window definition is copied by the wimp and may be freed */
xfree(window);
return w;
return window;
}

View File

@ -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");
}

View File

@ -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);