use std::collections::HashMap;
use sea_orm::entity::prelude::*;
-use crate::collection;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "collection")]
});
});
}
+
+ pub fn call_action(&self, action: &str) {
+ let cstr = CString::new(action).unwrap();
+ unsafe {
+ ui_call_action(self.ctx.ptr, cstr.as_ptr());
+ }
+ }
}
pub trait UiModel {
0
}
+pub fn broadcast_action(action: &str) {
+ let cstr = CString::new(action).unwrap();
+ unsafe {
+ ui_mainthread_broadcast(cstr.as_ptr());
+ }
+}
+
+
/* ----------------------------------- Config ---------------------------------- */
pub fn app_configdir() -> String {
fn ui_text_selection(text: *const ffi::UiText, begin: *mut c_int, end: *mut c_int);
fn ui_text_length(text: *const ffi::UiText) -> c_int;
fn ui_text_remove(text: *mut ffi::UiText, begin: c_int, end: c_int);
+
+ fn ui_call_action(ctx: *mut ffi::UiContext, action: *const c_char);
+ fn ui_mainthread_broadcast(action: *const c_char);
}
#include "action.h"
#include "context.h"
+#include "object.h"
#include <cx/string.h>
}
}
}
+
+void ui_call_action(UiContext *ctx, const char *action_name) {
+ ui_call_action2(ctx, action_name, NULL, 0);
+}
+
+void ui_call_action2(UiContext *ctx, const char *action_name, void *eventdata, int intval) {
+ UiAction *action = uic_resolve_action(ctx, action_name);
+ if(action && action->callback) {
+ UiEvent event;
+ memset(&event, 0, sizeof(UiEvent));
+ event.obj = ctx->obj;
+ event.window = event.obj ? event.obj->window : NULL;
+ event.document = ctx->self_doc ? ctx->self_doc : ctx->document;
+ if(eventdata) {
+ event.eventdata = eventdata;
+ event.eventdatatype = UI_EVENT_DATA_POINTER;
+ }
+ event.intval = intval;
+ action->callback(&event, action->userdata);
+ }
+}
+
+void ui_broadcast_action(const char *action_name) {
+ ui_broadcast_action2(action_name, NULL, 0);
+}
+
+void ui_broadcast_action2(const char *action_name, void *eventdata, int intval) {
+ CxList *objects = uic_object_list();
+ CxIterator i = cxListIterator(objects);
+ cx_foreach(UiObject*, obj, i) {
+ ui_call_action2(obj->ctx, action_name, eventdata, intval);
+ }
+}
+
+typedef struct UiActionBroadcast {
+ char *action;
+ void *eventdata;
+ int intval;
+} UiActionBroadcast;
+
+void ui_mainthread_broadcast(const char *action_name) {
+ ui_mainthread_broadcast2(action_name, NULL, 0);
+}
+
+static int mainthread_action_broadcast(void *data) {
+ UiActionBroadcast *broadcast = data;
+ ui_broadcast_action2(broadcast->action, broadcast->eventdata, broadcast->intval);
+ free(broadcast->action);
+ free(broadcast);
+ return 0;
+}
+
+void ui_mainthread_broadcast2(const char *action_name, void *eventdata, int intval) {
+ UiActionBroadcast *broadcast = malloc(sizeof(UiActionBroadcast));
+ broadcast->action = strdup(action_name);
+ broadcast->eventdata = eventdata;
+ broadcast->intval = intval;
+ ui_call_mainthread(mainthread_action_broadcast, broadcast);
+}
static CxList *creation_callbacks;
static CxList *destruction_callbacks;
+static CxList *objects;
+
typedef struct objcallback {
ui_object_callback func;
void *userdata;
}
void uic_object_created(UiObject *obj) {
+ if(!objects) {
+ objects = cxLinkedListCreate(NULL, CX_STORE_POINTERS);
+ }
+ cxListAdd(objects, obj);
+
CxIterator i = cxListIterator(creation_callbacks);
cx_foreach(objcallback *, cb, i) {
cb->func(obj, cb->userdata);
}
void uic_object_destroyed(UiObject *obj) {
+ if(objects) {
+ cxListFindRemove(objects, obj);
+ }
+
CxIterator i = cxListIterator(destruction_callbacks);
cx_foreach(objcallback *, cb, i) {
cb->func(obj, cb->userdata);
}
}
+CxList* uic_object_list(void) {
+ return objects ? objects : cxEmptyList;
+}
+
void ui_object_ref(UiObject *obj) {
obj->ref++;
}
void uic_object_destroyed(UiObject *obj);
void uic_object_destroy(UiObject *obj);
+
+CxList* uic_object_list(void);
UiObject* uic_object_new_toplevel(void);
UiObject* uic_object_new(UiObject *toplevel, UIWIDGET widget);
const char *accelerator,
const char *accelerator_text);
UIEXPORT void ui_update_action_bindings(UiContext *ctx);
+UIEXPORT void ui_call_action(UiContext *ctx, const char *action_name);
+UIEXPORT void ui_call_action2(UiContext *ctx, const char *action_name, void *eventdata, int intval);
+UIEXPORT void ui_broadcast_action(const char *action_name);
+UIEXPORT void ui_broadcast_action2(const char *action_name, void *eventdata, int intval);
+UIEXPORT void ui_mainthread_broadcast(const char *action_name);
+UIEXPORT void ui_mainthread_broadcast2(const char *action_name, void *eventdata, int intval);
UIEXPORT void ui_set_state(UiContext *ctx, int state);
UIEXPORT void ui_unset_state(UiContext *ctx, int state);