#[cfg(target_os = "macos")]
pub fn enable<W: fltk::prelude::WidgetExt>(widget: &mut W) {
const VISIBLE_FOCUS: u32 = 1 << 9; const MAC_USE_ACCENTS_MENU: u32 = 1 << 19;
const SCAN_WORDS: usize = 32;
let base = widget.as_widget_ptr() as *mut u32;
if base.is_null() {
return;
}
let had_visible_focus = widget.has_visible_focus();
let snapshot = |base: *const u32| -> [u32; SCAN_WORDS] {
let mut words = [0u32; SCAN_WORDS];
for (i, slot) in words.iter_mut().enumerate() {
*slot = unsafe { base.add(i).read() };
}
words
};
widget.clear_visible_focus();
let cleared = snapshot(base);
widget.set_visible_focus();
let set = snapshot(base);
let mut flags_index = None;
for i in 0..SCAN_WORDS {
if set[i] ^ cleared[i] == VISIBLE_FOCUS {
if flags_index.is_some() {
flags_index = None; break;
}
flags_index = Some(i);
}
}
if had_visible_focus {
widget.set_visible_focus();
} else {
widget.clear_visible_focus();
}
if let Some(i) = flags_index {
let flags_ptr = unsafe { base.add(i) };
unsafe { flags_ptr.write(flags_ptr.read() | MAC_USE_ACCENTS_MENU) };
}
}
#[cfg(not(target_os = "macos"))]
pub fn enable<W: fltk::prelude::WidgetExt>(_widget: &mut W) {}
#[cfg(target_os = "macos")]
pub fn report_caret(x: i32, y: i32, height: i32) {
unsafe extern "C" {
#[link_name = "_ZN2Fl24insertion_point_locationEiii"]
fn fl_insertion_point_location(x: i32, y: i32, height: i32);
}
unsafe { fl_insertion_point_location(x, y, height) };
}
#[cfg(not(target_os = "macos"))]
pub fn report_caret(_x: i32, _y: i32, _height: i32) {}