mirror of
https://github.com/italicsjenga/rust_minifb.git
synced 2025-01-11 03:21:32 +11:00
Removed old menu code
This commit is contained in:
parent
06c7c6b05b
commit
57906b26b8
|
@ -655,192 +655,6 @@ impl Window {
|
|||
1);
|
||||
}
|
||||
|
||||
/*
|
||||
fn format_name(menu_item: &Menu, key_name: &'static str) -> String {
|
||||
let mut name = menu_item.name.to_owned();
|
||||
|
||||
name.push_str("\t");
|
||||
|
||||
if (menu_item.modifier & MENU_KEY_WIN) == MENU_KEY_WIN {
|
||||
name.push_str("Win-");
|
||||
}
|
||||
|
||||
if (menu_item.modifier & MENU_KEY_SHIFT) == MENU_KEY_SHIFT {
|
||||
name.push_str("Shift-");
|
||||
}
|
||||
|
||||
if (menu_item.modifier & MENU_KEY_CTRL) == MENU_KEY_CTRL {
|
||||
name.push_str("Ctrl-");
|
||||
}
|
||||
|
||||
if (menu_item.modifier & MENU_KEY_ALT) == MENU_KEY_ALT {
|
||||
name.push_str("Alt-");
|
||||
}
|
||||
|
||||
name.push_str(key_name);
|
||||
|
||||
name
|
||||
}
|
||||
|
||||
fn is_key_virtual_range(key: raw::c_int) -> u32 {
|
||||
if (key >= 0x30 && key <= 0x30) ||
|
||||
(key >= 0x41 && key <= 0x5a) {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
fn get_virt_key(menu_item: &Menu, key: raw::c_int) -> u32 {
|
||||
let mut virt = Self::is_key_virtual_range(key);
|
||||
|
||||
if (menu_item.modifier & MENU_KEY_ALT) == MENU_KEY_ALT {
|
||||
virt |= 0x10;
|
||||
}
|
||||
|
||||
if (menu_item.modifier & MENU_KEY_CTRL) == MENU_KEY_CTRL {
|
||||
virt |= 0x8;
|
||||
}
|
||||
|
||||
if (menu_item.modifier & MENU_KEY_SHIFT) == MENU_KEY_SHIFT {
|
||||
virt |= 0x4;
|
||||
}
|
||||
|
||||
virt
|
||||
}
|
||||
|
||||
fn add_accel(accel_table: &mut Vec<ACCEL>, menu_item: &Menu) {
|
||||
let vk_accel = Self::map_key_to_vk_accel(menu_item.key);
|
||||
let virt = Self::get_virt_key(menu_item, vk_accel.0);
|
||||
let accel = winuser::ACCEL {
|
||||
fVirt: virt as BYTE,
|
||||
cmd: menu_item.id as WORD,
|
||||
key: vk_accel.0 as WORD };
|
||||
|
||||
accel_table.push(accel);
|
||||
}
|
||||
|
||||
unsafe fn add_menu_item(&mut self, parent_menu: HMENU, menu_item: &Menu) {
|
||||
let item_name = to_wstring(menu_item.name);
|
||||
let vk_accel = Self::map_key_to_vk_accel(menu_item.key);
|
||||
|
||||
match vk_accel.0 {
|
||||
0 => {
|
||||
user32::AppendMenuW(parent_menu, 0x10, menu_item.id as UINT_PTR, item_name.as_ptr());
|
||||
},
|
||||
_ => {
|
||||
let menu_name = Self::format_name(menu_item, vk_accel.1);
|
||||
let w_name = to_wstring(&menu_name);
|
||||
user32::AppendMenuW(parent_menu, 0x10, menu_item.id as UINT_PTR, w_name.as_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unsafe fn recursive_add_menu(&mut self, parent_menu: HMENU, name: &str, menu: &Vec<Menu>) -> HMENU {
|
||||
let menu_name = to_wstring(name);
|
||||
|
||||
let popup_menu = user32::CreatePopupMenu();
|
||||
|
||||
user32::AppendMenuW(parent_menu, 0x10, popup_menu as UINT_PTR, menu_name.as_ptr());
|
||||
|
||||
for m in menu.iter() {
|
||||
if let Some(ref sub_menu) = m.sub_menu {
|
||||
Self::recursive_add_menu(self, popup_menu, m.name, sub_menu);
|
||||
} else {
|
||||
if m.id == 0xffffffff {
|
||||
user32::AppendMenuW(popup_menu, 0x800, 0, ptr::null()); // separator
|
||||
} else {
|
||||
Self::add_menu_item(self, popup_menu, m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
popup_menu
|
||||
}
|
||||
|
||||
pub fn menu_exists(&mut self, menu_name: &str) -> bool {
|
||||
for menu in self.menus.iter() {
|
||||
if menu.name == menu_name {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
fn clone_menu(accel_dest: &mut Vec<ACCEL>, menu: &Vec<Menu>) {
|
||||
for m in menu.iter() {
|
||||
if let Some(ref sub_menu) = m.sub_menu {
|
||||
Self::clone_menu(accel_dest, sub_menu);
|
||||
}
|
||||
|
||||
if m.key != Key::Unknown {
|
||||
Self::add_accel(accel_dest, m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn add_menu_store(&mut self, parent_menu: HMENU, menu_name: &str, menu: &Vec<Menu>) {
|
||||
let mut items = Vec::<ACCEL>::new();
|
||||
let menu_handle = Self::recursive_add_menu(self, parent_menu, menu_name, menu);
|
||||
|
||||
Self::clone_menu(&mut items, menu);
|
||||
|
||||
self.menus.push(MenuStore {
|
||||
name: menu_name.to_owned(),
|
||||
menu: menu_handle,
|
||||
accel_items: items
|
||||
});
|
||||
}
|
||||
|
||||
pub fn add_menu(&mut self, menu_name: &str, menu: &Vec<Menu>) -> Result<()> {
|
||||
if Self::menu_exists(self, menu_name) {
|
||||
return Err(Error::MenuExists(menu_name.to_owned()));
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let window = self.window.unwrap();
|
||||
let mut main_menu = user32::GetMenu(window);
|
||||
|
||||
if main_menu == ptr::null_mut() {
|
||||
main_menu = user32::CreateMenu();
|
||||
user32::SetMenu(window, main_menu);
|
||||
Self::adjust_window_size_for_menu(window);
|
||||
}
|
||||
|
||||
Self::add_menu_store(self, main_menu, menu_name, menu);
|
||||
Self::set_accel_table(self);
|
||||
|
||||
user32::DrawMenuBar(window);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
pub fn update_menu(&mut self, menu_name: &str, menu: &Vec<Menu>) -> Result<()> {
|
||||
try!(Self::remove_menu(self, menu_name));
|
||||
Self::add_menu(self, menu_name, menu)
|
||||
}
|
||||
|
||||
pub fn remove_menu(&mut self, menu_name: &str) -> Result<()> {
|
||||
for i in 0..self.menus.len() {
|
||||
if self.menus[i].name == menu_name {
|
||||
unsafe {
|
||||
user32::DestroyMenu(self.menus[i].menu);
|
||||
user32::DrawMenuBar(self.window.unwrap());
|
||||
self.menus.swap_remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Proper return here
|
||||
Ok(())
|
||||
}
|
||||
*/
|
||||
|
||||
unsafe fn set_accel_table(&mut self) {
|
||||
let mut temp_accel_table = Vec::<ACCEL>::new();
|
||||
|
||||
|
|
Loading…
Reference in a new issue