static TBOOL tek_lib_exec_init_link_to_parent(lua_State *L, struct LuaExecTask *lexec) { struct TExecBase *TExecBase = lexec->exec; TAPTR atom; /* task's userdata initially contains a pointer to ** childtask-userdata in parent Lua state */ struct LuaExecChild *ctx = TGetTaskData(TNULL); /* now relink to own task */ TSetTaskData(TNULL, lexec); lexec->parent = ctx ? ctx->parent : TNULL; if (ctx && ctx->taskname) { /* child context */ strcpy(lexec->atomname, ctx->atomname); lexec->taskname = lexec->atomname + TEK_LIB_TASK_ATOMNAME_OFFSET; lexec->shared = ctx->parent->shared; } else { /* root context */ lexec->taskname = tek_lib_exec_taskname(lexec->atomname, "main"); lexec->shared = TAlloc(TNULL, sizeof(struct SharedState)); if (lexec->shared == TNULL) return TFALSE; } atom = TLockAtom(TEK_LIB_BASETASK_ATOMNAME, TATOMF_CREATE | TATOMF_NAME | TATOMF_TRY); if (atom) { TSetAtomData(atom, (TTAG) lexec->task); TUnlockAtom(atom, TATOMF_KEEP); } return TTRUE; }
static TBOOL fb_initwindow(TAPTR task) { struct TExecBase *TExecBase = TGetExecBase(task); struct TVRequest *req = TGetTaskData(task); TTAGITEM *tags = req->tvr_Op.OpenWindow.Tags; WINDISPLAY *mod = (WINDISPLAY *) req->tvr_Req.io_Device; WINWINDOW *win; req->tvr_Op.OpenWindow.Window = TNULL; for (;;) { RECT wrect; BITMAPINFOHEADER *bmi; TUINT style; TUINT exstyle; TIMSG *imsg; const char *classname; TSTRPTR title; win = TAlloc0(mod->fbd_MemMgr, sizeof(WINWINDOW)); if (win == TNULL) break; TInitList(&win->penlist); win->fbv_Width = (TUINT) TGetTag(tags, TVisual_Width, FB_DEF_WIDTH); win->fbv_Height = (TUINT) TGetTag(tags, TVisual_Height, FB_DEF_HEIGHT); win->fbv_Left = (TUINT) TGetTag(tags, TVisual_WinLeft, 0xffffffff); win->fbv_Top = (TUINT) TGetTag(tags, TVisual_WinTop, 0xffffffff); win->fbv_Title = (TSTRPTR) TGetTag(tags, TVisual_Title, (TTAG) "TEKlib Visual"); win->fbv_Borderless = TGetTag(tags, TVisual_Borderless, TFALSE); win->fbv_UserData = TGetTag(tags, TVisual_UserData, TNULL); win->fbv_MinWidth = (TINT) TGetTag(tags, TVisual_MinWidth, (TTAG) -1); win->fbv_MinHeight = (TINT) TGetTag(tags, TVisual_MinHeight, (TTAG) -1); win->fbv_MaxWidth = (TINT) TGetTag(tags, TVisual_MaxWidth, (TTAG) -1); win->fbv_MaxHeight = (TINT) TGetTag(tags, TVisual_MaxHeight, (TTAG) -1); if (win->fbv_Borderless) { style = (WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS) & ~WS_BORDER; classname = FB_DISPLAY_CLASSNAME_POPUP; title = NULL; exstyle = WS_EX_TOPMOST | WS_EX_TOOLWINDOW; } else { style = WS_OVERLAPPEDWINDOW; classname = FB_DISPLAY_CLASSNAME; title = win->fbv_Title; exstyle = 0; } wrect.left = wrect.right = wrect.top = wrect.bottom = 0; AdjustWindowRectEx(&wrect, style, FALSE, exstyle); win->fbv_BorderWidth = wrect.right - wrect.left; win->fbv_BorderHeight = wrect.bottom - wrect.top; win->fbv_BorderLeft = -wrect.left; win->fbv_BorderTop = -wrect.top; if (!win->fbv_Borderless) { TINT m1, m2, m3, m4; win_getminmax(win, &m1, &m2, &m3, &m4, TTRUE); win->fbv_Width = TCLAMP(m1, (TINT) win->fbv_Width, m3); win->fbv_Height = TCLAMP(m2, (TINT) win->fbv_Height, m4); } if (win->fbv_Left != 0xffffffff && win->fbv_Top != 0xffffffff) { wrect.left = win->fbv_Left; wrect.top = win->fbv_Top; wrect.right = win->fbv_Left + win->fbv_Width; wrect.bottom = win->fbv_Top + win->fbv_Height; if (!AdjustWindowRectEx(&wrect, style, FALSE, exstyle)) break; win->fbv_Left = wrect.left; win->fbv_Top = wrect.top; win->fbv_HWnd = CreateWindowEx(exstyle, classname, title, style, win->fbv_Left, win->fbv_Top, wrect.right - wrect.left, wrect.bottom - wrect.top, (HWND) NULL, (HMENU) NULL, mod->fbd_HInst, (LPVOID) NULL); } else { win->fbv_HWnd = CreateWindowEx(exstyle, classname, title, style, CW_USEDEFAULT, CW_USEDEFAULT, win->fbv_Width, win->fbv_Height, (HWND) NULL, (HMENU) NULL, mod->fbd_HInst, (LPVOID) NULL); } if (win->fbv_HWnd == TNULL) break; 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; SetWindowLong(win->fbv_HWnd, GWL_USERDATA, (LONG) win); win->fbv_HDC = GetDC(win->fbv_HWnd); win->fbv_Display = mod; win->fbv_InputMask = (TUINT) TGetTag(tags, TVisual_EventMask, 0); win->fbv_IMsgPort = req->tvr_Op.OpenWindow.IMsgPort; bmi = &win->fbv_DrawBitMap; bmi->biSize = sizeof(BITMAPINFOHEADER); bmi->biPlanes = 1; bmi->biBitCount = 32; bmi->biCompression = BI_RGB; bmi->biSizeImage = 0; bmi->biXPelsPerMeter = 1; bmi->biYPelsPerMeter = 1; bmi->biClrUsed = 0; bmi->biClrImportant = 0; TInitList(&win->fbv_IMsgQueue); req->tvr_Op.OpenWindow.Window = win; win->fbv_Task = task; TLock(mod->fbd_Lock); /* init default font */ win->fbv_CurrentFont = mod->fbd_FontManager.deffont; mod->fbd_FontManager.defref++; /* register default font */ /*TDBPRINTF(TDB_TRACE,("Add window: %p\n", win->window));*/ /* add window on top of window stack: */ TAddHead(&mod->fbd_VisualList, &win->fbv_Node); TUnlock(mod->fbd_Lock); SetBkMode(win->fbv_HDC, TRANSPARENT); ShowWindow(win->fbv_HWnd, SW_SHOWNORMAL); UpdateWindow(win->fbv_HWnd); TSetTaskData(task, win); if ((win->fbv_InputMask & TITYPE_FOCUS) && (fb_getimsg(mod, win, &imsg, TITYPE_FOCUS))) { imsg->timsg_Code = 1; fb_sendimsg(mod, win, imsg); } if ((win->fbv_InputMask & TITYPE_REFRESH) && (fb_getimsg(mod, win, &imsg, TITYPE_REFRESH))) { imsg->timsg_X = 0; imsg->timsg_Y = 0; imsg->timsg_Width = win->fbv_Width; imsg->timsg_Height = win->fbv_Height; fb_sendimsg(mod, win, imsg); } return TTRUE; } TDBPRINTF(TDB_ERROR,("Window open failed\n")); fb_closeall(mod, win, TFALSE); return TFALSE; }