bindings.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * dselect - Debian package maintenance user interface
  3. * bindings.h - keybindings class header file
  4. *
  5. * Copyright © 1994,1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
  6. *
  7. * This is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. #ifndef BINDINGS_H
  21. #define BINDINGS_H
  22. struct keybindings {
  23. struct interpretation;
  24. struct orgbinding {
  25. int key;
  26. const char *action;
  27. };
  28. struct keyname {
  29. int key;
  30. const char *kname;
  31. };
  32. struct description {
  33. const char *action, *desc;
  34. };
  35. struct binding {
  36. binding *next;
  37. int key;
  38. const struct interpretation *interp;
  39. const char *desc;
  40. };
  41. private:
  42. static const keyname keynames[];
  43. static const description descriptions[];
  44. binding *bindings;
  45. const description *iterate;
  46. const interpretation *interps;
  47. bool bind(int key, const char *action);
  48. public:
  49. int name2key(const char *name);
  50. const char *key2name(int key);
  51. bool bind(const char *name, const char *action)
  52. { return bind(name2key(name), action); }
  53. const interpretation *operator()(int key);
  54. const char *find(const char *action);
  55. void describestart() { iterate=descriptions; }
  56. const char **describenext();
  57. //... returns array, null-term, first element is description, rest are key strings
  58. // caller must delete[] the array. Null means end.
  59. keybindings(const interpretation *ints, const orgbinding *orgbindings);
  60. ~keybindings();
  61. };
  62. #include "pkglist.h"
  63. #include "method.h"
  64. struct keybindings::interpretation {
  65. const char *action;
  66. void (methodlist::*mfn)();
  67. void (packagelist::*pfn)();
  68. quitaction qa;
  69. };
  70. extern const keybindings::interpretation packagelist_kinterps[];
  71. extern const keybindings::orgbinding packagelist_korgbindings[];
  72. extern const keybindings::interpretation methodlist_kinterps[];
  73. extern const keybindings::orgbinding methodlist_korgbindings[];
  74. #ifndef CTRL
  75. #define CTRL(x) ((x) - 'a' + 1)
  76. #endif
  77. #endif /* BINDINGS_H */