1 /* 2 ** Copyright 2002, Double Precision Inc. 3 ** 4 ** See COPYING for distribution information. 5 */ 6 7 #ifndef curseskeyhandler_H 8 #define curseskeyhandler_H 9 10 #include <list> 11 12 #include "mycurses.H" 13 14 #define PRI_STATUSOVERRIDEHANDLER -4 // Override even the status line 15 #define PRI_STATUSHANDLER -3 // Status line 16 #define PRI_DIALOGHANDLER -2 // Dialog 17 #define PRI_PRISCREENHANDLER -1 // Normal screenwide handler, 18 // but prior to any focus handling 19 #define PRI_SCREENHANDLER 0 // Normal screenwide handler 20 #define PRI_DEFAULTCTRLCHANDLER 1 // CTRL-C handler 21 22 ///////////////////////////////////////////////////////////////////////////// 23 // 24 // A list of prioritized key handlers. CursesKeyHandler objects are created 25 // whenever a function key shortcut should be used. Each CursesKeyHandler 26 // defines a processKey() method that returns true if it has processed the 27 // received key input. The object should also implement listKeys(), to append 28 // a list of keys it handles to the list argument. 29 // 30 // Each key handler has a defined priority. The handle() method runs 31 // the processKey method of all defined handlers, in priority order, until 32 // processKey returns true. 33 // The processKeyInFocus method of the specified Curses object may be called 34 // (if focus is not NULL), in the event that no key handler with a negative 35 // priority processed the key (and if processKeyInFocus also doesn't handle 36 // the key, any remaining non-negative keyhandlers are given a crack at this). 37 38 class CursesKeyHandler { 39 40 int priority; 41 42 public: 43 CursesKeyHandler(int priorityArg); 44 virtual ~CursesKeyHandler(); 45 46 static bool handle(const Curses::Key &key, Curses *focus); 47 // Returns true if the key was consumed. 48 49 protected: 50 virtual bool processKey(const Curses::Key &key)=0; 51 52 // Key handlers should subclass this and enumerate all the keys 53 // they handle. <key name, description> should be added to list. 54 // Subclass should return true to ignore the rest of keyhandlers. 55 public: 56 virtual bool listKeys( std::vector< std::pair<std::string, 57 std::string> > &list); 58 59 private: 60 static std::list<CursesKeyHandler *> handlers; 61 62 public: begin()63 static std::list<CursesKeyHandler *>::const_iterator begin() 64 { 65 return handlers.begin(); 66 } 67 end()68 static std::list<CursesKeyHandler *>::const_iterator end() 69 { 70 return handlers.end(); 71 } 72 73 static bool handlerListModified; 74 // Reset to true each time a handler is added or removed, used to 75 // indicate when the status line should be redrawn 76 77 }; 78 79 #endif 80