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

[ui] improve tooltip handling

* only reference the HANDLE of the control the tooltip is associated with
This commit is contained in:
Pete Batard 2012-05-21 11:11:42 +01:00
parent 3fde2a5472
commit 4a74c9de38
4 changed files with 38 additions and 38 deletions

View file

@ -106,8 +106,7 @@ int rufus_version[4];
extern char szStatusMessage[256];
static HANDLE format_thid = NULL;
static HWND hDeviceTooltip = NULL, hFSTooltip = NULL, hProgress = NULL;
static HWND hDOS = NULL, hSelectISO = NULL, hISOToolTip = NULL, hPassesToolTip = NULL;
static HWND hProgress = NULL, hDOS = NULL, hSelectISO = NULL;
static HICON hIconDisc, hIconDown, hIconUp;
static StrArray DriveID, DriveLabel;
static char szTimer[12] = "00:00:00";
@ -352,19 +351,19 @@ static BOOL GetDriveInfo(void)
if (!r || size <= 0) {
uprintf("IOCTL_DISK_GET_DRIVE_LAYOUT_EX failed for drive %c: %s\n", DrivePath[0], WindowsErrorString());
} else {
DestroyTooltip(hFSTooltip);
hFSTooltip = NULL;
r = FALSE;
switch (DriveLayout->PartitionStyle) {
case PARTITION_STYLE_MBR:
for (i=0; i<DriveLayout->PartitionCount; i++) {
if (DriveLayout->PartitionEntry[i].Mbr.PartitionType != PARTITION_ENTRY_UNUSED) {
uprintf("Partition #%d:\n", ++nb_partitions);
if (hFSTooltip == NULL) {
if (!r) {
// TODO: provide all partitions FS on tooltip, not just the one
safe_sprintf(tmp, sizeof(tmp), "Current file system: %s (0x%02x)",
GetPartitionType(DriveLayout->PartitionEntry[i].Mbr.PartitionType),
DriveLayout->PartitionEntry[i].Mbr.PartitionType);
hFSTooltip = CreateTooltip(hFileSystem, tmp, -1);
CreateTooltip(hFileSystem, tmp, -1);
r = TRUE;
}
uprintf(" Type: %s (0x%02x)\n Boot: %s\n Recognized: %s\n Hidden Sectors: %d\n",
GetPartitionType(DriveLayout->PartitionEntry[i].Mbr.PartitionType),
@ -499,10 +498,6 @@ static BOOL PopulateProperties(int ComboIndex)
IGNORE_RETVAL(ComboBox_ResetContent(hClusterSize));
EnableWindow(GetDlgItem(hMainDialog, IDC_START), FALSE);
SetWindowTextA(hLabel, "");
DestroyTooltip(hDeviceTooltip);
DestroyTooltip(hFSTooltip);
hDeviceTooltip = NULL;
hFSTooltip = NULL;
memset(&SelectedDrive, 0, sizeof(SelectedDrive));
EnableWindow(hDOS, FALSE);
@ -530,7 +525,7 @@ static BOOL PopulateProperties(int ComboIndex)
}
IGNORE_RETVAL(ComboBox_AddStringU(hCapacity, capacity));
IGNORE_RETVAL(ComboBox_SetCurSel(hCapacity, 0));
hDeviceTooltip = CreateTooltip(hDeviceList, DriveID.Table[ComboIndex], -1);
CreateTooltip(hDeviceList, DriveID.Table[ComboIndex], -1);
// Set a proposed label according to the size (eg: "256MB", "8GB")
if (HumanReadableSize < 1.0) {
@ -1322,7 +1317,7 @@ void InitDialog(HWND hDlg)
IGNORE_RETVAL(ComboBox_AddStringU(hNBPasses, "3 Passes"));
IGNORE_RETVAL(ComboBox_AddStringU(hNBPasses, "4 Passes"));
IGNORE_RETVAL(ComboBox_SetCurSel(hNBPasses, 1));
hPassesToolTip = CreateTooltip(hNBPasses, "Pattern: 0x55, 0xAA", -1);
CreateTooltip(hNBPasses, "Pattern: 0x55, 0xAA", -1);
// Fill up the DOS type dropdown
IGNORE_RETVAL(ComboBox_SetItemData(hDOSType, ComboBox_AddStringU(hDOSType, "MS-DOS"), DT_WINME));
IGNORE_RETVAL(ComboBox_SetCurSel(hDOSType, DT_WINME));
@ -1371,7 +1366,7 @@ void InitDialog(HWND hDlg)
SendMessage(hSelectISO, BCM_SETIMAGELIST, 0, (LPARAM)&bi_iso);
SendMessage(GetDlgItem(hDlg, IDC_ADVANCED), BCM_SETIMAGELIST, 0, (LPARAM)&bi_down);
hISOToolTip = CreateTooltip(hSelectISO, "Click to select...", -1);
CreateTooltip(hSelectISO, "Click to select...", -1);
CreateTooltip(GetDlgItem(hDlg, IDC_SET_ICON), "Create an autorun.inf on the target drive, to set the icon. "
"Also allow the display of non-English labels.", 10000);
@ -1479,19 +1474,18 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
case IDC_NBPASSES:
if (HIWORD(wParam) != CBN_SELCHANGE)
break;
DestroyTooltip(hPassesToolTip);
switch(ComboBox_GetCurSel(hNBPasses)) {
case 0:
hPassesToolTip = CreateTooltip(hNBPasses, "Pattern: 0x55", -1);
CreateTooltip(hNBPasses, "Pattern: 0x55", -1);
break;
case 1:
hPassesToolTip = CreateTooltip(hNBPasses, "Pattern: 0x55, 0xAA", -1);
CreateTooltip(hNBPasses, "Pattern: 0x55, 0xAA", -1);
break;
case 2:
hPassesToolTip = CreateTooltip(hNBPasses, "Pattern: 0x55, 0xAA, 0xFF", -1);
CreateTooltip(hNBPasses, "Pattern: 0x55, 0xAA, 0xFF", -1);
break;
case 3:
hPassesToolTip = CreateTooltip(hNBPasses, "Pattern: 0x55, 0xAA, 0xFF, 0x00", -1);
CreateTooltip(hNBPasses, "Pattern: 0x55, 0xAA, 0xFF, 0x00", -1);
break;
}
break;
@ -1564,15 +1558,14 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
}
return (INT_PTR)TRUE;
case IDC_SELECT_ISO:
DestroyTooltip(hISOToolTip);
safe_free(iso_path);
iso_path = FileDialog(FALSE, NULL, "*.iso", "iso", "ISO Image");
if (iso_path == NULL) {
hISOToolTip = CreateTooltip(hSelectISO, "Click to select...", -1);
CreateTooltip(hSelectISO, "Click to select...", -1);
break;
}
selection_default = DT_ISO;
hISOToolTip = CreateTooltip(hSelectISO, iso_path, -1);
CreateTooltip(hSelectISO, iso_path, -1);
FormatStatus = 0;
// You'd think that Windows would let you instantiate a modeless dialog wherever
// but you'd be wrong. It must be done in the main callback!

View file

@ -217,7 +217,7 @@ extern BOOL CreateTaskbarList(void);
extern BOOL SetTaskbarProgressState(TASKBAR_PROGRESS_FLAGS tbpFlags);
extern BOOL SetTaskbarProgressValue(ULONGLONG ullCompleted, ULONGLONG ullTotal);
extern INT_PTR CreateAboutBox(void);
extern HWND CreateTooltip(HWND hControl, const char* message, int duration);
extern BOOL CreateTooltip(HWND hControl, const char* message, int duration);
extern void DestroyTooltip(HWND hWnd);
extern void DestroyAllTooltips(void);
extern BOOL Notification(int type, char* title, char* format, ...);

View file

@ -30,7 +30,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 206, 316
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "Rufus v1.2.0.173"
CAPTION "Rufus v1.2.0.174"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Start",IDC_START,94,278,50,14
@ -76,7 +76,7 @@ BEGIN
DEFPUSHBUTTON "OK",IDOK,231,175,50,14,WS_GROUP
CONTROL "<a href=""http://rufus.akeo.ie"">http://rufus.akeo.ie</a>",IDC_ABOUT_RUFUS_URL,
"SysLink",WS_TABSTOP,46,47,114,9
LTEXT "Version 1.2.0 (Build 173)",IDC_STATIC,46,19,78,8
LTEXT "Version 1.2.0 (Build 174)",IDC_STATIC,46,19,78,8
PUSHBUTTON "License...",IDC_ABOUT_LICENSE,46,175,50,14,WS_GROUP
EDITTEXT IDC_ABOUT_COPYRIGHTS,46,107,235,63,ES_MULTILINE | ES_READONLY | WS_VSCROLL
LTEXT "Report bugs or request enhancements at:",IDC_STATIC,46,66,187,8
@ -221,8 +221,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,2,0,173
PRODUCTVERSION 1,2,0,173
FILEVERSION 1,2,0,174
PRODUCTVERSION 1,2,0,174
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -239,13 +239,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "akeo.ie"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "1.2.0.173"
VALUE "FileVersion", "1.2.0.174"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "1.2.0.173"
VALUE "ProductVersion", "1.2.0.174"
END
END
BLOCK "VarFileInfo"

View file

@ -683,7 +683,8 @@ BOOL Notification(int type, char* title, char* format, ...)
}
static struct {
HWND hTip;
HWND hTip; // Tooltip handle
HWND hCtrl; // Handle of the control the tooltip belongs to
WNDPROC original_proc;
LPWSTR wstring;
} ttlist[MAX_TOOLTIPS] = { {0} };
@ -721,22 +722,25 @@ INT_PTR CALLBACK TooltipCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM
* duration sets the duration in ms. Use -1 for default
* message is an UTF-8 string
*/
HWND CreateTooltip(HWND hControl, const char* message, int duration)
BOOL CreateTooltip(HWND hControl, const char* message, int duration)
{
TOOLINFOW toolInfo = {0};
int i;
if ( (hControl == NULL) || (message == NULL) ) {
return (HWND)NULL;
return FALSE;
}
// Destroy existing tooltip if any
DestroyTooltip(hControl);
// Find an empty slot
for (i=0; i<MAX_TOOLTIPS; i++) {
if (ttlist[i].hTip == NULL) break;
}
if (i == MAX_TOOLTIPS) {
uprintf("Maximum number of tooltips reached\n");
return (HWND)NULL;
return FALSE;
}
// Create the tooltip window
@ -745,8 +749,9 @@ HWND CreateTooltip(HWND hControl, const char* message, int duration)
hMainInstance, NULL);
if (ttlist[i].hTip == NULL) {
return (HWND)NULL;
return FALSE;
}
ttlist[i].hCtrl = hControl;
// Subclass the tooltip to handle multiline
ttlist[i].original_proc = (WNDPROC)SetWindowLongPtr(ttlist[i].hTip, GWLP_WNDPROC, (LONG_PTR)TooltipCallback);
@ -765,22 +770,24 @@ HWND CreateTooltip(HWND hControl, const char* message, int duration)
toolInfo.lpszText = LPSTR_TEXTCALLBACKW;
SendMessageW(ttlist[i].hTip, TTM_ADDTOOLW, 0, (LPARAM)&toolInfo);
return ttlist[i].hTip;
return TRUE;
}
void DestroyTooltip(HWND hWnd)
/* Destroy a tooltip. hCtrl = handle of the control the tooltip is associated with */
void DestroyTooltip(HWND hControl)
{
int i;
if (hWnd == NULL) return;
if (hControl == NULL) return;
for (i=0; i<MAX_TOOLTIPS; i++) {
if (ttlist[i].hTip == hWnd) break;
if (ttlist[i].hCtrl == hControl) break;
}
if (i == MAX_TOOLTIPS) return;
DestroyWindow(hWnd);
DestroyWindow(ttlist[i].hTip);
safe_free(ttlist[i].wstring);
ttlist[i].original_proc = NULL;
ttlist[i].hTip = NULL;
ttlist[i].hCtrl = NULL;
}
void DestroyAllTooltips(void)