⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ui.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
📖 第 1 页 / 共 2 页
字号:
VOID UiDrawText(ULONG X, ULONG Y, PCSTR Text, UCHAR Attr)
{
	if (VideoTextMode == UiDisplayMode)
	{
		TuiDrawText(X, Y, Text, Attr);
	}
	else
	{
		UNIMPLEMENTED();
		//GuiDrawText(X, Y, Text, Attr);
	}
}

VOID UiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCSTR TextString, UCHAR Attr)
{
	if (VideoTextMode == UiDisplayMode)
	{
		TuiDrawCenteredText(Left, Top, Right, Bottom, TextString, Attr);
	}
	else
	{
		UNIMPLEMENTED();
		//GuiDrawCenteredText(Left, Top, Right, Bottom, TextString, Attr);
	}
}

VOID UiDrawStatusText(PCSTR StatusText)
{
	if (!UserInterfaceUp) return;

	if (VideoTextMode == UiDisplayMode)
	{
		TuiDrawStatusText(StatusText);
	}
	else
	{
		UNIMPLEMENTED();
		//GuiDrawStatusText(StatusText);
	}
}

VOID UiUpdateDateTime(VOID)
{
	if (VideoTextMode == UiDisplayMode)
	{
		TuiUpdateDateTime();
	}
	else
	{
		UNIMPLEMENTED();
		//GuiUpdateDateTime();
	}
}

VOID UiInfoBox(PCSTR MessageText)
{
	ULONG		TextLength;
	ULONG		BoxWidth;
	ULONG		BoxHeight;
	ULONG		LineBreakCount;
	ULONG		Index;
	ULONG		LastIndex;
	ULONG		Left;
	ULONG		Top;
	ULONG		Right;
	ULONG		Bottom;

	TextLength = strlen(MessageText);

	// Count the new lines and the box width
	LineBreakCount = 0;
	BoxWidth = 0;
	LastIndex = 0;
	for (Index=0; Index<TextLength; Index++)
	{
		if (MessageText[Index] == '\n')
		{
			LastIndex = Index;
			LineBreakCount++;
		}
		else
		{
			if ((Index - LastIndex) > BoxWidth)
			{
				BoxWidth = (Index - LastIndex);
			}
		}
	}

	// Calc the box width & height
	BoxWidth += 6;
	BoxHeight = LineBreakCount + 4;

	// Calc the box coordinates
	Left = (UiScreenWidth / 2) - (BoxWidth / 2);
	Top =(UiScreenHeight / 2) - (BoxHeight / 2);
	Right = (UiScreenWidth / 2) + (BoxWidth / 2);
	Bottom = (UiScreenHeight / 2) + (BoxHeight / 2);

	// Draw the box
	UiDrawBox(Left,
			  Top,
			  Right,
			  Bottom,
			  VERT,
			  HORZ,
			  TRUE,
			  TRUE,
			  ATTR(UiMenuFgColor, UiMenuBgColor)
			  );

	// Draw the text
	UiDrawCenteredText(Left, Top, Right, Bottom, MessageText, ATTR(UiTextColor, UiMenuBgColor));
}

VOID UiMessageBox(PCSTR MessageText)
{
	// We have not yet displayed the user interface
	// We are probably still reading the .ini file
	// and have encountered an error. Just use printf()
	// and return.
	if (!UserInterfaceUp)
	{
		printf("%s\n", MessageText);
		printf("Press any key\n");
		MachConsGetCh();
		return;
	}

	if (VideoTextMode == UiDisplayMode)
	{
		TuiMessageBox(MessageText);
	}
	else
	{
		UNIMPLEMENTED();
		//GuiMessageBox(MessageText);
	}
}

VOID UiMessageBoxCritical(PCSTR MessageText)
{
	// We have not yet displayed the user interface
	// We are probably still reading the .ini file
	// and have encountered an error. Just use printf()
	// and return.
	if (!UserInterfaceUp)
	{
		printf("%s\n", MessageText);
		printf("Press any key\n");
		MachConsGetCh();
		return;
	}

	if (VideoTextMode == UiDisplayMode)
	{
		TuiMessageBoxCritical(MessageText);
	}
	else
	{
		UNIMPLEMENTED();
		//GuiMessageBoxCritical(MessageText);
	}
}

UCHAR UiTextToColor(PCSTR ColorText)
{
	if (VideoTextMode == UiDisplayMode)
	{
		return TuiTextToColor(ColorText);
	}
	else
	{
		UNIMPLEMENTED();
		return 0;
		//return GuiTextToColor(ColorText);
	}
}

UCHAR UiTextToFillStyle(PCSTR FillStyleText)
{
	if (VideoTextMode == UiDisplayMode)
	{
		return TuiTextToFillStyle(FillStyleText);
	}
	else
	{
		UNIMPLEMENTED();
		return 0;
		//return GuiTextToFillStyle(FillStyleText);
	}
}

VOID UiDrawProgressBarCenter(ULONG Position, ULONG Range, PCHAR ProgressText)
{
	if (!UserInterfaceUp) return;

	if (VideoTextMode == UiDisplayMode)
	{
		TuiDrawProgressBarCenter(Position, Range, ProgressText);
	}
	else
	{
		UNIMPLEMENTED();
		//GuiDrawProgressBarCenter(Position, Range, ProgressText);
	}
}

VOID UiDrawProgressBar(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, ULONG Position, ULONG Range, PCHAR ProgressText)
{
	if (VideoTextMode == UiDisplayMode)
	{
		TuiDrawProgressBar(Left, Top, Right, Bottom, Position, Range, ProgressText);
	}
	else
	{
		UNIMPLEMENTED();
		//GuiDrawProgressBar(Left, Top, Right, Bottom, Position, Range, ProgressText);
	}
}

VOID UiShowMessageBoxesInSection(PCSTR SectionName)
{
	ULONG		Idx;
	CHAR	SettingName[80];
	CHAR	SettingValue[80];
	PCHAR	MessageBoxText;
	ULONG		MessageBoxTextSize;
	ULONG		SectionId;

	if (!IniOpenSection(SectionName, &SectionId))
	{
		sprintf(SettingName, "Section %s not found in freeldr.ini.\n", SectionName);
		UiMessageBox(SettingName);
		return;
	}

	//
	// Find all the message box settings and run them
	//
	for (Idx=0; Idx<IniGetNumSectionItems(SectionId); Idx++)
	{
		IniReadSettingByNumber(SectionId, Idx, SettingName, sizeof(SettingName), SettingValue, sizeof(SettingValue));

		if (_stricmp(SettingName, "MessageBox") == 0)
		{
			// Get the real length of the MessageBox text
			MessageBoxTextSize = IniGetSectionSettingValueSize(SectionId, Idx);

			//if (MessageBoxTextSize > 0)
			{
				// Allocate enough memory to hold the text
				MessageBoxText = MmAllocateMemory(MessageBoxTextSize);

				if (MessageBoxText)
				{
					// Get the MessageBox text
					IniReadSettingByNumber(SectionId, Idx, SettingName, sizeof(SettingName), MessageBoxText, MessageBoxTextSize);

					// Fix it up
					UiEscapeString(MessageBoxText);

					// Display it
					UiMessageBox(MessageBoxText);

					// Free the memory
					MmFreeMemory(MessageBoxText);
				}
			}
		}
	}
}

VOID UiEscapeString(PCHAR String)
{
	ULONG		Idx;

	for (Idx=0; Idx<strlen(String); Idx++)
	{
		// Escape the new line characters
		if (String[Idx] == '\\' && String[Idx+1] == 'n')
		{
			// Escape the character
			String[Idx] = '\n';

			// Move the rest of the string up
			strcpy(&String[Idx+1], &String[Idx+2]);
		}
	}
}

VOID UiTruncateStringEllipsis(PCHAR StringText, ULONG MaxChars)
{
	if (strlen(StringText) > MaxChars)
	{
		strcpy(&StringText[MaxChars - 3], "...");
	}
}

BOOLEAN UiDisplayMenu(PCSTR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, ULONG* SelectedMenuItem, BOOLEAN CanEscape, UiMenuKeyPressFilterCallback KeyPressFilter)
{
	if (VideoTextMode == UiDisplayMode)
	{
		return TuiDisplayMenu(MenuItemList, MenuItemCount, DefaultMenuItem, MenuTimeOut, SelectedMenuItem, CanEscape, KeyPressFilter);
	}
	else
	{
		UNIMPLEMENTED();
		return FALSE;
		//return GuiDisplayMenu(MenuItemList, MenuItemCount, DefaultMenuItem, MenuTimeOut, SelectedMenuItem, CanEscape, KeyPressFilter);
	}
}

VOID UiFadeInBackdrop(VOID)
{
	if (VideoTextMode == UiDisplayMode)
	{
		TuiFadeInBackdrop();
	}
	else
	{
		UNIMPLEMENTED();
		//GuiFadeInBackdrop();
	}
}

VOID UiFadeOut(VOID)
{
	if (VideoTextMode == UiDisplayMode)
	{
		TuiFadeOut();
	}
	else
	{
		UNIMPLEMENTED();
		//GuiFadeInOut();
	}
}

BOOLEAN UiEditBox(PCSTR MessageText, PCHAR EditTextBuffer, ULONG Length)
{
	if (VideoTextMode == UiDisplayMode)
	{
		return TuiEditBox(MessageText, EditTextBuffer, Length);
	}
	else
	{
		UNIMPLEMENTED();
		return FALSE;
		//return GuiEditBox(MessageText, EditTextBuffer, Length);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -