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. */
19 #include <xview/xview.h>
20 #include <xview/frame.h>
21 #include <xview/panel.h>
32 extern Frame menubarframe
;
33 int menubar_visible
= 1; /* We do not use this */
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
,
42 /* is_right = strcmp ((char *) xv_get (menu, XV_KEY_DATA, MENU_CLIENT_DATA),
45 xv_post_proc (midnight_dlg
, callback
, NULL
);
48 Menu
create_menu (char *name
, menu_entry
*entries
, int count
)
53 menu
= (Menu
) xv_create ((Frame
)NULL
, MENU
,
54 MENU_CLIENT_DATA
, name
,
56 for (i
= 0; i
< count
; i
++)
57 if (*(entries
[i
].text
))
60 MENU_STRING
, entries
[i
].text
,
61 MENU_NOTIFY_PROC
, menu_notify_proc
,
62 MENU_CLIENT_DATA
, entries
[i
].call_back
,
75 void destroy_menu (Menu menu
)
81 void menu_done_proc (Frame frame
)
83 xv_post_proc (midnight_dlg
, (void (*)(void *))quit_cmd
, NULL
);
86 int create_menubar (WMenu
*menubar
)
92 menubarframe
= (Frame
) xv_create (mcframe
, FRAME
,
97 FRAME_LABEL
, "The Midnight X Commander",
98 FRAME_SHOW_FOOTER
, FALSE
,
99 FRAME_DONE_PROC
, menu_done_proc
,
102 menubarpanel
= (Panel
) xv_create (menubarframe
, PANEL
,
103 PANEL_LAYOUT
, PANEL_HORIZONTAL
,
106 for (i
= 0; i
< menubar
->items
; i
++)
107 xv_create (menubarpanel
, PANEL_BUTTON
,
109 xv_get (menubar
->menu
[i
],
112 PANEL_ITEM_MENU
, menubar
->menu
[i
],
114 window_fit (menubarpanel
);
115 window_fit (menubarframe
);
116 xv_set (menubarframe
,
119 menubar
->widget
.wdata
= (widget_data
) menubarframe
;
123 static int menubar_callback (Dlg_head
*h
, WMenu
*menubar
, int msg
, int par
)
126 case WIDGET_INIT
: return create_menubar (menubar
);
128 return default_proc (h
, msg
, par
);
131 int menubar_event (Gpm_Event
*event
, WMenu
*menubar
)
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
;
151 menubar
->dropped
= 0;
152 menubar
->items
= items
;
153 menubar
->selected
= 0;
154 widget_want_cursor (menubar
->widget
, 0);