Dynamically recalculate the toolbar dropdown position

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@7024 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2018-10-21 12:28:10 +00:00
parent 8de43bfab1
commit 1d937a6abb
3 changed files with 28 additions and 23 deletions

View file

@ -478,13 +478,11 @@ INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam
case TBN_DROPDOWN: case TBN_DROPDOWN:
{ {
LPNMTOOLBAR pToolBar = (LPNMTOOLBAR) lParam; LPNMTOOLBAR pToolBar = (LPNMTOOLBAR) lParam;
if(pToolBar->hdr.hwndFrom == g_toolbar.hwnd && pToolBar->iItem == IDM_COMPRESSOR) { if (pToolBar->hdr.hwndFrom == g_toolbar.hwnd && pToolBar->iItem == IDM_COMPRESSOR) {
ShowToolbarDropdownMenu(); ShowCompressorToolbarDropdownMenu(*pToolBar);
return TBDDRET_DEFAULT; return TBDDRET_DEFAULT;
} }
else { return TBDDRET_NODEFAULT;
return TBDDRET_NODEFAULT;
}
} }
} }
return TRUE; return TRUE;

View file

@ -77,7 +77,7 @@ void CreateToolBar()
// For Comctl32.dll version detection // For Comctl32.dll version detection
#ifndef _WIN64 #ifndef _WIN64
HMODULE hMod = GetModuleHandle(_T("comctl32.dll")); HMODULE hMod = GetModuleHandle(_T("comctl32.dll"));
const FARPROC hasCC4_70 = GetProcAddress(hMod, "InitCommonControlsEx"); const FARPROC hasCC4_70 = sizeof(TCHAR) > 1 ? (FARPROC) TRUE : GetProcAddress(hMod, "InitCommonControlsEx"); // NT4 shipped with v4.70
const FARPROC hasCC4_71 = GetProcAddress(hMod, "DllGetVersion"); const FARPROC hasCC4_71 = GetProcAddress(hMod, "DllGetVersion");
#else #else
const bool hasCC4_70 = true, hasCC4_71 = true; const bool hasCC4_70 = true, hasCC4_71 = true;
@ -108,13 +108,6 @@ void CreateToolBar()
tbBitmap.nID = IDB_TOOLBAR; tbBitmap.nID = IDB_TOOLBAR;
SendMessage(g_toolbar.hwnd, TB_ADDBITMAP, IMAGECOUNT, (LPARAM) &tbBitmap); SendMessage(g_toolbar.hwnd, TB_ADDBITMAP, IMAGECOUNT, (LPARAM) &tbBitmap);
} }
HMENU toolmenu = FindSubMenu(g_sdata.menu, IDM_SCRIPT);
g_toolbar.dropdownmenu = FindSubMenu(toolmenu, IDM_COMPRESSOR_SUBMENU);
RECT rect;
SendMessage(g_toolbar.hwnd, TB_GETITEMRECT, TBB_COMPRESSOR, (LPARAM) &rect);
g_toolbar.dropdownpoint.x = rect.left;
g_toolbar.dropdownpoint.y = rect.bottom+1;
} }
void UpdateToolBarCompressorButton() void UpdateToolBarCompressorButton()
@ -188,12 +181,28 @@ void EnableToolBarButton(int cmdid, BOOL enabled)
SendMessage(g_toolbar.hwnd, TB_SETSTATE, cmdid, MAKELPARAM(state, 0)); SendMessage(g_toolbar.hwnd, TB_SETSTATE, cmdid, MAKELPARAM(state, 0));
} }
void ShowToolbarDropdownMenu() static UINT IsRTL(HWND hWnd) { return ((UINT) GetWindowLongPtr(hWnd, GWL_EXSTYLE)) & (WS_EX_LAYOUTRTL); } // WS_EX_RIGHT? WS_EX_RTLREADING?
static UINT GetToolbarDropdownMenuPos(HWND hTB, UINT Id, POINT&pt)
{ {
RECT rect; RECT r;
GetWindowRect(g_toolbar.hwnd, &rect); INT_PTR idx = SendMessage(hTB, TB_COMMANDTOINDEX, Id, 0);
TrackPopupMenu(g_toolbar.dropdownmenu, 0, SendMessage(hTB, TB_GETITEMRECT, idx, (LPARAM) &r);
rect.left + g_toolbar.dropdownpoint.x, MapWindowPoints(hTB, NULL, (POINT*) &r, 2);
rect.top + g_toolbar.dropdownpoint.y, pt.x = IsRTL(hTB) ? r.right : r.left, pt.y = r.bottom;
0, g_sdata.hwnd, 0); return GetSystemMetrics(SM_MENUDROPALIGNMENT) ? TPM_RIGHTALIGN : TPM_LEFTALIGN;
}
static void ShowToolbarDropdownMenu(const NMTOOLBAR&nmtb, HWND hNotifyWnd, HMENU hParentMenu, UINT SubMenuId = -1)
{
POINT pt;
HMENU hMenu = SubMenuId == -1 ? hParentMenu : FindSubMenu(hParentMenu, SubMenuId);
UINT tpmf = GetToolbarDropdownMenuPos(nmtb.hdr.hwndFrom, nmtb.iItem, pt);
TrackPopupMenu(hMenu, tpmf, pt.x, pt.y, 0, hNotifyWnd, NULL);
}
void ShowCompressorToolbarDropdownMenu(const NMTOOLBAR&nmtb)
{
HMENU hParentMenu = FindSubMenu(g_sdata.menu, IDM_SCRIPT);
ShowToolbarDropdownMenu(nmtb, g_sdata.hwnd, hParentMenu, IDM_COMPRESSOR_SUBMENU);
} }

View file

@ -64,8 +64,6 @@
typedef struct ToolBarStruct { typedef struct ToolBarStruct {
HWND hwnd; HWND hwnd;
HMENU dropdownmenu;
POINT dropdownpoint;
HIMAGELIST imagelist; HIMAGELIST imagelist;
HIMAGELIST imagelistd; HIMAGELIST imagelistd;
HIMAGELIST imagelisth; HIMAGELIST imagelisth;
@ -74,6 +72,6 @@ typedef struct ToolBarStruct {
void CreateToolBar(); void CreateToolBar();
void EnableToolBarButton(int, BOOL); void EnableToolBarButton(int, BOOL);
void AddToolBarTooltips(); void AddToolBarTooltips();
void ShowToolbarDropdownMenu(); void ShowCompressorToolbarDropdownMenu(const NMTOOLBAR&nmtb);
void UpdateToolBarCompressorButton(); void UpdateToolBarCompressorButton();
#endif #endif