Chandra
view release on metacpan or search on metacpan
call_method("dispatch_eval_js", G_DISCARD);
}
FREETMPS; LEAVE;
} else {
dSP;
ENTER; SAVETMPS;
PUSHMARK(SP);
XPUSHs(*sc_svp);
PUTBACK;
call_method("inject", G_DISCARD);
FREETMPS; LEAVE;
}
}
}
}
/* DragDrop */
{
SV **dd_svp = hv_fetchs(hv, "_dragdrop", 0);
if (dd_svp && SvOK(*dd_svp) && SvROK(*dd_svp)) {
HV *dd_hv = (HV *)SvRV(*dd_svp);
SV **h_svp = hv_fetchs(dd_hv, "_handlers", 0);
SV **dz_svp = hv_fetchs(dd_hv, "_drop_zones", 0);
int has_handlers = (h_svp && SvROK(*h_svp)
&& HvUSEDKEYS((HV *)SvRV(*h_svp)) > 0);
int has_zones = (dz_svp && SvROK(*dz_svp)
&& HvUSEDKEYS((HV *)SvRV(*dz_svp)) > 0);
if (has_handlers || has_zones) {
if (dispatch) {
dSP;
int count;
SV *dd_js;
ENTER; SAVETMPS;
PUSHMARK(SP);
XPUSHs(*dd_svp);
PUTBACK;
count = call_method("js_code", G_SCALAR);
SPAGAIN;
if (count > 0) {
dd_js = POPs;
PUSHMARK(SP);
XPUSHs(*wv_svp);
XPUSHs(dd_js);
PUTBACK;
call_method("dispatch_eval_js", G_DISCARD);
}
FREETMPS; LEAVE;
} else {
dSP;
ENTER; SAVETMPS;
PUSHMARK(SP);
XPUSHs(*dd_svp);
PUTBACK;
call_method("inject", G_DISCARD);
FREETMPS; LEAVE;
}
}
}
}
/* ContextMenu */
{
SV **cm_svp = hv_fetchs(hv, "_contextmenu", 0);
if (cm_svp && SvOK(*cm_svp) && SvROK(*cm_svp)) {
HV *cm_hv = (HV *)SvRV(*cm_svp);
SV **att_svp = hv_fetchs(cm_hv, "_attachments", 0);
SV **gl_svp = hv_fetchs(cm_hv, "_global", 0);
int has_attach = (att_svp && SvROK(*att_svp)
&& HvUSEDKEYS((HV *)SvRV(*att_svp)) > 0);
int is_global = (gl_svp && SvTRUE(*gl_svp));
if (has_attach || is_global) {
if (dispatch) {
dSP;
int count;
SV *cm_js;
ENTER; SAVETMPS;
PUSHMARK(SP);
XPUSHs(*cm_svp);
PUTBACK;
count = call_method("js_code", G_SCALAR);
SPAGAIN;
if (count > 0) {
cm_js = POPs;
PUSHMARK(SP);
XPUSHs(*wv_svp);
XPUSHs(cm_js);
PUTBACK;
call_method("dispatch_eval_js", G_DISCARD);
}
FREETMPS; LEAVE;
} else {
dSP;
ENTER; SAVETMPS;
PUSHMARK(SP);
XPUSHs(*cm_svp);
PUTBACK;
call_method("inject", G_DISCARD);
FREETMPS; LEAVE;
}
}
}
}
/* Global JS */
{
SV **gjs_svp = hv_fetchs(hv, "_global_js", 0);
if (gjs_svp && SvROK(*gjs_svp)) {
AV *arr = (AV *)SvRV(*gjs_svp);
I32 len = av_len(arr) + 1;
if (len > 0) {
SV *joined = newSVpvs("");
I32 i;
SV *escaped;
SV *js;
for (i = 0; i < len; i++) {
SV **elem = av_fetch(arr, i, 0);
if (i > 0) sv_catpvs(joined, ";\n");
if (elem && SvOK(*elem)) sv_catsv(joined, *elem);
}
escaped = chandra_escape_js(aTHX_ joined);
{
SV *dd;
dSP;
int count;
/* Get or create drag_drop instance */
ENTER; SAVETMPS;
PUSHMARK(SP);
XPUSHs(self);
PUTBACK;
count = call_method("drag_drop", G_SCALAR);
SPAGAIN;
dd = (count > 0) ? POPs : &PL_sv_undef;
PUSHMARK(SP);
XPUSHs(dd);
XPUSHs(callback);
PUTBACK;
call_method("on_file_drop", G_DISCARD);
FREETMPS; LEAVE;
RETVAL = SvREFCNT_inc(self);
}
OUTPUT:
RETVAL
# ---- drop_zone($selector, $coderef) - convenience for drag_drop->add_drop_zone ----
SV *
drop_zone(self, selector, callback)
SV *self
SV *selector
SV *callback
CODE:
{
SV *dd;
dSP;
int count;
ENTER; SAVETMPS;
PUSHMARK(SP);
XPUSHs(self);
PUTBACK;
count = call_method("drag_drop", G_SCALAR);
SPAGAIN;
dd = (count > 0) ? POPs : &PL_sv_undef;
PUSHMARK(SP);
XPUSHs(dd);
XPUSHs(selector);
XPUSHs(callback);
PUTBACK;
call_method("add_drop_zone", G_DISCARD);
FREETMPS; LEAVE;
RETVAL = SvREFCNT_inc(self);
}
OUTPUT:
RETVAL
# ---- context_menu_instance() - lazy Chandra::ContextMenu accessor ----
SV *
context_menu_instance(self)
SV *self
CODE:
{
HV *hv = (HV *)SvRV(self);
SV **cached_svp = hv_fetchs(hv, "_contextmenu", 0);
if (cached_svp && SvOK(*cached_svp)) {
RETVAL = SvREFCNT_inc(*cached_svp);
} else {
dSP;
int count;
load_module(PERL_LOADMOD_NOIMPORT,
newSVpvs("Chandra::ContextMenu"), NULL);
ENTER; SAVETMPS;
PUSHMARK(SP);
XPUSHs(sv_2mortal(newSVpvs("Chandra::ContextMenu")));
XPUSHs(sv_2mortal(newSVpvs("app")));
XPUSHs(self);
PUTBACK;
count = call_method("new", G_SCALAR);
SPAGAIN;
RETVAL = (count > 0) ? SvREFCNT_inc(POPs) : &PL_sv_undef;
PUTBACK; FREETMPS; LEAVE;
(void)hv_stores(hv, "_contextmenu", SvREFCNT_inc(RETVAL));
}
}
OUTPUT:
RETVAL
# ---- context_menu(selector, items_or_cb) - convenience method ----
SV *
context_menu(self, selector, items_or_cb)
SV *self
SV *selector
SV *items_or_cb
CODE:
{
SV *cm;
dSP;
int count;
/* Get or create context_menu instance */
ENTER; SAVETMPS;
PUSHMARK(SP);
XPUSHs(self);
PUTBACK;
count = call_method("context_menu_instance", G_SCALAR);
SPAGAIN;
cm = (count > 0) ? POPs : &PL_sv_undef;
if (SvROK(items_or_cb) && SvTYPE(SvRV(items_or_cb)) == SVt_PVCV) {
/* Dynamic: attach(selector, coderef) */
PUSHMARK(SP);
XPUSHs(cm);
XPUSHs(selector);
XPUSHs(items_or_cb);
PUTBACK;
call_method("attach", G_DISCARD);
} else if (SvROK(items_or_cb) && SvTYPE(SvRV(items_or_cb)) == SVt_PVAV) {
/* Static items: set items, then attach */
HV *cm_hv = (HV *)SvRV(cm);
(void)hv_stores(cm_hv, "_items", newSVsv(items_or_cb));
/* Register actions */
{
SV **actions_svp = hv_fetchs(cm_hv, "_actions", 0);
_cm_register_actions(aTHX_ cm_hv,
(AV *)SvRV(items_or_cb), (HV *)SvRV(*actions_svp));
}
PUSHMARK(SP);
XPUSHs(cm);
XPUSHs(selector);
PUTBACK;
( run in 0.645 second using v1.01-cache-2.11-cpan-6aa56a78535 )