diff options
-rw-r--r-- | win32/PlatWin.cxx | 115 | ||||
-rw-r--r-- | win32/ScintillaWin.cxx | 6 | ||||
-rw-r--r-- | win32/makefile | 11 |
3 files changed, 69 insertions, 63 deletions
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index aad7bcf24..ffb129d49 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -18,11 +18,9 @@ #include <map> #undef _WIN32_WINNT -#ifdef WIN_TARGET -#define _WIN32_WINNT WIN_TARGET -#else #define _WIN32_WINNT 0x0500 -#endif +#undef WINVER +#define WINVER 0x0500 #include <windows.h> #include <commctrl.h> #include <richedit.h> @@ -42,13 +40,6 @@ #include "XPM.h" #include "FontQuality.h" -// We want to use multi monitor functions, but via LoadLibrary etc -// Luckily microsoft has done the heavy lifting for us, so we'll just use their stub functions! -#if defined(_MSC_VER) && (_MSC_VER > 1200) -#define COMPILE_MULTIMON_STUBS -#include <MultiMon.h> -#endif - #ifndef IDC_HAND #define IDC_HAND MAKEINTRESOURCE(32649) #endif @@ -90,13 +81,24 @@ static LONG_PTR GetWindowLongPtr(HWND hWnd, int nIndex) { } #endif +// Declarations needed for functions dynamically loaded as not available on all Windows versions. typedef BOOL (WINAPI *AlphaBlendSig)(HDC, int, int, int, int, HDC, int, int, int, int, BLENDFUNCTION); +typedef HMONITOR (WINAPI *MonitorFromPointSig)(POINT, DWORD); +typedef HMONITOR (WINAPI *MonitorFromRectSig)(LPCRECT, DWORD); +typedef BOOL (WINAPI *GetMonitorInfoSig)(HMONITOR, LPMONITORINFO); static CRITICAL_SECTION crPlatformLock; static HINSTANCE hinstPlatformRes = 0; static bool onNT = false; + static HMODULE hDLLImage = 0; static AlphaBlendSig AlphaBlendFn = 0; + +static HMODULE hDLLUser32 = 0; +static HMONITOR (WINAPI *MonitorFromPointFn)(POINT, DWORD) = 0; +static HMONITOR (WINAPI *MonitorFromRectFn)(LPCRECT, DWORD) = 0; +static BOOL (WINAPI *GetMonitorInfoFn)(HMONITOR, LPMONITORINFO) = 0; + static HCURSOR reverseArrowCursor = NULL; bool IsNT() { @@ -1853,6 +1855,19 @@ void Window::SetPosition(PRectangle rc) { 0, rc.left, rc.top, rc.Width(), rc.Height(), SWP_NOZORDER|SWP_NOACTIVATE); } +static RECT RectFromMonitor(HMONITOR hMonitor) { + if (GetMonitorInfoFn) { + MONITORINFO mi = {0}; + mi.cbSize = sizeof(mi); + if (GetMonitorInfoFn(hMonitor, &mi)) { + return mi.rcWork; + } + } + RECT rc = {0, 0, 0, 0}; + ::SystemParametersInfoA(SPI_GETWORKAREA, 0, &rc, 0); + return rc; +} + void Window::SetPositionRelative(PRectangle rc, Window w) { LONG style = ::GetWindowLong(reinterpret_cast<HWND>(wid), GWL_STYLE); if (style & WS_POPUP) { @@ -1860,31 +1875,29 @@ void Window::SetPositionRelative(PRectangle rc, Window w) { ::ClientToScreen(reinterpret_cast<HWND>(w.GetID()), &ptOther); rc.Move(ptOther.x, ptOther.y); - // This #ifdef is for VC 98 which has problems with MultiMon.h under some conditions. -#ifdef MONITOR_DEFAULTTONULL - // We're using the stub functionality of MultiMon.h to decay gracefully on machines - // (ie, pre Win2000, Win95) that do not support the newer functions. RECT rcMonitor = RectFromPRectangle(rc); - MONITORINFO mi = {0}; - mi.cbSize = sizeof(mi); - HMONITOR hMonitor = ::MonitorFromRect(&rcMonitor, MONITOR_DEFAULTTONEAREST); + HMONITOR hMonitor = NULL; + if (MonitorFromRectFn) + hMonitor = MonitorFromRectFn(&rcMonitor, MONITOR_DEFAULTTONEAREST); // If hMonitor is NULL, that's just the main screen anyways. - ::GetMonitorInfo(hMonitor, &mi); - - // Now clamp our desired rectangle to fit inside the work area - // This way, the menu will fit wholly on one screen. An improvement even - // if you don't have a second monitor on the left... Menu's appears half on - // one screen and half on the other are just U.G.L.Y.! - if (rc.right > mi.rcWork.right) - rc.Move(mi.rcWork.right - rc.right, 0); - if (rc.bottom > mi.rcWork.bottom) - rc.Move(0, mi.rcWork.bottom - rc.bottom); - if (rc.left < mi.rcWork.left) - rc.Move(mi.rcWork.left - rc.left, 0); - if (rc.top < mi.rcWork.top) - rc.Move(0, mi.rcWork.top - rc.top); -#endif + //::GetMonitorInfo(hMonitor, &mi); + RECT rcWork = RectFromMonitor(hMonitor); + + if (rcWork.left < rcWork.right) { + // Now clamp our desired rectangle to fit inside the work area + // This way, the menu will fit wholly on one screen. An improvement even + // if you don't have a second monitor on the left... Menu's appears half on + // one screen and half on the other are just U.G.L.Y.! + if (rc.right > rcWork.right) + rc.Move(rcWork.right - rc.right, 0); + if (rc.bottom > rcWork.bottom) + rc.Move(0, rcWork.bottom - rc.bottom); + if (rc.left < rcWork.left) + rc.Move(rcWork.left - rc.left, 0); + if (rc.top < rcWork.top) + rc.Move(0, rcWork.top - rc.top); + } } SetPosition(rc); } @@ -1999,30 +2012,25 @@ void Window::SetTitle(const char *s) { /* Returns rectangle of monitor pt is on, both rect and pt are in Window's coordinates */ PRectangle Window::GetMonitorRect(Point pt) { -#ifdef MONITOR_DEFAULTTONULL - // MonitorFromPoint and GetMonitorInfo are not available on Windows 95 so are not used. - // There could be conditional code and dynamic loading in a future version - // so this would work on those platforms where they are available. + // MonitorFromPoint and GetMonitorInfo are not available on Windows 95 and NT 4. PRectangle rcPosition = GetPosition(); POINT ptDesktop = {static_cast<LONG>(pt.x + rcPosition.left), static_cast<LONG>(pt.y + rcPosition.top)}; - HMONITOR hMonitor = ::MonitorFromPoint(ptDesktop, MONITOR_DEFAULTTONEAREST); - MONITORINFO mi = {0}; - memset(&mi, 0, sizeof(mi)); - mi.cbSize = sizeof(mi); - if (::GetMonitorInfo(hMonitor, &mi)) { + HMONITOR hMonitor = NULL; + if (MonitorFromPointFn) + hMonitor = MonitorFromPointFn(ptDesktop, MONITOR_DEFAULTTONEAREST); + + RECT rcWork = RectFromMonitor(hMonitor); + if (rcWork.left < rcWork.right) { PRectangle rcMonitor( - mi.rcWork.left - rcPosition.left, - mi.rcWork.top - rcPosition.top, - mi.rcWork.right - rcPosition.left, - mi.rcWork.bottom - rcPosition.top); + rcWork.left - rcPosition.left, + rcWork.top - rcPosition.top, + rcWork.right - rcPosition.left, + rcWork.bottom - rcPosition.top); return rcMonitor; } else { return PRectangle(); } -#else - return PRectangle(); -#endif } struct ListItemData { @@ -3224,6 +3232,15 @@ void Platform_Initialise(void *hInstance) { if (hDLLImage) { AlphaBlendFn = (AlphaBlendSig)::GetProcAddress(hDLLImage, "AlphaBlend"); } + if (!hDLLUser32) { + hDLLUser32 = ::LoadLibrary(TEXT("User32")); + } + if (hDLLUser32) { + MonitorFromPointFn = (MonitorFromPointSig)::GetProcAddress(hDLLUser32, "MonitorFromPoint"); + MonitorFromRectFn = (MonitorFromRectSig)::GetProcAddress(hDLLUser32, "MonitorFromRect"); + GetMonitorInfoFn = (GetMonitorInfoSig)::GetProcAddress(hDLLUser32, "GetMonitorInfoA"); + } + ListBoxX_Register(); } diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index e92bd7b13..367e33466 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -18,11 +18,9 @@ #include <map> #undef _WIN32_WINNT -#ifdef WIN_TARGET -#define _WIN32_WINNT WIN_TARGET -#else #define _WIN32_WINNT 0x0500 -#endif +#undef WINVER +#define WINVER 0x0500 #include <windows.h> #include <commctrl.h> #include <richedit.h> diff --git a/win32/makefile b/win32/makefile index 4339cde7c..c71997c65 100644 --- a/win32/makefile +++ b/win32/makefile @@ -8,15 +8,6 @@ CC = g++ DEL = del /q -# Discover Windows version by running 'VER' command and parsing output -# For Windows 2000 looks like:Microsoft Windows 2000 [Version 5.00.2195] -WINVERWORDS:=$(wordlist 1,2,$(subst ., ,$(lastword $(shell ver)))) -WINVER:=$(firstword $(WINVERWORDS)).$(lastword $(WINVERWORDS)) -# Windows NT 4 does not support GetMonitorInfo -ifeq '$(WINVER)' '4.0' - VERSION_DEFINES:=-DWIN_TARGET=0x0400 -endif - COMPONENT = ../bin/Scintilla.dll LEXCOMPONENT = ../bin/SciLexer.dll LEXLIB = Lexers.a @@ -28,7 +19,7 @@ LDFLAGS=-shared -static -Wl,--enable-runtime-pseudo-reloc-v2 -mwindows -Wl,--add LIBS=-lstdc++ -limm32 -lole32 -luuid # Add -MMD to get dependencies INCLUDEDIRS=-I ../include -I ../src -I../lexlib -CXXBASEFLAGS=-Wall -Wno-missing-braces -Wno-char-subscripts -pedantic $(INCLUDEDIRS) -fno-rtti $(VERSION_DEFINES) +CXXBASEFLAGS=-Wall -Wno-missing-braces -Wno-char-subscripts -pedantic $(INCLUDEDIRS) -fno-rtti ifdef DEBUG CXXFLAGS=-DDEBUG -g $(CXXBASEFLAGS) |