mirror of
https://github.com/pbatard/rufus.git
synced 2024-08-14 23:57:05 +00:00
[ui] fix display of icons for RTL languages
* Ensure that the 'Save', 'Hash' and 'World' icons are not mirrored for RTL * Also call DestroyIcon() where required and clean up code
This commit is contained in:
parent
c709d3c030
commit
070e28aa5a
4 changed files with 85 additions and 30 deletions
46
src/rufus.c
46
src/rufus.c
|
@ -78,7 +78,6 @@ static HFONT hInfoFont;
|
|||
static WNDPROC progress_original_proc = NULL;
|
||||
static HANDLE format_thid = NULL, dialog_handle = NULL;
|
||||
static HWND hSelectImage = NULL, hStart = NULL;
|
||||
static HICON hIconSave, hIconHash, hIconDown, hIconUp;
|
||||
static char szTimer[12] = "00:00:00";
|
||||
static wchar_t wtbtext[2][128];
|
||||
static unsigned int timer;
|
||||
|
@ -99,7 +98,6 @@ OPENED_LIBRARIES_VARS;
|
|||
HINSTANCE hMainInstance;
|
||||
HWND hMainDialog, hMultiToolbar, hSaveToolbar, hHashToolbar, hAdvancedDeviceToolbar, hAdvancedFormatToolbar, hUpdatesDlg = NULL;
|
||||
HIMAGELIST hUpImageList, hDownImageList;
|
||||
BUTTON_IMAGELIST bi_iso = { 0 }, bi_up = { 0 }, bi_down = { 0 }, bi_save = { 0 };
|
||||
char szFolderPath[MAX_PATH], app_dir[MAX_PATH], system_dir[MAX_PATH], temp_dir[MAX_PATH], sysnative_dir[MAX_PATH];
|
||||
char *image_path = NULL, *short_image_path;
|
||||
float fScale = 1.0f;
|
||||
|
@ -1915,6 +1913,7 @@ static INT_PTR CALLBACK ProgressCallback(HWND hCtrl, UINT message, WPARAM wParam
|
|||
static void CreateSmallButtons(HWND hDlg)
|
||||
{
|
||||
HIMAGELIST hImageList;
|
||||
HICON hIconSave, hIconHash;
|
||||
int icon_offset = 0, i16 = GetSystemMetrics(SM_CXSMICON);
|
||||
TBBUTTON tbToolbarButtons[1];
|
||||
unsigned char* buffer;
|
||||
|
@ -1925,17 +1924,15 @@ static void CreateSmallButtons(HWND hDlg)
|
|||
else if (i16 >= 20)
|
||||
icon_offset = 10;
|
||||
|
||||
buffer = GetResource(hMainInstance, MAKEINTRESOURCEA(IDI_SAVE_16 + icon_offset), _RT_RCDATA, "save icon", &bufsize, FALSE);
|
||||
hIconSave = CreateIconFromResourceEx(buffer, bufsize, TRUE, 0x30000, 0, 0, 0);
|
||||
buffer = GetResource(hMainInstance, MAKEINTRESOURCEA(IDI_HASH_16 + icon_offset), _RT_RCDATA, "hash icon", &bufsize, FALSE);
|
||||
hIconHash = CreateIconFromResourceEx(buffer, bufsize, TRUE, 0x30000, 0, 0, 0);
|
||||
|
||||
hSaveToolbar = CreateWindowExW(0, TOOLBARCLASSNAME, NULL,
|
||||
WS_CHILD | WS_TABSTOP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CCS_NOPARENTALIGN |
|
||||
CCS_NODIVIDER | TBSTYLE_BUTTON | TBSTYLE_TOOLTIPS | TBSTYLE_AUTOSIZE,
|
||||
0, 0, 0, 0, hMainDialog, (HMENU)IDC_SAVE_TOOLBAR, hMainInstance, NULL);
|
||||
hImageList = ImageList_Create(i16, i16, ILC_COLOR32, 1, 0);
|
||||
hImageList = ImageList_Create(i16, i16, ILC_COLOR32 | ILC_HIGHQUALITYSCALE | ILC_MIRROR, 1, 0);
|
||||
buffer = GetResource(hMainInstance, MAKEINTRESOURCEA(IDI_SAVE_16 + icon_offset), _RT_RCDATA, "save icon", &bufsize, FALSE);
|
||||
hIconSave = CreateIconFromResourceEx(buffer, bufsize, TRUE, 0x30000, 0, 0, 0);
|
||||
ImageList_AddIcon(hImageList, hIconSave);
|
||||
DestroyIcon(hIconSave);
|
||||
SendMessage(hSaveToolbar, TB_SETIMAGELIST, (WPARAM)0, (LPARAM)hImageList);
|
||||
SendMessage(hSaveToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
|
||||
memset(tbToolbarButtons, 0, sizeof(TBBUTTON));
|
||||
|
@ -1949,8 +1946,11 @@ static void CreateSmallButtons(HWND hDlg)
|
|||
WS_CHILD | WS_TABSTOP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CCS_NOPARENTALIGN |
|
||||
CCS_NODIVIDER | TBSTYLE_BUTTON | TBSTYLE_TOOLTIPS | TBSTYLE_AUTOSIZE,
|
||||
0, 0, 0, 0, hMainDialog, (HMENU)IDC_HASH_TOOLBAR, hMainInstance, NULL);
|
||||
hImageList = ImageList_Create(i16, i16, ILC_COLOR32, 1, 0);
|
||||
hImageList = ImageList_Create(i16, i16, ILC_COLOR32 | ILC_HIGHQUALITYSCALE | ILC_MIRROR, 1, 0);
|
||||
buffer = GetResource(hMainInstance, MAKEINTRESOURCEA(IDI_HASH_16 + icon_offset), _RT_RCDATA, "hash icon", &bufsize, FALSE);
|
||||
hIconHash = CreateIconFromResourceEx(buffer, bufsize, TRUE, 0x30000, 0, 0, 0);
|
||||
ImageList_AddIcon(hImageList, hIconHash);
|
||||
DestroyIcon(hIconHash);
|
||||
SendMessage(hHashToolbar, TB_SETIMAGELIST, (WPARAM)0, (LPARAM)hImageList);
|
||||
SendMessage(hHashToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
|
||||
memset(tbToolbarButtons, 0, sizeof(TBBUTTON));
|
||||
|
@ -1965,6 +1965,7 @@ static void CreateAdditionalControls(HWND hDlg)
|
|||
{
|
||||
HINSTANCE hDll;
|
||||
HIMAGELIST hToolbarImageList;
|
||||
HICON hIcon, hIconUp, hIconDown;
|
||||
RECT rc;
|
||||
SIZE sz;
|
||||
int icon_offset = 0, i, i16, s16, toolbar_dx = -4 - ((fScale > 1.49f) ? 1 : 0) - ((fScale > 1.99f) ? 1 : 0);
|
||||
|
@ -1996,8 +1997,8 @@ static void CreateAdditionalControls(HWND hDlg)
|
|||
hIconUp = (HICON)LoadImage(hDll, MAKEINTRESOURCE(16749), IMAGE_ICON, s16, s16, LR_DEFAULTCOLOR | LR_SHARED);
|
||||
if (hIconDown == NULL)
|
||||
hIconDown = (HICON)LoadImage(hDll, MAKEINTRESOURCE(16750), IMAGE_ICON, s16, s16, LR_DEFAULTCOLOR | LR_SHARED);
|
||||
hUpImageList = ImageList_Create(i16, i16, ILC_COLOR32, 1, 0);
|
||||
hDownImageList = ImageList_Create(i16, i16, ILC_COLOR32, 1, 0);
|
||||
hUpImageList = ImageList_Create(i16, i16, ILC_COLOR32 | ILC_HIGHQUALITYSCALE, 1, 0);
|
||||
hDownImageList = ImageList_Create(i16, i16, ILC_COLOR32 | ILC_HIGHQUALITYSCALE, 1, 0);
|
||||
ImageList_AddIcon(hUpImageList, hIconUp);
|
||||
ImageList_AddIcon(hDownImageList, hIconDown);
|
||||
|
||||
|
@ -2053,10 +2054,16 @@ static void CreateAdditionalControls(HWND hDlg)
|
|||
WS_CHILD | WS_TABSTOP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CCS_NOPARENTALIGN |
|
||||
CCS_NODIVIDER | TBSTYLE_FLAT | TBSTYLE_LIST | TBSTYLE_TRANSPARENT | TBSTYLE_TOOLTIPS | TBSTYLE_AUTOSIZE,
|
||||
0, 0, 0, 0, hMainDialog, (HMENU)IDC_MULTI_TOOLBAR, hMainInstance, NULL);
|
||||
hToolbarImageList = ImageList_Create(i16, i16, ILC_COLOR32, 8, 0);
|
||||
hToolbarImageList = ImageList_Create(i16, i16, ILC_COLOR32 | ILC_HIGHQUALITYSCALE, 8, 0);
|
||||
for (i = 0; i < ARRAYSIZE(multitoolbar_icons); i++) {
|
||||
buffer = GetResource(hMainInstance, MAKEINTRESOURCEA(multitoolbar_icons[i] + icon_offset), _RT_RCDATA, "toolbar icon", &bufsize, FALSE);
|
||||
ImageList_AddIcon(hToolbarImageList, CreateIconFromResourceEx(buffer, bufsize, TRUE, 0x30000, 0, 0, 0));
|
||||
buffer = GetResource(hMainInstance, MAKEINTRESOURCEA(multitoolbar_icons[i] + icon_offset),
|
||||
_RT_RCDATA, "toolbar icon", &bufsize, FALSE);
|
||||
hIcon = CreateIconFromResourceEx(buffer, bufsize, TRUE, 0x30000, 0, 0, 0);
|
||||
// Mirror the "world" icon on RTL since we can't use an ImageList mirroring flag for that...
|
||||
if (right_to_left_mode && (i == 0))
|
||||
hIcon = CreateMirroredIcon(hIcon);
|
||||
ImageList_AddIcon(hToolbarImageList, hIcon);
|
||||
DestroyIcon(hIcon);
|
||||
}
|
||||
SendMessage(hMultiToolbar, TB_SETIMAGELIST, (WPARAM)0, (LPARAM)hToolbarImageList);
|
||||
SendMessage(hMultiToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
|
||||
|
@ -2091,17 +2098,6 @@ static void CreateAdditionalControls(HWND hDlg)
|
|||
tbToolbarButtons[6].iBitmap = 3;
|
||||
SendMessage(hMultiToolbar, TB_ADDBUTTONS, (WPARAM)7, (LPARAM)&tbToolbarButtons);
|
||||
SendMessage(hMultiToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(0, ddbh));
|
||||
|
||||
// Set the icons on the the buttons
|
||||
bi_save.uAlign = BUTTON_IMAGELIST_ALIGN_CENTER;
|
||||
bi_down.himl = ImageList_Create(i16, i16, ILC_COLOR32 | ILC_MASK, 1, 0);
|
||||
ImageList_ReplaceIcon(bi_down.himl, -1, hIconDown);
|
||||
SetRect(&bi_down.margin, 0, 0, 0, 0);
|
||||
bi_down.uAlign = BUTTON_IMAGELIST_ALIGN_CENTER;
|
||||
bi_up.himl = ImageList_Create(i16, i16, ILC_COLOR32 | ILC_MASK, 1, 0);
|
||||
ImageList_ReplaceIcon(bi_up.himl, -1, hIconUp);
|
||||
SetRect(&bi_up.margin, 0, 0, 0, 0);
|
||||
bi_up.uAlign = BUTTON_IMAGELIST_ALIGN_CENTER;
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/a/20926332/1069307
|
||||
|
|
|
@ -515,6 +515,7 @@ extern BYTE SearchProcess(char* HandleName, DWORD dwTimeout, BOOL bPartialMatch,
|
|||
extern BOOL EnablePrivileges(void);
|
||||
extern void FlashTaskbar(HANDLE handle);
|
||||
extern DWORD WaitForSingleObjectWithMessages(HANDLE hHandle, DWORD dwMilliseconds);
|
||||
extern HICON CreateMirroredIcon(HICON hiconOrg);
|
||||
#define GetTextWidth(hDlg, id) GetTextSize(GetDlgItem(hDlg, id), NULL).cx
|
||||
|
||||
DWORD WINAPI FormatThread(void* param);
|
||||
|
|
10
src/rufus.rc
10
src/rufus.rc
|
@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
|
|||
IDD_DIALOG DIALOGEX 12, 12, 232, 326
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
EXSTYLE WS_EX_ACCEPTFILES
|
||||
CAPTION "Rufus 3.0.1271"
|
||||
CAPTION "Rufus 3.0.1272"
|
||||
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
|
||||
BEGIN
|
||||
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
|
||||
|
@ -389,8 +389,8 @@ END
|
|||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 3,0,1271,0
|
||||
PRODUCTVERSION 3,0,1271,0
|
||||
FILEVERSION 3,0,1272,0
|
||||
PRODUCTVERSION 3,0,1272,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
|
@ -407,13 +407,13 @@ BEGIN
|
|||
BEGIN
|
||||
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
|
||||
VALUE "FileDescription", "Rufus"
|
||||
VALUE "FileVersion", "3.0.1271"
|
||||
VALUE "FileVersion", "3.0.1272"
|
||||
VALUE "InternalName", "Rufus"
|
||||
VALUE "LegalCopyright", "© 2011-2018 Pete Batard (GPL v3)"
|
||||
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
|
||||
VALUE "OriginalFilename", "rufus.exe"
|
||||
VALUE "ProductName", "Rufus"
|
||||
VALUE "ProductVersion", "3.0.1271"
|
||||
VALUE "ProductVersion", "3.0.1272"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
|
58
src/stdlg.c
58
src/stdlg.c
|
@ -1922,6 +1922,64 @@ void FlashTaskbar(HANDLE handle)
|
|||
FlashWindowEx(&pf);
|
||||
}
|
||||
|
||||
// https://docs.microsoft.com/en-us/globalization/localizability/mirroring-in-win32
|
||||
// Note: This function *destroys* the original icon
|
||||
HICON CreateMirroredIcon(HICON hiconOrg)
|
||||
{
|
||||
HDC hdcScreen, hdcBitmap, hdcMask = NULL;
|
||||
HBITMAP hbm, hbmMask, hbmOld, hbmOldMask;
|
||||
BITMAP bm;
|
||||
ICONINFO ii;
|
||||
HICON hicon = NULL;
|
||||
hdcBitmap = CreateCompatibleDC(NULL);
|
||||
if (hdcBitmap) {
|
||||
hdcMask = CreateCompatibleDC(NULL);
|
||||
if (hdcMask) {
|
||||
SetLayout(hdcBitmap, LAYOUT_RTL);
|
||||
SetLayout(hdcMask, LAYOUT_RTL);
|
||||
} else {
|
||||
DeleteDC(hdcBitmap);
|
||||
hdcBitmap = NULL;
|
||||
}
|
||||
}
|
||||
hdcScreen = GetDC(NULL);
|
||||
if (hdcScreen) {
|
||||
if (hdcBitmap && hdcMask) {
|
||||
if (hiconOrg) {
|
||||
if (GetIconInfo(hiconOrg, &ii) && GetObject(ii.hbmColor, sizeof(BITMAP), &bm)) {
|
||||
// Do the cleanup for the bitmaps.
|
||||
DeleteObject(ii.hbmMask);
|
||||
DeleteObject(ii.hbmColor);
|
||||
ii.hbmMask = ii.hbmColor = NULL;
|
||||
hbm = CreateCompatibleBitmap(hdcScreen, bm.bmWidth, bm.bmHeight);
|
||||
hbmMask = CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, NULL);
|
||||
hbmOld = (HBITMAP)SelectObject(hdcBitmap, hbm);
|
||||
hbmOldMask = (HBITMAP)SelectObject(hdcMask, hbmMask);
|
||||
DrawIconEx(hdcBitmap, 0, 0, hiconOrg, bm.bmWidth, bm.bmHeight, 0, NULL, DI_IMAGE);
|
||||
DrawIconEx(hdcMask, 0, 0, hiconOrg, bm.bmWidth, bm.bmHeight, 0, NULL, DI_MASK);
|
||||
SelectObject(hdcBitmap, hbmOld);
|
||||
SelectObject(hdcMask, hbmOldMask);
|
||||
|
||||
// Create the new mirrored icon and delete bitmaps
|
||||
ii.hbmMask = hbmMask;
|
||||
ii.hbmColor = hbm;
|
||||
hicon = CreateIconIndirect(&ii);
|
||||
DeleteObject(hbm);
|
||||
DeleteObject(hbmMask);
|
||||
}
|
||||
}
|
||||
}
|
||||
ReleaseDC(NULL, hdcScreen);
|
||||
}
|
||||
|
||||
if (hdcBitmap)
|
||||
DeleteDC(hdcBitmap);
|
||||
if (hdcMask)
|
||||
DeleteDC(hdcMask);
|
||||
DestroyIcon(hiconOrg);
|
||||
return hicon;
|
||||
}
|
||||
|
||||
#ifdef RUFUS_TEST
|
||||
static __inline LPWORD lpwAlign(LPWORD addr)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue