This commit is contained in:
Daniel Collin 2016-05-08 10:31:58 +02:00
parent ab924a4b0d
commit 10de5cd84e
2 changed files with 18 additions and 90 deletions

View file

@ -645,7 +645,7 @@ uint64_t mfb_add_menu_item(
[newItem setOnStateImage: newItem.offStateImage]; [newItem setOnStateImage: newItem.offStateImage];
[menu addItem:newItem]; [menu addItem:newItem];
[newItem release]; //[newItem release];
return (uint64_t)newItem; return (uint64_t)newItem;
} }
@ -669,15 +669,8 @@ void mfb_add_sub_menu(void* parent_menu, const char* menu_name, void* attach_men
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void* mfb_create_menu(const char* name) { void* mfb_create_menu(const char* name) {
const char* n = strdup(name); // WHY? NSString* ns_name = [NSString stringWithUTF8String: name];
NSString* ns_name = [NSString stringWithUTF8String: n];
//NSMenuItem* menu_item = [[NSMenuItem alloc] initWithTitle:name action:NULL keyEquivalent:@""];
NSMenu* menu = [[NSMenu alloc] initWithTitle:ns_name]; NSMenu* menu = [[NSMenu alloc] initWithTitle:ns_name];
//[menu_item setSubmenu:menu];
//printf("created menu %p\n");
return (void*)menu; return (void*)menu;
} }
@ -696,11 +689,22 @@ void mfb_destroy_menu(void* menu_item, const char* name)
void mfb_remove_menu_item(void* parent, uint64_t menu_item) { void mfb_remove_menu_item(void* parent, uint64_t menu_item) {
NSMenu* menu = (NSMenu*)parent; NSMenu* menu = (NSMenu*)parent;
NSMenuItem* item = (NSMenuItem*)(uintptr_t)menu_item; NSMenuItem* item = (NSMenuItem*)(uintptr_t)menu_item;
printf("remove item menu %p item %p\n", menu, item);
[menu removeItem:item]; [menu removeItem:item];
} }

View file

@ -151,20 +151,6 @@ static KEY_MAPPINGS: [Key; 128] = [
]; ];
/*
#[repr(C)]
struct CMenu {
name: [i8; STRING_SIZE],
sub_menu: *mut raw::c_void,
id: raw::c_int,
key: raw::c_int,
special_key: raw::c_int,
modifier: raw::c_int,
mac_mod: raw::c_int,
enabled: raw::c_int,
}
*/
#[link(name = "Cocoa", kind = "framework")] #[link(name = "Cocoa", kind = "framework")]
#[link(name = "Carbon", kind = "framework")] #[link(name = "Carbon", kind = "framework")]
extern { extern {
@ -182,9 +168,6 @@ extern {
fn mfb_is_active(window: *mut c_void) -> u32; fn mfb_is_active(window: *mut c_void) -> u32;
fn mfb_add_menu(window: *mut c_void, menu: *mut c_void); fn mfb_add_menu(window: *mut c_void, menu: *mut c_void);
fn mfb_add_sub_menu(parent_menu: *mut c_void, name: *const c_char, menu: *mut c_void); fn mfb_add_sub_menu(parent_menu: *mut c_void, name: *const c_char, menu: *mut c_void);
//fn mfb_remove_menu(window: *mut c_void, name: *const c_char);
//fn mfb_update_menu(window: *mut c_void, name: *const c_char, menu: *mut c_void);
//fn mfb_active_menu(window: *mut c_void) -> i32;
fn mfb_create_menu(name: *const c_char) -> *mut c_void; fn mfb_create_menu(name: *const c_char) -> *mut c_void;
//fn mfb_destroy_menu(menu_item: *mut c_void); //fn mfb_destroy_menu(menu_item: *mut c_void);
@ -436,62 +419,6 @@ impl Window {
return factor; return factor;
} }
/*
*/
/*
unsafe fn recursive_convert(menu_build_vec: &mut Vec<Vec<CMenu>>, in_menu: &Option<&Vec<Menu>>) -> *mut raw::c_void {
if in_menu.is_none() {
return ptr::null_mut();
}
let mut menu_build = Vec::<CMenu>::new();
let menu_vec = in_menu.as_ref().unwrap();
for m in menu_vec.iter() {
let key_map = Self::map_key_to_menu_key(m.key);
let mut menu = CMenu {
name: mem::uninitialized(),
id: m.id as raw::c_int,
key: key_map as raw::c_int,
special_key: 0,
modifier: m.modifier as raw::c_int,
mac_mod: m.mac_mod as raw::c_int,
enabled: m.enabled as raw::c_int,
sub_menu : Self::recursive_convert(menu_build_vec, &m.sub_menu),
};
let name = CString::new(m.name).unwrap();
let name_len = m.name.len();
ptr::copy_nonoverlapping(name.as_ptr(),
menu.name.as_mut_ptr() as *mut i8,
name_len);
menu.name[name_len] = 0;
menu_build.push(menu);
}
// end marker
menu_build.push(CMenu {
name: [0; STRING_SIZE],
id: -2,
key: 0,
special_key: 0,
modifier: 0,
mac_mod: 0,
enabled: 0,
sub_menu : ptr::null_mut(),
});
let ptr = menu_build.as_mut_ptr() as *mut raw::c_void ;
menu_build_vec.push(menu_build);
ptr
}
*/
} }
pub struct Menu { pub struct Menu {
@ -629,12 +556,9 @@ impl Menu {
let item_name = CString::new(item.label.as_str()).unwrap(); let item_name = CString::new(item.label.as_str()).unwrap();
let conv_key = Self::map_key_to_menu_key(item.key); let conv_key = Self::map_key_to_menu_key(item.key);
println!("key {:?} conv {}", item.key, conv_key); MenuItemHandle(mfb_add_menu_item(self.menu_handle,
item.id as i32, item_name.as_ptr(),
MenuItemHandle(mfb_add_menu_item(self.menu_handle, item.id as i32, item_name.as_ptr(), item.enabled, conv_key, item.modifier))
item.enabled,
Self::map_key_to_menu_key(item.key),
item.modifier))
} }
} }