Add color samples on menu items for styling features

Fix #8983, close #9089
This commit is contained in:
Scott Sumner 2020-10-21 16:50:24 -04:00 committed by Don HO
parent c189cc7571
commit c28116a04f
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
6 changed files with 85 additions and 4 deletions

View File

@ -411,6 +411,8 @@ LRESULT Notepad_plus::init(HWND hwnd)
// Menu Section // // Menu Section //
// ------------ // // ------------ //
setupColorSampleBitmapsOnMainMenuItems();
// Macro Menu // Macro Menu
std::vector<MacroShortcut> & macros = nppParam.getMacroList(); std::vector<MacroShortcut> & macros = nppParam.getMacroList();
HMENU hMacroMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_MACRO); HMENU hMacroMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_MACRO);
@ -2157,6 +2159,68 @@ void Notepad_plus::checkSyncState()
enableCommand(IDM_VIEW_SYNSCROLLH, canDoSync, MENU | TOOLBAR); enableCommand(IDM_VIEW_SYNSCROLLH, canDoSync, MENU | TOOLBAR);
} }
void Notepad_plus::setupColorSampleBitmapsOnMainMenuItems()
{
// set up bitmaps on menu items
// style-related bitmaps of color samples
struct
{
int firstOfThisColorMenuId;
int styleIndic;
std::vector<int> sameColorMenuIds;
}
bitmapOnStyleMenuItemsInfo[] =
{
{ IDM_SEARCH_GONEXTMARKER5, SCE_UNIVERSAL_FOUND_STYLE_EXT5, { IDM_SEARCH_MARKALLEXT5, IDM_SEARCH_UNMARKALLEXT5, IDM_SEARCH_GOPREVMARKER5, IDM_SEARCH_STYLE5TOCLIP } },
{ IDM_SEARCH_GONEXTMARKER4, SCE_UNIVERSAL_FOUND_STYLE_EXT4, { IDM_SEARCH_MARKALLEXT4, IDM_SEARCH_UNMARKALLEXT4, IDM_SEARCH_GOPREVMARKER4, IDM_SEARCH_STYLE4TOCLIP } },
{ IDM_SEARCH_GONEXTMARKER3, SCE_UNIVERSAL_FOUND_STYLE_EXT3, { IDM_SEARCH_MARKALLEXT3, IDM_SEARCH_UNMARKALLEXT3, IDM_SEARCH_GOPREVMARKER3, IDM_SEARCH_STYLE3TOCLIP } },
{ IDM_SEARCH_GONEXTMARKER2, SCE_UNIVERSAL_FOUND_STYLE_EXT2, { IDM_SEARCH_MARKALLEXT2, IDM_SEARCH_UNMARKALLEXT2, IDM_SEARCH_GOPREVMARKER2, IDM_SEARCH_STYLE2TOCLIP } },
{ IDM_SEARCH_GONEXTMARKER1, SCE_UNIVERSAL_FOUND_STYLE_EXT1, { IDM_SEARCH_MARKALLEXT1, IDM_SEARCH_UNMARKALLEXT1, IDM_SEARCH_GOPREVMARKER1, IDM_SEARCH_STYLE1TOCLIP } },
{ IDM_SEARCH_GONEXTMARKER_DEF, SCE_UNIVERSAL_FOUND_STYLE, { IDM_SEARCH_GOPREVMARKER_DEF, IDM_SEARCH_MARKEDTOCLIP } }
};
for (int j = 0; j < sizeof(bitmapOnStyleMenuItemsInfo) / sizeof(bitmapOnStyleMenuItemsInfo[0]); ++j)
{
StyleArray& stylers = NppParameters::getInstance().getMiscStylerArray();
int iFind = stylers.getStylerIndexByID(bitmapOnStyleMenuItemsInfo[j].styleIndic);
if (iFind != -1)
{
Style const* pStyle = &(stylers.getStyler(iFind));
HDC hDC = GetDC(NULL);
const int bitmapXYsize = 16;
HBITMAP hNewBitmap = CreateCompatibleBitmap(hDC, bitmapXYsize, bitmapXYsize);
HDC hDCn = CreateCompatibleDC(hDC);
HBITMAP hOldBitmap = static_cast<HBITMAP>(SelectObject(hDCn, hNewBitmap));
RECT rc = { 0, 0, bitmapXYsize, bitmapXYsize };
// paint full-size black square
HBRUSH hBlackBrush = CreateSolidBrush(RGB(0,0,0));
FillRect(hDCn, &rc, hBlackBrush);
DeleteObject(hBlackBrush);
// overpaint a slightly smaller colored square
rc.left = rc.top = 1;
rc.right = rc.bottom = bitmapXYsize - 1;
HBRUSH hColorBrush = CreateSolidBrush(pStyle->_bgColor);
FillRect(hDCn, &rc, hColorBrush);
DeleteObject(hColorBrush);
// restore old bitmap so we can delete it to avoid leak
SelectObject(hDCn, hOldBitmap);
DeleteDC(hDCn);
SetMenuItemBitmaps(_mainMenuHandle, bitmapOnStyleMenuItemsInfo[j].firstOfThisColorMenuId, MF_BYCOMMAND, hNewBitmap, hNewBitmap);
for (int relatedMenuId : bitmapOnStyleMenuItemsInfo[j].sameColorMenuIds)
{
SetMenuItemBitmaps(_mainMenuHandle, relatedMenuId, MF_BYCOMMAND, hNewBitmap, NULL);
}
}
}
}
bool doCheck(HMENU mainHandle, int id) bool doCheck(HMENU mainHandle, int id)
{ {
MENUITEMINFO mii; MENUITEMINFO mii;

View File

@ -469,6 +469,7 @@ private:
void checkUndoState(); void checkUndoState();
void checkMacroState(); void checkMacroState();
void checkSyncState(); void checkSyncState();
void setupColorSampleBitmapsOnMainMenuItems();
void dropFiles(HDROP hdrop); void dropFiles(HDROP hdrop);
void checkModifiedDocument(bool bCheckOnlyCurrentBuffer); void checkModifiedDocument(bool bCheckOnlyCurrentBuffer);

View File

@ -1750,6 +1750,12 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
return TRUE; return TRUE;
} }
case WM_UPDATEMAINMENUBITMAPS:
{
setupColorSampleBitmapsOnMainMenuItems();
return TRUE;
}
case WM_QUERYENDSESSION: case WM_QUERYENDSESSION:
case WM_CLOSE: case WM_CLOSE:
{ {

View File

@ -266,6 +266,7 @@ INT_PTR CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM l
//(nppParamInst.getNppGUI())._themeName //(nppParamInst.getNppGUI())._themeName
::SendMessage(_hSwitch2ThemeCombo, CB_SETCURSEL, _currentThemeIndex, 0); ::SendMessage(_hSwitch2ThemeCombo, CB_SETCURSEL, _currentThemeIndex, 0);
::SendMessage(_hParent, WM_UPDATESCINTILLAS, 0, 0); ::SendMessage(_hParent, WM_UPDATESCINTILLAS, 0, 0);
::SendMessage(_hParent, WM_UPDATEMAINMENUBITMAPS, 0, 0);
} }
::EnableWindow(::GetDlgItem(_hSelf, IDC_SAVECLOSE_BUTTON), FALSE/*!_isSync*/); ::EnableWindow(::GetDlgItem(_hSelf, IDC_SAVECLOSE_BUTTON), FALSE/*!_isSync*/);
display(false); display(false);
@ -293,6 +294,7 @@ INT_PTR CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM l
//_isSync = true; //_isSync = true;
display(false); display(false);
::SendMessage(_hParent, WM_UPDATESCINTILLAS, 0, 0); ::SendMessage(_hParent, WM_UPDATESCINTILLAS, 0, 0);
::SendMessage(_hParent, WM_UPDATEMAINMENUBITMAPS, 0, 0);
return TRUE; return TRUE;
} }
@ -885,4 +887,5 @@ void WordStyleDlg::apply()
::EnableWindow(::GetDlgItem(_hSelf, IDOK), FALSE); ::EnableWindow(::GetDlgItem(_hSelf, IDOK), FALSE);
::SendMessage(_hParent, WM_UPDATESCINTILLAS, 0, 0); ::SendMessage(_hParent, WM_UPDATESCINTILLAS, 0, 0);
::SendMessage(_hParent, WM_UPDATEMAINMENUBITMAPS, 0, 0);
} }

View File

@ -34,6 +34,7 @@
#define WM_UPDATESCINTILLAS (WORDSTYLE_USER + 1) //GlobalStyleDlg's msg 2 send 2 its parent #define WM_UPDATESCINTILLAS (WORDSTYLE_USER + 1) //GlobalStyleDlg's msg 2 send 2 its parent
#define WM_UPDATEMAINMENUBITMAPS (WORDSTYLE_USER + 2)
enum fontStyleType {BOLD_STATUS, ITALIC_STATUS, UNDERLINE_STATUS}; enum fontStyleType {BOLD_STATUS, ITALIC_STATUS, UNDERLINE_STATUS};

View File

@ -61,6 +61,7 @@ void ContextMenu::create(HWND hParent, const std::vector<MenuItemUnit> & menuIte
HMENU hParentFolder = NULL; HMENU hParentFolder = NULL;
generic_string currentParentFolderStr; generic_string currentParentFolderStr;
int j = 0; int j = 0;
MENUITEMINFO mii;
for (size_t i = 0, len = menuItemArray.size(); i < len; ++i) for (size_t i = 0, len = menuItemArray.size(); i < len; ++i)
{ {
@ -109,7 +110,6 @@ void ContextMenu::create(HWND hParent, const std::vector<MenuItemUnit> & menuIte
lastIsSep = true; lastIsSep = true;
} }
if (mainMenuHandle) if (mainMenuHandle)
{ {
bool isEnabled = (::GetMenuState(mainMenuHandle, item._cmdID, MF_BYCOMMAND)&(MF_DISABLED|MF_GRAYED)) == 0; bool isEnabled = (::GetMenuState(mainMenuHandle, item._cmdID, MF_BYCOMMAND)&(MF_DISABLED|MF_GRAYED)) == 0;
@ -118,8 +118,14 @@ void ContextMenu::create(HWND hParent, const std::vector<MenuItemUnit> & menuIte
enableItem(item._cmdID, isEnabled); enableItem(item._cmdID, isEnabled);
if (isChecked) if (isChecked)
checkItem(item._cmdID, isChecked); checkItem(item._cmdID, isChecked);
}
// set up any menu item bitmaps in the context menu, using main menu bitmaps
memset(&mii, 0, sizeof(mii));
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_CHECKMARKS;
mii.fType = MFT_BITMAP;
GetMenuItemInfo(mainMenuHandle, item._cmdID, FALSE, &mii);
SetMenuItemInfo(_hMenu, item._cmdID, FALSE, &mii);
}
} }
} }