add last backwards-compatible version
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "win32_misc.h"
|
||||
#include "TypeFind.h"
|
||||
#include "SmartStrStr.h"
|
||||
|
||||
#ifdef FOOBAR2000_MOBILE_WINDOWS
|
||||
#include <pfc/pp-winapi.h>
|
||||
@@ -119,6 +121,153 @@ void registerclass_scope_delayed::toggle_off() {
|
||||
}
|
||||
}
|
||||
|
||||
unsigned QueryScreenDPI(HWND wnd) {
|
||||
HDC dc = GetDC(wnd);
|
||||
unsigned ret = GetDeviceCaps(dc,LOGPIXELSY);
|
||||
ReleaseDC(wnd,dc);
|
||||
return ret;
|
||||
}
|
||||
unsigned QueryScreenDPI_X(HWND wnd) {
|
||||
HDC dc = GetDC(wnd);
|
||||
unsigned ret = GetDeviceCaps(dc,LOGPIXELSX);
|
||||
ReleaseDC(wnd,dc);
|
||||
return ret;
|
||||
}
|
||||
unsigned QueryScreenDPI_Y(HWND wnd) {
|
||||
HDC dc = GetDC(wnd);
|
||||
unsigned ret = GetDeviceCaps(dc,LOGPIXELSY);
|
||||
ReleaseDC(wnd,dc);
|
||||
return ret;
|
||||
}
|
||||
|
||||
SIZE QueryScreenDPIEx(HWND wnd) {
|
||||
HDC dc = GetDC(wnd);
|
||||
SIZE ret = { GetDeviceCaps(dc,LOGPIXELSX), GetDeviceCaps(dc,LOGPIXELSY) };
|
||||
ReleaseDC(wnd,dc);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool IsMenuNonEmpty(HMENU menu) {
|
||||
unsigned n,m=GetMenuItemCount(menu);
|
||||
for(n=0;n<m;n++) {
|
||||
if (GetSubMenu(menu,n)) return true;
|
||||
if (!(GetMenuState(menu,n,MF_BYPOSITION)&MF_SEPARATOR)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
PFC_NORETURN PFC_NOINLINE void WIN32_OP_FAIL() {
|
||||
const DWORD code = GetLastError();
|
||||
PFC_ASSERT( code != NO_ERROR );
|
||||
throw exception_win32(code);
|
||||
}
|
||||
|
||||
PFC_NORETURN PFC_NOINLINE void WIN32_OP_FAIL_CRITICAL(const char * what) {
|
||||
const DWORD code = GetLastError();
|
||||
PFC_ASSERT( code != NO_ERROR );
|
||||
pfc::string_formatter msg; msg << what << " failure #" << (uint32_t)code;
|
||||
TRACK_CODE(msg.get_ptr(), uBugCheck());
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
void WIN32_OP_D_FAIL(const wchar_t * _Message, const wchar_t *_File, unsigned _Line) {
|
||||
const DWORD code = GetLastError();
|
||||
pfc::array_t<wchar_t> msgFormatted; msgFormatted.set_size(pfc::strlen_t(_Message) + 64);
|
||||
wsprintfW(msgFormatted.get_ptr(), L"%s (code: %u)", _Message, code);
|
||||
if (IsDebuggerPresent()) {
|
||||
OutputDebugString(TEXT("WIN32_OP_D() failure:\n"));
|
||||
OutputDebugString(msgFormatted.get_ptr());
|
||||
OutputDebugString(TEXT("\n"));
|
||||
pfc::crash();
|
||||
}
|
||||
_wassert(msgFormatted.get_ptr(),_File,_Line);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void GetOSVersionString(pfc::string_base & out) {
|
||||
out.reset(); GetOSVersionStringAppend(out);
|
||||
}
|
||||
|
||||
static bool running_under_wine(void) {
|
||||
HMODULE module = GetModuleHandle(_T("ntdll.dll"));
|
||||
if (!module) return false;
|
||||
return GetProcAddress(module, "wine_server_call") != NULL;
|
||||
}
|
||||
static bool FetchWineInfoAppend(pfc::string_base & out) {
|
||||
typedef const char *(__cdecl *t_wine_get_build_id)(void);
|
||||
typedef void (__cdecl *t_wine_get_host_version)( const char **sysname, const char **release );
|
||||
const HMODULE ntdll = GetModuleHandle(_T("ntdll.dll"));
|
||||
if (ntdll == NULL) return false;
|
||||
t_wine_get_build_id wine_get_build_id;
|
||||
t_wine_get_host_version wine_get_host_version;
|
||||
wine_get_build_id = (t_wine_get_build_id)GetProcAddress(ntdll, "wine_get_build_id");
|
||||
wine_get_host_version = (t_wine_get_host_version)GetProcAddress(ntdll, "wine_get_host_version");
|
||||
if (wine_get_build_id == NULL || wine_get_host_version == NULL) {
|
||||
if (GetProcAddress(ntdll, "wine_server_call") != NULL) {
|
||||
out << "wine (unknown version)";
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
const char * sysname = NULL; const char * release = NULL;
|
||||
wine_get_host_version(&sysname, &release);
|
||||
out << wine_get_build_id() << ", on: " << sysname << " / " << release;
|
||||
return true;
|
||||
}
|
||||
void GetOSVersionStringAppend(pfc::string_base & out) {
|
||||
|
||||
if (FetchWineInfoAppend(out)) return;
|
||||
|
||||
OSVERSIONINFO ver = {}; ver.dwOSVersionInfoSize = sizeof(ver);
|
||||
WIN32_OP( GetVersionEx(&ver) );
|
||||
SYSTEM_INFO info = {};
|
||||
GetNativeSystemInfo(&info);
|
||||
|
||||
out << "Windows " << (int)ver.dwMajorVersion << "." << (int)ver.dwMinorVersion << "." << (int)ver.dwBuildNumber;
|
||||
if (ver.szCSDVersion[0] != 0) out << " " << pfc::stringcvt::string_utf8_from_os(ver.szCSDVersion, PFC_TABSIZE(ver.szCSDVersion));
|
||||
|
||||
switch(info.wProcessorArchitecture) {
|
||||
case PROCESSOR_ARCHITECTURE_AMD64:
|
||||
out << " x64"; break;
|
||||
case PROCESSOR_ARCHITECTURE_IA64:
|
||||
out << " IA64"; break;
|
||||
case PROCESSOR_ARCHITECTURE_INTEL:
|
||||
out << " x86"; break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SetDefaultMenuItem(HMENU p_menu,unsigned p_id) {
|
||||
MENUITEMINFO info = {sizeof(info)};
|
||||
info.fMask = MIIM_STATE;
|
||||
GetMenuItemInfo(p_menu,p_id,FALSE,&info);
|
||||
info.fState |= MFS_DEFAULT;
|
||||
SetMenuItemInfo(p_menu,p_id,FALSE,&info);
|
||||
}
|
||||
|
||||
bool SetClipboardDataBlock(UINT p_format, const void * p_block, t_size p_block_size) {
|
||||
bool success = false;
|
||||
if (OpenClipboard(NULL)) {
|
||||
EmptyClipboard();
|
||||
HANDLE handle = GlobalAlloc(GMEM_MOVEABLE, p_block_size);
|
||||
if (handle == NULL) {
|
||||
CloseClipboard();
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
{CGlobalLock lock(handle);memcpy(lock.GetPtr(), p_block, p_block_size);}
|
||||
if (SetClipboardData(p_format, handle) == NULL) {
|
||||
GlobalFree(handle);//todo?
|
||||
}
|
||||
else {
|
||||
success = true;
|
||||
}
|
||||
CloseClipboard();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
void CModelessDialogEntry::Set(HWND p_new) {
|
||||
auto api = modeless_dialog_manager::get();
|
||||
if (m_wnd) api->remove(m_wnd);
|
||||
@@ -183,6 +332,16 @@ void winLocalFileScope::close() {
|
||||
m_path.clear();
|
||||
}
|
||||
|
||||
LRESULT RelayEraseBkgnd(HWND p_from, HWND p_to, HDC p_dc) {
|
||||
LRESULT status;
|
||||
POINT pt = { 0, 0 }, pt_old = { 0,0 };
|
||||
MapWindowPoints(p_from, p_to, &pt, 1);
|
||||
OffsetWindowOrgEx(p_dc, pt.x, pt.y, &pt_old);
|
||||
status = SendMessage(p_to, WM_ERASEBKGND, (WPARAM)p_dc, 0);
|
||||
SetWindowOrgEx(p_dc, pt_old.x, pt_old.y, 0);
|
||||
return status;
|
||||
}
|
||||
|
||||
bool IsWindowsS() {
|
||||
bool ret = false;
|
||||
#if FB2K_TARGET_MICROSOFT_STORE
|
||||
@@ -208,8 +367,58 @@ bool IsWindowsS() {
|
||||
return ret;
|
||||
}
|
||||
|
||||
WORD GetOSVersion() {
|
||||
// wrap libPPUI function
|
||||
return ::GetOSVersionCode();
|
||||
|
||||
// TYPEFIND IMPLEMENTATION
|
||||
|
||||
namespace TypeFindImpl {
|
||||
|
||||
static size_t _ItemCount(HWND wnd) {
|
||||
return ListView_GetItemCount(wnd);
|
||||
}
|
||||
static const wchar_t * _ItemText(HWND wnd, size_t index, int subItem = 0) {
|
||||
NMLVDISPINFO info = {};
|
||||
info.hdr.code = LVN_GETDISPINFO;
|
||||
info.hdr.idFrom = GetDlgCtrlID(wnd);
|
||||
info.hdr.hwndFrom = wnd;
|
||||
info.item.iItem = index;
|
||||
info.item.iSubItem = subItem;
|
||||
info.item.mask = LVIF_TEXT;
|
||||
::SendMessage(::GetParent(wnd), WM_NOTIFY, info.hdr.idFrom, reinterpret_cast<LPARAM>(&info));
|
||||
if (info.item.pszText == NULL) return L"";
|
||||
return info.item.pszText;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
LRESULT TypeFind::Handler(NMHDR* hdr, int subItemFrom, int subItemCnt) {
|
||||
using namespace TypeFindImpl;
|
||||
NMLVFINDITEM * info = reinterpret_cast<NMLVFINDITEM*>(hdr);
|
||||
const HWND wnd = hdr->hwndFrom;
|
||||
if (info->lvfi.flags & LVFI_NEARESTXY) return -1;
|
||||
const size_t count = _ItemCount(wnd);
|
||||
if (count == 0) return -1;
|
||||
const size_t base = (size_t)info->iStart % count;
|
||||
|
||||
static SmartStrStr tool;
|
||||
|
||||
for (size_t walk = 0; walk < count; ++walk) {
|
||||
const size_t index = (walk + base) % count;
|
||||
for (int subItem = subItemFrom; subItem < subItemFrom + subItemCnt; ++subItem) {
|
||||
if (tool.matchHereW(_ItemText(wnd, index, subItem), info->lvfi.psz)) return (LRESULT)index;
|
||||
}
|
||||
}
|
||||
for (size_t walk = 0; walk < count; ++walk) {
|
||||
const size_t index = (walk + base) % count;
|
||||
for (int subItem = subItemFrom; subItem < subItemFrom + subItemCnt; ++subItem) {
|
||||
if ( tool.strStrEndW(_ItemText(wnd, index, subItem), info->lvfi.psz) ) return (LRESULT)index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // FOOBAR2000_DESKTOP_WINDOWS
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user