Esempio n. 1
0
EVENT uigadgetfilter( EVENT ev, p_gadget g )
{
    int         m_anchor, m_linear;
    int         tmp;
    EVENT       newev;
    ORD         start;
    int         length;
    int         pos = 0;

    if( uimouseinstalled() ) {
        uiunprotect( g->win );
        uimousepos( g->win, &m_anchor, &m_linear );
        uiprotect( g->win );
        if( g->dir == VERTICAL ) {
            tmp = m_linear;
            m_linear = m_anchor;
            m_anchor = tmp;
        }
        if( ( ev == EV_MOUSE_PRESS ) || ( ev == EV_MOUSE_DCLICK ) ) {
            if( ( m_anchor != g->anchor ) || ( m_linear < g->start ) ||
                ( m_linear > g->end ) || ( Pressed != NULL ) ) {
                return( ev );
            } else {
                Pressed = g;
            }
        }
        /* ignore everything if the gadget was not pressed */
        if( Pressed != g ) return( ev );
        length = g->end - g->start - 1;
        /* don't send pagefoward followed by pagebackward, then forward */
        /* ignore non-mouse events */
        switch( ev ) {
        case EV_MOUSE_PRESS :
            StartPos = g->pos;
        case EV_MOUSE_DCLICK :
            RepeatEvent = EV_NO_EVENT;
        case EV_MOUSE_REPEAT :
            if( Drag ) {
                break;
            }
            if( m_linear == g->start ) {
                return( g->backward );
            }
            if( m_linear == g->end ) {
                return( g->forward );
            }
            /* don't do page up and page down when total size is less than
               or equal to the page size */
            if( g->total_size <= g->page_size ) break;
            start = g->linear; //CalcStart( g, g->pos, length );
            if( m_linear < start ) {
                if( RepeatEvent == g->pageforward ) {
                    return( EV_NO_EVENT );
                } else {
                    RepeatEvent = g->pagebackward;
                    return( g->pagebackward );
                }
            }
            if( m_linear > start ) {
                if( RepeatEvent == g->pagebackward ) {
                    return( EV_NO_EVENT );
                } else {
                    RepeatEvent = g->pageforward;
                    return( g->pageforward );
                }
            }
            break;
        case EV_MOUSE_DRAG :
            /* don't do draging if total_size is less than or equal to the
               page size or mouse is too far from gadget */
            if( ( m_anchor < ( g->anchor -1 ) ) || ( m_anchor > (g->anchor+1) ) ||
                ( g->total_size <= g->page_size ) ) {
                return( EV_NO_EVENT );
            } else {
                Drag = TRUE; /* so we don't send page events on MOUSE_REPEAT */
                if( g->slider == EV_NO_EVENT ) {
                    return( EV_NO_EVENT );
                }
            }
        case EV_MOUSE_RELEASE :
            if( Pressed == NULL ) {
                break;
            }
            if( g->slider == EV_NO_EVENT ) {
                Drag = FALSE;
            }
            if( Drag ) {
                if( ( m_anchor < ( g->anchor -1 ) ) || ( m_anchor > (g->anchor+1) ) ) {
                    /* note : must have got EV_MOUSE_RELEASE */
                    pos = StartPos;
                    setgadget( g, pos, FALSE );
                    m_linear = g->linear;
                    Drag = FALSE;
                } else {
                    /* mouse drag to first scroll character or further left,
                       so pos = 0 */
                    if( m_linear <= ( g->start + 1 ) ) {
                        m_linear = g->start + 1;
                        pos = 0;
                    } else {
                        /* mouse drag to last scroll character or further right,
                           so pos = total_size */
                        if( m_linear >= ( g->end - 1 ) ) {
                            m_linear = g->end - 1;
                            pos = g->total_size - g->page_size;
                         } else {
                            pos = (int)((long)( m_linear - g->start ) *
                                        (long)( g->total_size - g->page_size ) /
                                        (long)length);
                         }
                    }
                }
                g->linear = m_linear;
                uidrawgadget( g );
            }
            if( ( ev == EV_MOUSE_RELEASE ) || ( g->flags & GADGET_TRACK ) ) {
                if( Drag ) {
                    StartPos = pos;
                    g->pos = pos;
                    g->linear = m_linear;
                    setlinear( g );
                    if( g->linear < m_linear ) {
                        g->pos++;
                        setlinear( g );
                    }
                    if( g->linear > m_linear ) {
                        g->pos--;
                        setlinear( g );
                    }
                    newev = g->slider;
                } else {
                    newev = EV_NO_EVENT;
                }
                if( ev == EV_MOUSE_RELEASE ) {
                    Drag = FALSE;
                    Pressed = NULL;
                }
            } else {
                newev = EV_NO_EVENT;
            }
            return( newev );
        case EV_MOUSE_HOLD :
            break;
        default :
            return( ev );
        }
    } else {
        return( ev );
    }
    return( EV_NO_EVENT );
}
Esempio n. 2
0
bool GUIProcessEvent( EVENT ev )
{
    gui_event   gui_ev;
    ORD         row, col;
    gui_window  *wnd;
    int         prev;
    int         diff;
    gui_ctl_id  id;
    gui_window  *menu_window;
    bool        new_curr_wnd;
    VSCREEN     *screen;

    // this is processed before all others and signals the end for all
    // GUI UI windows ( unconditional )
    if( ev == EV_KILL_UI ) {
        GUIDestroyWnd( NULL );
        return( false );
    }

    ev = MapMiddleToRight( ev );
    ev = CheckPrevEvent( ev );
    wnd = NULL;
    if( uimouseinstalled() ) {
        screen = uivmousepos( NULL, &row, &col );
        if( screen != NULL && (screen->flags & V_GUI_WINDOW) != 0 ) {
            wnd = (gui_window *)((char *)screen - offsetof( gui_window, screen ));
        }
    }
    if( GUIDoKeyboardMoveResize( ev ) ) {
        return( true );
    }
    if( MouseState == MOUSE_MOVE || MouseState == MOUSE_SIZE ) {
        if( GUIDoMoveResizeCheck( GUIMouseWnd, ev, row, col ) ) {
            MouseState = MOUSE_FREE;
            return( true );
        }
        if( GUI_WND_MINIMIZED( GUIMouseWnd ) ) {
            switch( ev ) {
            case EV_MOUSE_DCLICK :
            case EV_MOUSE_RELEASE :
            case EV_MOUSE_DRAG :
                ProcessMinimizedMouseEvent( ev, row, col );
            }
        } else {
            switch( ev ) {
            case EV_MOUSE_RELEASE :
            case EV_MOUSE_DRAG :
            case EV_MOUSE_DRAG_R :
                ProcessMouseReleaseDrag( ev, GUI_LBUTTONUP, row, col );
            }
        }
        return( true );
    }
    new_curr_wnd = SetCurrWnd( ev, wnd );
    if( GUIProcessAltMenuEvent( ev ) ) {
        return( true );
    }
    /* Only deal with press and dclick events for minimized windows.
     * All other non-menu events are ingored.
     */
    if( !IS_CTLEVENT( ev ) && ( GUICurrWnd != NULL ) && GUI_WND_MINIMIZED( GUICurrWnd ) ) {
        /* ignore event if mouse not in minimized current window */
        if( GUICurrWnd == wnd ) {
            switch( ev ) {
            case EV_MOUSE_PRESS :
            case EV_MOUSE_DCLICK :
            case EV_MOUSE_RELEASE :
                GUIMouseWnd = GUICurrWnd;
                ProcessMinimizedMouseEvent( ev, row, col );
                break;
            }
        }
        return( true );
    }
    if( !IS_CTLEVENT( ev ) && ( GUICurrWnd != NULL ) && GUIIsOpen( GUICurrWnd ) ) {
        /* see if any of the controls in the window consume the event */
        ev = GUIProcessControlEvent( GUICurrWnd, ev, row, col );
        /* See if the event is for on of the scroll bars. */
        /* Diff and prev are used if the event return is  */
        /* EV_SCROLL_HORIZONTAL or EV_SCROLL_VERTICAL.    */
        if( !new_curr_wnd || ( GUIGetWindowStyles() & ( GUI_INACT_GADGETS+GUI_INACT_SAME ) ) ) {
            ev = GUIGadgetFilter( GUICurrWnd, ev, &prev, &diff );
        }
        if( ev == EV_NO_EVENT ) {
            return( true );
        }
    }
    gui_ev = GUI_NO_EVENT;
    ev = GUIMapKeys( ev );
    switch( ev ) {
    case EV_MOUSE_DCLICK_R :
        ProcessMousePos( GUI_RBUTTONDBLCLK, row, col, wnd );
        return( true );
        break;
    case EV_MOUSE_RELEASE_R :
        ProcessMouseReleaseDrag( ev, GUI_RBUTTONUP, row, col );
        return( true );
        break;
    case EV_MOUSE_DRAG_R :
        if( GUICurrWnd != GUIMouseWnd ) {
            /* got drag without press first */
            ProcessMousePress( EV_MOUSE_PRESS_R, GUI_LBUTTONDOWN, row, col,
                               new_curr_wnd );
        }
    case EV_MOUSE_MOVE :
        ProcessMousePos( GUI_MOUSEMOVE, row, col, wnd );
        return( true );
        break;
    case EV_MOUSE_RELEASE :
        ProcessMouseReleaseDrag( ev, GUI_LBUTTONUP, row, col );
        return( true );
        break;
    case EV_MOUSE_DRAG :
        if( GUICurrWnd != GUIMouseWnd ) {
            /* got drag without press first */
            ProcessMousePress( EV_MOUSE_PRESS, GUI_LBUTTONDOWN, row, col,
                               new_curr_wnd );
        }
        ProcessMouseReleaseDrag( ev, GUI_MOUSEMOVE, row, col );
        return( true );
        break;
    case EV_MOUSE_PRESS_R :
        ProcessMousePress( ev, GUI_RBUTTONDOWN, row, col, new_curr_wnd );
        return( true );
        break;
    case EV_MOUSE_PRESS :
        ProcessMousePress( ev, GUI_LBUTTONDOWN, row, col, new_curr_wnd );
        return( true );
        break;
    case EV_MOUSE_DCLICK :
        ProcessMousePress( ev, GUI_LBUTTONDBLCLK, row, col, new_curr_wnd );
        return( true );
        break;
    case EV_NO_EVENT :
        gui_ev = GUI_NO_EVENT;
        break;
    case EV_SCROLL_UP :
    case EV_SCROLL_DOWN :
    case EV_SCROLL_PAGE_UP :
    case EV_SCROLL_PAGE_DOWN :
    case EV_SCROLL_LEFT :
    case EV_SCROLL_RIGHT :
    case EV_SCROLL_LEFT_PAGE :
    case EV_SCROLL_RIGHT_PAGE :
        if( GUICurrWnd != NULL ) {
            ProcessScrollEvent( ev );
            return( true );
        }
        break;
    case EV_SCROLL_VERTICAL :
        if( GUI_VSCROLL_EVENTS_SET( GUICurrWnd ) ) {
            DoScrollDrag( GUICurrWnd->vgadget, prev, diff );
        } else {
            GUIWholeWndDirty( GUICurrWnd );
        }
        return( true );
        break;
    case EV_SCROLL_HORIZONTAL :
        if( GUI_HSCROLL_EVENTS_SET( GUICurrWnd ) ) {
            DoScrollDrag( GUICurrWnd->hgadget, prev, diff );
        } else {
            GUIWholeWndDirty( GUICurrWnd );
        }
        return( true );
        break;
    case EV_MENU_INITPOPUP :
        ProcessInitPopupEvent();
        return( true );
        break;
#if 0
    case EV_BACKGROUND_RESIZE :
        {
            gui_window          *root;
            root = GUIGetRootWindow();
            if( root != NULL ) {
                GUIZoomWnd( root, GUI_NONE );
            }
        }
        return( true );
        break;
#endif
    default :
        if( IS_CTLEVENT( ev ) ) {
            if( !GUIMDIProcessEvent( ev ) ) {
                menu_window = GUIGetMenuWindow();
                if( menu_window != NULL ) {
                    id = EV2ID( ev );
                    GUIEVENTWND( menu_window, GUI_CLICKED, &id );
                }
            }
            return( true );
        }
        break;
    }
    if( ( GUICurrWnd != NULL ) && (gui_ev != GUI_NO_EVENT ) ) {
        GUIEVENTWND( GUICurrWnd, gui_ev, NULL );
    }
    return( true );
}