LOCAL void fb_setattrs(WINDISPLAY *mod, struct TVRequest *req) { struct attrdata data; struct THook hook; WINWINDOW *win = req->tvr_Op.SetAttrs.Window; TINT neww, newh; data.v = win; data.num = 0; data.mod = mod; data.neww = -1; data.newh = -1; TInitHook(&hook, setattrfunc, &data); TForEachTag(req->tvr_Op.SetAttrs.Tags, &hook); req->tvr_Op.SetAttrs.Num = data.num; win_getminmax(win, &win->fbv_MinWidth, &win->fbv_MinHeight, &win->fbv_MaxWidth, &win->fbv_MaxHeight, TFALSE); neww = data.neww < 0 ? (TINT) win->fbv_Width : data.neww; newh = data.newh < 0 ? (TINT) win->fbv_Height : data.newh; if (neww < win->fbv_MinWidth || newh < win->fbv_MinHeight) { neww = TMAX(neww, win->fbv_MinWidth); newh = TMAX(newh, win->fbv_MinHeight); neww += win->fbv_BorderWidth; newh += win->fbv_BorderHeight; SetWindowPos(win->fbv_HWnd, NULL, 0, 0, neww, newh, SWP_NOMOVE); } }
LOCAL void dfb_setattrs(DFBDISPLAY *mod, struct TVRequest *req) { struct attrdata data; struct THook hook; DFBWINDOW *v = req->tvr_Op.SetAttrs.Window; data.v = v; data.num = 0; data.mod = mod; data.sizechanged = TFALSE; TInitHook(&hook, setattrfunc, &data); TForEachTag(req->tvr_Op.SetAttrs.Tags, &hook); req->tvr_Op.SetAttrs.Num = data.num; if (data.sizechanged) { TIMSG *imsg; v->wminwidth = v->wminwidth <= 0 ? 1 : v->wminwidth; v->wminheight = v->wminheight <= 0 ? 1 : v->wminheight; v->wmaxwidth = v->wmaxwidth <= 0 ? 1000000 : v->wmaxwidth; v->wmaxheight = v->wmaxheight <= 0 ? 1000000 : v->wmaxheight; if (v->wmaxwidth > 0) v->winwidth = TMIN(v->winwidth, v->wmaxwidth); if (v->wmaxheight > 0) v->winheight = TMIN(v->winheight, v->wmaxheight); if (v->wminwidth > 0) v->winwidth = TMAX(v->winwidth, v->wminwidth); if (v->wminheight > 0) v->winheight = TMAX(v->winheight, v->wminheight); v->window->Resize(v->window, v->winwidth, v->winheight); if ((v->eventmask & TITYPE_NEWSIZE) && getimsg(mod, v, &imsg, TITYPE_NEWSIZE)) { imsg->timsg_Width = v->winwidth; imsg->timsg_Height = v->winheight; TAddTail(&v->imsgqueue, &imsg->timsg_Node); } if ((v->eventmask & TITYPE_REFRESH) && getimsg(mod, v, &imsg, TITYPE_REFRESH)) { imsg->timsg_X = v->winleft; imsg->timsg_Y = v->wintop; imsg->timsg_Width = v->winwidth; imsg->timsg_Height = v->winheight; TAddTail(&v->imsgqueue, &imsg->timsg_Node); } } }
LOCAL TAPTR dfb_hostqueryfonts(TMOD_DFB *mod, TTAGITEM *tags) { TSTRPTR fname = TNULL; struct fnt_attr fattr; struct TNode *node, *next; struct FontQueryHandle *fqh = TNULL; TAPTR exec = TGetExecBase(mod); TDBPRINTF(10, ("***********************************************\n")); /* init fontname list */ TInitList(&fattr.fnlist); /* fetch and parse fname */ fname = (TSTRPTR) TGetTag(tags, TVisual_FontName, (TTAG) FNT_WILDCARD); if (fname) fnt_getfnnodes(mod, &fattr.fnlist, fname); /* fetch user specified attributes */ fattr.fpxsize = (TINT) TGetTag(tags, TVisual_FontPxSize, (TTAG) FNT_DEFPXSIZE); fattr.fnum = (TINT) TGetTag(tags, TVisual_FontNumResults, (TTAG) INT_MAX); /* not yet fattr.fitalic = (TBOOL) TGetTag(tags, TVisual_FontItalic, (TTAG) FNTQUERY_UNDEFINED); fattr.fbold = (TBOOL) TGetTag(tags, TVisual_FontBold, (TTAG) FNTQUERY_UNDEFINED); */ /* init result list */ fqh = TExecAlloc0(exec, mod->dfb_MemMgr, sizeof(struct FontQueryHandle)); if (fqh) { fqh->handle.thn_Owner = mod; /* connect destructor */ TInitHook(&fqh->handle.thn_Hook, fqhdestroy, fqh); TInitList(&fqh->reslist); /* init list iterator */ fqh->nptr = &fqh->reslist.tlh_Head; hostqueryfonts(mod, fqh, &fattr); TDB(10,(fnt_dumplist(&fqh->reslist))); TDBPRINTF(10, ("***********************************************\n")); } else TDBPRINTF(20, ("out of memory :(\n")); /* free memory of fnt_nodes */ for (node = fattr.fnlist.tlh_Head; (next = node->tln_Succ); node = next) { struct fnt_node *fnn = (struct fnt_node *)node; TExecFree(exec, fnn->fname); TRemove(&fnn->node); TExecFree(exec, fnn); } return fqh; }
TLIBAPI void TInitInterface(struct TInterface *iface, struct TModule *mod, TSTRPTR name, TUINT16 version) { struct TExecBase *TExecBase = TGetExecBase(mod); TInitHook(&iface->tif_Handle.thn_Hook, teklib_destroyiface, TNULL); iface->tif_Handle.thn_Owner = TExecBase; iface->tif_Handle.thn_Name = name; iface->tif_Module = mod; iface->tif_Reserved = TNULL; iface->tif_Version = version; }
LOCAL void dfb_drawtags(DFBDISPLAY *mod, struct TVRequest *req) { struct THook hook; struct drawdata data; data.v = req->tvr_Op.DrawTags.Window; data.mod = mod; TInitHook(&hook, drawtagfunc, &data); TForEachTag(req->tvr_Op.DrawTags.Tags, &hook); }
LOCAL void fb_openwindow(WINDISPLAY *mod, struct TVRequest *req) { struct TExecBase *TExecBase = TGetExecBase(mod); TTAGITEM tags[2]; struct THook taskhook; tags[0].tti_Tag = TTask_UserData; tags[0].tti_Value = (TTAG) req; tags[1].tti_Tag = TTAG_DONE; TInitHook(&taskhook, fb_window_dispatch, TNULL); TCreateTask(&taskhook, tags); }
LOCAL void fb_drawtags(WINDISPLAY *mod, struct TVRequest *req) { WINWINDOW *win = req->tvr_Op.DrawTags.Window; struct THook hook; struct drawdata data; data.v = win; data.mod = mod; data.fgpen = TNULL; data.bgpen = TNULL; TInitHook(&hook, drawtagfunc, &data); TForEachTag(req->tvr_Op.DrawTags.Tags, &hook); }
LOCAL void dfb_getattrs(DFBDISPLAY *mod, struct TVRequest *req) { struct attrdata data; struct THook hook; data.v = req->tvr_Op.GetAttrs.Window; data.num = 0; data.mod = mod; TInitHook(&hook, getattrfunc, &data); TForEachTag(req->tvr_Op.GetAttrs.Tags, &hook); req->tvr_Op.GetAttrs.Num = data.num; }
LOCAL void fb_getfontattrs(WINDISPLAY *mod, struct TVRequest *req) { struct attrdata data; data.num = 0; struct THook hook; SelectObject(mod->fbd_DeviceHDC, req->tvr_Op.GetFontAttrs.Font); if (GetTextMetrics(mod->fbd_DeviceHDC, &data.textmetric)) { data.mod = mod; TInitHook(&hook, fb_hostgetfattrfunc, &data); TForEachTag(req->tvr_Op.GetFontAttrs.Tags, &hook); } req->tvr_Op.GetFontAttrs.Num = data.num; }
LOCAL void dfb_getfontattrs(DFBDISPLAY *mod, struct TVRequest *req) { struct attrdata data; struct THook hook; data.mod = mod; data.font = req->tvr_Op.GetFontAttrs.Font; data.num = 0; TInitHook(&hook, dfb_hostgetfattrfunc, &data); TForEachTag(req->tvr_Op.GetFontAttrs.Tags, &hook); req->tvr_Op.GetFontAttrs.Num = data.num; }
LOCAL void fb_getattrs(WINDISPLAY *mod, struct TVRequest *req) { struct attrdata data; struct THook hook; WINWINDOW *win = req->tvr_Op.GetAttrs.Window; data.v = win; data.num = 0; data.mod = mod; TInitHook(&hook, getattrfunc, &data); EnterCriticalSection(&win->fbv_LockExtents); TForEachTag(req->tvr_Op.GetAttrs.Tags, &hook); LeaveCriticalSection(&win->fbv_LockExtents); req->tvr_Op.GetAttrs.Num = data.num; }
LOCAL void fb_setattrs(WINDISPLAY *mod, struct TVRequest *req) { struct attrdata data; struct THook hook; WINWINDOW *win = req->tvr_Op.SetAttrs.Window; TINT noww, nowh, neww, newh, minw, minh; data.v = win; data.num = 0; data.mod = mod; data.neww = -1; data.newh = -1; TInitHook(&hook, setattrfunc, &data); EnterCriticalSection(&win->fbv_LockExtents); TForEachTag(req->tvr_Op.SetAttrs.Tags, &hook); win_getminmax(win, &win->fbv_MinWidth, &win->fbv_MinHeight, &win->fbv_MaxWidth, &win->fbv_MaxHeight, TFALSE); noww = (TINT) win->fbv_Width; nowh = (TINT) win->fbv_Height; minw = (TINT) win->fbv_MinWidth; minh = (TINT) win->fbv_MinHeight; LeaveCriticalSection(&win->fbv_LockExtents); neww = data.neww < 0 ? noww : data.neww; newh = data.newh < 0 ? nowh : data.newh; if (neww < minw || newh < minh) { neww = TMAX(neww, minw); newh = TMAX(newh, minh); neww += win->fbv_BorderWidth; newh += win->fbv_BorderHeight; SetWindowPos(win->fbv_HWnd, NULL, 0, 0, neww, newh, SWP_NOMOVE); } req->tvr_Op.SetAttrs.Num = data.num; }
LOCAL void fb_getattrs(WINDISPLAY *mod, struct TVRequest *req) { struct attrdata data; struct THook hook; RECT wrect; WINWINDOW *win = req->tvr_Op.GetAttrs.Window; data.v = win; data.num = 0; data.mod = mod; TInitHook(&hook, getattrfunc, &data); GetWindowRect(win->fbv_HWnd, &wrect); win->fbv_Left = wrect.left + win->fbv_BorderLeft; win->fbv_Top = wrect.top + win->fbv_BorderHeight; win->fbv_Width = wrect.right - wrect.left - win->fbv_BorderWidth; win->fbv_Height = wrect.bottom - wrect.top - win->fbv_BorderHeight; TForEachTag(req->tvr_Op.GetAttrs.Tags, &hook); req->tvr_Op.GetAttrs.Num = data.num; }
LOCAL TBOOL tek_lib_visual_io_open(TEKVisual *vis) { struct TExecBase *TExecBase = vis->vis_ExecBase; struct IOData *iodata = TAlloc(TNULL, sizeof(struct IOData)); if (iodata) { TTAGITEM tags[2]; sprintf(iodata->atomname, "msgport.ui.%p", TFindTask(TNULL)); iodata->vis = vis; vis->vis_IOData = iodata; tags[0].tti_Tag = TTask_UserData; tags[0].tti_Value = (TTAG) iodata; tags[1].tti_Tag = TTAG_DONE; struct THook taskhook; TInitHook(&taskhook, tek_lib_visual_io_dispatch, TNULL); vis->vis_IOTask = TCreateTask(&taskhook, tags); if (vis->vis_IOTask) return TTRUE; TFree(iodata); vis->vis_IOData = TNULL; } return TFALSE; }
static TBOOL tek_lib_visual_io_init(struct TTask *task) { struct TExecBase *TExecBase = TGetExecBase(task); struct IOData *iodata = TGetTaskData(task); #if defined(ENABLE_FILENO) || defined(ENABLE_DGRAM) TEKVisual *vis = iodata->vis; iodata->fd_pipe[0] = -1; iodata->fd_pipe[1] = -1; iodata->fdmax = 0; TInitHook(&iodata->mphook, tek_lib_visual_io_mphookfunc, iodata); TSetPortHook(TGetUserPort(TNULL), &iodata->mphook); #endif #if defined(ENABLE_FILENO) int fd = vis->vis_IOFileNo; iodata->fd_stdin = fd == -1 ? STDIN_FILENO : fd; visual_io_reader_init(&iodata->linereader, iodata->fd_stdin, IOMAXMSGSIZE); iodata->fdmax = TMAX(iodata->fdmax, iodata->fd_stdin); #endif #if defined(ENABLE_DGRAM) iodata->fd_dgram = socket(PF_INET, SOCK_DGRAM, 0); if (iodata->fd_dgram != -1) { int reuse = 1; setsockopt(iodata->fd_dgram, SOL_SOCKET, SO_REUSEADDR, (char *) &reuse, sizeof(reuse)); struct sockaddr_in addr; memset(&addr, 0, sizeof(struct sockaddr_in)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr(ENABLE_DGRAM_ADDR); addr.sin_port = htons(ENABLE_DGRAM); if (bind(iodata->fd_dgram, (struct sockaddr *) &addr, sizeof addr) == -1) { close(iodata->fd_dgram); iodata->fd_dgram = -1; } } if (iodata->fd_dgram == -1) { tek_lib_visual_io_exit(task); return TFALSE; } iodata->fdmax = TMAX(iodata->fdmax, iodata->fd_dgram); #endif #if defined(ENABLE_FILENO) || defined(ENABLE_DGRAM) if (pipe(iodata->fd_pipe) != 0) return TFALSE; iodata->fdmax = TMAX(iodata->fdmax, iodata->fd_pipe[0]) + 1; #endif TAPTR atom = TLockAtom(iodata->atomname, TATOMF_CREATE | TATOMF_NAME); if (atom) { TSetAtomData(atom, (TTAG) TGetUserPort(TNULL)); TUnlockAtom(atom, TATOMF_KEEP); } return TTRUE; }
static int tek_lib_exec_run(lua_State *L) { struct LuaExecTask *lexec = tek_lib_exec_check(L); struct TExecBase *TExecBase = lexec->exec; struct LuaExecChild *ctx; const char *fname = TNULL; const char *chunk = TNULL; const char *taskname = TNULL; size_t extralen = 0; struct THook hook; TTAGITEM tags[2]; int nremove = 1; TBOOL abort = TTRUE; for (;;) { if (lua_istable(L, 1)) { lua_getfield(L, 1, "abort"); if (lua_isboolean(L, -1)) abort = lua_toboolean(L, -1); lua_pop(L, 1); lua_getfield(L, 1, "taskname"); taskname = lua_tostring(L, -1); nremove = 2; lua_getfield(L, 1, "func"); if (!lua_isnoneornil(L, -1)) break; lua_pop(L, 1); lua_getfield(L, 1, "filename"); if (!lua_isnoneornil(L, -1)) break; lua_pop(L, 1); lua_getfield(L, 1, "chunk"); if (!lua_isnoneornil(L, -1)) { chunk = luaL_checklstring(L, -1, &extralen); break; } luaL_error(L, "required argument missing"); } lua_pushvalue(L, 1); break; } if (!chunk) { if (lua_type(L, -1) == LUA_TSTRING) fname = luaL_checklstring(L, -1, &extralen); else if (lua_isfunction(L, -1) && !lua_iscfunction(L, -1)) chunk = tek_lib_exec_dump(L, &extralen); else luaL_error(L, "not a Lua function, filename or table"); } ctx = lua_newuserdata(L, sizeof(struct LuaExecChild) + extralen + 1); memset(ctx, 0, sizeof *ctx); ctx->exec = lexec->exec; ctx->parent = lexec; ctx->taskname = tek_lib_exec_taskname(ctx->atomname, taskname); ctx->abort = abort; if (fname) { ctx->fname = (char *) (ctx + 1); strcpy(ctx->fname, (char *) fname); } else if (chunk) { memcpy(ctx + 1, chunk, extralen); ctx->chunklen = extralen; } /* remove arguments under userdata */ while (nremove--) lua_remove(L, -2); ctx->numargs = lua_gettop(L) - 2; /* push arg[0] on the stack, will be extraarg */ lua_getglobal(L, "arg"); if (lua_istable(L, -1)) { lua_rawgeti(L, -1, 0); lua_remove(L, -2); } if (lua_type(L, -1) != LUA_TSTRING) { lua_pop(L, 1); lua_pushnil(L); } ctx->args = tek_lib_exec_getargs(L, TExecBase, 2, ctx->numargs++, 1); lua_pop(L, 1); ctx->L = lua_newstate(tek_lib_exec_allocf, TExecBase); if (ctx->L == TNULL) { tek_lib_exec_freeargs(TExecBase, ctx->args, ctx->numargs); luaL_error(L, "cannot create interpreter"); } tags[0].tti_Tag = TTask_UserData; tags[0].tti_Value = (TTAG) ctx; tags[1].tti_Tag = TTAG_DONE; TInitHook(&hook, tek_lib_exec_run_dispatch, ctx); ctx->task = TCreateTask(&hook, tags); if (ctx->task == TNULL) { tek_lib_exec_freectxargs(ctx); lua_pop(L, 1); lua_pushnil(L); return 1; } lua_getfield(L, LUA_REGISTRYINDEX, TEK_LIB_TASK_CLASSNAME); lua_setmetatable(L, -2); lua_pushvalue(L, -1); ctx->ref = luaL_ref(L, lua_upvalueindex(2)); if (ctx->abort) tek_lib_exec_register_task_hook(L, TExecBase); return 1; }
LOCAL TAPTR fb_hostqueryfonts(WINDISPLAY *mod, TTAGITEM *tags) { struct TExecBase *TExecBase = TGetExecBase(mod); TSTRPTR names; LOGFONT logfont; char *namebuf = logfont.lfFaceName; struct FontQueryHandle *fqh; fqh = TAlloc0(TNULL, sizeof(struct FontQueryHandle)); if (fqh == TNULL) return TNULL; fqh->handle.thn_Owner = mod; TInitHook(&fqh->handle.thn_Hook, fqhdestroy, fqh); TInitList(&fqh->reslist); fqh->fpxsize = (TINT) TGetTag(tags, TVisual_FontPxSize, (TTAG) FNTQUERY_UNDEFINED); fqh->fitalic = (TBOOL) TGetTag(tags, TVisual_FontItalic, (TTAG) FNTQUERY_UNDEFINED); fqh->fbold = (TBOOL) TGetTag(tags, TVisual_FontBold, (TTAG) FNTQUERY_UNDEFINED); fqh->fscale = (TBOOL) TGetTag(tags, TVisual_FontScaleable, (TTAG) FNTQUERY_UNDEFINED); fqh->fnum = (TINT) TGetTag(tags, TVisual_FontNumResults, (TTAG) INT_MAX); fqh->success = TTRUE; names = (TSTRPTR) TGetTag(tags, TVisual_FontName, TNULL); if (names == TNULL) names = ""; for (;;) { TSTRPTR p = strchr(names, ','); if (p) { size_t len2 = TMIN(p - names, LF_FACESIZE - 1); memcpy(namebuf, names, len2); namebuf[len2] = 0; names += p - names + 1; } else { size_t len = strlen(names); size_t len2 = TMIN(len, LF_FACESIZE - 1); memcpy(namebuf, names, len2); namebuf[len2] = 0; names += len; } logfont.lfCharSet = ANSI_CHARSET; logfont.lfPitchAndFamily = 0; TDBPRINTF(TDB_INFO,("query font: %s\n", namebuf)); if (strcmp(namebuf, "") == 0) fqh->match_depth = 0; /* find font first */ else fqh->match_depth = 1; /* find style */ EnumFontFamiliesEx( mod->fbd_DeviceHDC, &logfont, (FONTENUMPROCA) fontenumcb, (LPARAM) fqh, 0); if (strlen(names) == 0) break; } fqh->nptr = &fqh->reslist.tlh_Head; if (fqh->success) return fqh; TDestroy(&fqh->handle); return TNULL; }
static struct TTask *init_tek_create(TTAGITEM *usertags) { struct TEKlibInit *init; TAPTR boot = TEKlib_Init(usertags); if (boot == TNULL) return TNULL; init = TEKlib_Alloc(boot, sizeof(struct TEKlibInit)); if (init) { init->tli_BootHnd = boot; init->tli_ProgDir = TEKlib_GetProgDir(boot, usertags); init->tli_SysDir = TEKlib_GetSysDir(boot, usertags); init->tli_ModDir = TEKlib_GetModDir(boot, usertags); /* load host abstraction module */ if (init_openhalmodule(init, usertags)) { /* load exec module */ if (init_openexecmodule(init, usertags)) { /* place application task into current context */ init->tli_ExecTags[0].tti_Tag = TTask_Name; init->tli_ExecTags[0].tti_Value = (TTAG) TTASKNAME_ENTRY; init->tli_ExecTags[1].tti_Tag = TTask_InitData; init->tli_ExecTags[1].tti_Value = (TTAG) init; init->tli_ExecTags[2].tti_Tag = TTAG_MORE; init->tli_ExecTags[2].tti_Value = (TTAG) usertags; init->tli_AppTask = TExecCreateSysTask(init->tli_ExecBase, TNULL, init->tli_ExecTags); if (init->tli_AppTask) { /* fill in missing fields in execbase */ ((struct TModule *) init->tli_ExecBase)->tmd_HALMod = init->tli_ExecMod; ((struct TModule *) init->tli_ExecBase)->tmd_InitTask = init->tli_AppTask; /* create ramlib task */ init->tli_ExecTags[0].tti_Value = (TTAG) TTASKNAME_RAMLIB; init->tli_IOTask = TExecCreateSysTask(init->tli_ExecBase, init_execfunc, init->tli_ExecTags); if (init->tli_IOTask) { /* create execbase task */ init->tli_ExecTags[0].tti_Value = (TTAG) TTASKNAME_EXEC; init->tli_ExecTask = TExecCreateSysTask(init->tli_ExecBase, init_execfunc, init->tli_ExecTags); if (init->tli_ExecTask) { /* this is the backdoor for the remaining ** initializations in the entrytask context */ if (TExecDoExec(init->tli_ExecBase, TEXEC_CMD_INIT, TNULL)) { struct THandle *ath = (struct THandle *) init->tli_AppTask; /* overwrite apptask destructor */ init->tli_OrgAppTaskHook = ath->thn_Hook; TInitHook(&ath->thn_Hook, init_destroyapptask, TNULL); init_appatoms(init, usertags); /* application is running */ return init->tli_AppTask; } TExecSignal(init->tli_ExecBase, init->tli_ExecTask, TTASK_SIG_ABORT); TDESTROY(init->tli_ExecTask); } TExecSignal(init->tli_ExecBase, init->tli_IOTask, TTASK_SIG_ABORT); TDESTROY(init->tli_IOTask); } TDESTROY(init->tli_AppTask); } init_closeexecmodule(init); } else TDBPRINTF(20, ("could not open Exec module\n")); init_closehalmodule(init); } else TDBPRINTF(20, ("could not open HAL module\n")); TEKlib_FreeVec(boot, init->tli_ProgDir); TEKlib_FreeVec(boot, init->tli_SysDir); TEKlib_FreeVec(boot, init->tli_ModDir); TEKlib_Free(boot, init, sizeof(struct TEKlibInit)); } TEKlib_Exit(boot); return TNULL; }