ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

ui.c
Go to the documentation of this file.
00001 /*
00002  *  FreeLoader
00003  *  Copyright (C) 1998-2003  Brian Palmer  <brianp@sginet.com>
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License along
00016  *  with this program; if not, write to the Free Software Foundation, Inc.,
00017  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018  */
00019 #ifndef _M_ARM
00020 #include <freeldr.h>
00021 #include <debug.h>
00022 #include <reactos/buildno.h>
00023 
00024 DBG_DEFAULT_CHANNEL(UI);
00025 
00026 ULONG   UiScreenWidth;                          // Screen Width
00027 ULONG   UiScreenHeight;                         // Screen Height
00028 
00029 UCHAR   UiStatusBarFgColor          = COLOR_BLACK;          // Status bar foreground color
00030 UCHAR   UiStatusBarBgColor          = COLOR_CYAN;           // Status bar background color
00031 UCHAR   UiBackdropFgColor           = COLOR_WHITE;          // Backdrop foreground color
00032 UCHAR   UiBackdropBgColor           = COLOR_BLUE;           // Backdrop background color
00033 UCHAR   UiBackdropFillStyle         = MEDIUM_FILL;          // Backdrop fill style
00034 UCHAR   UiTitleBoxFgColor           = COLOR_WHITE;          // Title box foreground color
00035 UCHAR   UiTitleBoxBgColor           = COLOR_RED;            // Title box background color
00036 UCHAR   UiMessageBoxFgColor         = COLOR_WHITE;          // Message box foreground color
00037 UCHAR   UiMessageBoxBgColor         = COLOR_BLUE;           // Message box background color
00038 UCHAR   UiMenuFgColor               = COLOR_WHITE;          // Menu foreground color
00039 UCHAR   UiMenuBgColor               = COLOR_BLUE;           // Menu background color
00040 UCHAR   UiTextColor                 = COLOR_YELLOW;         // Normal text color
00041 UCHAR   UiSelectedTextColor         = COLOR_BLACK;          // Selected text color
00042 UCHAR   UiSelectedTextBgColor       = COLOR_GRAY;           // Selected text background color
00043 UCHAR   UiEditBoxTextColor          = COLOR_WHITE;          // Edit box text color
00044 UCHAR   UiEditBoxBgColor            = COLOR_BLACK;          // Edit box text background color
00045 
00046 CHAR    UiTitleBoxTitleText[260]    = "Boot Menu";          // Title box's title text
00047 
00048 BOOLEAN UiUseSpecialEffects         = FALSE;                // Tells us if we should use fade effects
00049 BOOLEAN UiDrawTime                  = TRUE;                 // Tells us if we should draw the time
00050 BOOLEAN UiCenterMenu                = TRUE;                 // Tells us if we should use a centered or left-aligned menu
00051 BOOLEAN UiMenuBox                   = TRUE;                 // Tells us if we shuld draw a box around the menu
00052 CHAR    UiTimeText[260] = "[Time Remaining: ] ";
00053 
00054 const CHAR  UiMonthNames[12][15] = { "January ", "February ", "March ", "April ", "May ", "June ", "July ", "August ", "September ", "October ", "November ", "December " };
00055 
00056 UIVTBL UiVtbl =
00057 {
00058     NoUiInitialize,
00059     NoUiUnInitialize,
00060     NoUiDrawBackdrop,
00061     NoUiFillArea,
00062     NoUiDrawShadow,
00063     NoUiDrawBox,
00064     NoUiDrawText,
00065     NoUiDrawCenteredText,
00066     NoUiDrawStatusText,
00067     NoUiUpdateDateTime,
00068     NoUiMessageBox,
00069     NoUiMessageBoxCritical,
00070     NoUiDrawProgressBarCenter,
00071     NoUiDrawProgressBar,
00072     NoUiEditBox,
00073     NoUiTextToColor,
00074     NoUiTextToFillStyle,
00075     NoUiFadeInBackdrop,
00076     NoUiFadeOut,
00077     NoUiDisplayMenu,
00078     NoUiDrawMenu,
00079 };
00080 
00081 BOOLEAN UiInitialize(BOOLEAN ShowGui)
00082 {
00083     VIDEODISPLAYMODE    UiDisplayMode; // Tells us if we are in text or graphics mode
00084     BOOLEAN UiMinimal = FALSE; // Tells us if we should use a minimal console-like UI
00085     ULONG_PTR SectionId;
00086     CHAR    DisplayModeText[260];
00087     CHAR    SettingText[260];
00088     ULONG   Depth;
00089 
00090     if (!ShowGui) {
00091         if (!UiVtbl.Initialize())
00092         {
00093             MachVideoSetDisplayMode(NULL, FALSE);
00094             return FALSE;
00095         }
00096         return TRUE;
00097     }
00098 
00099     TRACE("Initializing User Interface.\n");
00100     TRACE("Reading in UI settings from [Display] section.\n");
00101 
00102     DisplayModeText[0] = '\0';
00103     if (IniOpenSection("Display", &SectionId))
00104     {
00105         if (! IniReadSettingByName(SectionId, "DisplayMode", DisplayModeText, sizeof(DisplayModeText)))
00106         {
00107             DisplayModeText[0] = '\0';
00108         }
00109         if (IniReadSettingByName(SectionId, "MinimalUI", SettingText, sizeof(SettingText)))
00110         {
00111             UiMinimal = (_stricmp(SettingText, "Yes") == 0 && strlen(SettingText) == 3);
00112         }
00113     }
00114 
00115     UiDisplayMode = MachVideoSetDisplayMode(DisplayModeText, TRUE);
00116     MachVideoGetDisplaySize(&UiScreenWidth, &UiScreenHeight, &Depth);
00117 
00118     if (VideoTextMode == UiDisplayMode)
00119         UiVtbl = UiMinimal ? MiniTuiVtbl : TuiVtbl;
00120     else
00121         UiVtbl = GuiVtbl;
00122 
00123     if (!UiVtbl.Initialize())
00124     {
00125         MachVideoSetDisplayMode(NULL, FALSE);
00126         return FALSE;
00127     }
00128 
00129     if (IniOpenSection("Display", &SectionId))
00130     {
00131         if (IniReadSettingByName(SectionId, "TitleText", SettingText, sizeof(SettingText)))
00132         {
00133             strcpy(UiTitleBoxTitleText, SettingText);
00134         }
00135         if (IniReadSettingByName(SectionId, "TimeText", SettingText, sizeof(SettingText)))
00136         {
00137             strcpy(UiTimeText, SettingText);
00138         }
00139         if (IniReadSettingByName(SectionId, "StatusBarColor", SettingText, sizeof(SettingText)))
00140         {
00141             UiStatusBarBgColor = UiTextToColor(SettingText);
00142         }
00143         if (IniReadSettingByName(SectionId, "StatusBarTextColor", SettingText, sizeof(SettingText)))
00144         {
00145             UiStatusBarFgColor = UiTextToColor(SettingText);
00146         }
00147         if (IniReadSettingByName(SectionId, "BackdropTextColor", SettingText, sizeof(SettingText)))
00148         {
00149             UiBackdropFgColor = UiTextToColor(SettingText);
00150         }
00151         if (IniReadSettingByName(SectionId, "BackdropColor", SettingText, sizeof(SettingText)))
00152         {
00153             UiBackdropBgColor = UiTextToColor(SettingText);
00154         }
00155         if (IniReadSettingByName(SectionId, "BackdropFillStyle", SettingText, sizeof(SettingText)))
00156         {
00157             UiBackdropFillStyle = UiTextToFillStyle(SettingText);
00158         }
00159         if (IniReadSettingByName(SectionId, "TitleBoxTextColor", SettingText, sizeof(SettingText)))
00160         {
00161             UiTitleBoxFgColor = UiTextToColor(SettingText);
00162         }
00163         if (IniReadSettingByName(SectionId, "TitleBoxColor", SettingText, sizeof(SettingText)))
00164         {
00165             UiTitleBoxBgColor = UiTextToColor(SettingText);
00166         }
00167         if (IniReadSettingByName(SectionId, "MessageBoxTextColor", SettingText, sizeof(SettingText)))
00168         {
00169             UiMessageBoxFgColor = UiTextToColor(SettingText);
00170         }
00171         if (IniReadSettingByName(SectionId, "MessageBoxColor", SettingText, sizeof(SettingText)))
00172         {
00173             UiMessageBoxBgColor = UiTextToColor(SettingText);
00174         }
00175         if (IniReadSettingByName(SectionId, "MenuTextColor", SettingText, sizeof(SettingText)))
00176         {
00177             UiMenuFgColor = UiTextToColor(SettingText);
00178         }
00179         if (IniReadSettingByName(SectionId, "MenuColor", SettingText, sizeof(SettingText)))
00180         {
00181             UiMenuBgColor = UiTextToColor(SettingText);
00182         }
00183         if (IniReadSettingByName(SectionId, "TextColor", SettingText, sizeof(SettingText)))
00184         {
00185             UiTextColor = UiTextToColor(SettingText);
00186         }
00187         if (IniReadSettingByName(SectionId, "SelectedTextColor", SettingText, sizeof(SettingText)))
00188         {
00189             UiSelectedTextColor = UiTextToColor(SettingText);
00190         }
00191         if (IniReadSettingByName(SectionId, "SelectedColor", SettingText, sizeof(SettingText)))
00192         {
00193             UiSelectedTextBgColor = UiTextToColor(SettingText);
00194         }
00195         if (IniReadSettingByName(SectionId, "EditBoxTextColor", SettingText, sizeof(SettingText)))
00196         {
00197             UiEditBoxTextColor = UiTextToColor(SettingText);
00198         }
00199         if (IniReadSettingByName(SectionId, "EditBoxColor", SettingText, sizeof(SettingText)))
00200         {
00201             UiEditBoxBgColor = UiTextToColor(SettingText);
00202         }
00203         if (IniReadSettingByName(SectionId, "SpecialEffects", SettingText, sizeof(SettingText)))
00204         {
00205             UiUseSpecialEffects = (_stricmp(SettingText, "Yes") == 0 && strlen(SettingText) == 3);
00206         }
00207         if (IniReadSettingByName(SectionId, "ShowTime", SettingText, sizeof(SettingText)))
00208         {
00209             UiDrawTime = (_stricmp(SettingText, "Yes") == 0 && strlen(SettingText) == 3);
00210         }
00211         if (IniReadSettingByName(SectionId, "MenuBox", SettingText, sizeof(SettingText)))
00212         {
00213             UiMenuBox = (_stricmp(SettingText, "Yes") == 0 && strlen(SettingText) == 3);
00214         }
00215         if (IniReadSettingByName(SectionId, "CenterMenu", SettingText, sizeof(SettingText)))
00216         {
00217             UiCenterMenu = (_stricmp(SettingText, "Yes") == 0 && strlen(SettingText) == 3);
00218         }
00219     }
00220 
00221     // Draw the backdrop and fade it in if special effects are enabled
00222     UiFadeInBackdrop();
00223 
00224     TRACE("UiInitialize() returning TRUE.\n");
00225     return TRUE;
00226 }
00227 
00228 BOOLEAN SetupUiInitialize(VOID)
00229 {
00230     CHAR    DisplayModeText[260];
00231     ULONG   Depth;
00232     SIZE_T  Length;
00233 
00234 
00235     DisplayModeText[0] = '\0';
00236 
00237     MachVideoSetDisplayMode(DisplayModeText, TRUE);
00238     MachVideoGetDisplaySize(&UiScreenWidth, &UiScreenHeight, &Depth);
00239 
00240     UiVtbl = TuiVtbl;
00241     UiVtbl.Initialize();
00242 
00243     // Draw the backdrop and fade it in if special effects are enabled
00244     UiVtbl.FillArea(0,
00245             0,
00246             UiScreenWidth - 1,
00247             UiScreenHeight - 2,
00248             0,
00249             ATTR(UiBackdropFgColor, UiBackdropBgColor));
00250 
00251     UiDrawTime = FALSE;
00252     UiStatusBarBgColor = 7;
00253 
00254     Length = strlen("ReactOS " KERNEL_VERSION_STR " Setup");
00255     memset(DisplayModeText, 0xcd, Length + 2);
00256     DisplayModeText[Length + 2] = '\0';
00257 
00258     UiVtbl.DrawText(4, 1, "ReactOS " KERNEL_VERSION_STR " Setup", ATTR(COLOR_GRAY, UiBackdropBgColor));
00259     UiVtbl.DrawText(3, 2, DisplayModeText, ATTR(COLOR_GRAY, UiBackdropBgColor));
00260 
00261     TRACE("UiInitialize() returning TRUE.\n");
00262 
00263     return TRUE;
00264 }
00265 
00266 VOID UiUnInitialize(PCSTR BootText)
00267 {
00268     UiDrawBackdrop();
00269     UiDrawStatusText("Booting...");
00270     UiInfoBox(BootText);
00271 
00272     UiVtbl.UnInitialize();
00273 }
00274 
00275 VOID UiDrawBackdrop(VOID)
00276 {
00277     UiVtbl.DrawBackdrop();
00278 }
00279 
00280 VOID UiFillArea(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, CHAR FillChar, UCHAR Attr /* Color Attributes */)
00281 {
00282     UiVtbl.FillArea(Left, Top, Right, Bottom, FillChar, Attr);
00283 }
00284 
00285 VOID UiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom)
00286 {
00287     UiVtbl.DrawShadow(Left, Top, Right, Bottom);
00288 }
00289 
00290 VOID UiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOLEAN Fill, BOOLEAN Shadow, UCHAR Attr)
00291 {
00292     UiVtbl.DrawBox(Left, Top, Right, Bottom, VertStyle, HorzStyle, Fill, Shadow, Attr);
00293 }
00294 
00295 VOID UiDrawText(ULONG X, ULONG Y, PCSTR Text, UCHAR Attr)
00296 {
00297     UiVtbl.DrawText(X, Y, Text, Attr);
00298 }
00299 
00300 VOID UiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCSTR TextString, UCHAR Attr)
00301 {
00302     UiVtbl.DrawCenteredText(Left, Top, Right, Bottom, TextString, Attr);
00303 }
00304 
00305 VOID UiDrawStatusText(PCSTR StatusText)
00306 {
00307     UiVtbl.DrawStatusText(StatusText);
00308 }
00309 
00310 VOID UiUpdateDateTime(VOID)
00311 {
00312     UiVtbl.UpdateDateTime();
00313 }
00314 
00315 VOID UiInfoBox(PCSTR MessageText)
00316 {
00317     SIZE_T      TextLength;
00318     ULONG       BoxWidth;
00319     ULONG       BoxHeight;
00320     ULONG       LineBreakCount;
00321     SIZE_T      Index;
00322     SIZE_T      LastIndex;
00323     ULONG       Left;
00324     ULONG       Top;
00325     ULONG       Right;
00326     ULONG       Bottom;
00327 
00328     TextLength = strlen(MessageText);
00329 
00330     // Count the new lines and the box width
00331     LineBreakCount = 0;
00332     BoxWidth = 0;
00333     LastIndex = 0;
00334     for (Index=0; Index<TextLength; Index++)
00335     {
00336         if (MessageText[Index] == '\n')
00337         {
00338             LastIndex = Index;
00339             LineBreakCount++;
00340         }
00341         else
00342         {
00343             if ((Index - LastIndex) > BoxWidth)
00344             {
00345                 BoxWidth = (ULONG)(Index - LastIndex);
00346             }
00347         }
00348     }
00349 
00350     // Calc the box width & height
00351     BoxWidth += 6;
00352     BoxHeight = LineBreakCount + 4;
00353 
00354     // Calc the box coordinates
00355     Left = (UiScreenWidth / 2) - (BoxWidth / 2);
00356     Top =(UiScreenHeight / 2) - (BoxHeight / 2);
00357     Right = (UiScreenWidth / 2) + (BoxWidth / 2);
00358     Bottom = (UiScreenHeight / 2) + (BoxHeight / 2);
00359 
00360     // Draw the box
00361     UiDrawBox(Left,
00362               Top,
00363               Right,
00364               Bottom,
00365               VERT,
00366               HORZ,
00367               TRUE,
00368               TRUE,
00369               ATTR(UiMenuFgColor, UiMenuBgColor)
00370               );
00371 
00372     // Draw the text
00373     UiDrawCenteredText(Left, Top, Right, Bottom, MessageText, ATTR(UiTextColor, UiMenuBgColor));
00374 }
00375 
00376 VOID UiMessageBox(PCSTR MessageText)
00377 {
00378     UiVtbl.MessageBox(MessageText);
00379 }
00380 
00381 VOID UiMessageBoxCritical(PCSTR MessageText)
00382 {
00383     UiVtbl.MessageBoxCritical(MessageText);
00384 }
00385 
00386 UCHAR UiTextToColor(PCSTR ColorText)
00387 {
00388     return UiVtbl.TextToColor(ColorText);
00389 }
00390 
00391 UCHAR UiTextToFillStyle(PCSTR FillStyleText)
00392 {
00393     return UiVtbl.TextToFillStyle(FillStyleText);
00394 }
00395 
00396 VOID UiDrawProgressBarCenter(ULONG Position, ULONG Range, PCHAR ProgressText)
00397 {
00398     UiVtbl.DrawProgressBarCenter(Position, Range, ProgressText);
00399 }
00400 
00401 VOID UiDrawProgressBar(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, ULONG Position, ULONG Range, PCHAR ProgressText)
00402 {
00403     UiVtbl.DrawProgressBar(Left, Top, Right, Bottom, Position, Range, ProgressText);
00404 }
00405 
00406 VOID UiShowMessageBoxesInSection(PCSTR SectionName)
00407 {
00408     ULONG       Idx;
00409     CHAR    SettingName[80];
00410     CHAR    SettingValue[80];
00411     PCHAR   MessageBoxText;
00412     ULONG       MessageBoxTextSize;
00413     ULONG_PTR   SectionId;
00414 
00415     if (!IniOpenSection(SectionName, &SectionId))
00416     {
00417         return;
00418     }
00419 
00420     //
00421     // Find all the message box settings and run them
00422     //
00423     for (Idx=0; Idx<IniGetNumSectionItems(SectionId); Idx++)
00424     {
00425         IniReadSettingByNumber(SectionId, Idx, SettingName, sizeof(SettingName), SettingValue, sizeof(SettingValue));
00426 
00427         if (_stricmp(SettingName, "MessageBox") == 0)
00428         {
00429             // Get the real length of the MessageBox text
00430             MessageBoxTextSize = IniGetSectionSettingValueSize(SectionId, Idx);
00431 
00432             //if (MessageBoxTextSize > 0)
00433             {
00434                 // Allocate enough memory to hold the text
00435                 MessageBoxText = MmHeapAlloc(MessageBoxTextSize);
00436 
00437                 if (MessageBoxText)
00438                 {
00439                     // Get the MessageBox text
00440                     IniReadSettingByNumber(SectionId, Idx, SettingName, sizeof(SettingName), MessageBoxText, MessageBoxTextSize);
00441 
00442                     // Fix it up
00443                     UiEscapeString(MessageBoxText);
00444 
00445                     // Display it
00446                     UiMessageBox(MessageBoxText);
00447 
00448                     // Free the memory
00449                     MmHeapFree(MessageBoxText);
00450                 }
00451             }
00452         }
00453     }
00454 }
00455 
00456 VOID UiEscapeString(PCHAR String)
00457 {
00458     ULONG       Idx;
00459 
00460     for (Idx=0; Idx<strlen(String); Idx++)
00461     {
00462         // Escape the new line characters
00463         if (String[Idx] == '\\' && String[Idx+1] == 'n')
00464         {
00465             // Escape the character
00466             String[Idx] = '\n';
00467 
00468             // Move the rest of the string up
00469             strcpy(&String[Idx+1], &String[Idx+2]);
00470         }
00471     }
00472 }
00473 
00474 VOID UiTruncateStringEllipsis(PCHAR StringText, ULONG MaxChars)
00475 {
00476     if (strlen(StringText) > MaxChars)
00477     {
00478         strcpy(&StringText[MaxChars - 3], "...");
00479     }
00480 }
00481 
00482 BOOLEAN UiDisplayMenu(PCSTR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, ULONG* SelectedMenuItem, BOOLEAN CanEscape, UiMenuKeyPressFilterCallback KeyPressFilter)
00483 {
00484     return UiVtbl.DisplayMenu(MenuItemList, MenuItemCount, DefaultMenuItem, MenuTimeOut, SelectedMenuItem, CanEscape, KeyPressFilter);
00485 }
00486 
00487 VOID UiFadeInBackdrop(VOID)
00488 {
00489     UiVtbl.FadeInBackdrop();
00490 }
00491 
00492 VOID UiFadeOut(VOID)
00493 {
00494     UiVtbl.FadeOut();
00495 }
00496 
00497 BOOLEAN UiEditBox(PCSTR MessageText, PCHAR EditTextBuffer, ULONG Length)
00498 {
00499     return UiVtbl.EditBox(MessageText, EditTextBuffer, Length);
00500 }
00501 #endif

Generated on Sun May 27 2012 04:19:18 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.