00001 /* AbiSource Program Utilities 00002 * Copyright (C) 1998 AbiSource, Inc. 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00017 * 02110-1301 USA. 00018 */ 00019 00020 00021 00022 00023 #ifndef EV_EDITEVENTMAPPER_H 00024 #define EV_EDITEVENTMAPPER_H 00025 00026 /**************************************************************** 00027 ***************************************************************** 00028 ** EditEventMapper, EditBinding, and EditMethod form the basis for 00029 ** all editing operations. All keystrokes and mouse events 00030 ** are directed thru here. These are 00031 ** defined as classes outside of the document so that we may switch 00032 ** between different implementations as we want. 00033 ** 00034 ** EditEventMapper is in charge. It receives each event, applies 00035 ** any policy decisions, and then uses the EditBindings to decide 00036 ** what to do. (An example policy decision might be whether or 00037 ** not to do sticky-control and -shift keys for one-handed users; 00038 ** we may have 2 different implementations of EditEventMapper -- 00039 ** a normal one and a sticky one, for example. (Another policy 00040 ** decision might be whether or not to support Control- and 00041 ** Shift- toolbar events.) 00042 ** 00043 ** EditBindings provides an emacs-like single/multiple key/event 00044 ** sequence to action mapping. Each EditBinding table provides 00045 ** a mapping from a single event (key, mouse, etc.) to an action. 00046 ** If the action maps to a EditMethod, the key/event sequence is 00047 ** considered complete and the indicated EditMethod is returned 00048 ** to allow the caller to invoke it. If the action maps to another 00049 ** EditBinding table, the key/event sequence is considered to be 00050 ** a prefix to a longer sequence; in this case, the EditEventMapper 00051 ** updates it state and waits for the next key/event. We can 00052 ** think of these EditBinding tables as forming a tree. 00053 ** 00054 ** An EditMethod (and EditMethodContainer) provides a handle to 00055 ** a specific editing operation (such as InsertCharacter, NextLine, 00056 ** etc). The EditMethodContainer should contain a static set of 00057 ** builtin methods and a set of dynamically created ones (dare 00058 ** I say JavaScript macros). Provision has been made to allow 00059 ** the implementation of the static methods to be switched based 00060 ** upon user language or some other criteria; this allows us to 00061 ** define multiple sets of the basic primitives, in case we want 00062 ** to simplify the selection of various WordProcessor emmulations 00063 ** or language quirks. For example, does NextWord() go to the 00064 ** first whitespace at the end of the current word or go to the 00065 ** beginning of the next word and for those languages which don't 00066 ** use whitespace, where does it go or is it even defined. 00067 ** 00068 ** The EditEventMapper may have more than one set of EditBinding 00069 ** trees -- much like emacs's global bindings and mode bindings. 00070 ** A key/event sequence will searched for in the mode bindings 00071 ** and then in the global bindings. 00072 ** 00073 ** The EditEventMapper returns the EditMethod rather than invoking 00074 ** it directly. This allows our caller to query the EditMethod 00075 ** for it's properties (such as a short description for the 00076 ** status bar when the menu item is highlighted). 00077 ** 00078 ** The EditEventMapper has seperate event methods for keystrokes, 00079 ** and mouse operations. 00080 ** 00081 ** Keystroke Events: 00082 ** 00083 ** Mouse Events: 00084 ** Mouse buttons are numbered from 1 to n. It is upto the GUI/OS 00085 ** to decide which physical button is mapped to 1 and which to n. 00086 ** 00087 ** Keyboard modifiers are respected. 00088 ** 00089 ** Depending upon the GUI, a Double click may also generate Single 00090 ** (and Double) click and release events, so be aware. 00091 ** 00092 ** A drag is processed as a sequence of mouse movements. 00093 ** The quantity and granularity of the movement is GUI/OS 00094 ** dependent; we will simply map each of them as we see 00095 ** them. We allow the keyboard modifiers to change during 00096 ** the drag, so the mapping may change between successive 00097 ** drag events. Again, be aware. 00098 ** 00099 ** We do not attempt to support sequences where a second 00100 ** mouse button is pressed during a drag (while the first 00101 ** mouse button is still down). 00102 ** 00103 ** We now support mouse events for button-up-motion events. 00104 ** (These are primarily used for context cursors.) 00105 ** 00106 ** We now suport the notion of mouse contexts. 00107 ** 00108 ** TODO Question: If another event (keystroke, mouse click) 00109 ** TODO occurs during a drag, do we: 00110 ** TODO (1) end the drag with or without issuing an 00111 ** TODO implicit release and then process the new 00112 ** TODO event (and ignore the eventual actual 00113 ** TODO release), or 00114 ** TODO (2) ignore the new event and keep the 00115 ** TODO drag active until the actual release, or 00116 ** TODO (3) ?? 00117 ** 00118 ** 00119 ** TODO Question: Should Menus and Toolbars recognize keyboard 00120 ** TODO modifiers (control, shift, etc) like keystroke 00121 ** TODO and mouse events ?? 00122 ** 00123 ** TODO Question: Should we distinguish between left- and right-versions 00124 ** TODO of SHFIT, CONTROL, ALT, etc ?? 00125 ** 00126 ****************************************************************** 00127 *****************************************************************/ 00128 00129 #include "ut_types.h" 00130 #include "ev_EditBits.h" 00131 #include "ev_EditMethod.h" 00132 00133 typedef UT_uint32 EV_EditEventMapperResult; 00134 #define EV_EEMR_BOGUS_START ((EV_EditEventMapperResult) 1) /* start of unknown event sequence */ 00135 #define EV_EEMR_BOGUS_CONT ((EV_EditEventMapperResult) 2) /* unknown continuation event sequence */ 00136 #define EV_EEMR_INCOMPLETE ((EV_EditEventMapperResult) 3) /* accumulating valid prefix */ 00137 #define EV_EEMR_COMPLETE ((EV_EditEventMapperResult) 4) /* complete sequence */ 00138 00139 /****************************************************************/ 00140 00141 // fwd. decl. 00142 class EV_EditBindingMap; 00143 00144 /****************************************************************/ 00145 00146 class ABI_EXPORT EV_EditEventMapper 00147 { 00148 public: 00149 EV_EditEventMapper(EV_EditBindingMap * pebm); 00150 00151 EV_EditEventMapperResult Keystroke(EV_EditBits eb, EV_EditMethod ** ppEM); 00152 EV_EditEventMapperResult Mouse(EV_EditBits eb, EV_EditMethod ** ppEM); 00153 00154 const char * getShortcutFor(const EV_EditMethod * pEM) const; 00155 00156 protected: 00157 EV_EditBindingMap * m_pebmTopLevel; 00158 EV_EditBindingMap * m_pebmInProgress; 00159 }; 00160 00161 #endif /* EV_EDITEVENTMAPPER_H */