gui_event.hpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:10k
- /*
- * ===========================================================================
- * PRODUCTION $Log: gui_event.hpp,v $
- * PRODUCTION Revision 1000.2 2004/06/01 19:51:12 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6
- * PRODUCTION
- * ===========================================================================
- */
- #ifndef GUI_CORE___GUI_EVENT__HPP
- #define GUI_CORE___GUI_EVENT__HPP
- /* $Id: gui_event.hpp,v 1000.2 2004/06/01 19:51:12 gouriano Exp $
- * ===========================================================================
- *
- * PUBLIC DOMAIN NOTICE
- * National Center for Biotechnology Information
- *
- * This software/database is a "United States Government Work" under the
- * terms of the United States Copyright Act. It was written as part of
- * the author's official duties as a United States Government employee and
- * thus cannot be copyrighted. This software/database is freely available
- * to the public for use. The National Library of Medicine and the U.S.
- * Government have not placed any restriction on its use or reproduction.
- *
- * Although all reasonable efforts have been taken to ensure the accuracy
- * and reliability of the software and data, the NLM and the U.S.
- * Government do not and cannot warrant the performance or results that
- * may be obtained by using this software or data. The NLM and the U.S.
- * Government disclaim all warranties, express or implied, including
- * warranties of performance, merchantability or fitness for any particular
- * purpose.
- *
- * Please cite the author in any work or product based on this material.
- *
- * ===========================================================================
- *
- * Authors: Andrey Yazhuk
- *
- * File Description:
- */
- #include <corelib/ncbiobj.hpp>
- #include <gui/gui.hpp>
- #include <map>
- #include <vector>
- #include <set>
- /** @addtogroup GUI_UTILS
- *
- * @{
- */
- BEGIN_NCBI_SCOPE
- class NCBI_GUIUTILS_EXPORT CFltkEvent
- {
- public:
- // enumerated flags for events
- enum FEventFlags {
- fLeftMouse = 0x0001,
- fMiddleMouse = 0x0002,
- fRightMouse = 0x0004,
- fShift = 0x0008,
- fCtrl = 0x0010,
- fAlt = 0x0020,
- fMeta = 0x0040,
- fDoubleClick = 0x0080,
- fShiftLeftMouse = (fShift | fLeftMouse),
- fShiftMiddleMouse = (fShift | fMiddleMouse),
- fShiftRightMouse = (fShift | fRightMouse),
- fCtrlLeftMouse = (fCtrl | fLeftMouse),
- fCtrlMiddleMouse = (fCtrl | fMiddleMouse),
- fCtrlRightMouse = (fCtrl | fRightMouse),
- fAltLeftMouse = (fAlt | fLeftMouse),
- fAltMiddleMouse = (fAlt | fMiddleMouse),
- fAltRightMouse = (fAlt | fRightMouse),
- fMetaLeftMouse = (fMeta | fLeftMouse),
- fMetaMiddleMouse = (fMeta | fMiddleMouse),
- fMetaRightMouse = (fMeta | fRightMouse)
- };
- typedef int TEvent; // bitmask of FEvent
- // enumerated states for processed events
- enum EEvent {
- eNoState,
- eSelectState,
- eMultiSelectState,
- ePopupState,
- eRotateState,
- eZoomState,
- ePanState
- };
- // Access the current event state.
- // This is a composed and processed listing of the current states as
- // reported by FLTK. This function is provided as a convenience for
- // standardizing forms of interaction as well as for better use in switch()
- // statements.
- static TEvent GetEvent (void);
- static EEvent GetProcessedEvent(void);
- // Accessors to remap the current event states.
- // These are guaranteed (internally) to be unique and consistent. True is
- // returned if the state was successfully set.
- static void SetState(EEvent, TEvent);
- static TEvent GetState(EEvent);
- // Set up a standard set of OS-dependent mouse bindings.
- // Here we hide some of the complexity of dealing with OSs that support
- // odd-numbered buttons (i.e., MacOS = 1, Windows = 2, Unix = 3 button
- // mice).
- static void SetOSDefaults(void);
- private:
- // cache of user-remappable event states
- typedef map<TEvent, EEvent> TEventMap;
- static TEventMap sm_EventMap;
- };
- /// CGUIEvent provides mapping of FLTK events to Semantic Events.
- ///
- /// Goals:
- /// 1. To isolate programs from the complexities of platform-dependent bindings of
- /// mouse and keyboard events to Actions.
- /// 2. To simplify event handling in programs by mapping multiple FLTK events to
- /// a single Semantic Event (for instance 'Ctrl'+C and 'Ctrl'+'Ins' - > eCopy)
- /// 3. To provide uniform and consistent mapping of Events to Actions controlled
- /// in one place.
- /// 4. To provide workarounds for some deficiencies of FLTK event handling system.
- ///
- /// CGUIEvent support two type of Semantic Events - mouse events and shortcuts.
- /// Both types of events may emit Signals depending on the current state of modifiers
- /// , however, there is a significant difference in a way mapping is declared.
- ///
- /// States for mouse events are explicintly declared and registered in CGUIEvent using
- /// RegisterState() function. Then it is possible to bind a Signal to a particular mouse
- /// Event depending on the current State. States for mouse events represent different
- /// GUI modes, user enter a mode by pressing a combination of modifier keys and remains
- /// in this mode by holding the keys pressed.
- ///
- /// Shortcuts also depend on pressed modifiers, but defining Shortcuts does not require
- /// registering special states. RegisterShortcut() function takes a combination of
- /// modifiers and an action key. If action key is pressed while specified combination of
- /// modifiers is being hold - CGUIEvent generates a Signal corresponding to shortcut.
- /// Handling shortcuts does not change current state and so do not interfere with handling
- /// of mouse events.
- class NCBI_GUIUTILS_EXPORT CGUIEvent
- {
- public:
- enum EModifierFlags {
- fShift = 0x0001,
- fCtrl = 0x0002,
- fAlt = 0x0004,
- fMeta = 0x0008,
- fModifiersMask = fShift | fCtrl | fAlt | fMeta
- };
- enum EMouseEvent {
- eNone,
- eMouseMove,
- eLeftMousePush,
- eLeftMouseDrag,
- eLeftMouseRelease,
- eMiddleMousePush,
- eMiddleMouseDrag,
- eMiddleMouseRelease,
- eRightMousePush,
- eRightMouseDrag,
- eRightMouseRelease
- };
- enum EGUIState {
- // default state
- eDefaultState,
- // selection states
- eSelectState,
- eSelectIncState,
- eSelectExtState,
- eSelectAltState,
- eSelectAllState,
- // mouse-mediated states (in general)
- ePopupState,
- eZoomState,
- ePanState,
- eZoomRectState,
- eMarkState,
- // cut/copy/paste
- eCopyState,
- ePasteState,
- eCutState,
- eUndoState,
- eRedoState,
- // delete events
- eDeleteState,
-
- // Zoom In/Out
- eInsZoomStateIn,
- eInsZoomStateOut,
-
- // Lense zoom state
- eLensZoomState,
- };
- enum EGUISignal {
- eDefaultSignal = 0,
- eSelectSignal,
- ePopupSignal,
- ePush,
- eDrag,
- eRelease,
- eMenuActivateSignal,
- eZoomInSignal,
- eZoomOutSignal,
- eZoomAllSignal
- };
- public:
- CGUIEvent();
- void OnFLTKEvent(int event);
-
- EGUIState GetGUIState() const;
- EGUISignal GetGUISignal() const;
- /// return FLTK event identifier
- int GetFLTKEvent() const;
-
- /// registers State for mouse event
- void RegisterState(EGUIState state, int mod_flags, int key);
- /// registers Signal for mouse events
- void RegisterSignal(EGUISignal signal, EGUIState state, EMouseEvent event);
- /// register keyboard shortcut
- void RegisterShortcut(EGUISignal signal, int mod_flags, int key);
- /// Registers default states and signals with proper OS-dependen bindings
- void StandardConfig();
- int GetAccelByEvent();
- protected:
- typedef int TModTemplate;
- typedef int TEventTemplate; /// template for mouse events
- typedef int TShortcutTemplate; /// template for shortcuts
- typedef map<TModTemplate, EGUIState> TTemplToState;
- typedef map<TEventTemplate, EGUISignal> TTemplToSignal;
- typedef map<TShortcutTemplate, EGUISignal> TTemplToShortcut;
- void x_UpdateEventState();
- void x_OnKeyPressed();
- void x_OnKeyReleased();
-
- TModTemplate x_EncodeModTemplate(int mod_flags, int key) const;
- TEventTemplate x_EncodeEventTemplate(EGUIState state, EMouseEvent event) const;
-
- TModTemplate x_EncodeShortcutTemplate(int mod_flags, int key) const;
-
- protected:
- typedef set<int> TKeySet;
- TKeySet m_stPressedKeys;
- int m_LastFLTKEvent;
- int m_Modifiers;
- EMouseEvent m_MouseEvent;
-
- TTemplToState m_TemplToState;
- TTemplToSignal m_TemplToSignal; // Mouse Event template -> Mouse Event signal
-
- TTemplToShortcut m_TemplToShortcut; // Shortcut template -> Shortcut signal
-
- EGUIState m_GUIState;
- EGUISignal m_GUISignal;
-
- };
- END_NCBI_SCOPE
- /* @} */
- /*
- * ===========================================================================
- * $Log: gui_event.hpp,v $
- * Revision 1000.2 2004/06/01 19:51:12 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6
- *
- * Revision 1.6 2004/05/13 17:17:58 yazhuk
- * Added support for accelerators
- *
- * Revision 1.5 2004/05/03 12:41:09 dicuccio
- * Split library into gui_utils and gui_objutils. Added #include for gui/gui.hpp
- *
- * Revision 1.4 2004/04/16 14:27:17 dicuccio
- * Added doxygen module tag
- *
- * Revision 1.3 2004/04/05 14:39:16 yazhuk
- * Implemented support for Shortcuts
- *
- * Revision 1.2 2004/03/23 13:35:33 dicuccio
- * Added new state (eDeleteState)
- *
- * Revision 1.1 2004/03/17 19:50:38 yazhuk
- * Moved from fltk_utils.hpp
- *
- * ===========================================================================
- */
- #endif // GUI_CORE___GUI_EVENT__HPP