Bug 510162 - Updater dialog should size itself appropriately on mobile devices. r=vlad

This commit is contained in:
Robert Strong 2009-08-20 19:58:17 -07:00
parent 8ddb6fef0b
commit 4b5a702e05
5 changed files with 219 additions and 13 deletions

View File

@ -84,12 +84,17 @@ endif
ifeq ($(OS_ARCH),WINCE) ifeq ($(OS_ARCH),WINCE)
USE_STATIC_LIBS = 1 USE_STATIC_LIBS = 1
HAVE_PROGRESSUI = 1 HAVE_PROGRESSUI = 1
RCINCLUDE = updater_wince.rc
CPPSRCS += \ CPPSRCS += \
updater_wince.cpp \ updater_wince.cpp \
progressui_win.cpp \ progressui_win.cpp \
$(NULL) $(NULL)
OS_LIBS += $(call EXPAND_LIBNAME,commctrl ws2) OS_LIBS += $(call EXPAND_LIBNAME,commctrl ws2)
ifdef WINCE_WINDOWS_MOBILE
OS_LIBS += $(call EXPAND_LIBNAME,aygshell)
RCINCLUDE = updater_winmo.rc
else
RCINCLUDE = updater_wince.rc
endif
DEFINES += -DUNICODE -D_UNICODE DEFINES += -DUNICODE -D_UNICODE
RCFLAGS += -I$(srcdir) RCFLAGS += -I$(srcdir)
REQUIRES += string REQUIRES += string

View File

@ -42,6 +42,11 @@
#include <commctrl.h> #include <commctrl.h>
#include <process.h> #include <process.h>
#include <io.h> #include <io.h>
#ifdef WINCE_WINDOWS_MOBILE
#include <aygshell.h>
#endif
#include "resource.h" #include "resource.h"
#include "progressui.h" #include "progressui.h"
#include "readstrings.h" #include "readstrings.h"
@ -168,9 +173,7 @@ InitDialog(HWND hDlg)
RECT infoSize, textSize; RECT infoSize, textSize;
HWND hWndInfo = GetDlgItem(hDlg, IDC_INFO); HWND hWndInfo = GetDlgItem(hDlg, IDC_INFO);
// We need the current size and font to calculate the adjustment. // Get the control's font for calculating the new size for the control
GetClientRect(hWndInfo, &infoSize);
HDC hDCInfo = GetDC(hWndInfo); HDC hDCInfo = GetDC(hWndInfo);
HFONT hInfoFont, hOldFont; HFONT hInfoFont, hOldFont;
hInfoFont = (HFONT)SendMessage(hWndInfo, WM_GETFONT, 0, 0); hInfoFont = (HFONT)SendMessage(hWndInfo, WM_GETFONT, 0, 0);
@ -178,12 +181,101 @@ InitDialog(HWND hDlg)
if (hInfoFont) if (hInfoFont)
hOldFont = (HFONT)SelectObject(hDCInfo, hInfoFont); hOldFont = (HFONT)SelectObject(hDCInfo, hInfoFont);
// Measure the space needed for the text - DT_CALCRECT means nothing is drawn. // There are three scenarios that need to be handled differently
if (DrawText(hDCInfo, szwInfo, wcslen(szwInfo) + 1, &textSize, // 1. Windows Mobile where dialog should be full screen.
DT_CALCRECT | DT_NOCLIP | DT_SINGLELINE)) { // 2. Windows CE where the dialog might wrap.
// 3. Windows where the dialog should never wrap. The Windows CE and Windows
// scenarios could be combined but then we would have to calculate the
// extra border space added by the Aero theme which just adds complexity.
#ifdef WINCE
#ifdef WINCE_WINDOWS_MOBILE
RECT rcDlgInner1, rcDlgInner2, rcInfoOuter1, rcInfoOuter2;
// The dialog's client rectangle and the window rectangle for the text before
// making the dialog full screen are needed to calculate the change in border
// sizes.
GetClientRect(hDlg, &rcDlgInner1);
GetWindowRect(hWndInfo, &rcInfoOuter1);
// Make the dialog fullscreen
SHINITDLGINFO shidi;
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN;
shidi.hDlg = hDlg;
SHInitDialog(&shidi);
if (!SHInitDialog(&shidi))
return;
// Hide the OK button
SHDoneButton(hDlg, SHDB_HIDE);
GetClientRect(hDlg, &rcDlgInner2);
GetWindowRect(hWndInfo, &rcInfoOuter2);
textSize.left = 0;
// Calculate the maximum possible width for the text by adding to the
// existing text rectangle's window width the change in the dialog rectangle's
// client width and the change in the text rectangle's window left position
// after the dialog has been made full screen.
textSize.right = (rcInfoOuter2.right - rcInfoOuter2.left) + \
(rcDlgInner2.right - rcDlgInner1.right) + \
(rcInfoOuter1.left - rcInfoOuter2.left);
#else
RECT rcWorkArea, rcInfoOuter1;
GetWindowRect(hWndInfo, &rcInfoOuter1);
SystemParametersInfo(SPI_GETWORKAREA, NULL, &rcWorkArea, NULL);
textSize.left = 0;
// Calculate the maximum possible width for the text by subtracting from the
// existing working area's width the text rectangle's margin.
textSize.right = (rcWorkArea.right - rcWorkArea.left) - \
(rcInfoOuter1.left + rcInfoOuter1.right);
#endif
// Measure the space needed for the text allowing multiple lines if necessary.
// DT_CALCRECT means nothing is drawn.
if (DrawText(hDCInfo, szwInfo, -1, &textSize,
DT_CALCRECT | DT_NOCLIP | DT_WORDBREAK)) {
GetClientRect(hWndInfo, &infoSize);
SIZE extra; SIZE extra;
extra.cx = (textSize.right - textSize.left) - (infoSize.right - infoSize.left); // Calculate the additional space needed for the text by subtracting from
extra.cy = (textSize.bottom - textSize.top) - (infoSize.bottom - infoSize.top); // the rectangle returned by DrawText the existing client rectangle's width
// and height.
extra.cx = (textSize.right - textSize.left) - \
(infoSize.right - infoSize.left);
extra.cy = (textSize.bottom - textSize.top) - \
(infoSize.bottom - infoSize.top);
// XXX rstrong - add 2 pixels to the width to prevent the text from wrapping
// due to Windows CE and Windows Mobile adding an extra pixel to the
// beginning and the end of the text. Though I have found no good reason for
// this it has been consistent with multiple font sizes.
extra.cx += 2;
RESIZE_WINDOW(hWndInfo, extra.cx, extra.cy);
RESIZE_WINDOW(hWndPro, extra.cx, 0);
#ifdef WINCE_WINDOWS_MOBILE
// Move the controls 1 pixel to the left on Windows Mobile to compensate for
// the 2 extra pixels added to the controls above. This isn't needed on
// Windows CE for reasons of the unknown variety.
MOVE_WINDOW(hWndInfo, -1, 0);
MOVE_WINDOW(hWndPro, -1, extra.cy);
#else
RESIZE_WINDOW(hDlg, extra.cx, extra.cy);
MOVE_WINDOW(hWndPro, 0, extra.cy);
#endif
}
#else
// Measure the space needed for the text on a single line. DT_CALCRECT means
// nothing is drawn.
if (DrawText(hDCInfo, szwInfo, -1, &textSize,
DT_CALCRECT | DT_NOCLIP | DT_SINGLELINE)) {
GetClientRect(hWndInfo, &infoSize);
SIZE extra;
// Calculate the additional space needed for the text by subtracting from
// the rectangle returned by DrawText the existing client rectangle's width
// and height.
extra.cx = (textSize.right - textSize.left) - \
(infoSize.right - infoSize.left);
extra.cy = (textSize.bottom - textSize.top) - \
(infoSize.bottom - infoSize.top);
if (extra.cx < 0) if (extra.cx < 0)
extra.cx = 0; extra.cx = 0;
if (extra.cy < 0) if (extra.cy < 0)
@ -195,13 +287,17 @@ InitDialog(HWND hDlg)
MOVE_WINDOW(hWndPro, 0, extra.cy); MOVE_WINDOW(hWndPro, 0, extra.cy);
} }
} }
#endif
if (hOldFont) if (hOldFont)
SelectObject(hDCInfo, hOldFont); SelectObject(hDCInfo, hOldFont);
ReleaseDC(hWndInfo, hDCInfo); ReleaseDC(hWndInfo, hDCInfo);
// On Windows Mobile the dialog is full screen so don't center it.
#ifndef WINCE_WINDOWS_MOBILE
CenterDialog(hDlg); // make dialog appear in the center of the screen CenterDialog(hDlg); // make dialog appear in the center of the screen
#endif
SetTimer(hDlg, TIMER_ID, TIMER_INTERVAL, NULL); SetTimer(hDlg, TIMER_ID, TIMER_INTERVAL, NULL);
} }

View File

@ -44,9 +44,8 @@ IDD_DIALOG DIALOGEX 0, 0, 253, 41
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION
FONT 8, "MS Shell Dlg", 400, 0, 0x1 FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN BEGIN
CONTROL "",IDC_PROGRESS,"msctls_progress32",WS_BORDER,7,24,239, CONTROL "",IDC_PROGRESS,"msctls_progress32",WS_BORDER,7,24,239,10
10 LTEXT "",IDC_INFO,7,8,239,13,SS_NOPREFIX
LTEXT "",IDC_INFO,7,8,239,13
END END

View File

@ -38,7 +38,7 @@ STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION
FONT 8, "MS Shell Dlg" FONT 8, "MS Shell Dlg"
BEGIN BEGIN
CONTROL "",IDC_PROGRESS,"msctls_progress32",WS_BORDER,7,24,139,10 CONTROL "",IDC_PROGRESS,"msctls_progress32",WS_BORDER,7,24,139,10
LTEXT "",IDC_INFO,7,8,139,13 LTEXT "",IDC_INFO,7,8,139,13,SS_NOPREFIX
END END

View File

@ -0,0 +1,106 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winuser.h"
#include "aygshell.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
IDI_DIALOG ICON "updater.ico"
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DIALOG DIALOG 0, 0, 153, 41
STYLE DS_SETFONT | WS_POPUP | WS_CAPTION | WS_NONAVDONEBUTTON
EXSTYLE 0x80000000L
FONT 8, "MS Shell Dlg"
BEGIN
CONTROL "",IDC_PROGRESS,"msctls_progress32",WS_BORDER,7,20,139,10
LTEXT "",IDC_INFO,7,4,139,13,SS_NOPREFIX
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_DIALOG, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 146
TOPMARGIN, 3
BOTTOMMARGIN, 39
END
END
#endif // APSTUDIO_INVOKED
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""winuser.h""\r\n"
"#include ""aygshell.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED