Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion PythonScript.Tests/PythonScript.Tests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@
<ClCompile Include="..\PythonScript\src\UTF8Iterator.cpp" />
<ClCompile Include="..\PythonScript\src\UtfConversion.cpp" />
<ClCompile Include="..\PythonScript\src\WcharMbcsConverter.cpp" />
<ClCompile Include="..\PythonScript\src\Utility.cpp" />
<ClCompile Include="TestRunner.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
Expand All @@ -321,4 +322,4 @@
<Error Condition="!Exists('..\packages\boost.1.87.0\build\boost.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost.1.87.0\build\boost.targets'))" />
<Error Condition="!Exists('..\packages\boost_python312-vc143.1.87.0\build\boost_python312-vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_python312-vc143.1.87.0\build\boost_python312-vc143.targets'))" />
</Target>
</Project>
</Project>
4 changes: 3 additions & 1 deletion PythonScript/project/PythonScript.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ xcopy $(ProjectDir)..\python_tests\*.* "e:\notepadtest\unicode\plugins\config\py
<ClCompile Include="..\src\UTF8Iterator.cpp" />
<ClCompile Include="..\src\UtfConversion.cpp" />
<ClCompile Include="..\src\WcharMbcsConverter.cpp" />
<ClCompile Include="..\src\Utility.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\PythonScript\NppPythonScript.h" />
Expand Down Expand Up @@ -535,6 +536,7 @@ xcopy $(ProjectDir)..\python_tests\*.* "e:\notepadtest\unicode\plugins\config\py
<ClInclude Include="..\src\UTF8Iterator.h" />
<ClInclude Include="..\src\UtfConversion.h" />
<ClInclude Include="..\src\WcharMbcsConverter.h" />
<ClInclude Include="..\src\Utility.h" />
<ClInclude Include="..\res\resource1.h" />
</ItemGroup>
<ItemGroup>
Expand All @@ -553,4 +555,4 @@ xcopy $(ProjectDir)..\python_tests\*.* "e:\notepadtest\unicode\plugins\config\py
<Error Condition="!Exists('..\..\packages\boost.1.87.0\build\boost.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\boost.1.87.0\build\boost.targets'))" />
<Error Condition="!Exists('..\..\packages\boost_python312-vc143.1.87.0\build\boost_python312-vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\boost_python312-vc143.1.87.0\build\boost_python312-vc143.targets'))" />
</Target>
</Project>
</Project>
12 changes: 8 additions & 4 deletions PythonScript/src/ConfigFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "ConfigFile.h"
#include "resource.h"
#include "WcharMbcsConverter.h"
#include "Utility.h"

ConfigFile* ConfigFile::s_instance;

Expand Down Expand Up @@ -58,7 +59,7 @@ void ConfigFile::readConfig()
char buffer[500];


HBITMAP hIcon;
HBITMAP hBitmap;

while (startupFile.good())
{
Expand Down Expand Up @@ -90,17 +91,20 @@ void ConfigFile::readConfig()
char *iconPath = strtok_s(NULL, "/", &context);
if (!iconPath || !(*iconPath))
{
hIcon = static_cast<HBITMAP>(LoadImage(m_hInst, MAKEINTRESOURCE(IDB_PYTHON), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE));
hBitmap = static_cast<HBITMAP>(LoadImage(m_hInst, MAKEINTRESOURCE(IDB_PYTHON), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE));
iconPath = NULL;
}
else
{
iconFullPath = expandPathIfNeeded(iconPath);
hIcon = static_cast<HBITMAP>(LoadImage(NULL, iconFullPath.c_str(), IMAGE_BITMAP, 16, 16, LR_LOADMAP3DCOLORS | LR_LOADFROMFILE));
hBitmap = static_cast<HBITMAP>(LoadImage(NULL, iconFullPath.c_str(), IMAGE_BITMAP, 16, 16, LR_LOADMAP3DCOLORS | LR_LOADFROMFILE));
if (hBitmap == NULL) {
hBitmap = ConvertIconToBitmap(const_cast<LPWSTR>(iconFullPath.c_str()));
}
}
if (scriptFullPath != L"")
{
m_toolbarItems.push_back(std::pair<tstring, std::pair<HBITMAP, tstring> >(scriptFullPath, std::pair<HBITMAP, tstring>(hIcon, iconPath ? iconFullPath : tstring())));
m_toolbarItems.push_back(std::pair<tstring, std::pair<HBITMAP, tstring> >(scriptFullPath, std::pair<HBITMAP, tstring>(hBitmap, iconPath ? iconFullPath : tstring())));
}
}
else if (0 == strcmp(element, "SETTING"))
Expand Down
9 changes: 7 additions & 2 deletions PythonScript/src/ShortcutDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "resource.h"
#include "MenuManager.h"
#include "Notepad_plus_msgs.h"

#include "Utility.h"

ShortcutDlg::ShortcutDlg(HINSTANCE hInst, NppData& nppData, const TCHAR *scriptDirAppend)
: m_hTree(NULL),
Expand Down Expand Up @@ -602,8 +602,13 @@ void ShortcutDlg::toolbarSetIcon()
if (GetOpenFileName(&ofn))
{
ConfigFile::ToolbarItemsTD::iterator it = m_toolbarItems.begin() + index;
it->second.first = static_cast<HBITMAP>(LoadImage(NULL, ofn.lpstrFile, IMAGE_BITMAP, 16, 16, LR_COLOR | LR_LOADFROMFILE));
HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, ofn.lpstrFile, IMAGE_BITMAP, 16, 16, LR_COLOR | LR_LOADFROMFILE);
if (hBitmap == NULL) {
hBitmap = ConvertIconToBitmap(ofn.lpstrFile);
}
it->second.first = hBitmap;
it->second.second = ofn.lpstrFile;

int imageIndex = ImageList_Add(m_hImageList, it->second.first, NULL);
LVITEM lvItem{};
lvItem.mask = LVIF_IMAGE;
Expand Down
33 changes: 33 additions & 0 deletions PythonScript/src/Utility.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "stdafx.h"
#include "Utility.h"

HBITMAP ConvertIconToBitmap(LPCWSTR file_path) {
HBITMAP hBitmap = nullptr;
HICON hIcon = (HICON)LoadImage(nullptr, file_path, IMAGE_ICON, 16, 16, LR_COLOR | LR_LOADFROMFILE);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe DPIManagerV2::loadIcon() could be used here for High DPI support.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The size is currently set to 16x16. To support really high dpi, further changes are probably needed, e.g. how to handle multiple bmp sizes.

if (hIcon) {
ICONINFO iconInfo;
if (GetIconInfo(hIcon, &iconInfo)) {
HDC hdc = GetDC(nullptr);
if (hdc) {
HDC hdcMem = CreateCompatibleDC(hdc);
if (hdcMem) {
BITMAP bm{};
if (GetObject(iconInfo.hbmColor, sizeof(BITMAP), &bm)) {
hBitmap = CreateCompatibleBitmap(hdc, 16, 16);
if (hBitmap) {
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, hBitmap);
DrawIconEx(hdcMem, 0, 0, hIcon, 16, 16, 0, nullptr, DI_NORMAL);
SelectObject(hdcMem, hbmOld);
}
}
DeleteDC(hdcMem);
}
ReleaseDC(nullptr, hdc);
}
DeleteObject(iconInfo.hbmColor);
DeleteObject(iconInfo.hbmMask);
}
DestroyIcon(hIcon);
}
return hBitmap;
}
7 changes: 7 additions & 0 deletions PythonScript/src/Utility.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef _PYTHONSCRIPT_UTILITY_H
#define _PYTHONSCRIPT_UTILITY_H
#endif

#include <wtypes.h>

HBITMAP ConvertIconToBitmap(LPCWSTR file_path);