From d7152c52128226fd0718ab9fba428fea2aae2663 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Fri, 12 Jul 2019 19:35:18 +0300 Subject: [PATCH] GUI scaling/DPI support update. --- od-win32/resources/resource.h | 20 +- od-win32/resources/winuae.exe.manifest | 2 +- od-win32/resources/winuae.rc | 13 +- od-win32/resources/winuae64.exe.manifest | 2 +- od-win32/win32.cpp | 70 +++- od-win32/win32.h | 4 +- od-win32/win32gfx.cpp | 240 ++++++----- od-win32/win32gui.cpp | 201 ++++------ od-win32/win32gui.h | 28 +- od-win32/win32gui_extra.cpp | 487 +++++++++++------------ 10 files changed, 562 insertions(+), 505 deletions(-) diff --git a/od-win32/resources/resource.h b/od-win32/resources/resource.h index c59ce3a7..63c8f85d 100644 --- a/od-win32/resources/resource.h +++ b/od-win32/resources/resource.h @@ -30,6 +30,14 @@ #define IDS_EXPANSION 22 #define IDS_EXPANSION2 23 #define IDS_BOARD 24 +#define IDC_PANELTREE 50 +#define IDD_PANEL 51 +#define IDC_PANEL_FRAME 52 +#define IDC_PANEL_FRAME_OUTER 53 +#define IDC_RESETAMIGA 54 +#define IDC_QUITEMU 55 +#define IDC_RESTARTEMU 56 +#define IDC_ERRORLOG 57 #define IDS_EXTTEXT 100 #define IDS_EXTACTUAL 101 #define IDS_SOUND 102 @@ -160,7 +168,6 @@ #define IDI_DISK 182 #define IDR_DRIVE_SPINND_A500_1 182 #define IDS_YES 182 -#define IDD_PANEL 183 #define IDS_NO 183 #define IDD_PATHS 184 #define IDS_PRI_ABOVENORMAL 184 @@ -720,19 +727,15 @@ #define IDC_SOCKETS 1503 #define IDC_HF_DOSTYPE 1503 #define IDC_HDF_CONTROLLER 1504 -#define IDC_RESETAMIGA 1504 -#define IDC_QUITEMU 1505 #define IDC_HDF_CONTROLLER_UNIT 1505 #define IDC_HDF_CONTROLLER_TYPE 1506 #define IDC_MAPDRIVES 1507 #define IDC_HDF_FEATURE_LEVEL 1507 #define IDC_CPUTEXT 1508 #define IDC_MAPDRIVES_NET 1508 -#define IDC_RESTARTEMU 1508 #define IDC_CACHETEXT 1509 #define IDC_SWAP 1509 #define IDC_MAPDRIVES_CD 1509 -#define IDC_ERRORLOG 1509 #define IDC_SELECTRESTEXT 1510 #define IDC_FLUSHPRINTER 1510 #define IDC_MAPDRIVES_REMOVABLE 1510 @@ -951,7 +954,6 @@ #define IDC_AVIOUTPUT_FRAMELIMITER 1645 #define IDC_STATEREC_RATE 1646 #define IDC_SOUNDDRIVESELECT 1647 -#define IDC_PANELTREE 1647 #define IDC_AVIOUTPUT_NOSOUNDOUTPUT 1647 #define IDC_STATE_BUFFERSIZE_TEXT 1648 #define IDC_CONFIGTREE 1648 @@ -974,11 +976,9 @@ #define IDC_SOUNDFREQ 1652 #define IDC_STATEREC_AUTOPLAY 1652 #define IDC_SOUNDFREQTXT 1653 -#define IDC_PANEL_FRAME 1653 #define IDC_SCREENSHOT_ORIGINALSIZE2 1653 #define IDC_SCREENSHOT_CLIP 1653 #define IDC_SOUNDFILTERTXT 1654 -#define IDC_PANEL_FRAME_OUTER 1654 #define IDC_SOUNDSTEREO 1655 #define IDC_CONFIGTYPE 1655 #define IDC_SOUNDDRIVETXT 1656 @@ -1310,6 +1310,7 @@ #define IDC_ROM_ADDRESS 1862 #define IDC_ROM_ADDRESS2 1863 #define IDC_CUSTOMROMFILE 1864 +#define IDC_SCSIROMFILEPCMCIA 1865 #define ID__FLOPPYDRIVES 40004 #define ID_FLOPPYDRIVES_DF0 40005 #define ID_ST_CONFIGURATION 40010 @@ -1351,7 +1352,6 @@ #define ID_ST_CDEJECTALL 40047 #define ID_CDDRIVES_CD 40048 #define ID_ST_CD0 40049 -#define IDC_STATIC -1 // Next default values for new objects // @@ -1361,7 +1361,7 @@ #define _APS_3D_CONTROLS 1 #define _APS_NEXT_RESOURCE_VALUE 407 #define _APS_NEXT_COMMAND_VALUE 40050 -#define _APS_NEXT_CONTROL_VALUE 1864 +#define _APS_NEXT_CONTROL_VALUE 1865 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/od-win32/resources/winuae.exe.manifest b/od-win32/resources/winuae.exe.manifest index cec16947..421ce311 100644 --- a/od-win32/resources/winuae.exe.manifest +++ b/od-win32/resources/winuae.exe.manifest @@ -34,7 +34,7 @@ True/PM - PerMonitorV2, PerMonitor + PerMonitorV2 true diff --git a/od-win32/resources/winuae.rc b/od-win32/resources/winuae.rc index 884729f9..724969d3 100644 --- a/od-win32/resources/winuae.rc +++ b/od-win32/resources/winuae.rc @@ -1047,7 +1047,7 @@ BEGIN PUSHBUTTON "Cancel",IDCANCEL,427,328,47,14 PUSHBUTTON "Help",IDHELP,479,328,47,14,WS_DISABLED GROUPBOX "",IDC_PANEL_FRAME_OUTER,116,2,409,324 - GROUPBOX "",IDC_PANEL_FRAME,119,5,402,318,NOT WS_VISIBLE + GROUPBOX "",IDC_PANEL_FRAME,119,5,402,318 CONTROL "",IDC_PANELTREE,"SysTreeView32",TVS_HASLINES | TVS_SHOWSELALWAYS | TVS_TRACKSELECT | TVS_NOHSCROLL | WS_BORDER | WS_TABSTOP,3,5,110,321,WS_EX_CLIENTEDGE END @@ -1345,7 +1345,7 @@ BEGIN RTEXT "Controller ID:",IDC_STATIC,241,23,110,15,SS_CENTERIMAGE COMBOBOX IDC_SCSIROMID,356,24,29,75,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP PUSHBUTTON "...",IDC_SCSIROMCHOOSER,376,42,10,15 - CONTROL "Autoboot disabled",IDC_SCSIROMFILEAUTOBOOT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,202,62,99,12 + CONTROL "Autoboot disabled",IDC_SCSIROMFILEAUTOBOOT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,202,62,94,12 CONTROL "",IDC_EXPANSIONBOARDCHECKBOX,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,202,76,99,12 EDITTEXT IDC_EXPANSIONBOARDSTRINGBOX,202,76,172,14,ES_AUTOHSCROLL COMBOBOX IDC_EXPANSIONBOARDSELECTOR,202,76,171,75,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP @@ -1370,6 +1370,7 @@ BEGIN "Button",BS_AUTOCHECKBOX | WS_TABSTOP,193,207,187,11 CONTROL "CD32 Full Motion Video cartridge",IDC_CS_CD32FMV,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,193,223,193,11 CONTROL "Enabled",IDC_SCSIROMSELECTED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,202,43,99,12 + CONTROL "PCMCIA inserted",IDC_SCSIROMFILEPCMCIA,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,301,62,84,12 END IDD_CHSQUERY DIALOGEX 0, 0, 396, 85 @@ -1395,8 +1396,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 4,2,1,0 - PRODUCTVERSION 4,2,1,0 + FILEVERSION 4,2,2,0 + PRODUCTVERSION 4,2,2,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -1412,12 +1413,12 @@ BEGIN BLOCK "040904b0" BEGIN VALUE "FileDescription", "WinUAE" - VALUE "FileVersion", "4.2.1.0" + VALUE "FileVersion", "4.2.2.0" VALUE "InternalName", "WinUAE" VALUE "LegalCopyright", "© 1996-2019 under the GNU Public License (GPL)" VALUE "OriginalFilename", "WinUAE.exe" VALUE "ProductName", "WinUAE" - VALUE "ProductVersion", "4.2.1.0" + VALUE "ProductVersion", "4.2.2.0" END END BLOCK "VarFileInfo" diff --git a/od-win32/resources/winuae64.exe.manifest b/od-win32/resources/winuae64.exe.manifest index a15ae169..67e51731 100644 --- a/od-win32/resources/winuae64.exe.manifest +++ b/od-win32/resources/winuae64.exe.manifest @@ -34,7 +34,7 @@ True/PM - PerMonitorV2, PerMonitor + PerMonitorV2 true diff --git a/od-win32/win32.cpp b/od-win32/win32.cpp index 9ed3c8b5..99fd4e34 100644 --- a/od-win32/win32.cpp +++ b/od-win32/win32.cpp @@ -175,6 +175,8 @@ int paraport_mask; HKEY hWinUAEKey = NULL; COLORREF g_dwBackgroundColor; +HMODULE userdll; +HMODULE kerneldll; int pause_emulation; @@ -2473,7 +2475,8 @@ static LRESULT CALLBACK AmigaWindowProc(HWND hWnd, UINT message, WPARAM wParam, case WM_DRAWCLIPBOARD: if (clipboard_initialized) { clipboard_changed(hWnd); - SendMessage(hwndNextViewer, message, wParam, lParam); + if (hwndNextViewer) + SendMessage(hwndNextViewer, message, wParam, lParam); return 0; } break; @@ -2664,24 +2667,29 @@ static LRESULT CALLBACK MainWindowProc (HWND hWnd, UINT message, WPARAM wParam, case WM_QUERYENDSESSION: case WM_ENDSESSION: return AmigaWindowProc (hWnd, message, wParam, lParam); -#if 0 + + case WM_DWMCOMPOSITIONCHANGED: + case WM_THEMECHANGED: case WM_DISPLAYCHANGE: - if (isfullscreen() <= 0 && !currprefs.gfx_filter && (wParam + 7) / 8 != DirectDraw_GetBytesPerPixel ()) - WIN32GFX_DisplayChangeRequested (); - break; -#endif - case WM_DWMCOMPOSITIONCHANGED: - case WM_THEMECHANGED: WIN32GFX_DisplayChangeRequested (-1); return 0; - case WM_POWERBROADCAST: + case WM_POWERBROADCAST: if (wParam == PBT_APMRESUMEAUTOMATIC) { setsystime (); return TRUE; } return 0; + case WM_DPICHANGED: + { + if (isfullscreen() == 0) { + RECT* const r = (RECT*)lParam; + SetWindowPos(hWnd, NULL, r->left, r->top, r->right - r->left, r->bottom - r->top, SWP_NOZORDER | SWP_NOACTIVATE); + return 0; + } + } + case WM_GETMINMAXINFO: { LPMINMAXINFO lpmmi; @@ -3521,7 +3529,7 @@ void logging_init (void) #ifdef _WIN64 wow64 = 1; #else - fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress (GetModuleHandle (_T("kernel32")), "IsWow64Process"); + fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(kerneldll, "IsWow64Process"); if (fnIsWow64Process) fnIsWow64Process (GetCurrentProcess (), &wow64); #endif @@ -5651,6 +5659,7 @@ static int betamessage (void) int os_admin, os_64bit, os_win7, os_win8, os_win10, os_vista, cpu_number, os_touch; BOOL os_dwm_enabled; +BOOL dpi_aware_v2; static int isadminpriv (void) { @@ -5717,10 +5726,9 @@ static int osdetect (void) PGETNATIVESYSTEMINFO pGetNativeSystemInfo; PISUSERANADMIN pIsUserAnAdmin; - pGetNativeSystemInfo = (PGETNATIVESYSTEMINFO)GetProcAddress ( - GetModuleHandle (_T("kernel32.dll")), "GetNativeSystemInfo"); - pIsUserAnAdmin = (PISUSERANADMIN)GetProcAddress ( - GetModuleHandle (_T("shell32.dll")), "IsUserAnAdmin"); + pGetNativeSystemInfo = (PGETNATIVESYSTEMINFO)GetProcAddress(kerneldll, "GetNativeSystemInfo"); + pIsUserAnAdmin = (PISUSERANADMIN)GetProcAddress( + GetModuleHandle(_T("shell32.dll")), "IsUserAnAdmin"); GetSystemInfo (&SystemInfo); if (pGetNativeSystemInfo) @@ -7346,12 +7354,9 @@ void registertouch(HWND hwnd) if (!os_touch) return; - pRegisterTouchWindow = (REGISTERTOUCHWINDOW)GetProcAddress( - GetModuleHandle (_T("user32.dll")), "RegisterTouchWindow"); - pGetTouchInputInfo = (GETTOUCHINPUTINFO)GetProcAddress( - GetModuleHandle (_T("user32.dll")), "GetTouchInputInfo"); - pCloseTouchInputHandle = (CLOSETOUCHINPUTHANDLE)GetProcAddress( - GetModuleHandle (_T("user32.dll")), "CloseTouchInputHandle"); + pRegisterTouchWindow = (REGISTERTOUCHWINDOW)GetProcAddress(userdll, "RegisterTouchWindow"); + pGetTouchInputInfo = (GETTOUCHINPUTINFO)GetProcAddress(userdll, "GetTouchInputInfo"); + pCloseTouchInputHandle = (CLOSETOUCHINPUTHANDLE)GetProcAddress(userdll, "CloseTouchInputHandle"); if (!pRegisterTouchWindow || !pGetTouchInputInfo || !pCloseTouchInputHandle) return; if (!pRegisterTouchWindow(hwnd, 0)) { @@ -7759,6 +7764,8 @@ bool is_mainthread(void) } typedef BOOL (CALLBACK* CHANGEWINDOWMESSAGEFILTER)(UINT, DWORD); +typedef DPI_AWARENESS_CONTEXT (CALLBACK* GETTHREADDPIAWARENESSCONTEXT)(void); +typedef DPI_AWARENESS (CALLBACK* GETAWARENESSFROMDPIAWARENESSCONTEXT)(DPI_AWARENESS_CONTEXT); #ifndef NDEBUG typedef BOOL(WINAPI* SETPROCESSMITIGATIONPOLICY)(DWORD, PVOID, SIZE_T); @@ -7786,12 +7793,17 @@ int PASCAL wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdL #endif #endif + userdll = GetModuleHandle(_T("user32.dll")); + kerneldll = GetModuleHandle(_T("kernel32.dll")); + if (!userdll || !kerneldll) + return 0; + #ifndef NDEBUG PROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY p = { 0 }; p.HandleExceptionsPermanentlyEnabled = 1; p.RaiseExceptionOnInvalidHandleReference = 1; //ProcessStrictHandleCheckPolicy = 3 - pSetProcessMitigationPolicy = (SETPROCESSMITIGATIONPOLICY)GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "SetProcessMitigationPolicy"); + pSetProcessMitigationPolicy = (SETPROCESSMITIGATIONPOLICY)GetProcAddress(kerneldll, "SetProcessMitigationPolicy"); pSetProcessMitigationPolicy(3, &p, sizeof p); #endif @@ -7803,6 +7815,20 @@ int PASCAL wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdL SetDllDirectory (_T("")); /* Make sure we do an InitCommonControls() to get some advanced controls */ CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); + + GETTHREADDPIAWARENESSCONTEXT pGetThreadDpiAwarenessContext = (GETTHREADDPIAWARENESSCONTEXT)GetProcAddress(userdll, "GetThreadDpiAwarenessContext"); + if (pGetThreadDpiAwarenessContext) { + DPI_AWARENESS_CONTEXT dpiawactx = pGetThreadDpiAwarenessContext(); + if (dpiawactx) { + GETAWARENESSFROMDPIAWARENESSCONTEXT pGetAwarenessFromDpiAwarenessContext = (GETAWARENESSFROMDPIAWARENESSCONTEXT)GetProcAddress(userdll, "GetAwarenessFromDpiAwarenessContext"); + if (pGetAwarenessFromDpiAwarenessContext) { + DPI_AWARENESS dpiawa = pGetAwarenessFromDpiAwarenessContext(dpiawactx); + if (dpiawa == DPI_AWARENESS_PER_MONITOR_AWARE) + dpi_aware_v2 = true; + } + } + } + InitCommonControls (); original_affinity = 1; @@ -7818,7 +7844,7 @@ int PASCAL wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdL #define MSGFLT_ADD 1 CHANGEWINDOWMESSAGEFILTER pChangeWindowMessageFilter; pChangeWindowMessageFilter = (CHANGEWINDOWMESSAGEFILTER)GetProcAddress( - GetModuleHandle(_T("user32.dll")), _T("ChangeWindowMessageFilter")); + userdll, "ChangeWindowMessageFilter"); if (pChangeWindowMessageFilter) pChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD); #endif diff --git a/od-win32/win32.h b/od-win32/win32.h index c0376598..62cb7292 100644 --- a/od-win32/win32.h +++ b/od-win32/win32.h @@ -90,7 +90,7 @@ extern int sound_available; extern TCHAR VersionStr[256]; extern TCHAR BetaStr[64]; extern int os_admin, os_64bit, os_vista, os_win7, os_win8, os_win10, cpu_number, os_touch; -extern BOOL os_dwm_enabled; +extern BOOL os_dwm_enabled, dpi_aware_v2; extern OSVERSIONINFO osVersion; extern int paraport_mask; extern int gui_active; @@ -98,6 +98,8 @@ extern int quickstart, configurationcache, saveimageoriginalpath, relativepaths, extern HKEY hWinUAEKey; extern HINSTANCE hInst; +extern HMODULE userdll; +extern HMODULE kerneldll; extern int af_path_2005; extern TCHAR start_path_new1[MAX_DPATH], start_path_new2[MAX_DPATH]; extern TCHAR bootlogpath[MAX_DPATH]; diff --git a/od-win32/win32gfx.cpp b/od-win32/win32gfx.cpp index e6a26dad..59b5c1ff 100644 --- a/od-win32/win32gfx.cpp +++ b/od-win32/win32gfx.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include "sysdeps.h" @@ -399,11 +400,11 @@ static bool get_display_vblank_params(int displayindex, int *activeheightp, int static GETDISPLAYCONFIGBUFFERSIZES pGetDisplayConfigBufferSizes; static DISPLAYCONFIGGETDEVICEINFO pDisplayConfigGetDeviceInfo; if (!pQueryDisplayConfig) - pQueryDisplayConfig = (QUERYDISPLAYCONFIG)GetProcAddress(GetModuleHandle(_T("user32.dll")), "QueryDisplayConfig"); + pQueryDisplayConfig = (QUERYDISPLAYCONFIG)GetProcAddress(userdll, "QueryDisplayConfig"); if (!pGetDisplayConfigBufferSizes) - pGetDisplayConfigBufferSizes = (GETDISPLAYCONFIGBUFFERSIZES)GetProcAddress(GetModuleHandle(_T("user32.dll")), "GetDisplayConfigBufferSizes"); + pGetDisplayConfigBufferSizes = (GETDISPLAYCONFIGBUFFERSIZES)GetProcAddress(userdll, "GetDisplayConfigBufferSizes"); if (!pDisplayConfigGetDeviceInfo) - pDisplayConfigGetDeviceInfo = (DISPLAYCONFIGGETDEVICEINFO)GetProcAddress(GetModuleHandle(_T("user32.dll")), "DisplayConfigGetDeviceInfo"); + pDisplayConfigGetDeviceInfo = (DISPLAYCONFIGGETDEVICEINFO)GetProcAddress(userdll, "DisplayConfigGetDeviceInfo"); if (!pQueryDisplayConfig || !pGetDisplayConfigBufferSizes || !pDisplayConfigGetDeviceInfo) return false; struct MultiDisplay *md = displayindex < 0 ? getdisplay(&currprefs, 0) : &Displays[displayindex]; @@ -2204,22 +2205,57 @@ static void reopen_gfx(struct AmigaMonitor *mon) render_screen(mon->monitor_id, 1, true); } -static int getstatuswindowheight(int monid) +static int getdpiformonitor(HMONITOR mon) +{ + if (mon) { + static HMODULE shcore; + if (!shcore) + shcore = LoadLibrary(_T("Shcore.dll")); + if (shcore) { + typedef HRESULT(CALLBACK * GETDPIFORMONITOR)(HMONITOR, MONITOR_DPI_TYPE, UINT*, UINT*); + GETDPIFORMONITOR pGetDpiForMonitor = (GETDPIFORMONITOR)GetProcAddress(userdll, "GetDpiForMonitor"); + if (pGetDpiForMonitor) { + UINT x, y; + if (SUCCEEDED(pGetDpiForMonitor(mon, MDT_EFFECTIVE_DPI, &x, &y))) + return y; + } + } + } + HDC hdc = GetDC(NULL); + int dpi = GetDeviceCaps(hdc, LOGPIXELSX); + ReleaseDC(NULL, hdc); + return dpi; +} + +static int getdpiforwindow(HWND hwnd) +{ + typedef UINT (CALLBACK *GETDPIFORWINDOW)(HWND); + GETDPIFORWINDOW pGetDpiForWindow = (GETDPIFORWINDOW)GetProcAddress(userdll, "GetDpiForWindow"); + if (pGetDpiForWindow) + return pGetDpiForWindow(hwnd); + HDC hdc = GetDC(NULL); + int dpi = GetDeviceCaps(hdc, LOGPIXELSY); + ReleaseDC(NULL, hdc); + return dpi; +} + +static int getstatuswindowheight(int monid, HWND hwnd) { if (monid > 0) return 0; int def = GetSystemMetrics (SM_CYMENU) + 3; WINDOWINFO wi; HWND h = CreateWindowEx ( - 0, STATUSCLASSNAME, (LPCTSTR) NULL, SBARS_TOOLTIPS | WS_CHILD | WS_VISIBLE, - 0, 0, 0, 0, hHiddenWnd, (HMENU) 1, hInst, NULL); + 0, STATUSCLASSNAME, (LPCTSTR) NULL, SBARS_TOOLTIPS | WS_CHILD, + 0, 0, 0, 0, hwnd ? hwnd : hHiddenWnd, (HMENU) 1, hInst, NULL); if (!h) return def; wi.cbSize = sizeof wi; - if (!GetWindowInfo (h, &wi)) - return def; + if (GetWindowInfo (h, &wi)) + def = wi.rcWindow.bottom - wi.rcWindow.top; + int dpi = hwnd ? getdpiforwindow(hwnd) : getdpiformonitor(NULL); DestroyWindow (h); - return wi.rcWindow.bottom - wi.rcWindow.top; + return dpi * def / 96; } void graphics_reset(bool forced) @@ -3246,10 +3282,13 @@ static void setDwmEnableMMCSS (bool state) { if (!os_vista) return; - DWMENABLEMMCSS pDwmEnableMMCSS; - pDwmEnableMMCSS = (DWMENABLEMMCSS)GetProcAddress(GetModuleHandle(_T("dwmapi.dll")), "DwmEnableMMCSS"); - if (pDwmEnableMMCSS) - pDwmEnableMMCSS (state); + HMODULE hm = GetModuleHandle(_T("dwmapi.dll")); + if (hm) { + DWMENABLEMMCSS pDwmEnableMMCSS; + pDwmEnableMMCSS = (DWMENABLEMMCSS)GetProcAddress(hm, "DwmEnableMMCSS"); + if (pDwmEnableMMCSS) + pDwmEnableMMCSS(state); + } } void close_windows(struct AmigaMonitor *mon) @@ -3269,7 +3308,6 @@ void close_windows(struct AmigaMonitor *mon) static void createstatuswindow(struct AmigaMonitor *mon) { - HDC hdc; RECT rc; HLOCAL hloc; LPINT lpParts; @@ -3277,7 +3315,7 @@ static void createstatuswindow(struct AmigaMonitor *mon) int fps_width, idle_width, snd_width, joy_width, net_width; int joys = currprefs.win32_statusbar > 1 ? 2 : 0; int num_parts = 12 + joys + 1; - double scaleX, scaleY; + float scale = 1.0; WINDOWINFO wi; int extra; @@ -3300,94 +3338,92 @@ static void createstatuswindow(struct AmigaMonitor *mon) wi.cbSize = sizeof wi; GetWindowInfo(mon->hMainWnd, &wi); extra = wi.rcClient.top - wi.rcWindow.top; - - hdc = GetDC(mon->hStatusWnd); - scaleX = GetDeviceCaps(hdc, LOGPIXELSX) / 96.0; - scaleY = GetDeviceCaps(hdc, LOGPIXELSY) / 96.0; - ReleaseDC(mon->hStatusWnd, hdc); - drive_width = (int)(24 * scaleX); - hd_width = (int)(24 * scaleX); - cd_width = (int)(24 * scaleX); - power_width = (int)(42 * scaleX); - fps_width = (int)(64 * scaleX); - idle_width = (int)(64 * scaleX); - net_width = (int)(24 * scaleX); + scale = getdpiforwindow(mon->hStatusWnd) / 96.0; + drive_width = (int)(24 * scale); + hd_width = (int)(24 * scale); + cd_width = (int)(24 * scale); + power_width = (int)(42 * scale); + fps_width = (int)(64 * scale); + idle_width = (int)(64 * scale); + net_width = (int)(24 * scale); if (is_ppc_cpu(&currprefs)) - idle_width += (int)(68 * scaleX); + idle_width += (int)(68 * scale); if (is_x86_cpu(&currprefs)) - idle_width += (int)(68 * scaleX); - snd_width = (int)(72 * scaleX); - joy_width = (int)(24 * scaleX); + idle_width += (int)(68 * scale); + snd_width = (int)(72 * scale); + joy_width = (int)(24 * scale); GetClientRect(mon->hMainWnd, &rc); /* Allocate an array for holding the right edge coordinates. */ hloc = LocalAlloc (LHND, sizeof (int) * (num_parts + 1)); if (hloc) { - int i = 0, i1, j; - lpParts = (LPINT)LocalLock (hloc); - // left side, msg area - lpParts[i] = rc.left + 2; - i++; - window_led_msg_start = i; - /* Calculate the right edge coordinate for each part, and copy the coords to the array. */ - int startx = rc.right - (drive_width * 4) - power_width - idle_width - fps_width - cd_width - hd_width - snd_width - net_width - joys * joy_width - extra; - for (j = 0; j < joys; j++) { + lpParts = (LPINT)LocalLock(hloc); + if (lpParts) { + int i = 0, i1; + // left side, msg area + lpParts[i] = rc.left + 2; + i++; + window_led_msg_start = i; + /* Calculate the right edge coordinate for each part, and copy the coords to the array. */ + int startx = rc.right - (drive_width * 4) - power_width - idle_width - fps_width - cd_width - hd_width - snd_width - net_width - joys * joy_width - extra; + for (int j = 0; j < joys; j++) { + lpParts[i] = startx; + i++; + startx += joy_width; + } + window_led_joy_start = i; + if (lpParts[0] >= startx) + lpParts[0] = startx - 1; + // snd lpParts[i] = startx; i++; - startx += joy_width; + // cpu + lpParts[i] = lpParts[i - 1] + snd_width; + i++; + // fps + lpParts[i] = lpParts[i - 1] + idle_width; + i++; + // power + lpParts[i] = lpParts[i - 1] + fps_width; + i++; + i1 = i; + // hd + lpParts[i] = lpParts[i - 1] + power_width; + i++; + // cd + lpParts[i] = lpParts[i - 1] + hd_width; + i++; + // net + lpParts[i] = lpParts[i - 1] + cd_width; + i++; + // df0 + lpParts[i] = lpParts[i - 1] + net_width; + i++; + // df1 + lpParts[i] = lpParts[i - 1] + drive_width; + i++; + // df2 + lpParts[i] = lpParts[i - 1] + drive_width; + i++; + // df3 + lpParts[i] = lpParts[i - 1] + drive_width; + i++; + // edge + lpParts[i] = lpParts[i - 1] + drive_width; + + window_led_msg = lpParts[window_led_msg_start - 1]; + window_led_msg_end = lpParts[window_led_msg_start - 1 + 1]; + window_led_joys = lpParts[window_led_joy_start - joys]; + window_led_joys_end = lpParts[window_led_joy_start - joys + 1]; + window_led_hd = lpParts[i1]; + window_led_hd_end = lpParts[i1 + 1]; + window_led_drives = lpParts[i1 + 3]; + window_led_drives_end = lpParts[i1 + 3 + 4]; + + /* Create the parts */ + SendMessage(mon->hStatusWnd, SB_SETPARTS, (WPARAM)num_parts, (LPARAM)lpParts); + LocalUnlock(hloc); + LocalFree(hloc); } - window_led_joy_start = i; - if (lpParts[0] >= startx) - lpParts[0] = startx - 1; - // snd - lpParts[i] = startx; - i++; - // cpu - lpParts[i] = lpParts[i - 1] + snd_width; - i++; - // fps - lpParts[i] = lpParts[i - 1] + idle_width; - i++; - // power - lpParts[i] = lpParts[i - 1] + fps_width; - i++; - i1 = i; - // hd - lpParts[i] = lpParts[i - 1] + power_width; - i++; - // cd - lpParts[i] = lpParts[i - 1] + hd_width; - i++; - // net - lpParts[i] = lpParts[i - 1] + cd_width; - i++; - // df0 - lpParts[i] = lpParts[i - 1] + net_width; - i++; - // df1 - lpParts[i] = lpParts[i - 1] + drive_width; - i++; - // df2 - lpParts[i] = lpParts[i - 1] + drive_width; - i++; - // df3 - lpParts[i] = lpParts[i - 1] + drive_width; - i++; - // edge - lpParts[i] = lpParts[i - 1] + drive_width; - - window_led_msg = lpParts[window_led_msg_start - 1]; - window_led_msg_end = lpParts[window_led_msg_start - 1 + 1]; - window_led_joys = lpParts[window_led_joy_start - joys]; - window_led_joys_end = lpParts[window_led_joy_start - joys + 1]; - window_led_hd = lpParts[i1]; - window_led_hd_end = lpParts[i1 + 1]; - window_led_drives = lpParts[i1 + 3]; - window_led_drives_end = lpParts[i1 + 3 + 4]; - - /* Create the parts */ - SendMessage(mon->hStatusWnd, SB_SETPARTS, (WPARAM)num_parts, (LPARAM)lpParts); - LocalUnlock(hloc); - LocalFree(hloc); } registertouch(mon->hStatusWnd); } @@ -3509,11 +3545,10 @@ static void getextramonitorpos(struct AmigaMonitor *mon, RECT *r) { typedef HRESULT(CALLBACK* DWMGETWINDOWATTRIBUTE)(HWND hwnd, DWORD dwAttribute, PVOID pvAttribute, DWORD cbAttribute); static DWMGETWINDOWATTRIBUTE pDwmGetWindowAttribute; - static HMODULE dwmapihandle; RECT r1, r2; - if (!pDwmGetWindowAttribute && !dwmapihandle && os_vista) { - dwmapihandle = LoadLibrary(_T("dwmapi.dll")); + if (!pDwmGetWindowAttribute && os_vista) { + HMODULE dwmapihandle = GetModuleHandle(_T("dwmapi.dll")); if (dwmapihandle) pDwmGetWindowAttribute = (DWMGETWINDOWATTRIBUTE)GetProcAddress(dwmapihandle, "DwmGetWindowAttribute"); } @@ -3568,7 +3603,6 @@ static int create_windows_2(struct AmigaMonitor *mon) int gap = 0; int x, y, w, h; struct MultiDisplay *md; - int sbheight; md = getdisplay(&currprefs, mon->monitor_id); if (mon->monitor_id && fsw) { @@ -3594,8 +3628,6 @@ static int create_windows_2(struct AmigaMonitor *mon) } mon->md = md; - sbheight = currprefs.win32_statusbar ? getstatuswindowheight(mon->monitor_id) : 0; - if (mon->hAmigaWnd) { RECT r; int w, h, x, y; @@ -3613,6 +3645,9 @@ static int create_windows_2(struct AmigaMonitor *mon) } #endif GetWindowRect (mon->hAmigaWnd, &r); + + int sbheight = currprefs.win32_statusbar ? getstatuswindowheight(mon->monitor_id, mon->hAmigaWnd) : 0; + x = r.left; y = r.top; w = r.right - r.left; @@ -3692,6 +3727,9 @@ static int create_windows_2(struct AmigaMonitor *mon) window_led_drives_end = 0; mon->hMainWnd = NULL; x = 0; y = 0; + + int sbheight = currprefs.win32_statusbar ? getstatuswindowheight(mon->monitor_id, NULL) : 0; + if (borderless) sbheight = cyborder = 0; @@ -3855,7 +3893,7 @@ static int create_windows_2(struct AmigaMonitor *mon) if (currprefs.win32_shutdown_notification && !rp_isactive()) { typedef BOOL(WINAPI *SHUTDOWNBLOCKREASONCREATE)(HWND, LPCWSTR); SHUTDOWNBLOCKREASONCREATE pShutdownBlockReasonCreate; - pShutdownBlockReasonCreate = (SHUTDOWNBLOCKREASONCREATE)GetProcAddress(GetModuleHandle(_T("user32.dll")), "ShutdownBlockReasonCreate"); + pShutdownBlockReasonCreate = (SHUTDOWNBLOCKREASONCREATE)GetProcAddress(userdll, "ShutdownBlockReasonCreate"); if (pShutdownBlockReasonCreate) { TCHAR tmp[MAX_DPATH]; WIN32GUI_LoadUIString(IDS_SHUTDOWN_NOTIFICATION, tmp, MAX_DPATH); diff --git a/od-win32/win32gui.cpp b/od-win32/win32gui.cpp index af0d0808..e150de77 100644 --- a/od-win32/win32gui.cpp +++ b/od-win32/win32gui.cpp @@ -99,6 +99,7 @@ #endif #include "ini.h" #include "specialmonitors.h" +#include "gayle.h" #define GUI_SCALE_DEFAULT 100 #define MIN_GUI_INTERNAL_WIDTH 512 @@ -246,6 +247,7 @@ static const int INPUTMAP_ID = MAX_C_PAGES - 1; static HWND pages[MAX_C_PAGES]; #define MAX_IMAGETOOLTIPS 10 static HWND guiDlg, panelDlg, ToolTipHWND; +static struct dlgcontext maindctx; static HACCEL hAccelTable; static HWND customDlg; static int customDlgType; @@ -6184,7 +6186,6 @@ static INT_PTR CALLBACK LoadSaveDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPA case WM_INITDIALOG: { recursive++; - scaleresource_setfont(hDlg); if (!configstore) { DeleteConfigTree(hDlg); CreateConfigStore(NULL, FALSE); @@ -6397,9 +6398,6 @@ static void SetupRichText(HWND hDlg, urlinfo *url) { CHARFORMAT CharFormat; CharFormat.cbSize = sizeof (CharFormat); - int my; - - scaleresource_getmult (NULL, &my); SetDlgItemText (hDlg, url->id, url->display); SendDlgItemMessage (hDlg, url->id, EM_GETCHARFORMAT, 0, (LPARAM)&CharFormat); @@ -6735,7 +6733,6 @@ static INT_PTR CALLBACK PathsDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM { case WM_INITDIALOG: recursive++; - scaleresource_setfont (hDlg); pages[PATHS_ID] = hDlg; setac (hDlg, IDC_PATHS_ROM); setac (hDlg, IDC_PATHS_CONFIG); @@ -7299,7 +7296,6 @@ static INT_PTR CALLBACK QuickstartDlgProc (HWND hDlg, UINT msg, WPARAM wParam, L { case WM_INITDIALOG: { - scaleresource_setfont (hDlg); int ids[] = { IDC_DF0TEXTQ, IDC_DF1TEXTQ, -1 }; pages[QUICKSTART_ID] = hDlg; currentpage = QUICKSTART_ID; @@ -7517,7 +7513,6 @@ static INT_PTR CALLBACK AboutDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM switch( msg ) { case WM_INITDIALOG: - scaleresource_setfont (hDlg); pages[ABOUT_ID] = hDlg; currentpage = ABOUT_ID; init_aboutdlg (hDlg); @@ -8527,7 +8522,6 @@ static INT_PTR CALLBACK DisplayDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPAR switch (msg) { case WM_INITDIALOG: - scaleresource_setfont (hDlg); pages[DISPLAY_ID] = hDlg; currentpage = DISPLAY_ID; SendDlgItemMessage (hDlg, IDC_FRAMERATE, TBM_SETPAGESIZE, 0, 1); @@ -8746,7 +8740,6 @@ static INT_PTR CALLBACK ChipsetDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPAR switch (msg) { case WM_INITDIALOG: { - scaleresource_setfont(hDlg); pages[CHIPSET_ID] = hDlg; currentpage = CHIPSET_ID; @@ -9133,7 +9126,6 @@ static INT_PTR CALLBACK ChipsetDlgProc2 (HWND hDlg, UINT msg, WPARAM wParam, LPA switch (msg) { case WM_INITDIALOG: { - scaleresource_setfont(hDlg); pages[CHIPSET2_ID] = hDlg; currentpage = CHIPSET2_ID; cs_compatible = workprefs.cs_compatible; @@ -10499,7 +10491,6 @@ static INT_PTR CALLBACK Expansion2DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LP case WM_INITDIALOG: { recursive++; - scaleresource_setfont (hDlg); pages[EXPANSION2_ID] = hDlg; currentpage = EXPANSION2_ID; int ids[] = { IDC_SCSIROMFILE, IDC_CPUBOARDROMFILE, -1 }; @@ -10892,7 +10883,6 @@ static INT_PTR CALLBACK ExpansionDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LP switch (msg) { case WM_INITDIALOG: - scaleresource_setfont (hDlg); pages[EXPANSION_ID] = hDlg; currentpage = EXPANSION_ID; @@ -11186,7 +11176,6 @@ static INT_PTR CALLBACK BoardsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM { case WM_INITDIALOG: recursive++; - scaleresource_setfont (hDlg); pages[BOARD_ID] = hDlg; currentpage = BOARD_ID; setchecked(hDlg, IDC_AUTOCONFIGCUSTOMSORT, workprefs.autoconfig_custom_sort); @@ -11314,7 +11303,6 @@ static INT_PTR CALLBACK MemoryDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARA { case WM_INITDIALOG: recursive++; - scaleresource_setfont (hDlg); pages[MEMORY_ID] = hDlg; currentpage = MEMORY_ID; SendDlgItemMessage (hDlg, IDC_CHIPMEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_CHIP_MEM, MAX_CHIP_MEM)); @@ -11683,7 +11671,6 @@ static INT_PTR CALLBACK KickstartDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LP { case WM_INITDIALOG: { - scaleresource_setfont (hDlg); int ids[] = { IDC_ROMFILE, IDC_ROMFILE2, IDC_CARTFILE, -1 }; pages[KICKSTART_ID] = hDlg; currentpage = KICKSTART_ID; @@ -11988,7 +11975,7 @@ static void misc_setlang (int v) static void misc_gui_font (HWND hDlg, int fonttype) { if (scaleresource_choosefont (hDlg, fonttype)) - gui_size_changed = 1; + gui_size_changed = 10; } static void values_to_miscdlg_dx(HWND hDlg) @@ -12085,11 +12072,13 @@ static void setdefaultguisize (void) { double dpix = 1.0, dpiy = 1.0; +#if 0 previous_dpix = 0; previous_dpiy = 0; if (isfullscreen() <= 0) { scaleresource_getdpimult(&dpix, &dpiy, &previous_dpix, &previous_dpiy); } +#endif gui_width = (int)(GUI_INTERNAL_WIDTH * dpix); gui_height = (int)(GUI_INTERNAL_HEIGHT * dpiy); @@ -12103,6 +12092,22 @@ static void setdefaultguisize (void) } } +static void saveguisize(void) +{ + if (gui_fullscreen) + return; + if (full_property_sheet || isfullscreen() == 0) { + regsetint(NULL, _T("GUISizeX"), gui_width); + regsetint(NULL, _T("GUISizeY"), gui_height); + } else if (isfullscreen() < 0) { + regsetint(NULL, _T("GUISizeFWX"), gui_width); + regsetint(NULL, _T("GUISizeFWY"), gui_height); + } else if (isfullscreen() > 0) { + regsetint(NULL, _T("GUISizeFSX"), gui_width); + regsetint(NULL, _T("GUISizeFSY"), gui_height); + } +} + static void getstoredguisize(void) { if (full_property_sheet || isfullscreen () == 0) { @@ -12132,7 +12137,6 @@ static INT_PTR MiscDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) switch (msg) { case WM_INITDIALOG: - scaleresource_setfont (hDlg); pages[currentpage] = hDlg; InitializeListView (hDlg); values_to_miscdlg (hDlg); @@ -12289,23 +12293,20 @@ static INT_PTR MiscDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) scaleresource_setdefaults (); v = SendDlgItemMessage (hDlg, IDC_GUI_SIZE, CB_GETCURSEL, 0, 0L); if (v != CB_ERR) { - double dpix = 1.0, dpiy = 1.0; if (v == 0) { v = GUI_SCALE_DEFAULT; } else { v--; v = 200 - v * 10; } - if (isfullscreen() <= 0) - scaleresource_getdpimult(&dpix, &dpiy, &previous_dpix, &previous_dpiy); - gui_width = (int)(GUI_INTERNAL_WIDTH * dpix * v / 100); - gui_height = (int)(GUI_INTERNAL_HEIGHT * dpiy * v / 100); + gui_width = (int)(GUI_INTERNAL_WIDTH * v / 100); + gui_height = (int)(GUI_INTERNAL_HEIGHT * v / 100); if (gui_width < MIN_GUI_INTERNAL_WIDTH || gui_height < MIN_GUI_INTERNAL_HEIGHT) { gui_width = MIN_GUI_INTERNAL_WIDTH; gui_height = MIN_GUI_INTERNAL_HEIGHT; } - scaleresource_setmult (guiDlg, gui_width, gui_height, gui_fullscreen); - gui_size_changed = 1; + scaleresource_setsize(gui_width, gui_height, gui_fullscreen); + gui_size_changed = 10; } break; case IDC_GUI_FONT: @@ -12317,17 +12318,18 @@ static INT_PTR MiscDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) case IDC_GUI_RESIZE: gui_resize_enabled = ischecked (hDlg, IDC_GUI_RESIZE); gui_fullscreen = -1; - gui_size_changed = 2; + gui_size_changed = 10; break; case IDC_GUI_FULLSCREEN: gui_fullscreen = ischecked (hDlg, IDC_GUI_FULLSCREEN); if (!gui_fullscreen) { gui_fullscreen = -1; gui_resize_enabled = false; + getstoredguisize(); } else { gui_resize_enabled = true; } - gui_size_changed = 2; + gui_size_changed = 10; break; case IDC_ASSOCIATE_ON: for (i = 0; exts[i].ext; i++) @@ -12764,7 +12766,6 @@ static INT_PTR CALLBACK CPUDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM l switch (msg) { case WM_INITDIALOG: recursive++; - scaleresource_setfont (hDlg); pages[CPU_ID] = hDlg; currentpage = CPU_ID; SendDlgItemMessage (hDlg, IDC_CACHE, TBM_SETRANGE, TRUE, MAKELONG (MIN_CACHE_SIZE, MAX_CACHE_SIZE)); @@ -13293,7 +13294,6 @@ static INT_PTR CALLBACK SoundDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM case WM_INITDIALOG: { recursive++; - scaleresource_setfont (hDlg); sound_loaddrivesamples (); SendDlgItemMessage (hDlg, IDC_SOUNDBUFFERRAM, TBM_SETRANGE, TRUE, MAKELONG (MIN_SOUND_MEM, MAX_SOUND_MEM)); SendDlgItemMessage (hDlg, IDC_SOUNDBUFFERRAM, TBM_SETPAGESIZE, 0, 1); @@ -14873,6 +14873,7 @@ static void new_hardfile (HWND hDlg, int entry) struct hardfiledata *hfd = get_hardfile_data (uci->configoffset); if (hfd) hardfile_media_change (hfd, &ci, true, false); + pcmcia_disk_reinsert(&workprefs, &uci->ci, false); } } @@ -14885,6 +14886,7 @@ static void new_harddrive (HWND hDlg, int entry) struct hardfiledata *hfd = get_hardfile_data (uci->configoffset); if (hfd) hardfile_media_change (hfd, ¤t_hfdlg.ci, true, false); + pcmcia_disk_reinsert(&workprefs, &uci->ci, false); } } @@ -15133,7 +15135,6 @@ static INT_PTR CALLBACK HarddiskDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPA { switch (msg) { case WM_INITDIALOG: - scaleresource_setfont (hDlg); clicked_entry = 0; pages[HARDDISK_ID] = hDlg; currentpage = HARDDISK_ID; @@ -15764,7 +15765,6 @@ static INT_PTR CALLBACK FloppyDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARA TCHAR ft35dd[20], ft35hd[20], ft35ddpc[20], ft35hdpc[20], ft525sd[20], ftdis[20], ft35ddescom[20]; int df0texts[] = { IDC_DF0TEXT, IDC_DF1TEXT, IDC_DF2TEXT, IDC_DF3TEXT, -1 }; - scaleresource_setfont (hDlg); WIN32GUI_LoadUIString (IDS_FLOPPYTYPE35DD, ft35dd, sizeof ft35dd / sizeof (TCHAR)); WIN32GUI_LoadUIString (IDS_FLOPPYTYPE35HD, ft35hd, sizeof ft35hd / sizeof (TCHAR)); WIN32GUI_LoadUIString (IDS_FLOPPYTYPE35DDPC, ft35ddpc, sizeof ft35ddpc / sizeof (TCHAR)); @@ -16099,7 +16099,6 @@ static INT_PTR CALLBACK SwapperDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPAR switch (msg) { case WM_INITDIALOG: - scaleresource_setfont (hDlg); pages[DISK_ID] = hDlg; currentpage = DISK_ID; InitializeListView (hDlg); @@ -16921,7 +16920,6 @@ static INT_PTR CALLBACK GamePortsDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LP case WM_INITDIALOG: { recursive++; - scaleresource_setfont (hDlg); pages[GAMEPORTS_ID] = hDlg; currentpage = GAMEPORTS_ID; @@ -17104,7 +17102,6 @@ static INT_PTR CALLBACK IOPortsDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPAR { case WM_INITDIALOG: recursive++; - scaleresource_setfont (hDlg); pages[IOPORTS_ID] = hDlg; currentpage = IOPORTS_ID; init_portsdlg (hDlg); @@ -18190,7 +18187,6 @@ static INT_PTR CALLBACK InputMapDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPA return TRUE; case WM_INITDIALOG: { - scaleresource_setfont (hDlg); inputmap_port_remap = -1; inputmap_remap_counter = -1; inputmap_view_offset = 0; @@ -18679,7 +18675,6 @@ static INT_PTR CALLBACK InputDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM { case WM_INITDIALOG: recursive++; - scaleresource_setfont (hDlg); pages[INPUT_ID] = hDlg; currentpage = INPUT_ID; inputdevice_updateconfig (NULL, &workprefs); @@ -19581,7 +19576,6 @@ static INT_PTR CALLBACK hw3dDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM } firstinit = true; } - scaleresource_setfont (hDlg); pages[HW3D_ID] = hDlg; currentpage = HW3D_ID; SendDlgItemMessage (hDlg, IDC_FILTERASPECT, CB_RESETCONTENT, 0, 0); @@ -19969,7 +19963,6 @@ static INT_PTR CALLBACK AVIOutputDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LP switch(msg) { case WM_INITDIALOG: - scaleresource_setfont (hDlg); pages[AVIOUTPUT_ID] = hDlg; currentpage = AVIOUTPUT_ID; AVIOutput_GetSettings (); @@ -20442,7 +20435,6 @@ static HWND updatePanel (int id, UINT action) HWND hDlg = guiDlg; static HWND hwndTT; static bool first = true; - RECT r1c, r1w, r2c, r2w, r3c, r3w; int w, h, x , y, i, pw, ph; int fullpanel; struct newresource *tres; @@ -20506,34 +20498,15 @@ static HWND updatePanel (int id, UINT action) return NULL; } - GetWindowRect (GetDlgItem (hDlg, IDC_PANEL_FRAME), &r1w); - GetClientRect (GetDlgItem (hDlg, IDC_PANEL_FRAME), &r1c); - GetWindowRect (hDlg, &r2w); - GetClientRect (hDlg, &r2c); - gui_width = r2c.right; - gui_height = r2c.bottom; - fullpanel = ppage[id].fullpanel; - tres = scaleresource (ppage[id].nres, hDlg, -1, 0, 0, false); + tres = scaleresource (ppage[id].nres, &maindctx, hDlg, -1, 0, 0, id + 1); panelDlg = CreateDialogIndirectParam (tres->inst, tres->resource, hDlg, ppage[id].dlgproc, id); + + //SetWindowRedraw(hDlg, FALSE); + + rescaleresource(tres, &maindctx, hDlg, panelDlg); + freescaleresource(tres); - - GetWindowRect (hDlg, &r3w); - GetClientRect (panelDlg, &r3c); - x = r1w.left - r2w.left; - y = r1w.top - r2w.top; - w = r3c.right - r3c.left + 1; - h = r3c.bottom - r3c.top + 1; - pw = r1w.right - r1w.left + 1; - ph = r1w.bottom - r1w.top + 1; - SetWindowPos (panelDlg, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOOWNERZORDER); - GetWindowRect (panelDlg, &r3w); - GetClientRect (panelDlg, &r3c); - x -= r3w.left - r2w.left - 1; - y -= r3w.top - r2w.top - 1; - if (!fullpanel) { - SetWindowPos (panelDlg, HWND_TOP, x + (pw - w) / 2, y + (ph - h) / 2, 0, 0, SWP_NOSIZE | SWP_NOOWNERZORDER); - } ShowWindow (GetDlgItem (hDlg, IDC_PANEL_FRAME), SW_HIDE); ShowWindow (GetDlgItem (hDlg, IDC_PANEL_FRAME_OUTER), !fullpanel ? SW_SHOW : SW_HIDE); @@ -20559,6 +20532,9 @@ static HWND updatePanel (int id, UINT action) EnumChildWindows (panelDlg, &childenumproc, (LPARAM)ppage[currentpage].nres->tmpl); SendMessage (panelDlg, WM_NULL, 0, 0); + //SetWindowRedraw(hDlg, TRUE); + //RedrawWindow(hDlg, NULL, NULL, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_UPDATENOW); + hAccelTable = ppage[currentpage].accel; if (ppage[id].focusid > 0 && action != TVC_BYKEYBOARD) { @@ -21112,14 +21088,16 @@ static INT_PTR CALLBACK DialogProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM l if (!gui_size_changed && hGUIWnd != NULL) { int dx = LOWORD(wParam); int dy = HIWORD(wParam); - if (dx != previous_dpix || dy != previous_dpiy) { - RECT *r = (RECT*)lParam; - previous_dpix = dx; - previous_dpiy = dy; - gui_width = (r->right - r->left); - gui_height = (r->bottom - r->top); - gui_size_changed = 1; - } + RECT *const r = (RECT*)lParam; + previous_dpix = dx; + previous_dpiy = dy; + gui_width = (r->right - r->left); + gui_height = (r->bottom - r->top); + oldwidth = gui_width; + oldheight = gui_height; + saveguisize(); + SetWindowPos(hDlg, NULL, r->left, r->top, r->right - r->left, r->bottom - r->top, SWP_NOZORDER | SWP_NOACTIVATE); + scaleresource_setsize(gui_width, gui_height, 0); } } break; @@ -21220,7 +21198,6 @@ static INT_PTR CALLBACK DialogProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM l return TRUE; case WM_INITDIALOG: guiDlg = hDlg; - scaleresource_setfont (hDlg); SendMessage (hDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon (GetModuleHandle (NULL), MAKEINTRESOURCE(IDI_APPICON))); if (full_property_sheet) { TCHAR tmp[100]; @@ -21367,12 +21344,13 @@ struct newresource *getresource (int tmpl) INT_PTR CustomDialogBox (int templ, HWND hDlg, DLGPROC proc) { struct newresource *res, *r; + struct dlgcontext dctx; INT_PTR h = -1; res = getresource (templ); if (!res) return h; - r = scaleresource (res, hDlg, -1, 0, 0, false); + r = scaleresource (res, &dctx, hDlg, -1, 0, 0, -1); if (r) { h = DialogBoxIndirect (r->inst, r->resource, hDlg, proc); freescaleresource (r); @@ -21386,12 +21364,13 @@ INT_PTR CustomDialogBox (int templ, HWND hDlg, DLGPROC proc) HWND CustomCreateDialog (int templ, HWND hDlg, DLGPROC proc) { struct newresource *res, *r; + struct dlgcontext dctx; HWND h = NULL; res = getresource (templ); if (!res) return h; - r = scaleresource (res, hDlg, -1, 0, 0, false); + r = scaleresource (res, &dctx, hDlg, -1, 0, 0, -1); if (r) { h = CreateDialogIndirect (r->inst, r->resource, hDlg, proc); freescaleresource (r); @@ -21529,7 +21508,7 @@ static int GetSettings (int all_options, HWND hwnd) HWND dhwnd; int first = 0; static struct newresource *panelresource; - struct newresource *tres; + struct newresource *tres = NULL; bool closed = false; gui_active++; @@ -21588,13 +21567,14 @@ static int GetSettings (int all_options, HWND hwnd) } int fmultx = 0, fmulty = 0; - setdefaultguisize (); + setdefaultguisize(); getstoredguisize(); + scaleresource_setsize(-1, -1, -1); for (;;) { int v = 0; int regexists; regexists = regqueryint (NULL, _T("GUIResize"), &v); - gui_fullscreen = false; + gui_fullscreen = 0; gui_resize_allowed = true; gui_resize_enabled = v != 0; v = 0; @@ -21602,12 +21582,13 @@ static int GetSettings (int all_options, HWND hwnd) if (v) { gui_resize_allowed = false; gui_resize_enabled = true; - gui_fullscreen = true; + gui_fullscreen = 1; } - if (!gui_fullscreen) { + if (!gui_fullscreen && !gui_size_changed) { setdefaultguisize (); getstoredguisize(); } + gui_size_changed = 0; if (!regexists) { scaleresource_setdefaults (); fmultx = 0; @@ -21652,18 +21633,15 @@ static int GetSettings (int all_options, HWND hwnd) write_log(_T("GUI Fullscreen %dx%d\n"), gui_width, gui_height); } } - scaleresource_setmult (hwnd, gui_width, gui_height, 1); + scaleresource_setsize(gui_width, gui_height, 1); int gw = gui_width; int gh = gui_height; getstoredguisize(); gui_width = gw; gui_height = gh; - scaleresource_setmult (hwnd, gui_width, gui_height, 1); + scaleresource_setsize(gui_width, gui_height, 1); } else { - if (fmultx > 0) - scaleresource_setmult (hwnd, -fmultx, -fmulty, 0); - else - scaleresource_setmult (hwnd, gui_width, gui_height, 0); + scaleresource_setsize(gui_width, gui_height, 0); } if (hwnd != NULL) @@ -21678,17 +21656,19 @@ static int GetSettings (int all_options, HWND hwnd) } } - tres = scaleresource (panelresource, hwnd, gui_resize_enabled, gui_fullscreen, workprefs.win32_gui_alwaysontop || workprefs.win32_main_alwaysontop ? WS_EX_TOPMOST : 0, true); + panelresource->width = gui_width; + panelresource->height = gui_height; + freescaleresource(tres); + tres = scaleresource (panelresource, &maindctx, hwnd, gui_resize_enabled, gui_fullscreen, workprefs.win32_gui_alwaysontop || workprefs.win32_main_alwaysontop ? WS_EX_TOPMOST : 0, 0); HWND phwnd = hwnd; if (isfullscreen() == 0) phwnd = 0; if (isfullscreen() > 0 && currprefs.gfx_api > 1) phwnd = 0; - dhwnd = CreateDialogIndirect (tres->inst, tres->resource, phwnd, DialogProc); + dhwnd = CreateDialogIndirect(tres->inst, tres->resource, phwnd, DialogProc); dialog_rect.top = dialog_rect.left = 0; dialog_rect.right = tres->width; dialog_rect.bottom = tres->height; - freescaleresource (tres); psresult = 0; if (dhwnd != NULL) { int dw = GetSystemMetrics(SM_CXSCREEN); @@ -21697,6 +21677,8 @@ static int GetSettings (int all_options, HWND hwnd) DWORD v; int w, h; + //rescaleresource(dhwnd); + getguisize (dhwnd, &w, &h); write_log (_T("Got GUI size = %dx%d\n"), w, h); if (w < 100 || h < 100 || (w > 8192 && w > dw + 500) || (h > 8192 && h > dh + 500)) { @@ -21768,15 +21750,23 @@ static int GetSettings (int all_options, HWND hwnd) } if (dialogreturn >= 0) break; - if (gui_size_changed > 0 && gui_size_changed < 10) { - if (gui_size_changed == 2) { - getstoredguisize(); - scaleresource_getmult (&fmultx, &fmulty); - } else { - fmultx = fmulty = 0; + if (gui_size_changed > 0) { + saveguisize(); + regsetint(NULL, _T("GUIResize"), gui_resize_enabled ? 1 : 0); + regsetint(NULL, _T("GUIFullscreen"), gui_fullscreen > 0 ? 1 : 0); + if (gui_size_changed < 10) { + scaleresource_setsize(gui_width, gui_height, 0); + rescaleresource(tres, &maindctx, dhwnd, panelDlg); + gui_size_changed = 0; } - gui_size_changed = 10; - SendMessage (dhwnd, WM_COMMAND, IDCANCEL, 0); + } + if (gui_size_changed >= 10) { + SendMessage(dhwnd, WM_COMMAND, IDCANCEL, 0); + scaleresource_setsize(-1, -1, -1); + } + if (gui_fullscreen < 0) { + // reset after IDCANCEL which would save coordinates + gui_fullscreen = 0; } } psresult = dialogreturn; @@ -21792,25 +21782,10 @@ static int GetSettings (int all_options, HWND hwnd) gui_size_changed = 10; } gui_exit: + freescaleresource(tres); + tres = NULL; if (!gui_size_changed) break; - if (!gui_fullscreen) { - if (full_property_sheet || isfullscreen () == 0) { - regsetint (NULL, _T("GUISizeX"), gui_width); - regsetint (NULL, _T("GUISizeY"), gui_height); - } else if (isfullscreen () < 0) { - regsetint (NULL, _T("GUISizeFWX"), gui_width); - regsetint (NULL, _T("GUISizeFWY"), gui_height); - } else if (isfullscreen () > 0) { - regsetint (NULL, _T("GUISizeFSX"), gui_width); - regsetint (NULL, _T("GUISizeFSY"), gui_height); - } - } - if (gui_fullscreen < 0) - gui_fullscreen = 0; - regsetint (NULL, _T("GUIResize"), gui_resize_enabled ? 1 : 0); - regsetint (NULL, _T("GUIFullscreen"), gui_fullscreen ? 1 : 0); - gui_size_changed = 0; quit_program = 0; } diff --git a/od-win32/win32gui.h b/od-win32/win32gui.h index 3366164c..006deac3 100644 --- a/od-win32/win32gui.h +++ b/od-win32/win32gui.h @@ -18,6 +18,22 @@ int dragdrop (HWND hDlg, HDROP hd, struct uae_prefs *prefs, int currentpage); UAEREG *read_disk_history (int type); void write_disk_history (void); +#define MAX_GUIIDPARAMS 16 +#define MAX_DLGID 100 + +struct dlgstore +{ + RECT r; + UINT wc; + HWND h; +}; + +struct dlgcontext +{ + struct dlgstore dstore[MAX_DLGID]; + int dlgstorecnt; +}; + struct newresource { LPCDLGTEMPLATEW resource; @@ -25,6 +41,10 @@ struct newresource int size; int tmpl; int width, height; + int listviews_id[MAX_GUIIDPARAMS]; + int setparam_id[MAX_GUIIDPARAMS]; + int listviewcnt; + int setparamcnt; }; #define GUI_INTERNAL_WIDTH 800 @@ -33,18 +53,16 @@ struct newresource extern struct uae_prefs workprefs; -extern struct newresource *scaleresource (struct newresource *res, HWND, int, int, DWORD, bool); +extern struct newresource* scaleresource(struct newresource*, struct dlgcontext *dctx, HWND, int, int, DWORD, int); +extern void rescaleresource(struct newresource*, struct dlgcontext*, HWND, HWND); extern void freescaleresource (struct newresource*); -extern void scaleresource_setmult (HWND hDlg, int w, int h, int fs); -extern void scaleresource_getmult (int *mx, int *my); +extern void scaleresource_setsize (int w, int h, int fs); extern HWND CustomCreateDialog (int templ, HWND hDlg, DLGPROC proc); extern INT_PTR CustomDialogBox (int templ, HWND hDlg, DLGPROC proc); extern struct newresource *getresource (int tmpl); extern void scaleresource_init (const TCHAR*, int); extern int scaleresource_choosefont (HWND hDlg, int fonttype); extern void scaleresource_setdefaults (void); -extern void scaleresource_setfont (HWND hDlg); -extern void scaleresource_getdpimult (double*, double*, int*, int*); extern void scalaresource_listview_font_info(int*); extern int getscaledfontsize(int size); extern bool show_box_art(const TCHAR*); diff --git a/od-win32/win32gui_extra.cpp b/od-win32/win32gui_extra.cpp index 230ff284..dc62541b 100644 --- a/od-win32/win32gui_extra.cpp +++ b/od-win32/win32gui_extra.cpp @@ -18,8 +18,10 @@ #define MAX_GUI_FONTS 2 #define DEFAULT_FONTSIZE 8 -static double multx, multy; +static float multx, multy; static int scaleresource_width, scaleresource_height; +static int scaleresource_reset; +static int dux, duy; static TCHAR fontname_gui[32], fontname_list[32]; static int fontsize_gui = DEFAULT_FONTSIZE; @@ -29,23 +31,10 @@ static int fontstyle_list = 0; static int fontweight_gui = FW_REGULAR; static int fontweight_list = FW_REGULAR; -static int listviewcnt; -static int listviews_id[16]; - -static int setparamcnt; -static int setparam_id[16]; - static HFONT listviewfont; static TEXTMETRIC listview_tm; static const TCHAR *fontprefix; -#define BASEMULT 1000 -static int baseunitx, baseunity; -static RECT baserect, baseclientrect; -static int baseborderwidth, baseborderheight; -static int basewidth, baseheight; -static int baseclientwidth, baseclientheight; - #include typedef struct { WORD dlgVer; @@ -145,17 +134,6 @@ static BYTE *todword (BYTE *p) return p; } -static void modifytemplate (DLGTEMPLATEEX *d, DLGTEMPLATEEX_END *d2, int id, int fullscreen) -{ - if (fullscreen) { - d->cx = scaleresource_width; - d->cy = scaleresource_height; - } else { - d->cx = mmx (d->cx); - d->cy = mmy (d->cy); - } -} - static void modifytemplatefont (DLGTEMPLATEEX *d, DLGTEMPLATEEX_END *d2) { if (!wcscmp (d2->typeface, wfont_old)) { @@ -166,67 +144,240 @@ static void modifytemplatefont (DLGTEMPLATEEX *d, DLGTEMPLATEEX_END *d2) } } -static void modifyitem (DLGTEMPLATEEX *d, DLGTEMPLATEEX_END *d2, DLGITEMTEMPLATEEX *dt, int id) +static void modifyitem (struct newresource *nr, DLGTEMPLATEEX *d, DLGTEMPLATEEX_END *d2, DLGITEMTEMPLATEEX *dt, int id) { - bool noyscale = false; int wc = 0; if (dt->windowClass[0] == 0xffff) wc = dt->windowClass[1]; - if (multy >= 89 && multy <= 111) { + if (wc == 0x0085) {// combo box + if (nr->setparamcnt < MAX_GUIIDPARAMS) { + nr->setparam_id[nr->setparamcnt] = dt->id; + nr->setparamcnt++; + } + } + + if (dt->windowClass[0] != 0xffff) { + if (!_tcsicmp (dt->windowClass, WC_LISTVIEWW) || !_tcsicmp (dt->windowClass, WC_TREEVIEWW)) { + if (nr->listviewcnt < MAX_GUIIDPARAMS) { + nr->listviews_id[nr->listviewcnt] = dt->id; + nr->listviewcnt++; + } + } + } + +} + +struct rescalestruct +{ + HWND main, sub; + int dlgid; + struct newresource *nr; + struct dlgcontext *dctx; +}; + +static struct dlgstore dstore_main[MAX_DLGID]; +static int dlgstorecnt_main; + +static BOOL CALLBACK rescaleproc(HWND hwnd, LPARAM lp) +{ + RECT rs; + struct rescalestruct *rss = (struct rescalestruct *)lp; + struct newresource *nr = rss->nr; + struct dlgcontext *dctx = rss->dctx; + HWND parent = GetParent(hwnd); + + // if not parent of sub panel or main panel: skip because for example + // combo boxes have child windows that should not be moved or resized. + if (parent != rss->main && parent != rss->sub) + return TRUE; + + GetClientRect(hwnd, &rs); + MapWindowPoints(hwnd, parent, (LPPOINT)&rs, 2); - if (wc == 0x0080 && dt->cy <= 20) { // button - noyscale = true; + int wc = 0; + bool found = false; + if (parent == rss->main) { + for (int i = 0; i < dlgstorecnt_main; i++) { + struct dlgstore *dsptr = &dstore_main[i]; + if (dsptr->h == hwnd) { + rs = dsptr->r; + found = true; + break; + } } - if (wc == 0x0085) {// combo box - noyscale = false; + if (!found) { + struct dlgstore *dsptr = &dstore_main[dlgstorecnt_main++]; + dsptr->h = hwnd; + dsptr->r = rs; } - if (wc == 0x0081 && dt->cy <= 20) { // edit box - noyscale = true; + } else { + for (int i = 0; i < dctx->dlgstorecnt; i++) { + struct dlgstore *dsptr = &dctx->dstore[i]; + if (dsptr->h == hwnd) { + rs = dsptr->r; + found = true; + break; + } + } + if (!found) { + struct dlgstore *dsptr = &dctx->dstore[dctx->dlgstorecnt++]; + dsptr->h = hwnd; + dsptr->r = rs; } } - if (!noyscale) - dt->cy = mmy (dt->cy); + int x = rs.left; + x *= multx; + x /= 100; - dt->cx = mmx (dt->cx); - dt->y = mmy (dt->y); - dt->x = mmx (dt->x); + int y = rs.top; + y *= multy; + y /= 100; - if (wc == 0x0085) {// combo box - setparam_id[setparamcnt] = dt->id; - setparamcnt++; + int xe = rs.right; + xe *= multx; + xe += 99; + xe /= 100; + + int ye = rs.bottom; + if (wc != 0x85) { + ye *= multy; + ye += 99; + ye /= 100; + } else { + ye = y + (rs.bottom - rs.top); } - if (dt->windowClass[0] != 0xffff) { - if (!_tcsicmp (dt->windowClass, WC_LISTVIEWW) || !_tcsicmp (dt->windowClass, WC_TREEVIEWW)) { - listviews_id[listviewcnt] = dt->id; - listviewcnt++; - } + SetWindowPos(hwnd, HWND_TOP, x, y, xe - x, ye - y, SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOCOPYBITS | SWP_DEFERERASE); + + return TRUE; +} + +static void openfont(bool force) +{ + HDC hdc; + int size; + int lm = 72; + + if (listviewfont && !force) + return; + if (listviewfont) + DeleteObject(listviewfont); + + hdc = GetDC(NULL); + + if (!dpi_aware_v2) { + lm = GetDeviceCaps(hdc, LOGPIXELSY); } + size = -MulDiv(fontsize_list, lm, 72); + listviewfont = CreateFont(size, 0, 0, 0, fontweight_list, (fontstyle_list & ITALIC_FONTTYPE) != 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, fontname_list); + HGDIOBJ o = SelectObject(hdc, listviewfont); + memset(&listview_tm, 0, sizeof listview_tm); + listview_tm.tmAveCharWidth = 8; + GetTextMetrics(hdc, &listview_tm); + SelectObject(hdc, o); + + ReleaseDC(NULL, hdc); } -static INT_PTR CALLBACK DummyProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) +static void scaleresource_setfont(struct newresource *nr, HWND hDlg) { - switch(msg) - { - case WM_DESTROY: - PostQuitMessage (0); - return TRUE; - case WM_CLOSE: - DestroyWindow(hDlg); - return TRUE; - case WM_INITDIALOG: - return TRUE; + if (nr->listviewcnt) { + if (!listviewfont) { + openfont(false); + if (!listviewfont) + return; + } + for (int i = 0; i < nr->listviewcnt; i++) { + HWND hwnd = GetDlgItem(hDlg, nr->listviews_id[i]); + if (hwnd) + SendMessage(hwnd, WM_SETFONT, WPARAM(listviewfont), FALSE); + } + } + if (os_vista) { + for (int i = 0; i < nr->setparamcnt; i++) { + HWND hwnd = GetDlgItem(hDlg, nr->setparam_id[i]); + if (hwnd) { + int v = SendMessage(hwnd, CB_GETITEMHEIGHT, -1, NULL); + if (v > 0 && mmy(v) > v) + SendMessage(hwnd, CB_SETITEMHEIGHT, -1, mmy(v)); + } + } } - return FALSE; } -extern int full_property_sheet; +void rescaleresource(struct newresource *nr, struct dlgcontext *dctx, HWND hwnd, HWND subhwnd) +{ + struct rescalestruct rss; + + scaleresource_setfont(nr, subhwnd); + scaleresource_setfont(nr, hwnd); + + TITLEBARINFO tbi = { 0 }; + tbi.cbSize = sizeof(TITLEBARINFO); + GetTitleBarInfo(hwnd, &tbi); + + int height = tbi.rcTitleBar.bottom - tbi.rcTitleBar.top; + + RECT rw; + GetWindowRect(hwnd, &rw); + + if (scaleresource_reset) { + RECT ru = { 0, 0, 8, 8 }; + MapDialogRect(hwnd, &ru); + dux = ru.right; + duy = ru.bottom; + scaleresource_reset = 0; + } + + WINDOWINFO pwi = { 0 }; + pwi.cbSize = sizeof(WINDOWINFO); + GetWindowInfo(hwnd, &pwi); + + SetWindowPos(hwnd, NULL, 0, 0, scaleresource_width, scaleresource_height, SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOCOPYBITS | SWP_DEFERERASE); + + float neww = scaleresource_width - pwi.cxWindowBorders * 2; + float oldw = (530.0 * dux) / 8.0; + multx = neww * 100.0 / oldw; + + float newh = scaleresource_height - height - pwi.cyWindowBorders * 2; + float oldh = (345.0 * duy) / 8.0; + multy = newh * 100.0 / oldh; + + rss.main = hwnd; + rss.sub = subhwnd; + rss.nr = nr; + rss.dctx = dctx; + EnumChildWindows(hwnd, rescaleproc, (LPARAM)&rss); + + RECT rf, rpf; + HWND pf = GetDlgItem(hwnd, IDC_PANEL_FRAME); + GetClientRect(subhwnd, &rpf); + GetClientRect(pf, &rf); + MapWindowPoints(pf, hwnd, (LPPOINT)& rf, 1); + SetWindowPos(subhwnd, HWND_TOP, rf.left, rf.top + (rf.bottom - rpf.bottom) / 2, 0, 0, SWP_NOSIZE | SWP_NOOWNERZORDER); + + RedrawWindow(hwnd, NULL, NULL, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN); +} -static struct newresource *scaleresource2 (struct newresource *res, HWND parent, int resize, int fullscreen, DWORD exstyle, bool main) +void scaleresource_setsize(int w, int h, int fullscreen) +{ + if (w < 0 || h < 0) { + scaleresource_reset = 1; + for (int i = 0; i < dlgstorecnt_main; i++) { + dstore_main[i].h = NULL; + } + dlgstorecnt_main = 0; + return; + } + scaleresource_width = w; + scaleresource_height = h; +} + +static struct newresource *scaleresource2 (struct newresource *res, HWND parent, int resize, int fullscreen, DWORD exstyle, int dlgid) { static int main_width, main_height; @@ -234,11 +385,10 @@ static struct newresource *scaleresource2 (struct newresource *res, HWND parent, DLGTEMPLATEEX_END *d2, *s2; DLGITEMTEMPLATEEX *dt; BYTE *p, *p2, *ps, *ps2; - int i; struct newresource *ns; - listviewcnt = 0; - setparamcnt = 0; + res->listviewcnt = 0; + res->setparamcnt = 0; d = (DLGTEMPLATEEX*)res->resource; d2 = (DLGTEMPLATEEX_END*)res->resource; @@ -249,6 +399,8 @@ static struct newresource *scaleresource2 (struct newresource *res, HWND parent, return 0; ns = xcalloc (struct newresource, 1); + if (!ns) + return 0; ns->inst = res->inst; ns->size = res->size; ns->tmpl = res->tmpl; @@ -308,11 +460,10 @@ static struct newresource *scaleresource2 (struct newresource *res, HWND parent, memcpy (p, ps2, ns->size - (ps2 - (BYTE*)res->resource)); - modifytemplate(d, d2, ns->tmpl, fullscreen); - - for (i = 0; i < d->cDlgItems; i++) { + int id2 = 0; + for (int i = 0; i < d->cDlgItems; i++) { dt = (DLGITEMTEMPLATEEX*)p; - modifyitem (d, d2, dt, ns->tmpl); + modifyitem(res, d, d2, dt, ns->tmpl); p += sizeof (DLGITEMTEMPLATEEX); p = skiptextone (p); p = skiptext (p); @@ -326,48 +477,34 @@ static struct newresource *scaleresource2 (struct newresource *res, HWND parent, return ns; } -struct newresource *scaleresource (struct newresource *res, HWND parent, int resize, int fullscreen, DWORD exstyle, bool main) +struct newresource *scaleresource (struct newresource *res, struct dlgcontext *dctx, HWND parent, int resize, int fullscreen, DWORD exstyle, int dlgid) { - return scaleresource2(res, parent, resize, fullscreen, exstyle, main); + dctx->dlgstorecnt = 0; + return scaleresource2(res, parent, resize, fullscreen, exstyle, dlgid); } void freescaleresource (struct newresource *ns) { + if (!ns) + return; xfree ((void*)ns->resource); xfree (ns); } int getscaledfontsize(int size) { - HDC hdc = GetDC(NULL); + int lm = 72; + if (size <= 0) size = fontsize_gui; - size = -MulDiv(size, GetDeviceCaps(hdc, LOGPIXELSY), 72); - ReleaseDC(NULL, hdc); - return size; -} - -static void openfont (bool force) -{ - HDC hdc; - int size; - - if (listviewfont && !force) - return; - if (listviewfont) - DeleteObject (listviewfont); - hdc = GetDC (NULL); - - size = -MulDiv (fontsize_list, GetDeviceCaps (hdc, LOGPIXELSY), 72); - listviewfont = CreateFont (size, 0, 0, 0, fontweight_list, (fontstyle_list & ITALIC_FONTTYPE) != 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, fontname_list); - HGDIOBJ o = SelectObject(hdc, listviewfont); - memset(&listview_tm, 0, sizeof listview_tm); - listview_tm.tmAveCharWidth = 8; - GetTextMetrics(hdc, &listview_tm); - SelectObject(hdc, o); - - ReleaseDC (NULL, hdc); + if (!dpi_aware_v2) { + HDC hdc = GetDC(NULL); + lm = GetDeviceCaps(hdc, LOGPIXELSY); + ReleaseDC(NULL, hdc); + } + size = -MulDiv(size, lm, 72); + return size; } void scalaresource_listview_font_info(int *w) @@ -375,27 +512,6 @@ void scalaresource_listview_font_info(int *w) *w = listview_tm.tmAveCharWidth; } -void scaleresource_setfont (HWND hDlg) -{ - if (listviewcnt) { - if (!listviewfont) { - openfont (false); - if (!listviewfont) - return; - } - for (int i = 0; i < listviewcnt; i++) { - SendMessage (GetDlgItem (hDlg, listviews_id[i]), WM_SETFONT, WPARAM(listviewfont), FALSE); - } - } - if (os_vista) { - for (int i = 0; i < setparamcnt; i++) { - int v = SendMessage (GetDlgItem (hDlg, setparam_id[i]), CB_GETITEMHEIGHT , -1, NULL); - if (v > 0 && mmy(v) > v) - SendMessage (GetDlgItem (hDlg, setparam_id[i]), CB_SETITEMHEIGHT , -1, mmy(v)); - } - } -} - static void setdeffont (void) { _tcscpy (fontname_gui, font_vista_ok ? wfont_vista : wfont_xp); @@ -474,59 +590,6 @@ void scaleresource_setdefaults (void) openfont (true); } -static INT_PTR CALLBACK TestProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - if (msg == WM_INITDIALOG) { - RECT r; - // there really is no better way? - r.left = 0; - r.top = 0; - r.bottom = BASEMULT; - r.right = BASEMULT; - MapDialogRect (hDlg, &r); - baseunitx = r.right * 4 / BASEMULT; - baseunity = r.bottom * 8 / BASEMULT; - GetWindowRect (hDlg, &baserect); - GetClientRect (hDlg, &baseclientrect); - } - return 0; -} - -// horrible or what? -static void getbaseunits (int fullscreen) -{ - multx = multy = 100; - struct newresource *nr, *nr2; - HWND hwnd; - nr = getresource (IDD_PANEL); - if (!nr) { - write_log (_T("getbaseunits fail!\n")); - abort(); - } - nr2 = scaleresource2(nr, NULL, -1, 0, 0, false); - hwnd = CreateDialogIndirect (nr2->inst, nr2->resource, NULL, TestProc); - if (hwnd) { - DestroyWindow (hwnd); - } else { - baserect.left = baserect.top = 0; - baserect.right = 800; - baserect.bottom = 600; - baseclientrect.left = baseclientrect.top = 0; - baseclientrect.right = 800; - baseclientrect.bottom = 600; - } - freescaleresource (nr2); - freescaleresource (nr); - basewidth = baserect.right - baserect.left; - baseheight = baserect.bottom - baserect.top; - baseclientwidth = baseclientrect.right - baseclientrect.left; - baseclientheight = baseclientrect.bottom - baseclientrect.top; - baseborderwidth = basewidth - baseclientwidth; - baseborderheight = baseheight - baseclientheight; - - write_log (_T("GUIBase %dx%d (%dx%d)\n"), basewidth, baseheight, baseunitx, baseunity); -} - void scaleresource_init (const TCHAR *prefix, int fullscreen) { if (os_vista) @@ -542,8 +605,6 @@ void scaleresource_init (const TCHAR *prefix, int fullscreen) //write_log (_T("GUI font %s:%d:%d:%d\n"), fontname_gui, fontsize_gui, fontstyle_gui, fontweight_gui); //write_log (_T("List font %s:%d:%d:%d\n"), fontname_list, fontsize_list, fontstyle_list, fontweight_list); - getbaseunits (fullscreen); - openfont (true); } @@ -574,78 +635,13 @@ static void sizefont (HWND hDlg, const TCHAR *name, int size, int style, int wei } #endif - -typedef enum MONITOR_DPI_TYPE { - MDT_EFFECTIVE_DPI = 0, - MDT_ANGULAR_DPI = 1, - MDT_RAW_DPI = 2, - MDT_DEFAULT = MDT_EFFECTIVE_DPI -} MONITOR_DPI_TYPE; -typedef HRESULT(CALLBACK* GETDPIFORMONITOR)(HMONITOR, MONITOR_DPI_TYPE, UINT*, UINT*); - -void scaleresource_getdpimult (double *dpixmp, double *dpiymp, int *dpixp, int *dpiyp) -{ - GETDPIFORMONITOR pGetDpiForMonitor; - POINT pt = { 32000, 32000 }; - HMONITOR mon = MonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY); - - *dpixmp = 1.0; - *dpiymp = 1.0; - *dpixp = 0; - *dpiyp = 0; - pGetDpiForMonitor = (GETDPIFORMONITOR)GetProcAddress(GetModuleHandle(_T("Shcore.dll")), "GetDpiForMonitor"); - if (pGetDpiForMonitor) { - UINT dpix, dpiy; - if (SUCCEEDED(pGetDpiForMonitor(mon, MDT_EFFECTIVE_DPI, &dpix, &dpiy))) { - if (dpix > 96) - *dpixmp = (double)dpix / 96.0; - if (dpiy > 96) - *dpiymp = (double)dpiy / 96.0; - *dpixp = dpix; - *dpiyp = dpiy; - } - } -} - -void scaleresource_setmult (HWND hDlg, int w, int h, int fullscreen) -{ - if (w < 0) { - multx = -w; - multy = -h; - return; - } - - scaleresource_width = w; - scaleresource_height = h; - - multx = w * 100.0 / basewidth; - multy = h * 100.0 / baseheight; - - if (multx < 50) - multx = 50; - if (multy < 50) - multy = 50; - - //write_log (_T("MX=%f MY=%f\n"), multx, multy); -} - -void scaleresource_getmult (int *mx, int *my) -{ - if (mx) - *mx = (int)(multx + 0.5); - if (my) - *my = (int)(multy + 0.5); -} - - int scaleresource_choosefont (HWND hDlg, int fonttype) { CHOOSEFONT cf = { 0 }; LOGFONT lf = { 0 }; - HDC hdc; TCHAR *fontname[2]; int *fontsize[2], *fontstyle[2], *fontweight[2]; - int lm; + int lm = 72; fontname[0] = fontname_gui; fontname[1] = fontname_list; @@ -661,10 +657,12 @@ int scaleresource_choosefont (HWND hDlg, int fonttype) cf.Flags = CF_FORCEFONTEXIST | CF_INITTOLOGFONTSTRUCT | CF_NOSCRIPTSEL | CF_SCREENFONTS; cf.lpLogFont = &lf; cf.nFontType = REGULAR_FONTTYPE; - cf.iPointSize = *fontsize[fonttype]; - hdc = GetDC (NULL); - lm = GetDeviceCaps (hdc, LOGPIXELSY); + if (!dpi_aware_v2) { + HDC hdc = GetDC(NULL); + lm = GetDeviceCaps(hdc, LOGPIXELSY); + ReleaseDC(NULL, hdc); + } _tcscpy (lf.lfFaceName, fontname[fonttype]); lf.lfHeight = -MulDiv (*fontsize[fonttype], lm, 72); @@ -672,20 +670,17 @@ int scaleresource_choosefont (HWND hDlg, int fonttype) lf.lfItalic = (*fontstyle[fonttype] & ITALIC_FONTTYPE) != 0; if (!ChooseFont (&cf)) { - ReleaseDC (NULL, hdc); return 0; } _tcscpy (fontname[fonttype], lf.lfFaceName); *fontsize[fonttype] = lf.lfHeight; - *fontsize[fonttype] = -MulDiv (*fontsize[fonttype], 72, GetDeviceCaps (hdc, LOGPIXELSY)); + *fontsize[fonttype] = -MulDiv (*fontsize[fonttype], 72, lm); *fontstyle[fonttype] = lf.lfItalic ? ITALIC_FONTTYPE : 0; *fontweight[fonttype] = lf.lfWeight; - ReleaseDC (NULL, hdc); - regsetfont (NULL, fontprefix, fontreg[fonttype], fontname[fonttype], *fontsize[fonttype], *fontstyle[fonttype], *fontweight[fonttype]); openfont (true); @@ -932,6 +927,8 @@ static void boxartpaint(HDC hdc, HWND hwnd) } } +extern int full_property_sheet; + bool show_box_art(const TCHAR *path) { TCHAR tmp1[MAX_DPATH]; -- 2.47.3