Пример #1
0
static TBOOL
exec_init(TEXECBASE *exec, TTAGITEM *tags)
{
	TAPTR *halp, hal;

	halp = (TAPTR *) TGetTag(tags, TExecBase_HAL, TNULL);
	if (!halp)
		return TFALSE;
	hal = *halp;

	THALFillMem(hal, exec, sizeof(TEXECBASE), 0);
	exec->texb_HALBase = hal;

	if (THALInitLock(hal, &exec->texb_Lock))
	{
		if (exec_initmm(exec, &exec->texb_MsgMemManager, TNULL, TMMT_Message,
			TNULL))
		{
			if (exec_initmm(exec, &exec->texb_BaseMemManager, TNULL,
				TMMT_MemManager, TNULL))
			{
				exec->texb_Module.tmd_Handle.thn_Hook.thk_Data = exec;
				exec->texb_Module.tmd_Handle.thn_Name = TMODNAME_EXEC;
				exec->texb_Module.tmd_Handle.thn_Owner =
					(struct TModule *) exec;
				exec->texb_Module.tmd_ModSuper = (struct TModule *) exec;
				exec->texb_Module.tmd_InitTask = TNULL; /* inserted later */
				exec->texb_Module.tmd_HALMod = TNULL; /* inserted later */
				exec->texb_Module.tmd_NegSize =
					EXEC_NUMVECTORS * sizeof(TAPTR);
				exec->texb_Module.tmd_PosSize = sizeof(TEXECBASE);
				exec->texb_Module.tmd_RefCount = 1;
				exec->texb_Module.tmd_Flags =
					TMODF_INITIALIZED | TMODF_VECTORTABLE;

				TInitList(&exec->texb_IntModList);
				exec->texb_InitModNode.tmin_Modules = (struct TInitModule *)
					TGetTag(tags, TExecBase_ModInit, TNULL);
				if (exec->texb_InitModNode.tmin_Modules)
				{
					TAddTail(&exec->texb_IntModList,
						&exec->texb_InitModNode.tmin_Node);
				}

				TInitList(&exec->texb_AtomList);
				TInitList(&exec->texb_TaskList);
				TInitList(&exec->texb_TaskInitList);
				TInitList(&exec->texb_TaskExitList);
				TInitList(&exec->texb_ModList);
				TAddHead(&exec->texb_ModList, (struct TNode *) exec);
				TAddHead(&exec->texb_ModList, (struct TNode *) hal);

				return TTRUE;
			}
			TDESTROY(&exec->texb_MsgMemManager);
		}
		THALDestroyLock(hal, &exec->texb_Lock);
	}
	return TFALSE;
}
Пример #2
0
Файл: hal.c Проект: callcc/tekui
static void CALLBACK
hal_timeproc(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
	struct TNode *node, *nnode;

	if (TryEnterCriticalSection(&g_hws->hsp_DevLock))
	{
		TTIME curtime;
		hal_getsystime(g_hal, &curtime);
		node = g_hws->hsp_ReqList.tlh_Head.tln_Succ;
		for (; (nnode = node->tln_Succ); node = nnode)
		{
			struct TTimeRequest *tr = (struct TTimeRequest *) node;
			if (TCmpTime(&curtime, &tr->ttr_Data.ttr_Time) >= 0)
			{
				TRemove(node);
				TAddTail(&g_ReplyList, node);
			}
		}

		node = g_ReplyList.tlh_Head.tln_Succ;
		for (; (nnode = node->tln_Succ); node = nnode)
		{
			struct TTimeRequest *tr = (struct TTimeRequest *) node;
			TRemove(node);
			if (!hal_replytimereq(tr))
				TAddHead(&g_ReplyList, node);
		}

		LeaveCriticalSection(&g_hws->hsp_DevLock);
	}
}
Пример #3
0
TLIBAPI void
TInsert(struct TList *list, struct TNode *node, struct TNode *prednode)
{
	if (list)
	{
		if (prednode)
		{
			struct TNode *temp = prednode->tln_Succ;
			if (temp)
			{
				node->tln_Succ = temp;
				node->tln_Pred = prednode;
				temp->tln_Pred = node;
				prednode->tln_Succ = node;
			}
			else
			{
				node->tln_Succ = prednode;
				temp = prednode->tln_Pred;
				node->tln_Pred = temp;
				prednode->tln_Pred = node;
				temp->tln_Succ = node;
			}
		}
		else
			TAddHead(list, node);
	}
}
Пример #4
0
LOCAL void
dfb_openvisual(DFBDISPLAY *mod, struct TVRequest *req)
{
	TTAGITEM *tags = req->tvr_Op.OpenWindow.Tags;
	TAPTR exec = TGetExecBase(mod);
	DFBWINDOW *v;
	DFBWindowDescription wdsc;

	struct FontNode *fn;

	v = TExecAlloc0(exec, mod->dfb_MemMgr, sizeof(DFBWINDOW));
	req->tvr_Op.OpenWindow.Window = v;
	if (v == TNULL) return;

	v->userdata = TGetTag(tags, TVisual_UserData, TNULL);
	v->eventmask = (TUINT) TGetTag(tags, TVisual_EventMask, 0);

	TInitList(&v->penlist);
	v->bgpen = TVPEN_UNDEFINED;
	v->fgpen = TVPEN_UNDEFINED;

	TInitList(&v->imsgqueue);
	v->imsgport = req->tvr_Op.OpenWindow.IMsgPort;

	v->title = (TSTRPTR)
		TGetTag(tags, TVisual_Title, (TTAG) "TEKlib visual");

	/* size/position calculation: */

	v->winwidth = (TINT) TGetTag(tags,
		TVisual_Width,
		(TTAG) TMIN(mod->dfb_ScrWidth, DEF_WINWIDTH));
	v->winheight = (TINT) TGetTag(tags,
		TVisual_Height,
		(TTAG) TMIN(mod->dfb_ScrHeight, DEF_WINHEIGHT));

	if (TGetTag(tags, TVisual_Center, TFALSE))
	{
		v->winleft = (mod->dfb_ScrWidth - v->winwidth) / 2;
		v->wintop = (mod->dfb_ScrHeight - v->winheight) / 2;
	}
	else if (TGetTag(tags, TVisual_FullScreen, TFALSE))
	{
		v->winwidth = mod->dfb_ScrWidth;
		v->winheight = mod->dfb_ScrHeight;
		v->winleft = 0;
		v->wintop = 0;
	}
	else
	{
		v->winleft = (TINT) TGetTag(tags, TVisual_WinLeft, (TTAG) -1);
		v->wintop = (TINT) TGetTag(tags, TVisual_WinTop, (TTAG) -1);
	}

	if (!TGetTag(tags, TVisual_Borderless, TFALSE))
	{
		v->wminwidth = (TINT) TGetTag(tags, TVisual_MinWidth, (TTAG) -1);
		v->wminheight = (TINT) TGetTag(tags, TVisual_MinHeight, (TTAG) -1);
		v->wmaxwidth = (TINT) TGetTag(tags, TVisual_MaxWidth, (TTAG) -1);
		v->wmaxheight = (TINT) TGetTag(tags, TVisual_MaxHeight, (TTAG) -1);

		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->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;
	}

	v->winleft = TMAX(v->winleft, 0);
	v->wintop = TMAX(v->wintop, 0);

	if (TGetTag(tags, TVisual_Borderless, TFALSE))
		v->borderless = TTRUE;

	wdsc.flags = (DWDESC_POSX | DWDESC_POSY | DWDESC_WIDTH | DWDESC_HEIGHT);
	wdsc.posx   = v->winleft;
	wdsc.posy   = v->wintop;
	wdsc.width  = v->winwidth;
	wdsc.height = v->winheight;

	if (mod->dfb_Layer->CreateWindow(mod->dfb_Layer, &wdsc, &v->window) == DFB_OK)
	{
		v->window->GetSurface(v->window, &v->winsurface);
		v->window->SetOpacity(v->window, 0xFF);
		v->window->GetID(v->window, &v->winid);
		v->window->AttachEventBuffer(v->window, mod->dfb_Events);

		v->window->RequestFocus(v->window);
		v->window->RaiseToTop(v->window);

		if (!v->borderless)
		{
			/* generate focus events */
			genimsg(mod, (DFBWINDOW *)mod->dfb_Focused, v, TITYPE_FOCUS);
			mod->dfb_Focused = (TAPTR) v;
		}

		v->winsurface->SetColor(v->winsurface, 0x00, 0x00, 0xff, 0xff);
		v->winsurface->DrawRectangle(v->winsurface, 0, 0, wdsc.width, wdsc.height);
		v->winsurface->SetColor(v->winsurface, 0x80, 0x80, 0x80, 0xff);
		v->winsurface->FillRectangle(v->winsurface, 1, 1, wdsc.width-2, wdsc.height-2);
		v->winsurface->Flip(v->winsurface, NULL, 0);

		/* init default font */
		fn = mod->dfb_fm.deffont;
		v->curfont = fn;
		mod->dfb_fm.defref++;

		if (v->winsurface->SetFont(v->winsurface, fn->font) == DFB_OK)
		{
			if (v->winsurface->SetFont(v->winsurface, fn->font) == DFB_OK)
			{
				TDBPRINTF(TDB_TRACE,("Add window: %p\n", v->window));
				TAddHead(&mod->dfb_vlist, &v->node);

				/* success: */
				return;
			}
		}
     }

	TExecFree(exec, v);

	/* failure: */
	TDBPRINTF(TDB_ERROR,("Open failed\n"));
	req->tvr_Op.OpenWindow.Window = TNULL;
}
Пример #5
0
LOCAL void
fb_openwindow(WINDISPLAY *mod, struct TVRequest *req)
{
	struct TExecBase *TExecBase = TGetExecBase(mod);
	TTAGITEM *tags = req->tvr_Op.OpenWindow.Tags;
	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);

		InitializeCriticalSection(&win->fbv_LockExtents);

		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 - win->fbv_BorderWidth, 
				wrect.bottom - wrect.top - win->fbv_BorderHeight,
				(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;

		SetWindowLongPtr(win->fbv_HWnd, GWLP_USERDATA, (LONG_PTR) 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;

		/* init default font */
		win->fbv_CurrentFont = mod->fbd_FontManager.deffont;
		mod->fbd_FontManager.defref++;

		if (win->fbv_InputMask & TITYPE_INTERVAL)
			++mod->fbd_NumInterval;

		/* 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);

		SetBkMode(win->fbv_HDC, TRANSPARENT);
		
		ShowWindow(win->fbv_HWnd, SW_SHOWNORMAL);
		UpdateWindow(win->fbv_HWnd);

		if ((win->fbv_InputMask & TITYPE_FOCUS) &&
			(fb_getimsg(mod, win, &imsg, TITYPE_FOCUS)))
		{
			imsg->timsg_Code = 1;
			TAddTail(&win->fbv_IMsgQueue, &imsg->timsg_Node);
		}
		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;
			TAddTail(&win->fbv_IMsgQueue, &imsg->timsg_Node);
		}
		
		return;
	}

	TDBPRINTF(TDB_ERROR,("Window open failed\n"));
	fb_closeall(mod, win, TFALSE);
}