update
[midnight-commander.git] / xv / xvmenu.c
blob1d745be02f803d151a72e5a457026f6293348642
1 /* Pulldown menu code.
2 Copyright (C) 1995 Jakub Jelinek.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
18 #include <config.h>
19 #include <xview/xview.h>
20 #include <xview/frame.h>
21 #include <xview/panel.h>
23 #include <string.h>
24 #include <malloc.h>
25 #include "mad.h"
26 #include "util.h"
27 #include "menu.h"
28 #include "dialog.h"
29 #include "xvmain.h"
31 extern Frame mcframe;
32 extern Frame menubarframe;
33 int menubar_visible = 1; /* We do not use this */
34 extern int is_right;
35 extern Dlg_head *midnight_dlg;
37 static void menu_notify_proc (Menu menu, Menu_item menu_item)
39 void (*callback)(void *) = (void (*)(void *)) xv_get (menu_item,
40 MENU_CLIENT_DATA);
42 /* is_right = strcmp ((char *) xv_get (menu, XV_KEY_DATA, MENU_CLIENT_DATA),
43 "Left");*/
45 xv_post_proc (midnight_dlg, callback, NULL);
48 Menu create_menu (char *name, menu_entry *entries, int count)
50 Menu menu;
51 int i;
53 menu = (Menu) xv_create ((Frame)NULL, MENU,
54 MENU_CLIENT_DATA, name,
55 NULL);
56 for (i = 0; i < count; i++)
57 if (*(entries [i].text))
58 xv_set (menu,
59 MENU_ITEM,
60 MENU_STRING, entries [i].text,
61 MENU_NOTIFY_PROC, menu_notify_proc,
62 MENU_CLIENT_DATA, entries [i].call_back,
63 NULL,
64 NULL);
65 else
66 xv_set (menu,
67 MENU_ITEM,
68 MENU_STRING, "",
69 MENU_FEEDBACK, FALSE,
70 NULL,
71 NULL);
72 return menu;
75 void destroy_menu (Menu menu)
79 int quit_cmd (void);
81 void menu_done_proc (Frame frame)
83 xv_post_proc (midnight_dlg, (void (*)(void *))quit_cmd, NULL);
86 int create_menubar (WMenu *menubar)
88 int i;
90 Panel menubarpanel;
92 menubarframe = (Frame) xv_create (mcframe, FRAME,
93 XV_X, 10,
94 XV_Y, 10,
95 XV_WIDTH, 10000,
96 XV_HEIGHT, 300,
97 FRAME_LABEL, "The Midnight X Commander",
98 FRAME_SHOW_FOOTER, FALSE,
99 FRAME_DONE_PROC, menu_done_proc,
100 NULL);
102 menubarpanel = (Panel) xv_create (menubarframe, PANEL,
103 PANEL_LAYOUT, PANEL_HORIZONTAL,
104 NULL);
106 for (i = 0; i < menubar->items; i++)
107 xv_create (menubarpanel, PANEL_BUTTON,
108 PANEL_LABEL_STRING,
109 xv_get (menubar->menu [i],
110 MENU_CLIENT_DATA,
111 NULL),
112 PANEL_ITEM_MENU, menubar->menu [i],
113 NULL);
114 window_fit (menubarpanel);
115 window_fit (menubarframe);
116 xv_set (menubarframe,
117 XV_SHOW, TRUE,
118 NULL);
119 menubar->widget.wdata = (widget_data) menubarframe;
120 return 1;
123 static int menubar_callback (Dlg_head *h, WMenu *menubar, int msg, int par)
125 switch (msg) {
126 case WIDGET_INIT: return create_menubar (menubar);
128 return default_proc (h, msg, par);
131 int menubar_event (Gpm_Event *event, WMenu *menubar)
133 return MOU_NORMAL;
136 static void menubar_destroy (WMenu *menubar)
138 xv_destroy_safe ((Frame)(menubar->widget.wdata));
141 WMenu *menubar_new (int y, int x, int cols, Menu menu [], int items)
143 WMenu *menubar = (WMenu *) xmalloc (sizeof (WMenu), "menubar_new");
145 init_widget (&menubar->widget, y, x, 1, cols,
146 (callback_fn) menubar_callback,
147 (destroy_fn) menubar_destroy,
148 (mouse_h) menubar_event, NULL);
149 menubar->menu = menu;
150 menubar->active = 0;
151 menubar->dropped = 0;
152 menubar->items = items;
153 menubar->selected = 0;
154 widget_want_cursor (menubar->widget, 0);
156 return menubar;