wxdragon_sys/
lib.rs

1#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)]
2
3// Include the generated FFI bindings (from bindgen)
4include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
5
6// Conditionally include the pre-generated constants based on target OS
7// Assumes files are located in `rust/wxdragon-sys/src/generated_constants/`
8#[cfg(target_os = "macos")]
9include!("generated_constants/wx_osx_constants.rs");
10
11#[cfg(target_os = "windows")]
12include!("generated_constants/wx_msw_constants.rs");
13
14#[cfg(target_os = "linux")]
15include!("generated_constants/wx_gtk_constants.rs");
16
17// Fallback or error for unsupported OS for constants, if necessary.
18// Alternatively, you could have a `wx_common_constants.rs` if some constants are universal
19// and only OS-specific parts are in the files above.
20#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "linux")))]
21compile_error!(
22    "Target OS not supported by pre-generated constants. Please add a constants file for this OS."
23);
24
25// Type alias for convenience maybe?
26// pub type wxWindow_t = self::wxd_Window_t; // Example
27
28// Additional constants or utility functions specific to the sys crate itself
29// (if any are ever needed, usually this file is minimal)
30
31// REMOVED redundant/incorrect manual definitions and extern block.
32// Bindgen now generates wxd_EVT_* constants directly from wxdragon.h
33// into the included bindings.rs file.
34
35// Need to find the actual values for these constants. // REMOVED Comment
36
37// Add necessary imports for the drop function
38use std::cell::RefCell;
39use std::os::raw::c_void;
40
41// Type placeholder for user data until a proper type is defined in the safe wrapper
42type WindowUserData = (); // Replace with actual user data type later if needed
43
44/// Function called by C++ (WxdRustClientData destructor) to drop the Rust Box<RefCell<T>>.
45/// # Safety
46/// The caller (C++) must ensure `user_data_ptr` is a valid pointer obtained
47/// from `Box::into_raw(Box::new(RefCell::new(data)))` and that it hasn't been
48/// dropped or invalidated since.
49#[no_mangle]
50pub extern "C" fn drop_rust_refcell_box(user_data_ptr: *mut c_void) {
51    if !user_data_ptr.is_null() {
52        // Reconstitute the Box and let it drop, freeing the memory
53        // and dropping the RefCell<WindowUserData>.
54        let _boxed_refcell: Box<RefCell<WindowUserData>> =
55            unsafe { Box::from_raw(user_data_ptr as *mut RefCell<WindowUserData>) };
56        // Drop happens automatically when `_boxed_refcell` goes out of scope here.
57    } else {
58        // Optional: Log a warning or handle null pointer case if necessary
59        // eprintln!("Warning: drop_rust_refcell_box called with null pointer.");
60    }
61}