rebol [ Title: "Eat-wake" File: %eat-wake.r Author: "Romano Paolo Tenca" Purpose: "Delete unuseful queued events, fix modal system, include win-offset? (from 1.3)" Version: 1.2.0 Date: 06/09/2006 License: { Copyright (c) 2003-4, Romano Paolo Tenca All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * The name of Romano Paolo Tenca may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. } History: [ 26-Mar-2004 1.1.0 "First version for Nren2" 06-Sep-2006 1.2.0 "Changed for View 1.3" ] ] ; comment the following line if you are using autodoc.r ;#do [document: func [text] [none]] #do [document { ===Event Filtering and Modal System Patches (eat-wake.r) Eat is a function that deletes identical queued events in the event port. By default it deletes only move events. Call it at the end of an event feel function. The /only refinement permits to define a block of event types to delete. ;Wake-event fix many bugs of the Rebol modal system. ;Win-offset? is the fixed 1.3 version of rebol win-offset?. }] context [ ;from 1.3 ;set 'win-offset? func [ ; "Returns the offset of a face within its window." ; face [object!] ; /local xy ;][ ; xy: 0x0 ; while [face/parent-face] [ ; xy: xy + face/offset ; face: face/parent-face ; if face/edge [xy: xy + face/edge/size] ; ] ; xy ;] ;system/view/wake-event: func [port /local event no-btn p-f] bind [ ; event: pick port 1 ; if none? event [ ; if debug [print "Event port awoke, but no event was present."] ; return false ; ] ; awake event ;] in system/view 'self ;awake: func [event /local no-btn p-f] bind [ ; either not p-f: pop-face [ ; do event ; empty? screen-face/pane ; ][ ; either all [ ; event/type = 'key ; event/key = escape ; ][hide-popup][ ; either any [ ; p-f = event/face ; ; all [ ; ; event/face ; ; same? p-f/parent-face find-window event/face ; ; within? event/offset win-offset? p-f p-f/size ; ; ] ; all [ ; event/face ; same? find-window p-f event/face ; not find [close offset inactive resize] event/type ; any [ ; find [scroll-line scroll-page key time] event/type ; within? event/offset win-offset? p-f p-f/size ; ] ; ] ; ; ][ ; no-btn: false ; if block? get in p-f 'pane [ ; no-btn: foreach item p-f/pane [if get in item 'action [break/return false] true] ; ] ; if any [all [event/type = 'up no-btn] event/type = 'close][hide-popup] ; do event ; ][ ;; either p-f/action [ ;; if not find [move time inactive] event/type [ ; hide-popup ; ] ; if find [time inactive resize close] event/type [do event] ; ][ ; if find [resize offset time] event/type [do event] ; ] ; either p-f/action [ ; if event/type <> 'move [ ; either find [time inactive key] event/type [ ; do event ; ][ ; hide-popup ; if not find [down alt-down] event/type [do event] ; ] ; ] ; ][ ; if find [time inactive key resize offset] event/type [do event] ; ] ; ] ; none? find pop-list p-f ; ] ; ] ; ] in system/view 'self free: true set 'eat func [/only blk [block!]][ if free [ free: false any [only blk: [move]] until [ only: pick system/view/event-port 1 not all [only find blk only/type] ] ; wake-event just uses pick so it will work with block instead of port if only [system/view/wake-event reduce [only]] free: true ] ] ]