ui/cocoa/menu.m

changeset 541
63289f61fb7f
equal deleted inserted replaced
540:d8b86f66721c 541:63289f61fb7f
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2014 Olaf Wintermann. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #import <stdio.h>
30 #import <stdlib.h>
31 #import <string.h>
32 #import <stdarg.h>
33
34 #import "menu.h"
35 #import "window.h"
36
37 static ui_menu_add_f createMenuItem[] = {
38 /* UI_MENU */ add_menu_widget,
39 /* UI_MENU_ITEM */ add_menuitem_widget,
40 /* UI_MENU_CHECK_ITEM */ add_checkitem_widget,
41 /* UI_MENU_RADIO_ITEM */ add_radioitem_widget,
42 /* UI_MENU_ITEM_LIST */ add_menuitem_list_widget,
43 /* UI_MENU_CHECKITEM_LIST */ add_menuitem_list_widget,
44 /* UI_MENU_RADIOITEM_LIST */ add_menuitem_list_widget,
45 /* UI_MENU_SEPARATOR */ add_menuseparator_widget
46 };
47
48 static void add_menu_items(NSMenu *parent, int i, UiMenu *menu) {
49 UiMenuItemI *it = menu->items_begin;
50 int index = 0;
51 while(it) {
52 createMenuItem[it->type](parent, index, it);
53 it = it->next;
54 index++;
55 }
56 }
57
58 void add_menu_widget(NSMenu *parent, int i, UiMenuItemI *item) {
59 UiMenu *it = (UiMenu*)item;
60 NSString *str = [[NSString alloc] initWithUTF8String:it->label];
61 NSMenu *menu = [[NSMenu alloc] initWithTitle: str];
62 NSMenuItem *menuItem = [parent addItemWithTitle:str action:nil keyEquivalent:@""];
63 [parent setSubmenu:menu forItem:menuItem];
64
65 add_menu_items(menu, i, it);
66 }
67
68 void add_menuitem_widget(NSMenu *parent, int i, UiMenuItemI *item) {
69 UiMenuItem *it = (UiMenuItem*)item;
70 NSString *str = [[NSString alloc] initWithUTF8String:it->label];
71 NSMenuItem *menuItem = [parent addItemWithTitle:str action:nil keyEquivalent:@""];
72 }
73
74 void add_menuseparator_widget(NSMenu *parent, int i, UiMenuItemI *item) {
75
76 }
77
78 void add_checkitem_widget(NSMenu *parent, int i, UiMenuItemI *item) {
79
80 }
81
82 void add_radioitem_widget(NSMenu *parent, int index, UiMenuItemI *item) {
83
84 }
85
86 void add_checkitemnv_widget(NSMenu *parent, int i, UiMenuItemI *item) {
87
88 }
89
90 void add_menuitem_list_widget(NSMenu *parent, int i, UiMenuItemI *item) {
91
92 }
93
94
95 void ui_menu_init(void) {
96 UiMenu *menus_begin = uic_get_menu_list();
97 UiMenu *ls = menus_begin;
98 while(ls) {
99 if(ls->item.type == UI_MENU) {
100 NSString *str = [[NSString alloc] initWithUTF8String:ls->label];
101 NSMenu *menu = [[NSMenu alloc] initWithTitle: str];
102 NSMenuItem *menuItem = [[NSApp mainMenu] addItemWithTitle:str action:nil keyEquivalent:@""];
103 [[NSApp mainMenu] setSubmenu:menu forItem:menuItem];
104
105 add_menu_items(menu, 0, ls);
106 }
107 ls = (UiMenu*)ls->item.next;
108 }
109 }

mercurial