tkmenu.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* Midnight Commander/Tk: Pulldown menu code.
  2. Copyright (C) 1995 Miguel de Icaza
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  14. #include <config.h>
  15. #include <string.h>
  16. #include <malloc.h>
  17. #include "main.h"
  18. #include "tkmain.h"
  19. #include "mad.h"
  20. #include "menu.h"
  21. /* Unused but required by the rest of the code */
  22. int menubar_visible = 1;
  23. static int
  24. tkmenu_callback (ClientData cd, Tcl_Interp *interp,
  25. int argc, char *argv [])
  26. {
  27. callfn callback = (callfn) cd;
  28. is_right = (argv [1][0] != '1');
  29. (*callback)();
  30. return TCL_OK;
  31. }
  32. /* We assume that menu titles are only one word length */
  33. Menu create_menu (char *name, menu_entry *entries, int count)
  34. {
  35. int i;
  36. char *xname = strdup (name), *p;
  37. static int menu_number;
  38. /* Lower case string, Tk requires this */
  39. for (p = xname; *p; p++){
  40. if (*p < 'a')
  41. *p |= 0x20;
  42. }
  43. /* And strip trailing space */
  44. *(p-1) = 0;
  45. /* Strip leading space */
  46. for (p = xname; *p == ' '; p++)
  47. ;
  48. menu_number++;
  49. tk_evalf ("create_menu %s %s", name, p);
  50. for (i = 0; i < count; i++){
  51. if (entries [i].text [0]){
  52. char cmd_name [20];
  53. sprintf (cmd_name, "m%d%s", i, p);
  54. Tcl_CreateCommand (interp, cmd_name, tkmenu_callback,
  55. entries [i].call_back, NULL);
  56. tk_evalf ("create_mentry %s {%s } %s %d", p, entries [i].text,
  57. cmd_name, menu_number);
  58. } else
  59. tk_evalf ("add_separator %s", xname);
  60. }
  61. free (xname);
  62. return 0;
  63. }
  64. static int menubar_callback (Dlg_head *h, WMenu *menubar, int msg, int par)
  65. {
  66. if (msg == WIDGET_FOCUS)
  67. return 0;
  68. return default_proc (h, msg, par);
  69. }
  70. int menubar_event (Gpm_Event *event, WMenu *menubar)
  71. {
  72. return MOU_NORMAL;
  73. }
  74. static void menubar_destroy (WMenu *menubar)
  75. {
  76. /* nothing yet */
  77. }
  78. WMenu *menubar_new (int y, int x, int cols, Menu menu [], int items)
  79. {
  80. WMenu *menubar = (WMenu *) xmalloc (sizeof (WMenu), "menubar_new");
  81. init_widget (&menubar->widget, y, x, 1, cols,
  82. (callback_fn) menubar_callback,
  83. (destroy_fn) menubar_destroy,
  84. (mouse_h) menubar_event, NULL);
  85. menubar->menu = menu;
  86. menubar->active = 0;
  87. menubar->dropped = 0;
  88. menubar->items = items;
  89. menubar->selected = 0;
  90. widget_want_cursor (menubar->widget, 0);
  91. return menubar;
  92. }
  93. void
  94. menubar_arrange (WMenu* menubar)
  95. {
  96. /* nothing to do I think (Norbert) */
  97. }
  98. void
  99. destroy_menu (Menu menu)
  100. {
  101. /* FIXME: need to implement? (Norbert) */
  102. }