File: curseskeyhandler.H

package info (click to toggle)
cone 0.89-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 25,628 kB
  • ctags: 14,171
  • sloc: ansic: 85,400; cpp: 82,903; sh: 11,713; makefile: 1,732; perl: 832; yacc: 291; sed: 16
file content (79 lines) | stat: -rw-r--r-- 2,486 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
** Copyright 2002, Double Precision Inc.
**
** See COPYING for distribution information.
*/

#ifndef curseskeyhandler_H
#define curseskeyhandler_H

#include <list>

#include "mycurses.H"

#define PRI_STATUSOVERRIDEHANDLER -4	// Override even the status line
#define PRI_STATUSHANDLER -3		// Status line
#define PRI_DIALOGHANDLER -2		// Dialog
#define PRI_PRISCREENHANDLER -1		// Normal screenwide handler,
					// but prior to any focus handling
#define PRI_SCREENHANDLER 0		// Normal screenwide handler
#define PRI_DEFAULTCTRLCHANDLER 1	// CTRL-C handler

/////////////////////////////////////////////////////////////////////////////
//
// A list of prioritized key handlers.  CursesKeyHandler objects are created
// whenever a function key shortcut should be used.  Each CursesKeyHandler
// defines a processKey() method that returns true if it has processed the
// received key input.  The object should also implement listKeys(), to append
// a list of keys it handles to the list argument.
//
// Each key handler has a defined priority. The handle() method runs
// the processKey method of all defined handlers, in priority order, until
// processKey returns true.
// The processKeyInFocus method of the specified Curses object may be called
// (if focus is not NULL), in the event that no key handler with a negative
// priority processed the key (and if processKeyInFocus also doesn't handle
// the key, any remaining non-negative keyhandlers are given a crack at this).

class CursesKeyHandler {

	int priority;

public:
	CursesKeyHandler(int priorityArg);
	virtual ~CursesKeyHandler();

	static bool handle(const Curses::Key &key, Curses *focus);
	// Returns true if the key was consumed.

protected:
	virtual bool processKey(const Curses::Key &key)=0;

	// Key handlers should subclass this and enumerate all the keys
	// they handle.  <key name, description> should be added to list.
	// Subclass should return true to ignore the rest of keyhandlers.
public:
	virtual bool listKeys( std::vector< std::pair<std::string,
			       std::string> > &list);

private:
	static std::list<CursesKeyHandler *> handlers;

public:
	static std::list<CursesKeyHandler *>::const_iterator begin()
	{
		return handlers.begin();
	}

	static std::list<CursesKeyHandler *>::const_iterator end()
	{
		return handlers.end();
	}

	static bool handlerListModified;
	// Reset to true each time a handler is added or removed, used to
	// indicate when the status line should be redrawn

};

#endif