pub struct UiList<T> {
pub ptr: *mut ffi::UiList,
+ ctx: *mut ffi::UiContext,
data: Box<Vec<T>>
}
fn default() -> Self {
Self {
ptr: std::ptr::null_mut(),
+ ctx: std::ptr::null_mut(),
data: Box::new(Vec::new())
}
}
unsafe {
let data: *mut Vec<T> = &mut *self.data;
self.ptr = ui_list_new2(ctx.ptr, c_str, list_init::<T>, data as *mut c_void);
+ self.ctx = ctx.ptr;
}
}
impl<T> Drop for UiList<T> {
fn drop(&mut self) {
unsafe {
- // This does not free the UiList pointer, because it could still be in use by
- // UI elements, but it will have no reference to any object managed by Rust
if !self.ptr.is_null() {
- ui_list_class_set_data(self.ptr, std::ptr::null_mut());
+ ui_list_free(self.ctx, self.ptr);
}
}
}
ui_list_class_set_next(list, list_next::<T>);
ui_list_class_set_get(list, list_get::<T>);
ui_list_class_set_count(list, list_count::<T>);
+ ui_list_class_set_destructor(list, list_destroy::<T>);
}
}
}
}
+extern "C" fn list_destroy<T>(_ctx: *mut ffi::UiContext, _list: *mut ffi::UiList, _data: *mut c_void) {
+ // noop
+}
+
/* -------------------------------- C functions -------------------------------- */
extern "C" {
fn ui_list_class_set_next(list: *mut ffi::UiList, func: UiListNextFunc);
fn ui_list_class_set_get(list: *mut ffi::UiList, func: UiListGetFunc);
fn ui_list_class_set_count(list: *mut ffi::UiList, func: UiListCountFunc);
+ fn ui_list_class_set_destructor(list: *mut ffi::UiList, destructor: UiListDestroyFunc);
fn ui_list_class_set_data(list: *mut ffi::UiList, data: *mut c_void);
fn ui_list_class_set_iter(list: *mut ffi::UiList, iter: *mut c_void);
fn ui_list_selection_get_count(list: *mut ffi::UiListSelection) -> c_int;
fn ui_list_selection_get_rows(list: *mut ffi::UiListSelection) -> *const c_int;
fn ui_list_selection_free(list: *mut ffi::UiListSelection);
+
+ fn ui_list_free(ctx: *mut ffi::UiContext, list: *mut ffi::UiList);
}
}
UiEvent ev;
- ev.window = NULL;
+ ev.obj = ctx->obj;
+ ev.window = ev.obj ? ev.obj->window : NULL;
ev.document = document;
- ev.obj = NULL;
ev.eventdata = NULL;
ev.eventdatatype = 0;
ev.intval = 0;
+ ev.set = 0;
if(ctx->close_callback) {
ctx->close_callback(&ev, ctx->close_data);
}
+
+ CxIterator i = cxListIterator(ctx->destroy_handler);
+ cx_foreach(UiDestroyHandler *, h, i) {
+ h->destructor(h->data);
+ }
+
cxMempoolFree(ctx->mp);
}
ctx->close_data = udata;
}
-void ui_context_destroy(UiContext *ctx) {
- CxIterator i = cxListIterator(ctx->destroy_handler);
- cx_foreach(UiDestroyHandler *, h, i) {
- h->destructor(h->data);
- }
- cxMempoolFree(ctx->mp);
-}
-
UiContext* ui_context_parent(UiContext *ctx) {
return ctx->parent;
}
}
void ui_reg_destructor(UiContext *ctx, void *data, ui_destructor_func destr) {
- cxMempoolRegister(ctx->mp, data, (cx_destructor_func)destr);
+ //cxMempoolRegister(ctx->mp, data, (cx_destructor_func)destr);
+ uic_context_add_destructor(ctx, destr, data);
}
void ui_set_destructor(void *mem, ui_destructor_func destr) {
}
void uic_object_destroy(UiObject *obj) {
- if(obj->ctx->close_callback) {
- UiEvent ev;
- ev.window = obj->window;
- ev.document = obj->ctx->document;
- ev.obj = obj;
- ev.eventdata = NULL;
- ev.eventdatatype = 0;
- ev.intval = 0;
- obj->ctx->close_callback(&ev, obj->ctx->close_data);
- }
uic_object_destroyed(obj);
- cxMempoolFree(obj->ctx->mp);
+ uic_context_destroy(obj->ctx, obj->ctx->document);
}
UiObject* uic_object_new_toplevel(void) {