[MKHIVE/USETUP]
[reactos.git] / reactos / base / setup / usetup / interface / consup.c
index c33bff3..6c74040 100644 (file)
@@ -12,9 +12,9 @@
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 /*
  * COPYRIGHT:       See COPYING in the top level directory
 #define NDEBUG
 #include <debug.h>
 
+/* GLOBALS ******************************************************************/
+
+HANDLE StdInput  = INVALID_HANDLE_VALUE;
+HANDLE StdOutput = INVALID_HANDLE_VALUE;
+
+SHORT xScreen = 0;
+SHORT yScreen = 0;
+
 /* FUNCTIONS *****************************************************************/
 
+BOOLEAN
+CONSOLE_Init(
+       VOID)
+{
+       CONSOLE_SCREEN_BUFFER_INFO csbi;
+       if (!HOST_InitConsole())
+               return FALSE;
+
+       StdInput = GetStdHandle(STD_INPUT_HANDLE);
+       StdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
+       if (!GetConsoleScreenBufferInfo(StdOutput, &csbi))
+               return FALSE;
+       xScreen = csbi.dwSize.X;
+       yScreen = 50;//csbi.dwSize.Y;
+       return TRUE;
+}
+
 VOID
 CONSOLE_ConInKey(
        OUT PINPUT_RECORD Buffer)
 {
-       ULONG Read;
+       DWORD Read;
 
        while (TRUE)
        {
@@ -53,7 +78,7 @@ VOID
 CONSOLE_ConOutChar(
        IN CHAR c)
 {
-       ULONG Written;
+       DWORD Written;
 
        WriteConsole(
                StdOutput,
@@ -67,12 +92,12 @@ VOID
 CONSOLE_ConOutPuts(
        IN LPCSTR szText)
 {
-       ULONG Written;
+       DWORD Written;
 
        WriteConsole(
                StdOutput,
                szText,
-               strlen(szText),
+               (ULONG)strlen(szText),
                &Written,
                NULL);
        WriteConsole(
@@ -98,11 +123,17 @@ CONSOLE_ConOutPrintf(
        WriteConsole(
                StdOutput,
                szOut,
-               strlen(szOut),
+               (ULONG)strlen(szOut),
                &dwWritten,
                NULL);
 }
 
+BOOL
+CONSOLE_Flush(VOID)
+{
+       return FlushConsoleInputBuffer(StdInput);
+}
+
 SHORT
 CONSOLE_GetCursorX(VOID)
 {
@@ -123,20 +154,6 @@ CONSOLE_GetCursorY(VOID)
        return csbi.dwCursorPosition.Y;
 }
 
-VOID
-CONSOLE_GetScreenSize(
-       OUT SHORT *maxx,
-       OUT SHORT *maxy)
-{
-       CONSOLE_SCREEN_BUFFER_INFO csbi;
-
-       GetConsoleScreenBufferInfo(StdOutput, &csbi);
-
-       *maxx = csbi.dwSize.X;
-
-       *maxy = csbi.dwSize.Y;
-}
-
 VOID
 CONSOLE_SetCursorType(
        IN BOOL bInsert,
@@ -166,7 +183,7 @@ VOID
 CONSOLE_ClearScreen(VOID)
 {
        COORD coPos;
-       ULONG Written;
+       DWORD Written;
 
        coPos.X = 0;
        coPos.Y = 0;
@@ -186,44 +203,6 @@ CONSOLE_ClearScreen(VOID)
                &Written);
 }
 
-VOID
-CONSOLE_SetStatusText(
-       IN LPCSTR fmt, ...)
-{
-       CHAR Buffer[128];
-       va_list ap;
-       COORD coPos;
-       ULONG Written;
-
-       va_start(ap, fmt);
-       vsprintf(Buffer, fmt, ap);
-       va_end(ap);
-
-       coPos.X = 0;
-       coPos.Y = yScreen - 1;
-
-       FillConsoleOutputAttribute(
-               StdOutput,
-               BACKGROUND_WHITE,
-               xScreen,
-               coPos,
-               &Written);
-
-       FillConsoleOutputCharacterA(
-               StdOutput,
-               ' ',
-               xScreen,
-               coPos,
-               &Written);
-
-       WriteConsoleOutputCharacterA(
-               StdOutput,
-               Buffer,
-               strlen(Buffer),
-               coPos,
-               &Written);
-}
-
 VOID
 CONSOLE_InvertTextXY(
        IN SHORT x,
@@ -232,7 +211,7 @@ CONSOLE_InvertTextXY(
        IN SHORT row)
 {
        COORD coPos;
-       ULONG Written;
+       DWORD Written;
 
        for (coPos.Y = y; coPos.Y < y + row; coPos.Y++)
        {
@@ -255,7 +234,7 @@ CONSOLE_NormalTextXY(
        IN SHORT row)
 {
        COORD coPos;
-       ULONG Written;
+       DWORD Written;
 
        for (coPos.Y = y; coPos.Y < y + row; coPos.Y++)
        {
@@ -277,7 +256,7 @@ CONSOLE_SetTextXY(
        IN LPCSTR Text)
 {
        COORD coPos;
-       ULONG Written;
+       DWORD Written;
 
        coPos.X = x;
        coPos.Y = y;
@@ -285,7 +264,7 @@ CONSOLE_SetTextXY(
        WriteConsoleOutputCharacterA(
                StdOutput,
                Text,
-               strlen(Text),
+               (ULONG)strlen(Text),
                coPos,
                &Written);
 }
@@ -298,14 +277,14 @@ CONSOLE_SetInputTextXY(
        IN LPCWSTR Text)
 {
        COORD coPos;
-       ULONG Length;
-       ULONG Written;
+       SHORT Length;
+       DWORD Written;
 
        coPos.X = x;
        coPos.Y = y;
 
-       Length = wcslen(Text);
-       if (Length > (ULONG)len - 1)
+       Length = (SHORT)wcslen(Text);
+       if (Length > len - 1)
                Length = len - 1;
 
        FillConsoleOutputAttribute(
@@ -318,7 +297,7 @@ CONSOLE_SetInputTextXY(
        WriteConsoleOutputCharacterW(
                StdOutput,
                Text,
-               Length,
+               (ULONG)Length,
                coPos,
                &Written);
 
@@ -330,7 +309,7 @@ CONSOLE_SetInputTextXY(
                coPos,
                &Written);
 
-       if ((ULONG)len > Length + 1)
+       if (len > Length + 1)
        {
                coPos.X++;
                FillConsoleOutputCharacterA(
@@ -349,13 +328,13 @@ CONSOLE_SetUnderlinedTextXY(
        IN LPCSTR Text)
 {
        COORD coPos;
-       ULONG Length;
-       ULONG Written;
+       DWORD Length;
+       DWORD Written;
 
        coPos.X = x;
        coPos.Y = y;
 
-       Length = strlen(Text);
+       Length = (ULONG)strlen(Text);
 
        WriteConsoleOutputCharacterA(
                StdOutput,
@@ -373,6 +352,110 @@ CONSOLE_SetUnderlinedTextXY(
                &Written);
 }
 
+VOID
+CONSOLE_SetStatusText(
+       IN LPCSTR fmt, ...)
+{
+       CHAR Buffer[128];
+       va_list ap;
+       COORD coPos;
+       DWORD Written;
+
+       va_start(ap, fmt);
+       vsprintf(Buffer, fmt, ap);
+       va_end(ap);
+
+       coPos.X = 0;
+       coPos.Y = yScreen - 1;
+
+       FillConsoleOutputAttribute(
+               StdOutput,
+               BACKGROUND_WHITE,
+               xScreen,
+               coPos,
+               &Written);
+
+       FillConsoleOutputCharacterA(
+               StdOutput,
+               ' ',
+               xScreen,
+               coPos,
+               &Written);
+
+       WriteConsoleOutputCharacterA(
+               StdOutput,
+               Buffer,
+               (ULONG)strlen(Buffer),
+               coPos,
+               &Written);
+}
+
+VOID
+CONSOLE_SetStatusTextX(
+    IN SHORT x,
+       IN LPCSTR fmt, ...)
+{
+       CHAR Buffer[128];
+       va_list ap;
+       COORD coPos;
+       DWORD Written;
+
+       va_start(ap, fmt);
+       vsprintf(Buffer, fmt, ap);
+       va_end(ap);
+
+       coPos.X = 0;
+       coPos.Y = yScreen - 1;
+
+       FillConsoleOutputAttribute(
+               StdOutput,
+               BACKGROUND_WHITE,
+               xScreen,
+               coPos,
+               &Written);
+
+       FillConsoleOutputCharacterA(
+               StdOutput,
+               ' ',
+               xScreen,
+               coPos,
+               &Written);
+
+    coPos.X = x;
+
+       WriteConsoleOutputCharacterA(
+               StdOutput,
+               Buffer,
+               (ULONG)strlen(Buffer),
+               coPos,
+               &Written);
+}
+
+VOID
+CONSOLE_SetStatusTextAutoFitX(
+    IN SHORT x,
+       IN LPCSTR fmt, ...)
+{
+       CHAR Buffer[128];
+    DWORD Length;
+       va_list ap;
+
+       va_start(ap, fmt);
+       vsprintf(Buffer, fmt, ap);
+       va_end(ap);
+
+    Length = (ULONG)strlen(Buffer);
+
+    if (Length + x <= 79)
+    {
+        CONSOLE_SetStatusTextX (x , Buffer);
+    }
+    else
+    {
+        CONSOLE_SetStatusTextX (79 - Length , Buffer);
+    }
+}
+
 VOID
 CONSOLE_SetInvertedTextXY(
        IN SHORT x,
@@ -380,13 +463,13 @@ CONSOLE_SetInvertedTextXY(
        IN LPCSTR Text)
 {
        COORD coPos;
-       ULONG Length;
-       ULONG Written;
+       DWORD Length;
+       DWORD Written;
 
        coPos.X = x;
        coPos.Y = y;
 
-       Length = strlen(Text);
+       Length = (ULONG)strlen(Text);
 
        FillConsoleOutputAttribute(
                StdOutput,
@@ -410,13 +493,13 @@ CONSOLE_SetHighlightedTextXY(
        IN LPCSTR Text)
 {
        COORD coPos;
-       ULONG Length;
-       ULONG Written;
+       DWORD Length;
+       DWORD Written;
 
        coPos.X = x;
        coPos.Y = y;
 
-       Length = strlen(Text);
+       Length = (ULONG)strlen(Text);
 
        FillConsoleOutputAttribute(
                StdOutput,
@@ -442,7 +525,7 @@ CONSOLE_PrintTextXY(
        CHAR buffer[512];
        va_list ap;
        COORD coPos;
-       ULONG Written;
+       DWORD Written;
 
        va_start(ap, fmt);
        vsprintf(buffer, fmt, ap);
@@ -454,7 +537,7 @@ CONSOLE_PrintTextXY(
        WriteConsoleOutputCharacterA(
                StdOutput,
                buffer,
-               strlen(buffer),
+               (ULONG)strlen(buffer),
                coPos,
                &Written);
 }
@@ -469,8 +552,8 @@ CONSOLE_PrintTextXYN(
        CHAR buffer[512];
        va_list ap;
        COORD coPos;
-       ULONG Length;
-       ULONG Written;
+       SHORT Length;
+       DWORD Written;
 
        va_start(ap, fmt);
        vsprintf(buffer, fmt, ap);
@@ -479,8 +562,8 @@ CONSOLE_PrintTextXYN(
        coPos.X = x;
        coPos.Y = y;
 
-       Length = strlen(buffer);
-       if (Length > (ULONG)len - 1)
+       Length = (SHORT)strlen(buffer);
+       if (Length > len - 1)
                Length = len - 1;
 
        WriteConsoleOutputCharacterA(
@@ -492,7 +575,7 @@ CONSOLE_PrintTextXYN(
 
        coPos.X += Length;
 
-       if ((ULONG)len > Length)
+       if (len > Length)
        {
                FillConsoleOutputCharacterA(
                        StdOutput,
@@ -503,4 +586,88 @@ CONSOLE_PrintTextXYN(
        }
 }
 
+VOID
+CONSOLE_SetStyledText(
+       IN SHORT x,
+       IN SHORT y,
+       IN INT Flags,
+       IN LPCSTR Text)
+{
+       COORD coPos;
+       DWORD Length;
+
+       coPos.X = x;
+       coPos.Y = y;
+
+       Length = (ULONG)strlen(Text);
+
+    if (Flags & TEXT_TYPE_STATUS)
+       {
+               coPos.X = x;
+               coPos.Y = yScreen - 1;
+       }
+    else /* TEXT_TYPE_REGULAR (Default) */
+    {
+        coPos.X = x;
+               coPos.Y = y;
+    }
+
+    if (Flags & TEXT_ALIGN_CENTER)
+       {
+               coPos.X = (xScreen - Length) /2; 
+       }
+    else if(Flags & TEXT_ALIGN_RIGHT)
+       {
+               coPos.X = coPos.X - Length; 
+
+               if (Flags & TEXT_PADDING_SMALL)
+               {
+                       coPos.X -= 1;
+               }
+               else if (Flags & TEXT_PADDING_MEDIUM)
+               {
+                       coPos.X -= 2; 
+               }
+               else if (Flags & TEXT_PADDING_BIG)
+               {
+                       coPos.X -= 3;
+               }
+       }
+       else /* TEXT_ALIGN_LEFT (Default) */
+       {
+               if (Flags & TEXT_PADDING_SMALL)
+               {
+                       coPos.X += 1;
+               }
+               else if (Flags & TEXT_PADDING_MEDIUM)
+               {
+                       coPos.X += 2; 
+               }               
+               else if (Flags & TEXT_PADDING_BIG)
+               {
+                       coPos.X += 3;
+               }
+       }
+
+       if (Flags & TEXT_TYPE_STATUS)
+       {
+        CONSOLE_SetStatusTextX(coPos.X, Text);
+       }
+    else /* TEXT_TYPE_REGULAR (Default) */
+    {
+        if (Flags & TEXT_STYLE_HIGHLIGHT)
+           {
+            CONSOLE_SetHighlightedTextXY(coPos.X, coPos.Y, Text);
+           }
+        else if (Flags & TEXT_STYLE_UNDERLINE)
+           {
+            CONSOLE_SetUnderlinedTextXY(coPos.X, coPos.Y, Text);
+           }
+        else /* TEXT_STYLE_NORMAL (Default) */
+        {
+            CONSOLE_SetTextXY(coPos.X, coPos.Y, Text);
+        }
+    }
+}
+
 /* EOF */