Exemple #1
0
ULONG
NTAPI
UiProcessMenuKeyboardEvent(IN PUI_MENU_INFO MenuInfo,
                           IN UiMenuKeyPressFilterCallback KeyPressFilter)
{
    ULONG KeyEvent = 0;
    ULONG Selected, Count;

    /* Check for a keypress */
    if (MachConsKbHit())
    {
        /* Check if the timeout is not already complete */
        if (MenuInfo->MenuTimeRemaining != -1)
        {
            /* Cancel it and remove it */
            MenuInfo->MenuTimeRemaining = -1;
            UiDrawMenuBox(MenuInfo);
        }

        /* Get the key */
        KeyEvent = MachConsGetCh();

        /* Is it extended? Then get the extended key */
        if (!KeyEvent) KeyEvent = MachConsGetCh();

        /*
         * Call the supplied key filter callback function to see
         * if it is going to handle this keypress.
         */
        if ((KeyPressFilter) && (KeyPressFilter(KeyEvent)))
        {
            /* It processed the key character, so redraw and exit */
            UiDrawMenu(MenuInfo);
            return 0;
        }

        /* Process the key */
        if ((KeyEvent == KEY_UP  ) || (KeyEvent == KEY_DOWN) ||
            (KeyEvent == KEY_HOME) || (KeyEvent == KEY_END ))
        {
            /* Get the current selected item and count */
            Selected = MenuInfo->SelectedMenuItem;
            Count = MenuInfo->MenuItemCount - 1;

            /* Check the key and change the selected menu item */
            if ((KeyEvent == KEY_UP) && (Selected > 0))
            {
                /* Deselect previous item and go up */
                MenuInfo->SelectedMenuItem--;
                UiDrawMenuItem(MenuInfo, Selected);
                Selected--;

                // Skip past any separators
                if ((Selected > 0) &&
                    (MenuInfo->MenuItemList[Selected] == NULL))
                {
                    MenuInfo->SelectedMenuItem--;
                }
            }
            else if ( ((KeyEvent == KEY_UP) && (Selected == 0)) ||
                       (KeyEvent == KEY_END) )
            {
                /* Go to the end */
                MenuInfo->SelectedMenuItem = Count;
                UiDrawMenuItem(MenuInfo, Selected);
            }
            else if ((KeyEvent == KEY_DOWN) && (Selected < Count))
            {
                /* Deselect previous item and go down */
                MenuInfo->SelectedMenuItem++;
                UiDrawMenuItem(MenuInfo, Selected);
                Selected++;

                // Skip past any separators
                if ((Selected < Count) &&
                    (MenuInfo->MenuItemList[Selected] == NULL))
                {
                    MenuInfo->SelectedMenuItem++;
                }
            }
            else if ( ((KeyEvent == KEY_DOWN) && (Selected == Count)) ||
                       (KeyEvent == KEY_HOME) )
            {
                /* Go to the beginning */
                MenuInfo->SelectedMenuItem = 0;
                UiDrawMenuItem(MenuInfo, Selected);
            }

            /* Select new item and update video buffer */
            UiDrawMenuItem(MenuInfo, MenuInfo->SelectedMenuItem);
        }
    }

    /*  Return the pressed key */
    return KeyEvent;
}
Exemple #2
0
ULONG
NTAPI
TuiProcessMenuKeyboardEvent(PUI_MENU_INFO MenuInfo,
                            UiMenuKeyPressFilterCallback KeyPressFilter)
{
    ULONG KeyEvent = 0;
    ULONG Selected, Count;

    //
    // Check for a keypress
    //
    if (MachConsKbHit())
    {
        //
        // Check if the timeout is not already complete
        //
        if (MenuInfo->MenuTimeRemaining != -1)
        {
            //
            // Cancel it and remove it
            //
            MenuInfo->MenuTimeRemaining = -1;
            TuiDrawMenuBox(MenuInfo); // FIXME: Remove for minimal UI too
        }

        //
        // Get the key
        //
        KeyEvent = MachConsGetCh();

        //
        // Is it extended? Then get the extended key
        //
        if (!KeyEvent) KeyEvent = MachConsGetCh();

        //
        // Call the supplied key filter callback function to see
        // if it is going to handle this keypress.
        //
        if ((KeyPressFilter) && (KeyPressFilter(KeyEvent)))
        {
            //
            // It processed the key character, so redraw and exit
            //
            UiVtbl.DrawMenu(MenuInfo);
            return 0;
        }

        //
        // Process the key
        //
        if ((KeyEvent == KEY_UP  ) || (KeyEvent == KEY_DOWN) ||
            (KeyEvent == KEY_HOME) || (KeyEvent == KEY_END ))
        {
            //
            // Get the current selected item and count
            //
            Selected = MenuInfo->SelectedMenuItem;
            Count = MenuInfo->MenuItemCount - 1;

            //
            // Check the key and change the selected menu item
            //
            if ((KeyEvent == KEY_UP) && (Selected > 0))
            {
                //
                // Deselect previous item and go up
                //
                MenuInfo->SelectedMenuItem--;
                TuiDrawMenuItem(MenuInfo, Selected);
                Selected--;

                // Skip past any separators
                if ((Selected > 0) &&
                    (MenuInfo->MenuItemList[Selected] == NULL))
                {
                    MenuInfo->SelectedMenuItem--;
                }
            }
            else if ( ((KeyEvent == KEY_UP) && (Selected == 0)) ||
                       (KeyEvent == KEY_END) )
            {
                //
                // Go to the end
                //
                MenuInfo->SelectedMenuItem = Count;
                TuiDrawMenuItem(MenuInfo, Selected);
            }
            else if ((KeyEvent == KEY_DOWN) && (Selected < Count))
            {
                //
                // Deselect previous item and go down
                //
                MenuInfo->SelectedMenuItem++;
                TuiDrawMenuItem(MenuInfo, Selected);
                Selected++;

                // Skip past any separators
                if ((Selected < Count) &&
                    (MenuInfo->MenuItemList[Selected] == NULL))
                {
                    MenuInfo->SelectedMenuItem++;
                }
            }
            else if ( ((KeyEvent == KEY_DOWN) && (Selected == Count)) ||
                       (KeyEvent == KEY_HOME) )
            {
                //
                // Go to the beginning
                //
                MenuInfo->SelectedMenuItem = 0;
                TuiDrawMenuItem(MenuInfo, Selected);
            }

            //
            // Select new item and update video buffer
            //
            TuiDrawMenuItem(MenuInfo, MenuInfo->SelectedMenuItem);
            VideoCopyOffScreenBufferToVRAM();
        }
    }

    //
    // Return the pressed key
    //
    return KeyEvent;
}
Exemple #3
0
BOOLEAN TuiEditBox(PCSTR MessageText, PCHAR EditTextBuffer, ULONG Length)
{
	int		width = 8;
	unsigned int	height = 1;
	int		curline = 0;
	int		k;
	size_t		i , j;
	int		x1, x2, y1, y2;
	char	temp[260];
	char	key;
	int		EditBoxLine;
	ULONG		EditBoxStartX, EditBoxEndX;
	int		EditBoxCursorX;
	unsigned int	EditBoxTextCount;
	int		EditBoxTextDisplayIndex;
	BOOLEAN	ReturnCode;
	PVOID	ScreenBuffer;

	// Save the screen contents
	ScreenBuffer = MmHeapAlloc(UiScreenWidth * UiScreenHeight * 2);
	TuiSaveScreen(ScreenBuffer);

	// Find the height
	for (i=0; i<strlen(MessageText); i++)
	{
		if (MessageText[i] == '\n')
			height++;
	}

	// Find the width
	for (i=0,j=0,k=0; i<height; i++)
	{
		while ((MessageText[j] != '\n') && (MessageText[j] != 0))
		{
			j++;
			k++;
		}

		if (k > width)
			width = k;

		k = 0;
		j++;
	}

	// Calculate box area
	x1 = (UiScreenWidth - (width+2))/2;
	x2 = x1 + width + 3;
	y1 = ((UiScreenHeight - height - 2)/2) + 1;
	y2 = y1 + height + 4;

	// Draw the box
	TuiDrawBox(x1, y1, x2, y2, D_VERT, D_HORZ, TRUE, TRUE, ATTR(UiMessageBoxFgColor, UiMessageBoxBgColor));

	// Draw the text
	for (i=0,j=0; i<strlen(MessageText)+1; i++)
	{
		if ((MessageText[i] == '\n') || (MessageText[i] == 0))
		{
			temp[j] = 0;
			j = 0;
			UiDrawText(x1+2, y1+1+curline, temp, ATTR(UiMessageBoxFgColor, UiMessageBoxBgColor));
			curline++;
		}
		else
			temp[j++] = MessageText[i];
	}

	EditBoxTextCount = 0;
	EditBoxLine = y2 - 2;
	EditBoxStartX = x1 + 3;
	EditBoxEndX = x2 - 3;
	UiFillArea(EditBoxStartX, EditBoxLine, EditBoxEndX, EditBoxLine, ' ', ATTR(UiEditBoxTextColor, UiEditBoxBgColor));

	// Show the cursor
	EditBoxCursorX = EditBoxStartX;
	MachVideoSetTextCursorPosition(EditBoxCursorX, EditBoxLine);
	MachVideoHideShowTextCursor(TRUE);

	// Draw status text
	UiDrawStatusText("Press ENTER to continue, or ESC to cancel");

	VideoCopyOffScreenBufferToVRAM();

	for (;;)
	{
		if (MachConsKbHit())
		{
			key = MachConsGetCh();
			if(key == KEY_EXTENDED)
			{
				key = MachConsGetCh();
			}

			if(key == KEY_ENTER)
			{
				ReturnCode = TRUE;
				break;
			}
			else if(key == KEY_ESC)
			{
				ReturnCode = FALSE;
				break;
			}
			else if (key == KEY_BACKSPACE) // Remove a character
			{
				if (EditBoxTextCount)
				{
					EditBoxTextCount--;
					EditTextBuffer[EditBoxTextCount] = 0;
				}
				else
				{
					MachBeep();
				}
			}
			else // Add this key to the buffer
			{
				if (EditBoxTextCount < Length - 1)
				{
					EditTextBuffer[EditBoxTextCount] = key;
					EditBoxTextCount++;
					EditTextBuffer[EditBoxTextCount] = 0;
				}
				else
				{
					MachBeep();
				}
			}
		}

		// Draw the edit box background
		UiFillArea(EditBoxStartX, EditBoxLine, EditBoxEndX, EditBoxLine, ' ', ATTR(UiEditBoxTextColor, UiEditBoxBgColor));

		// Fill the text in
		if (EditBoxTextCount > (EditBoxEndX - EditBoxStartX))
		{
			EditBoxTextDisplayIndex = EditBoxTextCount - (EditBoxEndX - EditBoxStartX);
			EditBoxCursorX = EditBoxEndX;
		}
		else
		{
			EditBoxTextDisplayIndex = 0;
			EditBoxCursorX = EditBoxStartX + EditBoxTextCount;
		}
		UiDrawText(EditBoxStartX, EditBoxLine, &EditTextBuffer[EditBoxTextDisplayIndex], ATTR(UiEditBoxTextColor, UiEditBoxBgColor));

		// Move the cursor
		MachVideoSetTextCursorPosition(EditBoxCursorX, EditBoxLine);

		TuiUpdateDateTime();

		VideoCopyOffScreenBufferToVRAM();
	}

	// Hide the cursor again
	MachVideoHideShowTextCursor(FALSE);

	// Restore the screen contents
	TuiRestoreScreen(ScreenBuffer);
	MmHeapFree(ScreenBuffer);

	return ReturnCode;
}
Exemple #4
0
ULONG
NTAPI
UiProcessMenuKeyboardEvent(IN PUI_MENU_INFO MenuInfo,
                           IN UiMenuKeyPressFilterCallback KeyPressFilter)
{
    ULONG KeyEvent = 0, Selected, Count;

    /* Check for a keypress */
    if (MachConsKbHit())
    {
        /* Check if the timeout is not already complete */
        if (MenuInfo->MenuTimeRemaining != -1)
        {
            //
            // Cancel it and remove it
            //
            MenuInfo->MenuTimeRemaining = -1;
            UiDrawMenuBox(MenuInfo);
        }

        /* Get the key */
        KeyEvent = MachConsGetCh();

        /* Is it extended? Then get the extended key */
        if (!KeyEvent) KeyEvent = MachConsGetCh();

        /* Call the supplied key filter callback function to see if it is going to handle this keypress. */
        if ((KeyPressFilter) && (KeyPressFilter(KeyEvent)))
        {
            /* It processed the key character, so redraw and exit */
            UiDrawMenu(MenuInfo);
            return 0;
        }

        /* Process the key */
        if ((KeyEvent == KEY_UP) || (KeyEvent == KEY_DOWN))
        {
            /* Get the current selected item and count */
            Selected = MenuInfo->SelectedMenuItem;
            Count = MenuInfo->MenuItemCount - 1;

            /* Check if this was a key up and there's a selected menu item */
            if ((KeyEvent == KEY_UP) && (Selected))
            {
                /* Update the menu (Deselect previous item) */
                MenuInfo->SelectedMenuItem--;
                UiDrawMenuItem(MenuInfo, Selected);
                Selected--;

                /* Skip past any separators */
                if ((Selected) &&
                    !(_stricmp(MenuInfo->MenuItemList[Selected], "SEPARATOR")))
                {
                    MenuInfo->SelectedMenuItem--;
                }
            }
            else if ((KeyEvent == KEY_DOWN) && (Selected < Count))
            {
                /* Update the menu (deselect previous item) */
                MenuInfo->SelectedMenuItem++;
                UiDrawMenuItem(MenuInfo, Selected);
                Selected++;

                /* Skip past any separators */
                if ((Selected < Count) &&
                    !(_stricmp(MenuInfo->MenuItemList[Selected], "SEPARATOR")))
                {
                    MenuInfo->SelectedMenuItem++;
                }
            }

            /* Select new item and update video buffer */
            UiDrawMenuItem(MenuInfo, MenuInfo->SelectedMenuItem);
        }
    }

    /*  Return the pressed key */
    return KeyEvent;
}
Exemple #5
0
VOID TuiMessageBoxCritical(PCSTR MessageText)
{
	int		width = 8;
	unsigned int	height = 1;
	int		curline = 0;
	int		k;
	size_t		i , j;
	int		x1, x2, y1, y2;
	char	temp[260];
	char	key;

	// Find the height
	for (i=0; i<strlen(MessageText); i++)
	{
		if (MessageText[i] == '\n')
			height++;
	}

	// Find the width
	for (i=0,j=0,k=0; i<height; i++)
	{
		while ((MessageText[j] != '\n') && (MessageText[j] != 0))
		{
			j++;
			k++;
		}

		if (k > width)
			width = k;

		k = 0;
		j++;
	}

	// Calculate box area
	x1 = (UiScreenWidth - (width+2))/2;
	x2 = x1 + width + 3;
	y1 = ((UiScreenHeight - height - 2)/2) + 1;
	y2 = y1 + height + 4;

	// Draw the box
	TuiDrawBox(x1, y1, x2, y2, D_VERT, D_HORZ, TRUE, TRUE, ATTR(UiMessageBoxFgColor, UiMessageBoxBgColor));

	// Draw the text
	for (i=0,j=0; i<strlen(MessageText)+1; i++)
	{
		if ((MessageText[i] == '\n') || (MessageText[i] == 0))
		{
			temp[j] = 0;
			j = 0;
			UiDrawText(x1+2, y1+1+curline, temp, ATTR(UiMessageBoxFgColor, UiMessageBoxBgColor));
			curline++;
		}
		else
			temp[j++] = MessageText[i];
	}

	// Draw OK button
	strcpy(temp, "   OK   ");
	UiDrawText(x1+((x2-x1)/2)-3, y2-2, temp, ATTR(COLOR_BLACK, COLOR_GRAY));

	// Draw status text
	UiDrawStatusText("Press ENTER to continue");

	VideoCopyOffScreenBufferToVRAM();

	for (;;)
	{
		if (MachConsKbHit())
		{
			key = MachConsGetCh();
			if(key == KEY_EXTENDED)
				key = MachConsGetCh();

			if(key == KEY_ENTER)
				break;
			else if(key == KEY_SPACE)
				break;
			else if(key == KEY_ESC)
				break;
		}

		TuiUpdateDateTime();

		VideoCopyOffScreenBufferToVRAM();
	}

}