fix for bug #336528: software update installation progress dialog doesn't stretch to fit contents (cut short, text is truncated)

patch=James Ross <silver@warwickcompsoc.co.uk>
r=rstrong
This commit is contained in:
sspitzer@mozilla.org 2007-07-11 12:04:48 -07:00
Родитель 1322fc32d6
Коммит 601c266cc1
1 изменённых файлов: 70 добавлений и 1 удалений

Просмотреть файл

@ -47,6 +47,26 @@
#define TIMER_ID 1
#define TIMER_INTERVAL 100
#define MAX_INFO_LENGTH 512
#define RESIZE_WINDOW(hwnd, extrax, extray) \
{ \
RECT windowSize; \
GetWindowRect(hwnd, &windowSize); \
SetWindowPos(hwnd, 0, 0, 0, windowSize.right - windowSize.left + extrax, \
windowSize.bottom - windowSize.top + extray, \
SWP_NOMOVE | SWP_NOZORDER); \
}
#define MOVE_WINDOW(hwnd, dx, dy) \
{ \
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); \
}
static float sProgress; // between 0 and 100
static BOOL sQuit = FALSE;
static HFONT sSystemFont = 0;
@ -72,6 +92,52 @@ UpdateDialog(HWND hDlg)
SendDlgItemMessage(hDlg, IDC_PROGRESS, PBM_SETPOS, pos, 0L);
}
static void
ResizeDialogToFit(HWND hDlg)
{
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);
}
// The code in this function is from MSDN:
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/usingdialogboxes.asp
static void
@ -109,7 +175,7 @@ CenterDialog(HWND hDlg)
static void
SetItemText(HWND hwnd, const char *key, const char *ini)
{
char text[512];
char text[MAX_INFO_LENGTH];
if (!GetPrivateProfileString("Strings", key, NULL, text, sizeof(text), ini))
return;
SetWindowText(hwnd, text);
@ -147,6 +213,9 @@ InitDialog(HWND hDlg)
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);