From e87596ad1f7755c50f7a00edc85e66908ad1ba10 Mon Sep 17 00:00:00 2001 From: Steve Fryatt Date: Sun, 8 Sep 2013 00:47:55 +0100 Subject: Restructure handling of DragEnd events. Add ro_mouse module to process mouse events during drags and on null polls. Implement support in ro_mouse for tracking the mouse during drags and passing on DragEnd events. Remove ro_gui_drag_end() and update all of its clients so that they use ro_mouse. Remove the unused ro_gui_window_frame_resize_end(). Termination of save drags with Escape is unimplemented, but appears broken anyway. The use of gui_drag_type is still required to handle Message_DatasaveAck processing. Mouse tracking is still handled via gui.c. --- riscos/mouse.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 riscos/mouse.c (limited to 'riscos/mouse.c') diff --git a/riscos/mouse.c b/riscos/mouse.c new file mode 100644 index 000000000..12b4e3e54 --- /dev/null +++ b/riscos/mouse.c @@ -0,0 +1,131 @@ +/* + * Copyright 2013 Stephen Fryatt + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** \file mouse.c + * Mouse dragging and tracking support (implementation). + * + * Two different functions are provided:- + * + * 1. Wimp_DragBox support, allowing clients to start a drag and specify + * callbacks to be used + * + * - on Null Polls while the drag is active, + * - when the drag terminates with Event_DragEnd, and + * - when the drag terminates with Escape being pressed. + */ + +#include "oslib/wimp.h" + +#include "riscos/mouse.h" +#include "utils/log.h" +#include "utils/utils.h" + +/* Data for the wimp drag handler. */ + +static void (*ro_mouse_drag_end_callback)(wimp_dragged *dragged, void *data) + = NULL; +static void (*ro_mouse_drag_track_callback)(wimp_pointer *pointer, void *data) + = NULL; +static void (*ro_mouse_drag_cancel_callback)(void *data) = NULL; +static void *ro_mouse_drag_data = NULL; + +/** + * Process Null polls for any drags and mouse trackers that are currently + * active. + */ + +void ro_mouse_poll(void) +{ + wimp_pointer pointer; + os_error *error; + + /* If no trackers are active, just exit. */ + + if (ro_mouse_drag_track_callback == NULL /* && no trackers */) + return; + + 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; + } + + /* Process the drag tracker, if one is active. */ + + if (ro_mouse_drag_track_callback != NULL) + ro_mouse_drag_track_callback(&pointer, ro_mouse_drag_data); +} + + +/** + * Start a drag, providing a function to be called when the Wimp_DragEnd event + * is received and optionally a tracking function to be called on null polls + * in between times. + * + * \param *drag_end Callback for when the drag terminates, or NULL for none. + * \param *drag_track Callback for mouse tracking during the drag, or NULL for + * none. + * \param *drag_cancel Callback for cancelling the drag, or NULL if the drag + * can't be cancelled. + * \param *data Data to be passed to the callback functions, or NULL. + */ + +void ro_mouse_drag_start(void (*drag_end)(wimp_dragged *dragged, void *data), + void (*drag_track)(wimp_pointer *pointer, void *data), + void (*drag_cancel)(void *data), void *data) +{ + /* A drag should never be started when one is already in progress. */ + + assert(ro_mouse_drag_end_callback == NULL && + ro_mouse_drag_track_callback == NULL && + ro_mouse_drag_cancel_callback == NULL && + ro_mouse_drag_data == NULL); + + ro_mouse_drag_end_callback = drag_end; + ro_mouse_drag_track_callback = drag_track; + ro_mouse_drag_cancel_callback = drag_cancel; + ro_mouse_drag_data = data; +} + + +/** + * Process Wimp_DragEnd events by passing the details on to any registered + * event handler. + * + * \param *dragged The Wimp_DragEnd data block. + */ + +void ro_mouse_drag_end(wimp_dragged *dragged) +{ + if (ro_mouse_drag_end_callback != NULL) + ro_mouse_drag_end_callback(dragged, ro_mouse_drag_data); + else + warn_user("WimpError", "No callback"); + + /* Wimp_DragEnd is a one-shot event, so clear the data ready for + * another claimant. + */ + + ro_mouse_drag_end_callback = NULL; + ro_mouse_drag_track_callback = NULL; + ro_mouse_drag_cancel_callback = NULL; + ro_mouse_drag_data = NULL; +} + -- cgit v1.2.3