use crate::co;
use crate::decl::*;
pub enum HhCmd<'a> {
CloseAll,
DisplayIndex(&'a str),
DisplayToc,
TpHelpContextMenu(&'a [(u16, u16)]),
TpHelpWmHelp(&'a [(u16, u16)]),
}
impl<'a> HhCmd<'a> {
#[must_use]
pub(in crate::htmlhelp) fn as_data(&self) -> (co::HH, HhCmdData) {
use HhCmd::*;
match self {
CloseAll => (co::HH::CLOSE_ALL, HhCmdData::None),
DisplayIndex(s) => (co::HH::DISPLAY_INDEX, Self::gen_str(s)),
DisplayToc => (co::HH::DISPLAY_TOC, HhCmdData::None),
TpHelpContextMenu(arr) => (co::HH::TP_HELP_CONTEXTMENU, Self::gen_vec(arr)),
TpHelpWmHelp(arr) => (co::HH::TP_HELP_WM_HELP, Self::gen_vec(arr)),
}
}
#[must_use]
fn gen_str(s: &str) -> HhCmdData {
HhCmdData::Str(WString::from_str(s))
}
#[must_use]
fn gen_vec(array: &[(u16, u16)]) -> HhCmdData {
let mut buf = Vec::<u32>::with_capacity(array.len() * 2 + 1);
for (ctrl_id, topic_id) in array.iter() {
buf.push(*ctrl_id as _);
buf.push(*topic_id as _);
}
buf.push(0);
HhCmdData::Ids(buf)
}
}
pub(in crate::htmlhelp) enum HhCmdData {
None,
Str(WString),
Ids(Vec<u32>),
}
impl HhCmdData {
#[must_use]
pub(in crate::htmlhelp) fn serialize(&self) -> usize {
use HhCmdData::*;
match self {
None => 0,
Str(s) => s.as_ptr() as _,
Ids(arr) => arr.as_ptr() as _,
}
}
}