OSDN Git Service

minor fix for win2k context menu icons
[tortoisegit/TortoiseGitJp.git] / src / TortoiseShell / ContextMenu.cpp
index 5f819b6..fb7db36 100644 (file)
@@ -670,27 +670,33 @@ void CShellExt::InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UIN
                _tcscpy_s(menutextbuffer, 255, _T("Git "));\r
        }\r
        _tcscat_s(menutextbuffer, 255, stringtablebuffer);\r
-       if ((fullver < 0x500)||(fullver == 0x500 && !uFlags))\r
+       if ((fullver < 0x500)||(fullver == 0x500 && !(uFlags&~(CMF_RESERVED|CMF_EXPLORE))))\r
        {\r
+               // on win2k, the context menu does not work properly if we use\r
+               // icon bitmaps. At least the menu text is empty in the context menu\r
+               // for folder backgrounds (seems like a win2k bug).\r
+               // the workaround is to use the check/unchecked bitmaps, which are drawn\r
+               // with AND raster op, but it's better than nothing at all\r
                InsertMenu(menu, pos, MF_BYPOSITION | MF_STRING , id, menutextbuffer);\r
-               if (fullver >= 0x500)\r
+               if (icon)\r
                {\r
-                       // on win2k, the context menu does not work properly if we use\r
-                       // icon bitmaps. At least the menu text is empty in the context menu\r
-                       // for folder backgrounds (seems like a win2k bug).\r
                        HBITMAP bmp = IconToBitmap(icon); \r
                        SetMenuItemBitmaps(menu, pos, MF_BYPOSITION, bmp, bmp);\r
                }\r
        }\r
        else\r
        {\r
-               MENUITEMINFO menuiteminfo = {0};\r
+               MENUITEMINFO menuiteminfo;\r
+               SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));\r
                menuiteminfo.cbSize = sizeof(menuiteminfo);\r
-               menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_BITMAP | MIIM_STRING;\r
+               menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;\r
                menuiteminfo.fType = MFT_STRING;\r
                menuiteminfo.dwTypeData = menutextbuffer;\r
                if (icon)\r
+               {\r
+                       menuiteminfo.fMask |= MIIM_BITMAP;\r
                        menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;\r
+               }\r
                menuiteminfo.wID = id;\r
                InsertMenuItem(menu, pos, TRUE, &menuiteminfo);\r
        }\r
@@ -1087,9 +1093,9 @@ STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
        // insert separator at start\r
        InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;\r
        bool bShowIcons = !!DWORD(CRegStdWORD(_T("Software\\TortoiseGit\\ShowContextMenuIcons"), TRUE));\r
-       // ?? TortoiseSVN had this as (fullver <= 0x0500) this disabled icons in win2k, but icons work fine in win2k\r
-       if (fullver < 0x0500)\r
-               bShowIcons = false;\r
+       // ?? TSV disabled icons for win2k and earlier, but they work for win2k and should work for win95 and up\r
+       /*if (fullver <= 0x500)\r
+               bShowIcons = false;*/\r
        while (menuInfo[menuIndex].command != ShellMenuLastEntry)\r
        {\r
                if (menuInfo[menuIndex].command == ShellSeparator)\r
@@ -1170,7 +1176,7 @@ STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
                                        // handle special cases (sub menus)\r
                                        if ((menuInfo[menuIndex].command == ShellMenuIgnoreSub)||(menuInfo[menuIndex].command == ShellMenuUnIgnoreSub))\r
                                        {\r
-                                               InsertIgnoreSubmenus(idCmd, idCmdFirst, hMenu, subMenu, indexMenu, indexSubMenu, topmenu, bShowIcons);\r
+                                               InsertIgnoreSubmenus(idCmd, idCmdFirst, hMenu, subMenu, indexMenu, indexSubMenu, topmenu, bShowIcons, uFlags);\r
                                                bMenuEntryAdded = true;\r
                                                bMenuEmpty = false;\r
                                        }\r
@@ -1242,19 +1248,26 @@ STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
                myIDMap[idCmd] = ShellSubMenu;\r
        }\r
        HBITMAP bmp = NULL;\r
-       if ((fullver < 0x500)||(fullver == 0x500 && !uFlags))\r
+       if ((fullver < 0x500)||(fullver == 0x500 && !(uFlags&~(CMF_RESERVED|CMF_EXPLORE))))\r
        {\r
-               bmp = IconToBitmap(uIcon);\r
-               menuiteminfo.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS | MIIM_DATA;\r
+               menuiteminfo.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU | MIIM_DATA;\r
+               if (uIcon)\r
+               {\r
+                       menuiteminfo.fMask |= MIIM_CHECKMARKS;\r
+                       bmp = IconToBitmap(uIcon);\r
+                       menuiteminfo.hbmpChecked = bmp;\r
+                       menuiteminfo.hbmpUnchecked = bmp;\r
+               }\r
        }\r
        else\r
        {\r
-               menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_BITMAP | MIIM_STRING;\r
-               if (bShowIcons)\r
+               menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_STRING;\r
+               if (uIcon)\r
+               {\r
+                       menuiteminfo.fMask |= MIIM_BITMAP;\r
                        menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(uIcon) : HBMMENU_CALLBACK;\r
+               }\r
        }\r
-       menuiteminfo.hbmpChecked = bmp;\r
-       menuiteminfo.hbmpUnchecked = bmp;\r
        menuiteminfo.hSubMenu = subMenu;\r
        menuiteminfo.wID = idCmd++;\r
        InsertMenuItem(hMenu, indexMenu++, TRUE, &menuiteminfo);\r
@@ -2011,7 +2024,7 @@ STDMETHODIMP CShellExt::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam,
        case WM_MEASUREITEM:\r
                {\r
                        MEASUREITEMSTRUCT* lpmis = (MEASUREITEMSTRUCT*)lParam;\r
-                       if (lpmis==NULL)\r
+                       if (lpmis==NULL||lpmis->CtlType!=ODT_MENU)\r
                                break;\r
                        lpmis->itemWidth += 2;\r
                        if (lpmis->itemHeight < 16)\r
@@ -2183,7 +2196,7 @@ bool CShellExt::IsIllegalFolder(std::wstring folder, int * cslidarray)
        return false;\r
 }\r
 \r
-void CShellExt::InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons)\r
+void CShellExt::InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons, UINT uFlags)\r
 {\r
        HMENU ignoresubmenu = NULL;\r
        int indexignoresub = 0;\r
@@ -2303,13 +2316,27 @@ void CShellExt::InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu,
                MENUITEMINFO menuiteminfo;\r
                SecureZeroMemory(&menuiteminfo, sizeof(menuiteminfo));\r
                menuiteminfo.cbSize = sizeof(menuiteminfo);\r
-               menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_BITMAP | MIIM_STRING;\r
+               if (fullver < 0x500 || (fullver == 0x500 && !(uFlags&~(CMF_RESERVED|CMF_EXPLORE))))\r
+               {\r
+                       menuiteminfo.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU | MIIM_DATA;\r
+                       if (icon)\r
+                       {\r
+                               HBITMAP bmp = IconToBitmap(icon);\r
+                               menuiteminfo.fMask |= MIIM_CHECKMARKS;\r
+                               menuiteminfo.hbmpChecked = bmp;\r
+                               menuiteminfo.hbmpUnchecked = bmp;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_STRING;\r
+                       if (icon)\r
+                       {\r
+                               menuiteminfo.fMask |= MIIM_BITMAP;\r
+                               menuiteminfo.hbmpItem = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : HBMMENU_CALLBACK;\r
+                       }\r
+               }\r
                menuiteminfo.fType = MFT_STRING;\r
-               HBITMAP bmp = (fullver >= 0x600) ? IconToBitmapPARGB32(icon) : IconToBitmap(icon);\r
-               if (icon)\r
-                       menuiteminfo.hbmpItem = (fullver >= 0x600) ? bmp : HBMMENU_CALLBACK;\r
-               menuiteminfo.hbmpChecked = bmp;\r
-               menuiteminfo.hbmpUnchecked = bmp;\r
                menuiteminfo.hSubMenu = ignoresubmenu;\r
                menuiteminfo.wID = idCmd;\r
                SecureZeroMemory(stringtablebuffer, sizeof(stringtablebuffer));\r