1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00

[ui] add marquee progress bar mode

* Also fix x86_64 warnings
This commit is contained in:
Pete Batard 2018-04-19 12:25:11 +01:00
parent 42c158917c
commit 5c57703c70
5 changed files with 108 additions and 49 deletions

View file

@ -223,7 +223,6 @@ DWORD DownloadFile(const char* url, const char* file, HWND hProgressDialog)
BOOL r = FALSE; BOOL r = FALSE;
DWORD dwFlags, dwSize, dwDownloaded, dwTotalSize; DWORD dwFlags, dwSize, dwDownloaded, dwTotalSize;
FILE* fd = NULL; FILE* fd = NULL;
LONG progress_style;
const char* accept_types[] = {"*/*\0", NULL}; const char* accept_types[] = {"*/*\0", NULL};
unsigned char buf[DOWNLOAD_BUFFER_SIZE]; unsigned char buf[DOWNLOAD_BUFFER_SIZE];
char agent[64], hostname[64], urlpath[128]; char agent[64], hostname[64], urlpath[128];
@ -238,8 +237,7 @@ DWORD DownloadFile(const char* url, const char* file, HWND hProgressDialog)
// Use the progress control provided, if any // Use the progress control provided, if any
hProgressBar = GetDlgItem(hProgressDialog, IDC_PROGRESS); hProgressBar = GetDlgItem(hProgressDialog, IDC_PROGRESS);
if (hProgressBar != NULL) { if (hProgressBar != NULL) {
progress_style = GetWindowLong(hProgressBar, GWL_STYLE); SendMessage(hProgressBar, PBM_SETMARQUEE, FALSE, 0);
SetWindowLong(hProgressBar, GWL_STYLE, progress_style & (~PBS_MARQUEE));
SendMessage(hProgressBar, PBM_SETPOS, 0, 0); SendMessage(hProgressBar, PBM_SETPOS, 0, 0);
} }
SendMessage(hProgressDialog, UM_PROGRESS_INIT, 0, 0); SendMessage(hProgressDialog, UM_PROGRESS_INIT, 0, 0);

View file

@ -1774,28 +1774,31 @@ static INT_PTR CALLBACK ProgressCallback(HWND hCtrl, UINT message, WPARAM wParam
SIZE size; SIZE size;
LONG full_right; LONG full_right;
wchar_t winfo[128]; wchar_t winfo[128];
static WORD pos = 0, min = 0, max = 0xFFFF; static BOOL marquee_mode = FALSE;
static COLORREF color = RGB(0x06, 0xB0, 0x25); static uint32_t pos = 0, min = 0, max = 0xFFFF;
static COLORREF color = PROGRESS_BAR_NORMAL_COLOR;
switch (message) { switch (message) {
case PBM_SETSTATE: case PBM_SETSTATE:
switch (wParam) { switch (wParam) {
case PBST_NORMAL: case PBST_NORMAL:
color = RGB(0x06, 0xB0, 0x25); color = PROGRESS_BAR_NORMAL_COLOR;
break; break;
case PBST_PAUSED: case PBST_PAUSED:
color = RGB(0xDA, 0xCB, 0x26); color = PROGRESS_BAR_PAUSED_COLOR;
break; break;
case PBST_ERROR: case PBST_ERROR:
color = RGB(0xDA, 0x26, 0x26); color = PROGRESS_BAR_ERROR_COLOR;
break; break;
} }
return (INT_PTR)TRUE; return (INT_PTR)TRUE;
case PBM_SETRANGE: case PBM_SETRANGE:
min = lParam & 0xFFFF; // Don't bother sanity checking min and max: If *you* want to
max = lParam >> 16; // be an ass about the progress bar range, it's *your* problem.
min = (uint32_t)(lParam & 0xFFFF);
max = (uint32_t)(lParam >> 16);
return (INT_PTR)TRUE; return (INT_PTR)TRUE;
case PBM_SETPOS: case PBM_SETPOS:
@ -1803,34 +1806,95 @@ static INT_PTR CALLBACK ProgressCallback(HWND hCtrl, UINT message, WPARAM wParam
InvalidateRect(hProgress, NULL, TRUE); InvalidateRect(hProgress, NULL, TRUE);
return (INT_PTR)TRUE; return (INT_PTR)TRUE;
case PBM_SETMARQUEE:
if ((wParam == TRUE) && (!marquee_mode)) {
marquee_mode = TRUE;
pos = min;
color = PROGRESS_BAR_NORMAL_COLOR;
SetTimer(hCtrl, TID_MARQUEE_TIMER, MARQUEE_TIMER_REFRESH, NULL);
InvalidateRect(hProgress, NULL, TRUE);
} else if ((wParam == FALSE) && (marquee_mode)) {
marquee_mode = FALSE;
KillTimer(hCtrl, TID_MARQUEE_TIMER);
pos = min;
InvalidateRect(hProgress, NULL, TRUE);
}
return (INT_PTR)TRUE;
case WM_TIMER:
if ((wParam == TID_MARQUEE_TIMER) && marquee_mode) {
pos += max((max - min) / (1000 / MARQUEE_TIMER_REFRESH), 1);
if ((pos > max) || (pos < min))
pos = min;
InvalidateRect(hProgress, NULL, TRUE);
return (INT_PTR)TRUE;
}
return (INT_PTR)FALSE;
case WM_PAINT: case WM_PAINT:
hDC = BeginPaint(hCtrl, &ps); hDC = BeginPaint(hCtrl, &ps);
GetClientRect(hCtrl, &rc); GetClientRect(hCtrl, &rc);
SelectObject(hDC, GetStockObject(DC_PEN)); SelectObject(hDC, GetStockObject(DC_PEN));
SelectObject(hDC, GetStockObject(NULL_BRUSH)); SelectObject(hDC, GetStockObject(NULL_BRUSH));
SetDCPenColor(hDC, RGB(0xBC, 0xBC, 0xBC)); SetDCPenColor(hDC, PROGRESS_BAR_BOX_COLOR);
Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
InflateRect(&rc, -1, -1); InflateRect(&rc, -1, -1);
// TODO: Handle SetText message so we can avoid this call // TODO: Handle SetText message so we can avoid this call
GetWindowTextW(hProgress, winfo, ARRAYSIZE(winfo)); GetWindowTextW(hProgress, winfo, ARRAYSIZE(winfo));
full_right = rc.right;
rc.right = (pos > min) ? MulDiv(pos - min, rc.right, max - min) : rc.left;
SelectObject(hDC, hInfoFont); SelectObject(hDC, hInfoFont);
GetTextExtentPoint32(hDC, winfo, wcslen(winfo), &size); GetTextExtentPoint32(hDC, winfo, (int)wcslen(winfo), &size);
// First half if (size.cx > rc.right)
SetTextColor(hDC, RGB(0xFF, 0xFF, 0xFF)); size.cx = rc.right;
SetBkColor(hDC, color); if (size.cy > rc.bottom)
ExtTextOut(hDC, (full_right - size.cx) / 2, (rc.bottom - size.cy) / 2, size.cy = rc.bottom;
ETO_CLIPPED | ETO_OPAQUE | ETO_NUMERICSLOCAL | (right_to_left_mode ? ETO_RTLREADING : 0), full_right = rc.right;
&rc, winfo, wcslen(winfo), NULL); if (marquee_mode) {
// Second half // Optional first segment
SetTextColor(hDC, RGB(0x00, 0x00, 0x00)); if (pos + ((max - min) / 5) > max) {
SetBkColor(hDC, RGB(0xE6, 0xE6, 0xE6)); rc.right = MulDiv(pos + ((max - min) / 5) - max, rc.right, max - min);
SetTextColor(hDC, PROGRESS_BAR_INVERTED_TEXT_COLOR);
SetBkColor(hDC, color);
ExtTextOut(hDC, (full_right - size.cx) / 2, (rc.bottom - size.cy) / 2,
ETO_CLIPPED | ETO_OPAQUE | ETO_NUMERICSLOCAL | (right_to_left_mode ? ETO_RTLREADING : 0),
&rc, winfo, (int)wcslen(winfo), NULL);
rc.left = rc.right;
rc.right = full_right;
}
// Optional second segment
if (pos > min) {
rc.right = MulDiv(pos - min, rc.right, max - min);
SetTextColor(hDC, PROGRESS_BAR_NORMAL_TEXT_COLOR);
SetBkColor(hDC, PROGRESS_BAR_BACKGROUND_COLOR);
ExtTextOut(hDC, (full_right - size.cx) / 2, (rc.bottom - size.cy) / 2,
ETO_CLIPPED | ETO_OPAQUE | ETO_NUMERICSLOCAL | (right_to_left_mode ? ETO_RTLREADING : 0),
&rc, winfo, (int)wcslen(winfo), NULL);
rc.left = rc.right;
rc.right = full_right;
}
// Second to last segment
rc.right = MulDiv(pos - min + ((max - min) / 5), rc.right, max - min);
SetTextColor(hDC, PROGRESS_BAR_INVERTED_TEXT_COLOR);
SetBkColor(hDC, color);
ExtTextOut(hDC, (full_right - size.cx) / 2, (rc.bottom - size.cy) / 2,
ETO_CLIPPED | ETO_OPAQUE | ETO_NUMERICSLOCAL | (right_to_left_mode ? ETO_RTLREADING : 0),
&rc, winfo, (int)wcslen(winfo), NULL);
} else {
// First segment
rc.right = (pos > min) ? MulDiv(pos - min, rc.right, max - min) : rc.left;
SetTextColor(hDC, PROGRESS_BAR_INVERTED_TEXT_COLOR);
SetBkColor(hDC, color);
ExtTextOut(hDC, (full_right - size.cx) / 2, (rc.bottom - size.cy) / 2,
ETO_CLIPPED | ETO_OPAQUE | ETO_NUMERICSLOCAL | (right_to_left_mode ? ETO_RTLREADING : 0),
&rc, winfo, (int)wcslen(winfo), NULL);
}
// Last segment
rc.left = rc.right; rc.left = rc.right;
rc.right = full_right; rc.right = full_right;
SetTextColor(hDC, PROGRESS_BAR_NORMAL_TEXT_COLOR);
SetBkColor(hDC, PROGRESS_BAR_BACKGROUND_COLOR);
ExtTextOut(hDC, (full_right - size.cx) / 2, (rc.bottom - size.cy) / 2, ExtTextOut(hDC, (full_right - size.cx) / 2, (rc.bottom - size.cy) / 2,
ETO_CLIPPED | ETO_OPAQUE | ETO_NUMERICSLOCAL | (right_to_left_mode ? ETO_RTLREADING : 0), ETO_CLIPPED | ETO_OPAQUE | ETO_NUMERICSLOCAL | (right_to_left_mode ? ETO_RTLREADING : 0),
&rc, winfo, wcslen(winfo), NULL); &rc, winfo, (int)wcslen(winfo), NULL);
EndPaint(hCtrl, &ps); EndPaint(hCtrl, &ps);
return (INT_PTR)TRUE; return (INT_PTR)TRUE;
} }
@ -2865,7 +2929,6 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
HDROP droppedFileInfo; HDROP droppedFileInfo;
POINT Point; POINT Point;
RECT rc, DialogRect, DesktopRect; RECT rc, DialogRect, DesktopRect;
LONG progress_style;
HDC hDC; HDC hDC;
PAINTSTRUCT ps; PAINTSTRUCT ps;
int nDeviceIndex, i, nWidth, nHeight, nb_devices, selected_language, offset; int nDeviceIndex, i, nWidth, nHeight, nb_devices, selected_language, offset;
@ -3468,30 +3531,20 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
case UM_PROGRESS_INIT: case UM_PROGRESS_INIT:
isMarquee = (wParam == PBS_MARQUEE); isMarquee = (wParam == PBS_MARQUEE);
if (isMarquee) { if (isMarquee)
progress_style = GetWindowLong(hProgress, GWL_STYLE);
SetWindowLong(hProgress, GWL_STYLE, progress_style | PBS_MARQUEE);
SendMessage(hProgress, PBM_SETMARQUEE, TRUE, 0); SendMessage(hProgress, PBM_SETMARQUEE, TRUE, 0);
} else { else
SendMessage(hProgress, PBM_SETPOS, 0, 0); SendMessage(hProgress, PBM_SETPOS, 0, 0);
}
SetTaskbarProgressState(TASKBAR_NORMAL); SetTaskbarProgressState(TASKBAR_NORMAL);
SetTaskbarProgressValue(0, MAX_PROGRESS); SetTaskbarProgressValue(0, MAX_PROGRESS);
break; break;
case UM_PROGRESS_EXIT: case UM_PROGRESS_EXIT:
if (isMarquee) { if (isMarquee) {
// Remove marquee style if previously set SendMessage(hProgress, PBM_SETMARQUEE, FALSE, 0);
progress_style = GetWindowLong(hProgress, GWL_STYLE);
SetWindowLong(hProgress, GWL_STYLE, progress_style & (~PBS_MARQUEE));
SetTaskbarProgressValue(0, MAX_PROGRESS); SetTaskbarProgressValue(0, MAX_PROGRESS);
SendMessage(hProgress, PBM_SETPOS, 0, 0);
} else if (!IS_ERROR(FormatStatus)) { } else if (!IS_ERROR(FormatStatus)) {
SetTaskbarProgressValue(MAX_PROGRESS, MAX_PROGRESS); SetTaskbarProgressValue(MAX_PROGRESS, MAX_PROGRESS);
// This is the only way to achieve instantaneous progress transition to 100%
SendMessage(hProgress, PBM_SETRANGE, 0, ((MAX_PROGRESS+1)<<16) & 0xFFFF0000);
SendMessage(hProgress, PBM_SETPOS, (MAX_PROGRESS+1), 0);
SendMessage(hProgress, PBM_SETRANGE, 0, (MAX_PROGRESS<<16) & 0xFFFF0000);
} }
SendMessage(hProgress, PBM_SETSTATE, (WPARAM)PBST_NORMAL, 0); SendMessage(hProgress, PBM_SETSTATE, (WPARAM)PBST_NORMAL, 0);
SetTaskbarProgressState(TASKBAR_NORMAL); SetTaskbarProgressState(TASKBAR_NORMAL);
@ -3517,10 +3570,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
GetDevices(DeviceNum); GetDevices(DeviceNum);
} }
if (!IS_ERROR(FormatStatus)) { if (!IS_ERROR(FormatStatus)) {
// This is the only way to achieve instantaneous progress transition to 100% SendMessage(hProgress, PBM_SETPOS, MAX_PROGRESS, 0);
SendMessage(hProgress, PBM_SETRANGE, 0, ((MAX_PROGRESS+1)<<16) & 0xFFFF0000);
SendMessage(hProgress, PBM_SETPOS, (MAX_PROGRESS+1), 0);
SendMessage(hProgress, PBM_SETRANGE, 0, (MAX_PROGRESS<<16) & 0xFFFF0000);
SetTaskbarProgressState(TASKBAR_NOPROGRESS); SetTaskbarProgressState(TASKBAR_NOPROGRESS);
PrintInfo(0, MSG_210); PrintInfo(0, MSG_210);
MessageBeep(MB_OK); MessageBeep(MB_OK);

View file

@ -53,7 +53,7 @@
#define MAX_TOOLTIPS 128 #define MAX_TOOLTIPS 128
#define MAX_SIZE_SUFFIXES 6 // bytes, KB, MB, GB, TB, PB #define MAX_SIZE_SUFFIXES 6 // bytes, KB, MB, GB, TB, PB
#define MAX_CLUSTER_SIZES 18 #define MAX_CLUSTER_SIZES 18
#define MAX_PROGRESS (0xFFFF-1) // leave room for 1 more for insta-progress workaround #define MAX_PROGRESS 0xFFFF
#define MAX_LOG_SIZE 0x7FFFFFFE #define MAX_LOG_SIZE 0x7FFFFFFE
#define MAX_REFRESH 25 // How long we should wait to refresh UI elements (in ms) #define MAX_REFRESH 25 // How long we should wait to refresh UI elements (in ms)
#define MAX_GUID_STRING_LENGTH 40 #define MAX_GUID_STRING_LENGTH 40
@ -62,6 +62,7 @@
#define MBR_UEFI_MARKER 0x49464555 // 'U', 'E', 'F', 'I', as a 32 bit little endian longword #define MBR_UEFI_MARKER 0x49464555 // 'U', 'E', 'F', 'I', as a 32 bit little endian longword
#define STATUS_MSG_TIMEOUT 3500 // How long should cheat mode messages appear for on the status bar #define STATUS_MSG_TIMEOUT 3500 // How long should cheat mode messages appear for on the status bar
#define WRITE_RETRIES 3 #define WRITE_RETRIES 3
#define MARQUEE_TIMER_REFRESH 10 // Time between progress bar marquee refreshes, in ms
#define FS_DEFAULT FS_FAT32 #define FS_DEFAULT FS_FAT32
#define SINGLE_CLUSTERSIZE_DEFAULT 0x00000100 #define SINGLE_CLUSTERSIZE_DEFAULT 0x00000100
#define BADBLOCK_PATTERNS {0xaa, 0x55, 0xff, 0x00} #define BADBLOCK_PATTERNS {0xaa, 0x55, 0xff, 0x00}
@ -185,7 +186,8 @@ enum timer_type {
TID_BADBLOCKS_UPDATE, TID_BADBLOCKS_UPDATE,
TID_APP_TIMER, TID_APP_TIMER,
TID_BLOCKING_TIMER, TID_BLOCKING_TIMER,
TID_REFRESH_TIMER TID_REFRESH_TIMER,
TID_MARQUEE_TIMER
}; };
/* Action type, for progress bar breakdown */ /* Action type, for progress bar breakdown */

View file

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326 IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 3.0.1251" CAPTION "Rufus 3.0.1252"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0 FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -371,8 +371,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,0,1251,0 FILEVERSION 3,0,1252,0
PRODUCTVERSION 3,0,1251,0 PRODUCTVERSION 3,0,1252,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -389,13 +389,13 @@ BEGIN
BEGIN BEGIN
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
VALUE "FileDescription", "Rufus" VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "3.0.1251" VALUE "FileVersion", "3.0.1252"
VALUE "InternalName", "Rufus" VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2018 Pete Batard (GPL v3)" VALUE "LegalCopyright", "© 2011-2018 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe" VALUE "OriginalFilename", "rufus.exe"
VALUE "ProductName", "Rufus" VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.0.1251" VALUE "ProductVersion", "3.0.1252"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View file

@ -22,6 +22,15 @@
#pragma once #pragma once
// Progress bar colors
#define PROGRESS_BAR_NORMAL_TEXT_COLOR RGB(0x00, 0x00, 0x00)
#define PROGRESS_BAR_INVERTED_TEXT_COLOR RGB(0xFF, 0xFF, 0xFF)
#define PROGRESS_BAR_BACKGROUND_COLOR RGB(0xE6, 0xE6, 0xE6)
#define PROGRESS_BAR_BOX_COLOR RGB(0xBC, 0xBC, 0xBC)
#define PROGRESS_BAR_NORMAL_COLOR RGB(0x06, 0xB0, 0x25)
#define PROGRESS_BAR_PAUSED_COLOR RGB(0xDA, 0xCB, 0x26)
#define PROGRESS_BAR_ERROR_COLOR RGB(0xDA, 0x26, 0x26)
static int image_option_move_ids[] = { static int image_option_move_ids[] = {
IDS_PARTITION_TYPE_TXT, IDS_PARTITION_TYPE_TXT,
IDC_PARTITION_TYPE, IDC_PARTITION_TYPE,