use std::mem;
use std::ptr::null;
use winapi::shared::basetsd::*;
use winapi::shared::windef::*;
use winapi::um::winuser::*;
use util::ToWide;
pub struct Menu {
hmenu: HMENU,
}
impl Drop for Menu {
fn drop(&mut self) {
unsafe {
DestroyMenu(self.hmenu);
}
}
}
impl Menu {
pub fn new() -> Menu {
unsafe {
let hmenu = CreateMenu();
Menu { hmenu }
}
}
pub fn into_hmenu(self) -> HMENU {
let hmenu = self.hmenu;
mem::forget(self);
hmenu
}
pub fn add_dropdown(&mut self, menu: Menu, text: &str) {
unsafe {
AppendMenuW(self.hmenu, MF_POPUP, menu.into_hmenu() as UINT_PTR,
text.to_wide().as_ptr());
}
}
pub fn add_item(&mut self, id: u32, text: &str) {
unsafe {
AppendMenuW(self.hmenu, MF_STRING, id as UINT_PTR, text.to_wide().as_ptr());
}
}
pub fn add_separator(&mut self) {
unsafe {
AppendMenuW(self.hmenu, MF_SEPARATOR, 0, null());
}
}
}