Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
progressui_win.cpp File Reference
#include <stdio.h>
#include <windows.h>
#include <commctrl.h>
#include <process.h>
#include <io.h>
#include "resource.h"

Go to the source code of this file.

Defines

#define TIMER_ID   1
#define TIMER_INTERVAL   100
#define MAX_INFO_LENGTH   512
#define RESIZE_WINDOW(hwnd, extrax, extray)
#define MOVE_WINDOW(hwnd, dx, dy)

Functions

static BOOL GetStringsFile (char filename[MAX_PATH])
static void UpdateDialog (HWND hDlg)
static void ResizeDialogToFit (HWND hDlg)
static void CenterDialog (HWND hDlg)
static void SetItemText (HWND hwnd, const char *key, const char *ini)
static void InitDialog (HWND hDlg)
static LRESULT CALLBACK DialogProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
int InitProgressUI (int *argc, char ***argv)
int ShowProgressUI ()
void QuitProgressUI ()
void UpdateProgressUI (float progress)

Variables

static float sProgress
static BOOL sQuit = FALSE
static HFONT sSystemFont = 0

Define Documentation

Definition at line 50 of file progressui_win.cpp.

#define MOVE_WINDOW (   hwnd,
  dx,
  dy 
)
Value:
{ \
    WINDOWPLACEMENT windowPos; \
    windowPos.length = sizeof(windowPos); \
    GetWindowPlacement(hwnd, &windowPos); \
    SetWindowPos(hwnd, 0, windowPos.rcNormalPosition.left + dx, windowPos.rcNormalPosition.top + dy, 0, 0, \
                 SWP_NOSIZE | SWP_NOZORDER); \
  }

Definition at line 61 of file progressui_win.cpp.

#define RESIZE_WINDOW (   hwnd,
  extrax,
  extray 
)
Value:
{ \
    RECT windowSize; \
    GetWindowRect(hwnd, &windowSize); \
    SetWindowPos(hwnd, 0, 0, 0, windowSize.right - windowSize.left + extrax, \
                 windowSize.bottom - windowSize.top + extray, \
                 SWP_NOMOVE | SWP_NOZORDER); \
  }

Definition at line 52 of file progressui_win.cpp.

#define TIMER_ID   1

Definition at line 47 of file progressui_win.cpp.

Definition at line 48 of file progressui_win.cpp.


Function Documentation

static void CenterDialog ( HWND  hDlg) [static]

Definition at line 144 of file progressui_win.cpp.

{
  RECT rc, rcOwner, rcDlg;

  // Get the owner window and dialog box rectangles. 
  HWND desktop = GetDesktopWindow();

  GetWindowRect(desktop, &rcOwner); 
  GetWindowRect(hDlg, &rcDlg); 
  CopyRect(&rc, &rcOwner); 

  // Offset the owner and dialog box rectangles so that 
  // right and bottom values represent the width and 
  // height, and then offset the owner again to discard 
  // space taken up by the dialog box. 

  OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); 
  OffsetRect(&rc, -rc.left, -rc.top); 
  OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); 

  // The new position is the sum of half the remaining 
  // space and the owner's original position. 

  SetWindowPos(hDlg, 
               HWND_TOP, 
               rcOwner.left + (rc.right / 2), 
               rcOwner.top + (rc.bottom / 2), 
               0, 0,          // ignores size arguments 
               SWP_NOSIZE); 
}

Here is the caller graph for this function:

static LRESULT CALLBACK DialogProc ( HWND  hDlg,
UINT  message,
WPARAM  wParam,
LPARAM  lParam 
) [static]

Definition at line 226 of file progressui_win.cpp.

{
  switch (message)
  {
  case WM_INITDIALOG:
    InitDialog(hDlg);
    return TRUE;

  case WM_TIMER:
    if (sQuit) {
      EndDialog(hDlg, 0);
      if (sSystemFont) {
        DeleteObject(sSystemFont);
        sSystemFont = 0;
      }
    } else {
      UpdateDialog(hDlg);
    }
    return TRUE;

  case WM_COMMAND:
    return TRUE;
  }
  return FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static BOOL GetStringsFile ( char  filename[MAX_PATH]) [static]

Definition at line 75 of file progressui_win.cpp.

{
  if (!GetModuleFileName(NULL, filename, MAX_PATH))
    return FALSE;

  char *dot = strrchr(filename, '.');
  if (!dot || stricmp(dot + 1, "exe"))
    return FALSE;

  strcpy(dot + 1, "ini");
  return TRUE;
}

Here is the caller graph for this function:

static void InitDialog ( HWND  hDlg) [static]

Definition at line 185 of file progressui_win.cpp.

{
  char filename[MAX_PATH];
  if (!GetStringsFile(filename))
    return;

  SetItemText(hDlg, "Title", filename);
  SetItemText(GetDlgItem(hDlg, IDC_INFO), "Info", filename);

  // On Win9x, we need to send WM_SETFONT for l10n builds.  Yes, we shouldn't
  // use the system font.  For example, if the text has Japanese characters on
  // Win98-en, then the text may not be displayed correctly.  We should perhaps
  // support loading a font named in updater.ini; however, even then there are
  // cases where it might not work properly.
  if (!sSystemFont) {
    NONCLIENTMETRICS ncm;
    memset(&ncm, 0, sizeof(ncm));
    ncm.cbSize = sizeof(ncm);
    SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
    sSystemFont = CreateFontIndirect(&ncm.lfMessageFont);
  }
  if (sSystemFont)
    SendDlgItemMessage(hDlg, IDC_INFO, WM_SETFONT, (WPARAM)sSystemFont, 0L);

  // Set dialog icon
  HICON hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_DIALOG));
  if (hIcon)
    SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM) hIcon);

  SendDlgItemMessage(hDlg, IDC_PROGRESS, PBM_SETRANGE, 0, MAKELPARAM(0, 100));

  // Resize dialog to fit all the text.
  ResizeDialogToFit(hDlg);

  CenterDialog(hDlg);  // make dialog appear in the center of the screen

  SetTimer(hDlg, TIMER_ID, TIMER_INTERVAL, NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int InitProgressUI ( int argc,
char ***  argv 
)

Definition at line 253 of file progressui_win.cpp.

{
  return 0;
}

Here is the caller graph for this function:

Definition at line 290 of file progressui_win.cpp.

{
  sQuit = TRUE;
}

Here is the caller graph for this function:

static void ResizeDialogToFit ( HWND  hDlg) [static]

Definition at line 96 of file progressui_win.cpp.

{
  char text[MAX_INFO_LENGTH];
  RECT infoSize, textSize;
  HFONT hInfoFont, hOldFont;

  HWND hWndInfo = GetDlgItem(hDlg, IDC_INFO);
  HWND hWndPro  = GetDlgItem(hDlg, IDC_PROGRESS);

  // Get the text that is displayed - this is what we're going to make fit.
  if (!GetWindowText(hWndInfo, text, sizeof(text)))
    return;

  // We need the current size and font to calculate the adjustment.
  GetClientRect(hWndInfo, &infoSize);
  HDC hDCInfo = GetDC(hWndInfo);
  hInfoFont = (HFONT)SendMessage(hWndInfo, WM_GETFONT, 0, 0);
  if (hInfoFont)
    hOldFont = (HFONT)SelectObject(hDCInfo, hInfoFont);

  // Measure the space needed for the text - DT_CALCRECT means nothing is drawn.
  if (DrawText(hDCInfo, text, -1, &textSize,
               DT_CALCRECT | DT_NOCLIP | DT_SINGLELINE)) {
    SIZE extra;
    extra.cx = (textSize.right - textSize.left) - (infoSize.right - infoSize.left);
    extra.cy = (textSize.bottom - textSize.top) - (infoSize.bottom - infoSize.top);
    if (extra.cx < 0)
      extra.cx = 0;
    if (extra.cy < 0)
      extra.cy = 0;

    if ((extra.cx > 0) || (extra.cy > 0)) {
      RESIZE_WINDOW(hDlg, extra.cx, extra.cy);
      RESIZE_WINDOW(hWndInfo, extra.cx, extra.cy);
      RESIZE_WINDOW(hWndPro, extra.cx, 0);
      MOVE_WINDOW(hWndPro, 0, extra.cy);
    }
  }

  if (hOldFont)
    SelectObject(hDCInfo, hOldFont);

  ReleaseDC(hWndInfo, hDCInfo);
}

Here is the caller graph for this function:

static void SetItemText ( HWND  hwnd,
const char *  key,
const char *  ini 
) [static]

Definition at line 176 of file progressui_win.cpp.

{
  char text[MAX_INFO_LENGTH];
  if (!GetPrivateProfileString("Strings", key, NULL, text, sizeof(text), ini))
    return;
  SetWindowText(hwnd, text);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 259 of file progressui_win.cpp.

{
  // Only show the Progress UI if the process is taking significant time.
  // Here we measure significant time as taking more than one second.

  Sleep(500);

  if (sQuit || sProgress > 50.0f)
    return 0;

  // If we do not have updater.ini, then we should not bother showing UI.
  char filename[MAX_PATH];
  if (!GetStringsFile(filename))
    return -1;
  if (_access(filename, 04))
    return -1;

  INITCOMMONCONTROLSEX icc = {
    sizeof(INITCOMMONCONTROLSEX),
    ICC_PROGRESS_CLASS
  };
  InitCommonControlsEx(&icc);

  DialogBox(GetModuleHandle(NULL),
            MAKEINTRESOURCE(IDD_DIALOG), NULL,
            (DLGPROC) DialogProc);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void UpdateDialog ( HWND  hDlg) [static]

Definition at line 89 of file progressui_win.cpp.

{
  int pos = int(sProgress + 0.5f);
  SendDlgItemMessage(hDlg, IDC_PROGRESS, PBM_SETPOS, pos, 0L);
}

Here is the caller graph for this function:

void UpdateProgressUI ( float  progress)

Definition at line 296 of file progressui_win.cpp.

{
  sProgress = progress;  // 32-bit writes are atomic
}

Here is the caller graph for this function:


Variable Documentation

float sProgress [static]

Definition at line 70 of file progressui_win.cpp.

BOOL sQuit = FALSE [static]

Definition at line 71 of file progressui_win.cpp.

HFONT sSystemFont = 0 [static]

Definition at line 72 of file progressui_win.cpp.