1 #include "allincludes.h"
2 
3 W_Window
W_MakeMenu(name,x,y,width,height,parent,border)4 W_MakeMenu(name, x, y, width, height, parent, border)
5     char   *name;
6     int     x, y, width, height;
7     W_Window parent;
8     int     border;
9 {
10     return (W_Window)w_MakeWindow(name, x, y, width, height, parent,
11 			"left_ptr", border, W_White, WIN_MENU);
12 }
13 
14 static void
redrawMenuItem(win,n)15 redrawMenuItem(win, n)
16     struct window *win;
17     int     n;
18 {
19     struct menuItem *items;
20     int     addr;
21 
22     items = (struct menuItem *) win->data;
23 
24     XFillRectangle(W_Display, win->drawable,
25 		   colortable[W_Black].contexts[0],
26 	  WIN_EDGE, n * (W_Textheight + MENU_PAD * 2 + MENU_BAR) + MENU_PAD,
27 		   win->width * W_Textwidth, (unsigned)W_Textheight);
28     if (items[n].string) {
29 	addr = fonts[fontNum(items[n].font)].baseline;
30 	XDrawImageString(W_Display, win->drawable,
31 		colortable[items[n].color].contexts[fontNum(items[n].font)],
32 			 WIN_EDGE,
33 	     n * (W_Textheight + MENU_PAD * 2 + MENU_BAR) + MENU_PAD + addr,
34 			 items[n].string, (int)strlen(items[n].string));
35     }
36 }
37 
38  void
redrawMenu(win)39 redrawMenu(win)
40     struct window *win;
41 {
42     int     count;
43 
44     for (count = 1; count < win->height; count++) {
45 	XFillRectangle(W_Display, win->drawable,
46 		       colortable[W_Grey].contexts[0],
47 	  0, count * (W_Textheight + MENU_PAD * 2) + (count - 1) * MENU_BAR,
48 		       win->width * W_Textwidth + WIN_EDGE * 2, MENU_BAR);
49     }
50     for (count = 0; count < win->height; count++) {
51 	redrawMenuItem(win, count);
52     }
53 }
54 
55  void
changeMenuItem(win,n,color,str,len,font)56 changeMenuItem(win, n, color, str, len, font)
57     struct window *win;
58     int     n;
59     W_Color color;
60     char   *str;
61     int     len;
62     W_Font  font;
63 {
64     struct menuItem *items;
65     char   *news;
66 
67     items = (struct menuItem *) win->data;
68     if (items[n].string) {
69 	free(items[n].string);
70     }
71     news = malloc((unsigned)(len + 1));
72     strncpy(news, str, (unsigned)len);
73     news[len] = 0;
74     items[n].string = news;
75     items[n].color = color;
76     items[n].font = font;
77     redrawMenuItem(win, n);
78     XFlush(W_Display);
79 }
80 
81 void
W_ResizeMenu(window,neww,newh)82 W_ResizeMenu(window, neww, newh)/* TSH 2/93 */
83     W_Window window;
84     int     neww, newh;
85 {
86     W_ResizeWindow(window, neww * W_Textwidth + WIN_EDGE * 2,
87 	      newh * (W_Textheight + MENU_PAD * 2) + (newh - 1) * MENU_BAR);
88 }
89 
90