File: tkmenu.c

package info (click to toggle)
mc 4.1.35-1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 6,924 kB
  • ctags: 9,665
  • sloc: ansic: 84,273; tcl: 1,779; makefile: 1,266; sh: 864; perl: 262; awk: 148; sed: 93; csh: 1
file content (124 lines) | stat: -rw-r--r-- 3,146 bytes parent folder | download | duplicates (2)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* Midnight Commander/Tk: Pulldown menu code.
   Copyright (C) 1995 Miguel de Icaza
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */

#include <config.h>
#include <string.h>
#include <malloc.h>
#include "main.h"
#include "tkmain.h"
#include "mad.h"
#include "menu.h"

/* Unused but required by the rest of the code */
int menubar_visible = 1;

static int
tkmenu_callback (ClientData cd, Tcl_Interp *interp,
		 int argc, char *argv [])
{
    callfn callback = (callfn) cd;

    is_right = (argv [1][0] != '1');
    (*callback)();
    return TCL_OK;
}

/* We assume that menu titles are only one word length */
Menu create_menu (char *name, menu_entry *entries, int count)
{
    int i;
    char *xname = strdup (name), *p;
    static int menu_number;
    
    /* Lower case string, Tk requires this */
    for (p = xname; *p; p++){
	if (*p < 'a')
	    *p |= 0x20;
    }
    /* And strip trailing space            */
    *(p-1) = 0;
    
    /* Strip leading space */
    for (p = xname; *p == ' '; p++)
	;

    menu_number++;
    tk_evalf ("create_menu %s %s", name, p);
    for (i = 0; i < count; i++){
	if (entries [i].text [0]){
	    char cmd_name [20];

	    sprintf (cmd_name, "m%d%s", i, p);
	    Tcl_CreateCommand (interp, cmd_name, tkmenu_callback,
	        entries [i].call_back, NULL);
	    tk_evalf ("create_mentry %s {%s } %s %d", p, entries [i].text,
		      cmd_name, menu_number);
	} else
	    tk_evalf ("add_separator %s", xname);
    }
    free (xname);
    return 0;
}

static int menubar_callback (Dlg_head *h, WMenu *menubar, int msg, int par)
{
    if (msg == WIDGET_FOCUS)
	return 0;
    
    return default_proc (h, msg, par);
}

int menubar_event (Gpm_Event *event, WMenu *menubar)
{
    return MOU_NORMAL;
}

static void menubar_destroy (WMenu *menubar)
{
    /* nothing yet */
}

WMenu *menubar_new (int y, int x, int cols, Menu menu [], int items)
{
    WMenu *menubar = (WMenu *) xmalloc (sizeof (WMenu), "menubar_new");

    init_widget (&menubar->widget, y, x, 1, cols,
                 (callback_fn) menubar_callback,
		 (destroy_fn)  menubar_destroy,
		 (mouse_h)     menubar_event, NULL);
    menubar->menu = menu;
    menubar->active = 0;
    menubar->dropped = 0;
    menubar->items = items;
    menubar->selected = 0;
    widget_want_cursor (menubar->widget, 0);
    
    return menubar;
}

void
menubar_arrange (WMenu* menubar)
{
    /* nothing to do I think (Norbert) */
}

void
destroy_menu (Menu menu)
{
    /* FIXME: need to implement? (Norbert) */
}