Finish event based GUI system transition and begin code cleanup.

svn path=/trunk/netsurf/; revision=2922
This commit is contained in:
Richard Wilson 2006-09-06 14:44:42 +00:00
parent 48adbd97db
commit 1999becb42
17 changed files with 336 additions and 441 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -26,6 +26,13 @@
#ifdef WITH_AUTH
#define ICON_401LOGIN_LOGIN 0
#define ICON_401LOGIN_CANCEL 1
#define ICON_401LOGIN_HOST 2
#define ICON_401LOGIN_REALM 3
#define ICON_401LOGIN_USERNAME 4
#define ICON_401LOGIN_PASSWORD 5
static void ro_gui_401login_close(wimp_w w);
static bool ro_gui_401login_apply(wimp_w w);
static void ro_gui_401login_open(struct browser_window *bw, const char *host,
@ -157,12 +164,14 @@ void ro_gui_401login_close(wimp_w w)
free(session->url);
free(session);
ro_gui_wimp_event_finalise(w);
ro_gui_dialog_close(w);
error = xwimp_delete_window(w);
if (error)
LOG(("xwimp_delete_window: 0x%x: %s",
error->errnum, error->errmess));
if (error) {
LOG(("xwimp_delete_window: 0x%x:%s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
}
ro_gui_wimp_event_finalise(w);
}

View File

@ -138,7 +138,6 @@ bool ro_gui_configure_click(wimp_pointer *pointer)
ro_gui_wimp_event_register_close_window(
tool->w,
ro_gui_configure_close);
} else {
ro_gui_dialog_open_top(tool->w, NULL, 0, 0);
}
@ -157,6 +156,7 @@ void ro_gui_configure_close(wimp_w w)
tool->open = false;
if (tool->finalise)
tool->finalise(w);
ro_gui_dialog_close(w);
break;
}
}

View File

@ -398,7 +398,6 @@ void ro_gui_dialog_close(wimp_w close)
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
}
ro_gui_wimp_event_close_window(close);
}

View File

@ -38,12 +38,19 @@
#include "netsurf/riscos/save.h"
#include "netsurf/riscos/query.h"
#include "netsurf/riscos/wimp.h"
#include "netsurf/riscos/wimp_event.h"
#include "netsurf/utils/log.h"
#include "netsurf/utils/messages.h"
#include "netsurf/utils/url.h"
#include "netsurf/utils/utf8.h"
#include "netsurf/utils/utils.h"
#define ICON_DOWNLOAD_ICON 0
#define ICON_DOWNLOAD_URL 1
#define ICON_DOWNLOAD_PATH 2
#define ICON_DOWNLOAD_DESTINATION 3
#define ICON_DOWNLOAD_PROGRESS 5
#define ICON_DOWNLOAD_STATUS 6
typedef enum
{
@ -122,22 +129,25 @@ static bool ro_gui_download_save(struct gui_download_window *dw,
const char *file_name, bool force_overwrite);
static void ro_gui_download_send_dataload(struct gui_download_window *dw);
static void ro_gui_download_window_destroy_wrapper(void *p);
static bool ro_gui_download_window_destroy(struct gui_download_window *dw, bool quit);
static void ro_gui_download_close_confirmed(query_id, enum query_response res, void *p);
static void ro_gui_download_close_cancelled(query_id, enum query_response res, void *p);
static void ro_gui_download_overwrite_confirmed(query_id, enum query_response res, void *p);
static void ro_gui_download_overwrite_cancelled(query_id, enum query_response res, void *p);
static bool ro_gui_download_click(wimp_pointer *pointer);
static bool ro_gui_download_keypress(wimp_key *key);
static void ro_gui_download_close(wimp_w w);
static const query_callback close_funcs =
{
ro_gui_download_close_confirmed,
ro_gui_download_close_cancelled,
ro_gui_download_close_cancelled
};
static const query_callback overwrite_funcs =
{
ro_gui_download_overwrite_confirmed,
ro_gui_download_overwrite_cancelled,
ro_gui_download_overwrite_cancelled
};
@ -328,6 +338,11 @@ struct gui_download_window *gui_download_window_create(const char *url,
ro_gui_dialog_open(dw->window);
ro_gui_wimp_event_set_user_data(dw->window, dw);
ro_gui_wimp_event_register_mouse_click(dw->window, ro_gui_download_click);
ro_gui_wimp_event_register_keypress(dw->window, ro_gui_download_keypress);
ro_gui_wimp_event_register_close_window(dw->window, ro_gui_download_close);
/* issue the warning now, so that it appears in front of the download
* window! */
if (space_warning)
@ -686,23 +701,6 @@ void gui_download_window_done(struct gui_download_window *dw)
}
/**
* Convert a RISC OS window handle to a gui_download_window.
*
* \param w RISC OS window handle
* \return pointer to a structure if found, 0 otherwise
*/
struct gui_download_window * ro_gui_download_window_lookup(wimp_w w)
{
struct gui_download_window *dw;
for (dw = download_window_list; dw; dw = dw->next)
if (dw->window == w)
return dw;
return 0;
}
/**
* Handle Mouse_Click events in a download window.
*
@ -710,13 +708,14 @@ struct gui_download_window * ro_gui_download_window_lookup(wimp_w w)
* \param pointer block returned by Wimp_Poll
*/
void ro_gui_download_window_click(struct gui_download_window *dw,
wimp_pointer *pointer)
bool ro_gui_download_click(wimp_pointer *pointer)
{
struct gui_download_window *dw;
char command[256] = "Filer_OpenDir ";
char *dot;
os_error *error;
dw = (struct gui_download_window *)ro_gui_wimp_event_get_user_data(pointer->w);
if (pointer->i == ICON_DOWNLOAD_ICON && !dw->error &&
!dw->saved) {
const char *sprite = ro_gui_get_icon_string(pointer->w, pointer->i);
@ -738,6 +737,7 @@ void ro_gui_download_window_click(struct gui_download_window *dw,
}
}
}
return true;
}
@ -749,8 +749,11 @@ void ro_gui_download_window_click(struct gui_download_window *dw,
* \return true iff key press handled
*/
bool ro_gui_download_window_keypress(struct gui_download_window *dw, wimp_key *key)
bool ro_gui_download_keypress(wimp_key *key)
{
struct gui_download_window *dw;
dw = (struct gui_download_window *)ro_gui_wimp_event_get_user_data(key->w);
switch (key->c)
{
case wimp_KEY_ESCAPE:
@ -1261,12 +1264,24 @@ void ro_gui_download_send_dataload(struct gui_download_window *dw)
}
/**
* Handle closing of download window
*/
void ro_gui_download_close(wimp_w w)
{
struct gui_download_window *dw;
dw = (struct gui_download_window *)ro_gui_wimp_event_get_user_data(w);
ro_gui_download_window_destroy(dw, false);
}
/**
* Close a download window and free any related resources.
*
* \param dw download window
* \param quit destroying because we're quitting the whole app
* \return true iff window destroyed, not waiting for user confirmation
* \return true if window destroyed, not waiting for user confirmation
*/
bool ro_gui_download_window_destroy(struct gui_download_window *dw, bool quit)
@ -1320,12 +1335,14 @@ bool ro_gui_download_window_destroy(struct gui_download_window *dw, bool quit)
dw->next->prev = dw->prev;
/* delete window */
ro_gui_dialog_close(dw->window);
error = xwimp_delete_window(dw->window);
if (error) {
LOG(("xwimp_delete_window: 0x%x: %s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
}
ro_gui_wimp_event_finalise(dw->window);
/* close download file */
if (dw->file) {
@ -1447,7 +1464,7 @@ void ro_gui_download_overwrite_confirmed(query_id id, enum query_response res, v
* Respond to PreQuit message, displaying a prompt message if we need
* the user to confirm the shutdown.
*
* \return true iff we can shutdown straightaway
* \return true if we can shutdown straightaway
*/
bool ro_gui_download_prequit(void)

View File

@ -142,14 +142,8 @@ const char * NETSURF_DIR;
char *default_stylesheet_url;
char *adblock_stylesheet_url;
#ifndef ncos
static const char *task_name = "NetSurf";
#define CHOICES_PREFIX "<Choices$Write>.WWW.NetSurf."
#else
static const char *task_name = "NCNetSurf";
#define CHOICES_PREFIX "<User$Path>.Choices.NetSurf."
#endif
/** The pointer is over a window which is tracking mouse movement. */
static bool gui_track = false;
@ -238,17 +232,16 @@ static struct
} screen_info;
static void ro_gui_create_dirs(void);
static void ro_gui_create_dir(char *path);
static void ro_gui_choose_language(void);
static void ro_gui_icon_bar_create(void);
static void ro_gui_signal(int sig);
static void ro_gui_cleanup(void);
static void ro_gui_handle_event(wimp_event_no event, wimp_block *block);
static void ro_gui_null_reason_code(void);
static void ro_gui_redraw_window_request(wimp_draw *redraw);
static void ro_gui_close_window_request(wimp_close *close);
static void ro_gui_pointer_leaving_window(wimp_leaving *leaving);
static void ro_gui_pointer_entering_window(wimp_entering *entering);
static void ro_gui_mouse_click(wimp_pointer *pointer);
static bool ro_gui_icon_bar_click(wimp_pointer *pointer);
static void ro_gui_check_resolvers(void);
static void ro_gui_drag_end(wimp_dragged *drag);
@ -475,8 +468,8 @@ void gui_init(int argc, char** argv)
*/
void ro_gui_create_dirs(void)
{
char *path;
char buf[256];
char *path;
/* Choices */
path = getenv("NetSurf$ChoicesSave");
@ -484,58 +477,46 @@ void ro_gui_create_dirs(void)
die("Failed to find NetSurf Choices save path");
snprintf(buf, sizeof(buf), "%s", path);
path = buf;
/* Given a path x.y.z, this will try to create x, x.y */
while ((path = strchr(path, '.'))) {
*path = '\0';
xosfile_create_dir(buf, 0);
*path++ = '.';
}
ro_gui_create_dir(buf);
/* URL */
snprintf(buf, sizeof(buf), "%s", option_url_save);
path = buf;
while ((path = strchr(path, '.'))) {
*path = '\0';
xosfile_create_dir(buf, 0);
*path++ = '.';
}
ro_gui_create_dir(buf);
/* Hotlist */
snprintf(buf, sizeof(buf), "%s", option_hotlist_save);
path = buf;
while ((path = strchr(path, '.'))) {
*path = '\0';
xosfile_create_dir(buf, 0);
*path++ = '.';
}
ro_gui_create_dir(buf);
/* Recent */
snprintf(buf, sizeof(buf), "%s", option_recent_save);
path = buf;
while ((path = strchr(path, '.'))) {
*path = '\0';
xosfile_create_dir(buf, 0);
*path++ = '.';
}
ro_gui_create_dir(buf);
/* Theme */
snprintf(buf, sizeof(buf), "%s", option_theme_save);
path = buf;
while ((path = strchr(path, '.'))) {
*path = '\0';
xosfile_create_dir(buf, 0);
*path++ = '.';
}
ro_gui_create_dir(buf);
/* and the final directory part (as theme_save is a directory) */
xosfile_create_dir(buf, 0);
}
/**
* Create directory structure for a path
*
* Given a path of x.y.z directories x and x.y will be created
*
* \param path the directory path to create
*/
void ro_gui_create_dir(char *path)
{
char *cur = path;
while ((cur = strchr(cur, '.'))) {
*cur = '\0';
xosfile_create_dir(path, 0);
*cur++ = '.';
}
}
/**
* Choose the language to use.
*/
@ -618,7 +599,6 @@ const char *ro_gui_default_language(void) {
void ro_gui_icon_bar_create(void)
{
#ifndef ncos
os_error *error;
wimp_icon_create icon = {
@ -635,7 +615,6 @@ void ro_gui_icon_bar_create(void)
}
ro_gui_wimp_event_register_mouse_click(wimp_ICON_BAR,
ro_gui_icon_bar_click);
#endif
}
@ -904,7 +883,7 @@ void ro_gui_handle_event(wimp_event_no event, wimp_block *block)
break;
case wimp_REDRAW_WINDOW_REQUEST:
ro_gui_redraw_window_request(&block->redraw);
ro_gui_wimp_event_redraw_window(&block->redraw);
break;
case wimp_OPEN_WINDOW_REQUEST:
@ -924,7 +903,7 @@ void ro_gui_handle_event(wimp_event_no event, wimp_block *block)
break;
case wimp_MOUSE_CLICK:
ro_gui_mouse_click(&block->pointer);
ro_gui_wimp_event_mouse_click(&block->pointer);
break;
case wimp_USER_DRAG_BOX:
@ -1025,50 +1004,23 @@ void ro_gui_null_reason_code(void)
}
/**
* Handle Redraw_Window_Request events.
*/
void ro_gui_redraw_window_request(wimp_draw *redraw)
{
struct gui_window *g;
if (ro_gui_wimp_event_redraw_window(redraw))
return;
g = ro_gui_window_lookup(redraw->w);
if (g)
ro_gui_window_redraw(g, redraw);
}
/**
* Handle Open_Window_Request events.
*/
void ro_gui_open_window_request(wimp_open *open)
{
struct gui_window *g;
os_error *error;
if (ro_gui_wimp_event_open_window(open))
return;
g = ro_gui_window_lookup(open->w);
if (g) {
ro_gui_window_open(g, open);
} else {
error = xwimp_open_window(open);
if (error) {
LOG(("xwimp_open_window: 0x%x: %s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
return;
}
g = ro_gui_status_lookup(open->w);
if (g && g->toolbar)
ro_gui_theme_resize_toolbar_status(g->toolbar);
error = xwimp_open_window(open);
if (error) {
LOG(("xwimp_open_window: 0x%x: %s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
return;
}
}
@ -1079,70 +1031,9 @@ void ro_gui_open_window_request(wimp_open *open)
void ro_gui_close_window_request(wimp_close *close)
{
struct gui_window *g;
struct gui_download_window *dw;
wimp_pointer pointer;
os_error *error;
char *temp_name, *r;
char *filename;
struct content *content = NULL;
if ((g = ro_gui_window_lookup(close->w)) != NULL) {
error = xwimp_get_pointer_info(&pointer);
if (error) {
LOG(("xwimp_get_pointer_info: 0x%x: %s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
return;
}
if (g->bw)
content = g->bw->current_content;
if (pointer.buttons & wimp_CLICK_ADJUST) {
filename = url_to_path(content->url);
if (filename) {
temp_name = malloc(strlen(filename) + 32);
if (temp_name) {
sprintf(temp_name, "Filer_OpenDir %s", filename);
r = temp_name + strlen(temp_name);
while (r > temp_name) {
if (*r == '.') {
*r = '\0';
break;
}
*r--;
}
error = xos_cli(temp_name);
if (error) {
LOG(("xos_cli: 0x%x: %s",
error->errnum, error->errmess));
warn_user("MiscError", error->errmess);
return;
}
free(temp_name);
}
free(filename);
} else {
/* this is pointless if we are about to close the window */
if (ro_gui_shift_pressed())
ro_gui_menu_handle_action(close->w, BROWSER_NAVIGATE_UP, true);
}
}
if (ro_gui_shift_pressed())
return;
ro_gui_url_complete_close(NULL, 0);
/* search must be closed before the main window so that
the content still exists */
ro_gui_dialog_close_persistent(close->w);
browser_window_destroy(g->bw);
if (ro_gui_wimp_event_close_window(close->w))
return;
} else if ((dw = ro_gui_download_window_lookup(close->w)) != NULL) {
ro_gui_download_window_destroy(dw, false);
} else {
ro_gui_dialog_close(close->w);
}
ro_gui_dialog_close_persistent(close->w);
ro_gui_dialog_close(close->w);
}
@ -1152,14 +1043,8 @@ void ro_gui_close_window_request(wimp_close *close)
void ro_gui_pointer_leaving_window(wimp_leaving *leaving)
{
if (gui_track_wimp_w == history_window) {
os_error *error = xwimp_close_window(dialog_tooltip);
if (error) {
LOG(("xwimp_close_window: 0x%x: %s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
}
}
if (gui_track_wimp_w == history_window)
ro_gui_dialog_close(dialog_tooltip);
switch (gui_current_drag_type) {
case GUI_DRAG_SELECTION:
@ -1201,24 +1086,6 @@ void ro_gui_pointer_entering_window(wimp_entering *entering)
}
/**
* Handle Mouse_Click events.
*/
void ro_gui_mouse_click(wimp_pointer *pointer)
{
struct gui_download_window *dw;
struct gui_query_window *qw;
if (ro_gui_wimp_event_mouse_click(pointer))
return;
else if ((dw = ro_gui_download_window_lookup(pointer->w)) != NULL)
ro_gui_download_window_click(dw, pointer);
else if ((qw = ro_gui_query_window_lookup(pointer->w)) != NULL)
ro_gui_query_window_click(qw, pointer);
}
/**
* Handle Mouse_Click events on the iconbar icon.
*/
@ -1309,19 +1176,9 @@ void ro_gui_drag_end(wimp_dragged *drag)
void ro_gui_keypress(wimp_key *key)
{
struct gui_download_window *dw;
struct gui_query_window *qw;
bool handled = false;
os_error *error;
if (ro_gui_wimp_event_keypress(key))
handled = true;
else if ((qw = ro_gui_query_window_lookup(key->w)) != NULL)
handled = ro_gui_query_window_keypress(qw, key);
else if ((dw = ro_gui_download_window_lookup(key->w)) != NULL)
handled = ro_gui_download_window_keypress(dw, key);
if (!handled) {
if (!ro_gui_wimp_event_keypress(key)) {
error = xwimp_process_key(key->c);
if (error) {
LOG(("xwimp_process_key: 0x%x: %s",

View File

@ -119,15 +119,9 @@ const char *ro_gui_default_language(void);
/* in download.c */
void ro_gui_download_init(void);
struct gui_download_window * ro_gui_download_window_lookup(wimp_w w);
void ro_gui_download_window_click(struct gui_download_window *dw,
wimp_pointer *pointer);
void ro_gui_download_drag_end(wimp_dragged *drag);
void ro_gui_download_datasave_ack(wimp_message *message);
bool ro_gui_download_window_destroy(struct gui_download_window *dw, bool quit);
bool ro_gui_download_prequit(void);
bool ro_gui_download_window_keypress(struct gui_download_window *dw,
wimp_key *key);
/* in 401login.c */
#ifdef WITH_AUTH
@ -144,8 +138,6 @@ void ro_gui_cert_open(struct tree *tree, struct node *node);
void ro_gui_window_quit(void);
void ro_gui_window_update_theme(void);
void ro_gui_window_update_dimensions(struct gui_window *g, int yscroll);
void ro_gui_window_open(struct gui_window *g, wimp_open *open);
void ro_gui_window_redraw(struct gui_window *g, wimp_draw *redraw);
void ro_gui_window_mouse_at(struct gui_window *g, wimp_pointer *pointer);
bool ro_gui_toolbar_click(wimp_pointer *pointer);
bool ro_gui_status_click(wimp_pointer *pointer);
@ -232,20 +224,6 @@ bool ro_gui_theme_install_apply(wimp_w w);
#define ICON_STATUS_RESIZE 0
#define ICON_STATUS_TEXT 1
#define ICON_DOWNLOAD_ICON 0
#define ICON_DOWNLOAD_URL 1
#define ICON_DOWNLOAD_PATH 2
#define ICON_DOWNLOAD_DESTINATION 3
#define ICON_DOWNLOAD_PROGRESS 5
#define ICON_DOWNLOAD_STATUS 6
#define ICON_401LOGIN_LOGIN 0
#define ICON_401LOGIN_CANCEL 1
#define ICON_401LOGIN_HOST 2
#define ICON_401LOGIN_REALM 3
#define ICON_401LOGIN_USERNAME 4
#define ICON_401LOGIN_PASSWORD 5
#define ICON_ZOOM_VALUE 1
#define ICON_ZOOM_DEC 2
#define ICON_ZOOM_INC 3
@ -276,11 +254,6 @@ bool ro_gui_theme_install_apply(wimp_w w);
#define ICON_WARNING_CONTINUE 1
#define ICON_WARNING_HELP 2
#define ICON_QUERY_MESSAGE 0
#define ICON_QUERY_YES 1
#define ICON_QUERY_NO 2
#define ICON_QUERY_HELP 3
#define ICON_SEARCH_TEXT 0
#define ICON_SEARCH_CASE_SENSITIVE 1
#define ICON_SEARCH_FIND_NEXT 2

View File

@ -11,10 +11,15 @@
#include "netsurf/riscos/dialog.h"
#include "netsurf/riscos/query.h"
#include "netsurf/riscos/wimp.h"
#include "netsurf/riscos/wimp_event.h"
#include "netsurf/utils/log.h"
#include "netsurf/utils/messages.h"
#include "netsurf/utils/utils.h"
#define ICON_QUERY_MESSAGE 0
#define ICON_QUERY_YES 1
#define ICON_QUERY_NO 2
#define ICON_QUERY_HELP 3
/** Data for a query window */
struct gui_query_window
@ -45,9 +50,12 @@ static struct wimp_window *query_template;
static int query_yes_width = 0;
static int query_no_width = 0;
static void ro_gui_query_window_destroy(struct gui_query_window *qw);
static struct gui_query_window *ro_gui_query_window_lookup_id(query_id id);
static bool ro_gui_query_click(wimp_pointer *pointer);
static void ro_gui_query_close(wimp_w w);
static bool ro_gui_query_apply(wimp_w w);
void ro_gui_query_init(void)
{
@ -55,22 +63,6 @@ void ro_gui_query_init(void)
}
/**
* Lookup a query window using its RISC OS window handle
*
* \param w RISC OS window handle
* \return pointer to query window or NULL
*/
struct gui_query_window *ro_gui_query_window_lookup(wimp_w w)
{
struct gui_query_window *qw = gui_query_window_list;
while (qw && qw->window != w)
qw = qw->next;
return qw;
}
/**
* Lookup a query window using its ID number
*
@ -128,10 +120,10 @@ query_id query_user(const char *query, const char *detail,
if (!yes) yes = messages_get("Yes");
if (!no) no = messages_get("No");
/* set the text of the 'No' button and size accordingly */
icn = &query_template->icons[ICON_QUERY_NO];
len = strnlen(no, icn->data.indirected_text.size - 1);
memcpy(icn->data.indirected_text.text, no, len);
/* set the text of the 'Yes' button and size accordingly */
icn = &query_template->icons[ICON_QUERY_YES];
len = strnlen(yes, icn->data.indirected_text.size - 1);
memcpy(icn->data.indirected_text.text, yes, len);
icn->data.indirected_text.text[len] = '\0';
error = xwimptextop_string_width(icn->data.indirected_text.text, len, &width);
@ -140,20 +132,20 @@ query_id query_user(const char *query, const char *detail,
error->errnum, error->errmess));
width = len * 16;
}
if (!query_no_width) query_no_width = icn->extent.x1 - icn->extent.x0;
if (width < query_no_width)
width = query_no_width;
if (!query_yes_width) query_yes_width = icn->extent.x1 - icn->extent.x0;
if (width < query_yes_width)
width = query_yes_width;
else
width += 44;
icn->extent.x0 = x = icn->extent.x1 - width;
/* set the text of the 'Yes' button and size accordingly */
icn = &query_template->icons[ICON_QUERY_YES];
len = strnlen(yes, icn->data.indirected_text.size - 1);
memcpy(icn->data.indirected_text.text, yes, len);
/* set the text of the 'No' button and size accordingly */
icn = &query_template->icons[ICON_QUERY_NO];
len = strnlen(no, icn->data.indirected_text.size - 1);
memcpy(icn->data.indirected_text.text, no, len);
icn->data.indirected_text.text[len] = '\0';
if (!query_yes_width) query_yes_width = icn->extent.x1 - icn->extent.x0;
if (!query_no_width) query_no_width = icn->extent.x1 - icn->extent.x0;
icn->extent.x1 = x - 16;
error = xwimptextop_string_width(icn->data.indirected_text.text, len, &width);
if (error) {
@ -161,8 +153,8 @@ query_id query_user(const char *query, const char *detail,
error->errnum, error->errmess));
width = len * 16;
}
if (width < query_yes_width)
width = query_yes_width;
if (width < query_no_width)
width = query_no_width;
else
width += 28;
icn->extent.x0 = icn->extent.x1 - width;
@ -185,6 +177,12 @@ query_id query_user(const char *query, const char *detail,
ro_gui_dialog_open(qw->window);
ro_gui_wimp_event_set_user_data(qw->window, qw);
ro_gui_wimp_event_register_mouse_click(qw->window, ro_gui_query_click);
ro_gui_wimp_event_register_cancel(qw->window, ICON_QUERY_NO);
ro_gui_wimp_event_register_ok(qw->window, ICON_QUERY_YES, ro_gui_query_apply);
ro_gui_wimp_event_register_close_window(qw->window, ro_gui_query_close);
error = xwimp_set_caret_position(qw->window, (wimp_i)-1, 0, 0, 1 << 25, -1);
if (error) {
LOG(("xwimp_get_caret_position: 0x%x : %s",
@ -204,34 +202,6 @@ query_id query_user(const char *query, const char *detail,
}
/**
* Close and destroy a query window, releasing all resources
*
* \param qw query window
*/
void ro_gui_query_window_destroy(struct gui_query_window *qw)
{
os_error *error = xwimp_delete_window(qw->window);
if (error) {
LOG(("xwimp_delete_window: 0x%x:%s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
}
/* remove from linked-list of query windows and release memory */
if (qw->prev)
qw->prev->next = qw->next;
else
gui_query_window_list = qw->next;
if (qw->next)
qw->next->prev = qw->prev;
free(qw);
}
/**
* Close a query window without waiting for a response from the user.
* (should normally only be called if the user has responded in some other
@ -243,7 +213,10 @@ void ro_gui_query_window_destroy(struct gui_query_window *qw)
void query_close(query_id id)
{
struct gui_query_window *qw = ro_gui_query_window_lookup_id(id);
if (qw) ro_gui_query_window_destroy(qw);
if (!qw)
return;
ro_gui_query_close(qw->window);
}
@ -266,59 +239,68 @@ void ro_gui_query_window_bring_to_front(query_id id)
/**
* Handle mouse clicks in a query window.
*
* \param qw query window
* \param key key press info from the Wimp
* Handle closing of query dialog
*/
void ro_gui_query_window_click(struct gui_query_window *qw, wimp_pointer *pointer)
void ro_gui_query_close(wimp_w w)
{
const query_callback *cb = qw->cb;
switch (pointer->i) {
case ICON_QUERY_YES:
cb->confirm(qw->id, QUERY_YES, qw->pw);
ro_gui_query_window_destroy(qw);
break;
struct gui_query_window *qw;
os_error *error;
case ICON_QUERY_NO:
cb->cancel(qw->id, QUERY_NO, qw->pw);
ro_gui_query_window_destroy(qw);
break;
qw = (struct gui_query_window *)ro_gui_wimp_event_get_user_data(w);
case ICON_QUERY_HELP:
/* \todo */
break;
ro_gui_dialog_close(w);
error = xwimp_delete_window(qw->window);
if (error) {
LOG(("xwimp_delete_window: 0x%x:%s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
}
ro_gui_wimp_event_finalise(w);
/* remove from linked-list of query windows and release memory */
if (qw->prev)
qw->prev->next = qw->next;
else
gui_query_window_list = qw->next;
if (qw->next)
qw->next->prev = qw->prev;
free(qw);
}
/**
* Handle keypresses in a query window.
*
* \param qw query window
* \param pointer mouse pointer state from Wimp.
* \return true iff the key press is the key press has been handled
* Handle acceptance of query dialog
*/
bool ro_gui_query_window_keypress(struct gui_query_window *qw, wimp_key *key)
bool ro_gui_query_apply(wimp_w w)
{
const query_callback *cb = qw->cb;
switch (key->c) {
case wimp_KEY_ESCAPE:
cb->escape(qw->id, QUERY_ESCAPE, qw->pw);
ro_gui_query_window_destroy(qw);
return true;
case wimp_KEY_RETURN:
if (qw->default_confirm)
cb->confirm(qw->id, QUERY_YES, qw->pw);
else
cb->cancel(qw->id, QUERY_NO, qw->pw);
ro_gui_query_window_destroy(qw);
return true;
}
struct gui_query_window *qw;
const query_callback *cb;
qw = (struct gui_query_window *)ro_gui_wimp_event_get_user_data(w);
cb = qw->cb;
cb->confirm(qw->id, QUERY_YES, qw->pw);
return true;
}
/**
* Handle clicks in query dialog
*/
bool ro_gui_query_click(wimp_pointer *pointer)
{
struct gui_query_window *qw;
const query_callback *cb;
qw = (struct gui_query_window *)ro_gui_wimp_event_get_user_data(pointer->w);
cb = qw->cb;
switch (pointer->i) {
case ICON_QUERY_NO:
cb->cancel(qw->id, QUERY_NO, qw->pw);
break;
default:
return false;
}
return false;
}

View File

@ -14,9 +14,6 @@
struct gui_query_window;
void ro_gui_query_init(void);
struct gui_query_window *ro_gui_query_window_lookup(wimp_w w);
void ro_gui_query_window_bring_to_front(query_id id);
void ro_gui_query_window_click(struct gui_query_window *qw, wimp_pointer *pointer);
bool ro_gui_query_window_keypress(struct gui_query_window *qw, wimp_key *key);
#endif

View File

@ -373,6 +373,7 @@ void ro_gui_cert_open(struct tree *tree, struct node *node)
void ro_gui_cert_close(wimp_w w)
{
struct session_data *data;
os_error *error;
unsigned long i;
data = (struct session_data *)ro_gui_wimp_event_get_user_data(w);
@ -390,12 +391,24 @@ void ro_gui_cert_close(wimp_w w)
if (data->tree) {
tree_delete_node(data->tree, data->tree->root, false);
xwimp_delete_window((wimp_w)data->tree->handle);
ro_gui_dialog_close((wimp_w)data->tree->handle);
error = xwimp_delete_window((wimp_w)data->tree->handle);
if (error) {
LOG(("xwimp_delete_window: 0x%x:%s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
}
ro_gui_wimp_event_finalise((wimp_w)data->tree->handle);
free(data->tree);
}
xwimp_delete_window(w);
ro_gui_wimp_event_finalise(w);
ro_gui_dialog_close(w);
error = xwimp_delete_window(w);
if (error) {
LOG(("xwimp_delete_window: 0x%x:%s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
}
}

View File

@ -78,6 +78,7 @@ static void ro_gui_theme_add_toolbar_icons(struct toolbar *toolbar,
const char* icons[], const char* ident);
static void ro_gui_theme_set_help_prefix(struct toolbar *toolbar);
static void ro_gui_theme_status_open(wimp_open *open);
/* A basic window for the toolbar and status
*/
@ -1119,8 +1120,11 @@ bool ro_gui_theme_update_toolbar(struct theme_descriptor *descriptor,
warn_user("WimpError", error->errmess);
return false;
}
ro_gui_wimp_event_set_user_data(toolbar->status_handle, toolbar);
ro_gui_wimp_event_register_mouse_click(toolbar->status_handle,
ro_gui_status_click);
ro_gui_wimp_event_register_open_window(toolbar->status_handle,
ro_gui_theme_status_open);
ro_gui_wimp_event_set_help_prefix(toolbar->status_handle, "HelpStatus");
/* Create the status resize icon
@ -1297,55 +1301,6 @@ bool ro_gui_theme_attach_toolbar(struct toolbar *toolbar, wimp_w parent) {
}
/**
* Updates the toolbars status bar settings to reflect the current size
*
* \param toolbar the toolbar to update
*/
void ro_gui_theme_resize_toolbar_status(struct toolbar *toolbar) {
os_error *error;
wimp_outline outline;
wimp_window_state state;
wimp_w parent = NULL;
int parent_size, status_size;
if ((!toolbar) || (!toolbar->parent_handle)) return;
/* Get the width to scale to
*/
parent = toolbar->parent_handle;
outline.w = toolbar->parent_handle;
error = xwimp_get_window_outline(&outline);
if (error) {
LOG(("xwimp_get_window_outline: 0x%x: %s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
return;
}
parent_size = outline.outline.x1 - outline.outline.x0 -
ro_get_vscroll_width(parent) - 2;
/* Get the current size
*/
state.w = toolbar->status_handle;
error = xwimp_get_window_state(&state);
if (error) {
LOG(("xwimp_get_window_state: 0x%x: %s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
return;
}
status_size = state.visible.x1 - state.visible.x0;
if (status_size <= 12)
status_size = 0;
/* Store the new size
*/
toolbar->status_width = (10000 * status_size) / parent_size;
if (toolbar->status_width > 10000) toolbar->status_width = 10000;
ro_gui_theme_process_toolbar(toolbar, -1);
}
/**
* Updates the toolbar to reflect changes to the icon flags and any reformatting
* required due to the change in parent window size.
@ -1375,7 +1330,7 @@ bool ro_gui_theme_process_toolbar(struct toolbar *toolbar, int width) {
int xeig, yeig;
os_coord pixel = {1, 1};
int top, bottom, right;
bool parent_hscroll;
bool parent_hscroll = false;
/* calculate 1px in OS units */
ro_convert_pixels_to_os_units(&pixel, (os_mode)-1);
@ -2431,3 +2386,43 @@ void ro_gui_theme_set_help_prefix(struct toolbar *toolbar) {
break;
}
}
void ro_gui_theme_status_open(wimp_open *open) {
struct toolbar *toolbar = (struct toolbar *)ro_gui_wimp_event_get_user_data(open->w);
os_error *error;
wimp_outline outline;
wimp_w parent = NULL;
int parent_size, status_size;
/* update the window size */
error = xwimp_open_window(open);
if (error) {
LOG(("xwimp_open_window: 0x%x: %s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
}
/* get the width to scale to */
parent = toolbar->parent_handle;
outline.w = toolbar->parent_handle;
error = xwimp_get_window_outline(&outline);
if (error) {
LOG(("xwimp_get_window_outline: 0x%x: %s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
return;
}
parent_size = outline.outline.x1 - outline.outline.x0 -
ro_get_vscroll_width(parent) - 2;
/* get the current size */
status_size = open->visible.x1 - open->visible.x0;
if (status_size <= 12)
status_size = 0;
/* Store the new size
*/
toolbar->status_width = (10000 * status_size) / parent_size;
if (toolbar->status_width > 10000) toolbar->status_width = 10000;
ro_gui_theme_process_toolbar(toolbar, -1);
}

View File

@ -154,7 +154,6 @@ void ro_gui_theme_close(struct theme_descriptor *descriptor, bool list);
struct toolbar *ro_gui_theme_create_toolbar(struct theme_descriptor *descriptor, toolbar_type type);
bool ro_gui_theme_update_toolbar(struct theme_descriptor *descriptor, struct toolbar *toolbar);
bool ro_gui_theme_attach_toolbar(struct toolbar *toolbar, wimp_w parent);
void ro_gui_theme_resize_toolbar_status(struct toolbar *toolbar);
bool ro_gui_theme_process_toolbar(struct toolbar *toolbar, int width);
void ro_gui_theme_destroy_toolbar(struct toolbar *toolbar);

View File

@ -79,6 +79,9 @@ static float scale_snap_to[] = {0.10, 0.125, 0.25, 0.333, 0.5, 0.75,
1.5, 2.0, 3.0, 4.0, 6.0, 8.0, 12.0, 16.0};
#define SCALE_SNAP_TO_SIZE (sizeof scale_snap_to) / (sizeof(float))
static void ro_gui_window_open(wimp_open *open);
static void ro_gui_window_close(wimp_w w);
static void ro_gui_window_redraw(wimp_draw *redraw);
static bool ro_gui_window_click(wimp_pointer *mouse);
static bool ro_gui_window_keypress(wimp_key *key);
static void ro_gui_window_launch_url(struct gui_window *g, const char *url);
@ -137,10 +140,9 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw,
g->throbtime = 0;
g->iconise_icon = -1;
/* Set the window position
*/
/* Set the window position */
if (bw->parent) {
/* fill the parent window until it's reformatted */
/* Open as a small window until we are reformatted */
state.w = clone->window->window;
error = xwimp_get_window_state(&state);
if (error) {
@ -169,8 +171,7 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw,
} else {
ro_gui_screen_size(&screen_width, &screen_height);
/* Check if we have a preferred position
*/
/* Check if we have a preferred position */
if ((option_window_screen_width != 0) &&
(option_window_screen_height != 0)) {
win_width = (option_window_width * screen_width) /
@ -193,7 +194,7 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw,
} else {
/* Base how we define the window height/width
on the compile time options set */
on the compile time options set */
win_width = screen_width * 3 / 4;
if (1600 < win_width)
win_width = 1600;
@ -207,13 +208,10 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw,
window.visible.y1 = window.visible.y0 + win_height;
}
/* Set the general window characteristics
*/
/* General flags for a non-movable, non-resizable, no-title bar window */
window.xscroll = 0;
window.yscroll = 0;
window.next = wimp_TOP;
/* General flags for a non-movable, non-resizable, no-title bar window */
window.flags = wimp_WINDOW_MOVEABLE |
wimp_WINDOW_NEW_FORMAT |
wimp_WINDOW_VSCROLL |
@ -293,6 +291,7 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw,
return 0;
}
/* Link into window list */
g->prev = 0;
g->next = window_list;
if (window_list)
@ -300,8 +299,7 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw,
window_list = g;
window_count++;
/* Add in a toolbar
*/
/* Add in a toolbar */
if (bw->browser_window_type == BROWSER_WINDOW_NORMAL) {
g->toolbar = ro_gui_theme_create_toolbar(NULL, THEME_BROWSER_TOOLBAR);
ro_gui_theme_attach_toolbar(g->toolbar, g->window);
@ -309,14 +307,23 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw,
g->toolbar = NULL;
}
/* Set the window options
*/
/* Set the window options */
bw->window = g;
ro_gui_window_clone_options(bw, clone);
ro_gui_prepare_navigate(g);
/* Open the window
*/
/* Register event handlers */
ro_gui_wimp_event_set_user_data(g->window, g);
ro_gui_wimp_event_register_open_window(g->window, ro_gui_window_open);
ro_gui_wimp_event_register_close_window(g->window, ro_gui_window_close);
ro_gui_wimp_event_register_redraw_window(g->window, ro_gui_window_redraw);
ro_gui_wimp_event_register_keypress(g->window, ro_gui_window_keypress);
if (g->toolbar)
ro_gui_wimp_event_register_keypress(g->toolbar->toolbar_handle,
ro_gui_window_keypress);
ro_gui_wimp_event_register_mouse_click(g->window, ro_gui_window_click);
/* Open the window at the top of the stack */
state.w = g->window;
error = xwimp_get_window_state(&state);
if (error) {
@ -325,9 +332,6 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw,
warn_user("WimpError", error->errmess);
return g;
}
/* Open the window at the top/back of the stack
*/
state.next = wimp_TOP;
if (bw->parent) {
top = browser_window_owner(bw);
@ -337,18 +341,9 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw,
wimp_CHILD_LINKS_PARENT_WORK_AREA
<< wimp_CHILD_YORIGIN_SHIFT);
}
ro_gui_window_open(g, (wimp_open*)&state);
ro_gui_window_open((wimp_open*)&state);
/* Register event handlers */
ro_gui_wimp_event_register_keypress(g->window,
ro_gui_window_keypress);
if (g->toolbar)
ro_gui_wimp_event_register_keypress(g->toolbar->toolbar_handle,
ro_gui_window_keypress);
ro_gui_wimp_event_register_mouse_click(g->window,
ro_gui_window_click);
/* Claim the caret position for top-level windows */
/* Claim the caret for top-level windows */
if (bw->browser_window_type == BROWSER_WINDOW_NORMAL) {
if (g->toolbar && g->toolbar->display_url) {
error = xwimp_set_caret_position(
@ -550,10 +545,11 @@ void gui_window_redraw_window(struct gui_window *g)
* Handle a Redraw_Window_Request for a browser window.
*/
void ro_gui_window_redraw(struct gui_window *g, wimp_draw *redraw)
void ro_gui_window_redraw(wimp_draw *redraw)
{
osbool more;
bool knockout = true;
struct gui_window *g = (struct gui_window *)ro_gui_wimp_event_get_user_data(redraw->w);
float scale = g->option.scale;
struct content *c = g->bw->current_content;
int clip_x0, clip_y0, clip_x1, clip_y1, clear_x1, clear_y1;
@ -889,7 +885,7 @@ void gui_window_set_scroll(struct gui_window *g, int sx, int sy)
state.yscroll = -sy * 2 * g->option.scale;
if (g->toolbar)
state.yscroll += ro_gui_theme_toolbar_full_height(g->toolbar);
ro_gui_window_open(g, (wimp_open *) &state);
ro_gui_window_open((wimp_open *) &state);
}
@ -960,7 +956,6 @@ void gui_window_scroll_visible(struct gui_window *g, int x0, int y0, int x1, int
cx0 -= padding_available;
}
padding_available = (height - y1 + y0) / 2;
LOG(("Padding available: %i", padding_available));
if (padding_available > 0) {
if (padding_available > SCROLL_VISIBLE_PADDING)
padding_available = SCROLL_VISIBLE_PADDING;
@ -974,7 +969,7 @@ void gui_window_scroll_visible(struct gui_window *g, int x0, int y0, int x1, int
state.xscroll = cx0;
state.yscroll = -cy0 + toolbar_height;
ro_gui_window_open(g, (wimp_open *)&state);
ro_gui_window_open((wimp_open *)&state);
}
@ -1065,7 +1060,7 @@ void gui_window_position_frame(struct gui_window *g, int x0, int y0, int x1, int
state.visible.y0 = py1 - y1;
state.visible.x1 = px0 + x1;
state.visible.y1 = py1 - y0 * 2;
ro_gui_window_open(g, (wimp_open *)&state);
ro_gui_window_open((wimp_open *)&state);
}
@ -1187,7 +1182,7 @@ void ro_gui_window_update_dimensions(struct gui_window *g, int yscroll) {
/* only allow a further reformat if we've gained/lost scrollbars */
flags = state.flags & (wimp_WINDOW_HSCROLL | wimp_WINDOW_VSCROLL);
update = g->reformat_pending;
ro_gui_window_open(g, (wimp_open *)&state);
ro_gui_window_open((wimp_open *)&state);
state.w = g->window;
error = xwimp_get_window_state(&state);
@ -1347,12 +1342,14 @@ void ro_gui_window_update_theme(void) {
}
}
/**
* Open a window using the given wimp_open, handling toolbars and resizing.
*/
void ro_gui_window_open(struct gui_window *g, wimp_open *open)
void ro_gui_window_open(wimp_open *open)
{
struct gui_window *g = (struct gui_window *)ro_gui_wimp_event_get_user_data(open->w);
int width = open->visible.x1 - open->visible.x0;
int height = open->visible.y1 - open->visible.y0;
int toolbar_height = 0;
@ -1525,6 +1522,66 @@ void ro_gui_window_open(struct gui_window *g, wimp_open *open)
}
/**
* Handle wimp closing event
*/
void ro_gui_window_close(wimp_w w) {
struct gui_window *g = (struct gui_window *)ro_gui_wimp_event_get_user_data(w);
wimp_pointer pointer;
os_error *error;
char *temp_name, *r;
char *filename;
struct content *content = NULL;
error = xwimp_get_pointer_info(&pointer);
if (error) {
LOG(("xwimp_get_pointer_info: 0x%x: %s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
return;
}
if (g->bw)
content = g->bw->current_content;
if (pointer.buttons & wimp_CLICK_ADJUST) {
filename = url_to_path(content->url);
if (filename) {
temp_name = malloc(strlen(filename) + 32);
if (temp_name) {
sprintf(temp_name, "Filer_OpenDir %s", filename);
r = temp_name + strlen(temp_name);
while (r > temp_name) {
if (*r == '.') {
*r = '\0';
break;
}
*r--;
}
error = xos_cli(temp_name);
if (error) {
LOG(("xos_cli: 0x%x: %s",
error->errnum, error->errmess));
warn_user("MiscError", error->errmess);
return;
}
free(temp_name);
}
free(filename);
} else {
/* this is pointless if we are about to close the window */
if (ro_gui_shift_pressed())
ro_gui_menu_handle_action(w, BROWSER_NAVIGATE_UP, true);
}
}
if (ro_gui_shift_pressed())
return;
ro_gui_url_complete_close(NULL, 0);
ro_gui_dialog_close_persistent(w);
browser_window_destroy(g->bw);
return;
}
/**
* Animate the "throbbers" of all browser windows.
*/
@ -1857,9 +1914,7 @@ bool ro_gui_window_click(wimp_pointer *pointer)
os_error *error;
int x, y;
g = ro_gui_window_lookup(pointer->w);
if (!g)
return false;
g = (struct gui_window *)ro_gui_wimp_event_get_user_data(pointer->w);
/* try to close url-completion */
ro_gui_url_complete_close(g, pointer->i);

View File

@ -43,7 +43,6 @@ typedef struct
{
void (*confirm)(query_id id, enum query_response res, void *pw);
void (*cancel)(query_id, enum query_response res, void *pw);
void (*escape)(query_id, enum query_response res, void *pw);
} query_callback;