diff --git a/include/wx/chkconf.h b/include/wx/chkconf.h index 9d0e7f743c..ff7cf9da65 100644 --- a/include/wx/chkconf.h +++ b/include/wx/chkconf.h @@ -2392,6 +2392,17 @@ # endif #endif /* wxUSE_RICHTEXT */ +#if wxUSE_RICHTOOLTIP +# if !wxUSE_POPUPWIN +# ifdef wxABORT_ON_CONFIG_ERROR +# error "wxRichToolTip requires wxUSE_POPUPWIN" +# else +# undef wxUSE_POPUPWIN +# define wxUSE_POPUPWIN 1 +# endif +# endif +#endif /* wxUSE_RICHTOOLTIP */ + #if wxUSE_PROPGRID # if !wxUSE_VARIANT # ifdef wxABORT_ON_CONFIG_ERROR diff --git a/include/wx/msw/nonownedwnd.h b/include/wx/msw/nonownedwnd.h index c5d40bfa97..a3f8aa4274 100644 --- a/include/wx/msw/nonownedwnd.h +++ b/include/wx/msw/nonownedwnd.h @@ -27,11 +27,27 @@ protected: virtual bool DoSetRegionShape(const wxRegion& region) wxOVERRIDE; #if wxUSE_GRAPHICS_CONTEXT virtual bool DoSetPathShape(const wxGraphicsPath& path) wxOVERRIDE; +#endif // wxUSE_GRAPHICS_CONTEXT + + virtual WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) wxOVERRIDE; + virtual void InheritAttributes() wxOVERRIDE; private: + bool HandleDPIChange(const wxSize& newDPI, const wxRect& newRect); + +#if wxUSE_GRAPHICS_CONTEXT wxNonOwnedWindowShapeImpl* m_shapeImpl; #endif // wxUSE_GRAPHICS_CONTEXT + // Keep track of the DPI used in this window. So when per-monitor dpi + // awareness is enabled, both old and new DPI are known for + // wxDPIChangedEvent and wxWindow::MSWUpdateOnDPIChange. + wxSize m_activeDPI; + + // This window supports handling per-monitor DPI awareness when the + // application manifest contains PerMonitorV2. + bool m_perMonitorDPIaware; + wxDECLARE_NO_COPY_CLASS(wxNonOwnedWindow); }; diff --git a/include/wx/msw/toplevel.h b/include/wx/msw/toplevel.h index d32764bb1f..5412de421e 100644 --- a/include/wx/msw/toplevel.h +++ b/include/wx/msw/toplevel.h @@ -115,7 +115,7 @@ public: virtual WXHWND MSWGetParent() const wxOVERRIDE; // window proc for the frames - WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) wxOVERRIDE; + virtual WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) wxOVERRIDE; // returns true if the platform should explicitly apply a theme border virtual bool CanApplyThemeBorder() const wxOVERRIDE { return false; } @@ -166,9 +166,6 @@ protected: int& x, int& y, int& w, int& h) const wxOVERRIDE; - // WM_DPICHANGED handler. - bool HandleDPIChange(const wxSize& newDPI, const wxRect& newRect); - // This field contains the show command to use when showing the window the // next time and also indicates whether the window should be considered // being iconized or maximized (which may be different from whether it's @@ -195,15 +192,6 @@ protected: wxWindowRef m_winLastFocused; private: - // Keep track of the DPI used in this window. So when per-monitor dpi - // awareness is enabled, both old and new DPI are known for - // wxDPIChangedEvent and wxWindow::MSWUpdateOnDPIChange. - wxSize m_activeDPI; - - // This window supports handling per-monitor DPI awareness when the - // application manifest contains PerMonitorV2. - bool m_perMonitorDPIaware; - // The system menu: initially NULL but can be set (once) by // MSWGetSystemMenu(). Owned by this window. wxMenu *m_menuSystem; diff --git a/samples/stc/defsext.h b/samples/stc/defsext.h index f046ecdbf2..f0c3189b46 100644 --- a/samples/stc/defsext.h +++ b/samples/stc/defsext.h @@ -24,11 +24,6 @@ //============================================================================ #define DEFAULT_LANGUAGE "" - -#define PAGE_COMMON _("Common") -#define PAGE_LANGUAGES _("Languages") -#define PAGE_STYLE_TYPES _("Style types") - #define STYLE_TYPES_COUNT 32 @@ -47,7 +42,6 @@ enum { myID_REPLACENEXT, myID_BRACEMATCH, myID_GOTO, - myID_PAGEACTIVE, myID_DISPLAYEOL, myID_INDENTGUIDE, myID_LINENUMBER, @@ -76,29 +70,18 @@ enum { myID_MULTIPLE_SELECTIONS, myID_MULTI_PASTE, myID_MULTIPLE_SELECTIONS_TYPING, + myID_TECHNOLOGY_DEFAULT, + myID_TECHNOLOGY_DIRECTWRITE, myID_CUSTOM_POPUP, myID_USECHARSET, myID_CHARSETANSI, myID_CHARSETMAC, - myID_PAGEPREV, - myID_PAGENEXT, myID_SELECTLINE, myID_EDIT_LAST = myID_SELECTLINE, myID_WINDOW_MINIMAL, // other IDs - myID_STATUSBAR, - myID_TITLEBAR, myID_ABOUTTIMER, - myID_UPDATETIMER, - - // dialog find IDs - myID_DLG_FIND_TEXT, - - // preferences IDs - myID_PREFS_LANGUAGE, - myID_PREFS_STYLETYPE, - myID_PREFS_KEYWORDS, }; // ---------------------------------------------------------------------------- diff --git a/samples/stc/edit.cpp b/samples/stc/edit.cpp index 0900639684..25b143eb93 100644 --- a/samples/stc/edit.cpp +++ b/samples/stc/edit.cpp @@ -128,6 +128,8 @@ wxBEGIN_EVENT_TABLE (Edit, wxStyledTextCtrl) EVT_MENU(myID_MULTI_PASTE, Edit::OnMultiPaste) EVT_MENU(myID_MULTIPLE_SELECTIONS_TYPING, Edit::OnMultipleSelectionsTyping) EVT_MENU(myID_CUSTOM_POPUP, Edit::OnCustomPopup) + EVT_MENU(myID_TECHNOLOGY_DEFAULT, Edit::OnTechnology) + EVT_MENU(myID_TECHNOLOGY_DIRECTWRITE, Edit::OnTechnology) // stc EVT_STC_MARGINCLICK (wxID_ANY, Edit::OnMarginClick) EVT_STC_CHARADDED (wxID_ANY, Edit::OnCharAdded) @@ -196,7 +198,7 @@ Edit::Edit (wxWindow *parent, wxWindowID id, // miscellaneous m_LineNrMargin = TextWidth (wxSTC_STYLE_LINENUMBER, "_999999"); - m_FoldingMargin = 16; + m_FoldingMargin = FromDIP(16); CmdKeyClear (wxSTC_KEY_TAB, 0); // this is done by the menu accelerator key SetLayoutCache (wxSTC_CACHE_PAGE); UsePopUp(wxSTC_POPUP_ALL); @@ -480,6 +482,11 @@ void Edit::OnCustomPopup(wxCommandEvent& evt) UsePopUp(evt.IsChecked() ? wxSTC_POPUP_NEVER : wxSTC_POPUP_ALL); } +void Edit::OnTechnology(wxCommandEvent& event) +{ + SetTechnology(event.GetId() == myID_TECHNOLOGY_DIRECTWRITE ? wxSTC_TECHNOLOGY_DIRECTWRITE : wxSTC_TECHNOLOGY_DEFAULT); +} + //! misc void Edit::OnMarginClick (wxStyledTextEvent &event) { if (event.GetMargin() == 2) { diff --git a/samples/stc/edit.h b/samples/stc/edit.h index 09ca020847..6465d0d9a0 100644 --- a/samples/stc/edit.h +++ b/samples/stc/edit.h @@ -102,6 +102,7 @@ public: void OnMultiPaste(wxCommandEvent& event); void OnMultipleSelectionsTyping(wxCommandEvent& event); void OnCustomPopup(wxCommandEvent& evt); + void OnTechnology(wxCommandEvent& event); // stc void OnMarginClick (wxStyledTextEvent &event); void OnCharAdded (wxStyledTextEvent &event); @@ -115,7 +116,6 @@ public: //! language/lexer wxString DeterminePrefs (const wxString &filename); bool InitializePrefs (const wxString &filename); - bool UserSettings (const wxString &filename); LanguageInfo const* GetLanguageInfo () {return m_language;} //! load/save file diff --git a/samples/stc/stctest.cpp b/samples/stc/stctest.cpp index 9c4f95c11b..d7aef83b25 100644 --- a/samples/stc/stctest.cpp +++ b/samples/stc/stctest.cpp @@ -63,12 +63,6 @@ #define APP_LICENCE "wxWidgets" #define APP_VERSION "0.1.alpha" -#define APP_BUILD __DATE__ - -#define APP_WEBSITE "http://www.wxWidgets.org" -#define APP_MAIL "mailto://???" - -#define NONAME _("") class AppBook; @@ -132,12 +126,8 @@ public: void OnClose (wxCloseEvent &event); void OnAbout (wxCommandEvent &event); void OnExit (wxCommandEvent &event); - void OnTimerEvent (wxTimerEvent &event); //! file - void OnFileNew (wxCommandEvent &event); - void OnFileNewFrame (wxCommandEvent &event); void OnFileOpen (wxCommandEvent &event); - void OnFileOpenFrame (wxCommandEvent &event); void OnFileSave (wxCommandEvent &event); void OnFileSaveAs (wxCommandEvent &event); void OnFileClose (wxCommandEvent &event); @@ -582,12 +572,17 @@ void AppFrame::CreateMenu () menuExtra->AppendCheckItem(myID_MULTI_PASTE, _("Toggle multi-&paste")); menuExtra->AppendCheckItem(myID_MULTIPLE_SELECTIONS_TYPING, _("Toggle t&yping on multiple selections")); menuExtra->AppendSeparator(); - menuExtra->AppendCheckItem (myID_CUSTOM_POPUP, _("C&ustom popup menu")); +#if defined(__WXMSW__) && wxUSE_GRAPHICS_DIRECT2D + wxMenu* menuTechnology = new wxMenu; + menuTechnology->AppendRadioItem(myID_TECHNOLOGY_DEFAULT, _("&Default")); + menuTechnology->AppendRadioItem(myID_TECHNOLOGY_DIRECTWRITE, _("Direct&Write")); + menuExtra->AppendSubMenu(menuTechnology, _("&Technology")); + menuExtra->AppendSeparator(); +#endif + menuExtra->AppendCheckItem (myID_CUSTOM_POPUP, _("C&ustom context menu")); // Window menu wxMenu *menuWindow = new wxMenu; - menuWindow->Append (myID_PAGEPREV, _("&Previous\tCtrl+Shift+Tab")); - menuWindow->Append (myID_PAGENEXT, _("&Next\tCtrl+Tab")); menuWindow->Append(myID_WINDOW_MINIMAL, _("&Minimal editor")); // Help menu @@ -763,7 +758,7 @@ public: } virtual bool SetFont(const wxFont& font) wxOVERRIDE { - StyleSetFont(wxSTC_STYLE_DEFAULT, (wxFont&)font); + StyleSetFont(wxSTC_STYLE_DEFAULT, font); return wxStyledTextCtrl::SetFont(font); } void SetLexerXml() @@ -823,7 +818,7 @@ public: MinimalEditorFrame() : wxFrame(NULL, wxID_ANY, _("Minimal Editor")) { MinimalEditor* editor = new MinimalEditor(this); - editor->SetFont(wxSystemSettings::GetFont(wxSYS_ANSI_FIXED_FONT)); + editor->SetFont(wxFontInfo().Family(wxFONTFAMILY_TELETYPE)); wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(editor, 1, wxEXPAND); SetSizer(sizer); diff --git a/src/msw/cursor.cpp b/src/msw/cursor.cpp index d57f980ea5..47b0caeed1 100644 --- a/src/msw/cursor.cpp +++ b/src/msw/cursor.cpp @@ -36,6 +36,8 @@ #include "wx/module.h" #endif +#include "wx/display.h" + #include "wx/msw/private.h" #include "wx/msw/missing.h" // IDC_HAND @@ -263,12 +265,20 @@ wxPoint wxCursor::GetHotSpot() const namespace { -void ReverseBitmap(HBITMAP bitmap, int width, int height) +wxSize ScaleAndReverseBitmap(HBITMAP& bitmap, float scale) { + BITMAP bmp; + if ( !::GetObject(bitmap, sizeof(bmp), &bmp) ) + return wxSize(); + wxSize cs(bmp.bmWidth * scale, bmp.bmHeight * scale); + MemoryHDC hdc; SelectInHDC selBitmap(hdc, bitmap); - ::StretchBlt(hdc, width - 1, 0, -width, height, - hdc, 0, 0, width, height, SRCCOPY); + if ( scale != 1 ) + ::SetStretchBltMode(hdc, HALFTONE); + ::StretchBlt(hdc, cs.x - 1, 0, -cs.x, cs.y, hdc, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY); + + return cs; } HCURSOR CreateReverseCursor(HCURSOR cursor) @@ -277,14 +287,15 @@ HCURSOR CreateReverseCursor(HCURSOR cursor) if ( !info.GetFrom(cursor) ) return NULL; - BITMAP bmp; - if ( !::GetObject(info.hbmMask, sizeof(bmp), &bmp) ) - return NULL; + const unsigned displayID = (unsigned)wxDisplay::GetFromPoint(wxGetMousePosition()); + wxDisplay disp(displayID == 0u || displayID < wxDisplay::GetCount() ? displayID : 0u); + const float scale = (float)disp.GetPPI().y / wxGetDisplayPPI().y; - ReverseBitmap(info.hbmMask, bmp.bmWidth, bmp.bmHeight); + wxSize cursorSize = ScaleAndReverseBitmap(info.hbmMask, scale); if ( info.hbmColor ) - ReverseBitmap(info.hbmColor, bmp.bmWidth, bmp.bmHeight); - info.xHotspot = (DWORD)bmp.bmWidth - 1 - info.xHotspot; + ScaleAndReverseBitmap(info.hbmColor, scale); + info.xHotspot = (DWORD)(cursorSize.x - 1 - info.xHotspot * scale); + info.yHotspot = (DWORD)(info.yHotspot * scale); return ::CreateIconIndirect(&info); } diff --git a/src/msw/nonownedwnd.cpp b/src/msw/nonownedwnd.cpp index 3876870071..15f4f89a83 100644 --- a/src/msw/nonownedwnd.cpp +++ b/src/msw/nonownedwnd.cpp @@ -36,7 +36,9 @@ #include "wx/graphics.h" #endif // wxUSE_GRAPHICS_CONTEXT +#include "wx/dynlib.h" #include "wx/scopedptr.h" +#include "wx/msw/missing.h" // ============================================================================ // wxNonOwnedWindow implementation @@ -128,16 +130,6 @@ private: wxDECLARE_NO_COPY_CLASS(wxNonOwnedWindowShapeImpl); }; -wxNonOwnedWindow::wxNonOwnedWindow() -{ - m_shapeImpl = NULL; -} - -wxNonOwnedWindow::~wxNonOwnedWindow() -{ - delete m_shapeImpl; -} - bool wxNonOwnedWindow::DoSetPathShape(const wxGraphicsPath& path) { delete m_shapeImpl; @@ -146,17 +138,115 @@ bool wxNonOwnedWindow::DoSetPathShape(const wxGraphicsPath& path) return true; } -#else // !wxUSE_GRAPHICS_CONTEXT +#endif // wxUSE_GRAPHICS_CONTEXT -// Trivial ctor and dtor as we don't have anything to do when wxGraphicsContext -// is not used but still define them here to avoid adding even more #if checks -// to the header, it it doesn't do any harm even though it's not needed. wxNonOwnedWindow::wxNonOwnedWindow() { +#if wxUSE_GRAPHICS_CONTEXT + m_shapeImpl = NULL; +#endif // wxUSE_GRAPHICS_CONTEXT + + m_activeDPI = wxDefaultSize; + m_perMonitorDPIaware = false; } wxNonOwnedWindow::~wxNonOwnedWindow() { +#if wxUSE_GRAPHICS_CONTEXT + delete m_shapeImpl; +#endif // wxUSE_GRAPHICS_CONTEXT } -#endif // wxUSE_GRAPHICS_CONTEXT/!wxUSE_GRAPHICS_CONTEXT +namespace +{ + +static bool IsPerMonitorDPIAware(HWND hwnd) +{ + bool dpiAware = false; + + // Determine if 'Per Monitor v2' DPI awareness is enabled in the + // applications manifest. +#if wxUSE_DYNLIB_CLASS + #define WXDPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((WXDPI_AWARENESS_CONTEXT)-4) + typedef WXDPI_AWARENESS_CONTEXT(WINAPI * GetWindowDpiAwarenessContext_t)(HWND hwnd); + typedef BOOL(WINAPI * AreDpiAwarenessContextsEqual_t)(WXDPI_AWARENESS_CONTEXT dpiContextA, WXDPI_AWARENESS_CONTEXT dpiContextB); + static GetWindowDpiAwarenessContext_t s_pfnGetWindowDpiAwarenessContext = NULL; + static AreDpiAwarenessContextsEqual_t s_pfnAreDpiAwarenessContextsEqual = NULL; + static bool s_initDone = false; + + if ( !s_initDone ) + { + wxLoadedDLL dllUser32("user32.dll"); + wxDL_INIT_FUNC(s_pfn, GetWindowDpiAwarenessContext, dllUser32); + wxDL_INIT_FUNC(s_pfn, AreDpiAwarenessContextsEqual, dllUser32); + s_initDone = true; + } + + if ( s_pfnGetWindowDpiAwarenessContext && s_pfnAreDpiAwarenessContextsEqual ) + { + WXDPI_AWARENESS_CONTEXT dpiAwarenessContext = s_pfnGetWindowDpiAwarenessContext(hwnd); + + if ( s_pfnAreDpiAwarenessContextsEqual(dpiAwarenessContext, WXDPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) == TRUE ) + { + dpiAware = true; + } + } +#endif // wxUSE_DYNLIB_CLASS + + return dpiAware; +} + +} + +void wxNonOwnedWindow::InheritAttributes() +{ + m_activeDPI = GetDPI(); + m_perMonitorDPIaware = IsPerMonitorDPIAware(GetHwnd()); + + wxNonOwnedWindowBase::InheritAttributes(); +} + +WXLRESULT wxNonOwnedWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) +{ + WXLRESULT rc = 0; + bool processed = false; + + switch ( message ) + { + case WM_DPICHANGED: + { + const RECT* const prcNewWindow = + reinterpret_cast(lParam); + + processed = HandleDPIChange(wxSize(LOWORD(wParam), + HIWORD(wParam)), + wxRectFromRECT(*prcNewWindow)); + } + break; + } + + if (!processed) + rc = wxNonOwnedWindowBase::MSWWindowProc(message, wParam, lParam); + + return rc; +} + +bool wxNonOwnedWindow::HandleDPIChange(const wxSize& newDPI, const wxRect& newRect) +{ + if ( !m_perMonitorDPIaware ) + { + return false; + } + + if ( newDPI != m_activeDPI ) + { + MSWUpdateOnDPIChange(m_activeDPI, newDPI); + m_activeDPI = newDPI; + } + + SetSize(newRect); + + Refresh(); + + return true; +} diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp index 2ede920e8b..4c552f2604 100644 --- a/src/msw/toplevel.cpp +++ b/src/msw/toplevel.cpp @@ -37,7 +37,6 @@ #include "wx/module.h" #endif //WX_PRECOMP -#include "wx/dynlib.h" #include "wx/scopeguard.h" #include "wx/tooltip.h" @@ -104,9 +103,6 @@ void wxTopLevelWindowMSW::Init() m_fsIsShowing = false; m_menuSystem = NULL; - - m_activeDPI = wxDefaultSize; - m_perMonitorDPIaware = false; } WXDWORD wxTopLevelWindowMSW::MSWGetStyle(long style, WXDWORD *exflags) const @@ -249,26 +245,6 @@ WXHWND wxTopLevelWindowMSW::MSWGetParent() const return (WXHWND)hwndParent; } -bool wxTopLevelWindowMSW::HandleDPIChange(const wxSize& newDPI, const wxRect& newRect) -{ - if ( !m_perMonitorDPIaware ) - { - return false; - } - - if ( newDPI != m_activeDPI ) - { - MSWUpdateOnDPIChange(m_activeDPI, newDPI); - m_activeDPI = newDPI; - } - - SetSize(newRect); - - Refresh(); - - return true; -} - WXLRESULT wxTopLevelWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) { WXLRESULT rc = 0; @@ -329,17 +305,6 @@ WXLRESULT wxTopLevelWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WX #endif // #ifndef __WXUNIVERSAL__ } break; - - case WM_DPICHANGED: - { - const RECT* const prcNewWindow = - reinterpret_cast(lParam); - - processed = HandleDPIChange(wxSize(LOWORD(wParam), - HIWORD(wParam)), - wxRectFromRECT(*prcNewWindow)); - } - break; } if ( !processed ) @@ -348,47 +313,6 @@ WXLRESULT wxTopLevelWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WX return rc; } -namespace -{ - -static bool IsPerMonitorDPIAware(HWND hwnd) -{ - bool dpiAware = false; - - // Determine if 'Per Monitor v2' DPI awareness is enabled in the - // applications manifest. -#if wxUSE_DYNLIB_CLASS - #define WXDPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((WXDPI_AWARENESS_CONTEXT)-4) - typedef WXDPI_AWARENESS_CONTEXT(WINAPI * GetWindowDpiAwarenessContext_t)(HWND hwnd); - typedef BOOL(WINAPI * AreDpiAwarenessContextsEqual_t)(WXDPI_AWARENESS_CONTEXT dpiContextA, WXDPI_AWARENESS_CONTEXT dpiContextB); - static GetWindowDpiAwarenessContext_t s_pfnGetWindowDpiAwarenessContext = NULL; - static AreDpiAwarenessContextsEqual_t s_pfnAreDpiAwarenessContextsEqual = NULL; - static bool s_initDone = false; - - if ( !s_initDone ) - { - wxLoadedDLL dllUser32("user32.dll"); - wxDL_INIT_FUNC(s_pfn, GetWindowDpiAwarenessContext, dllUser32); - wxDL_INIT_FUNC(s_pfn, AreDpiAwarenessContextsEqual, dllUser32); - s_initDone = true; - } - - if ( s_pfnGetWindowDpiAwarenessContext && s_pfnAreDpiAwarenessContextsEqual ) - { - WXDPI_AWARENESS_CONTEXT dpiAwarenessContext = s_pfnGetWindowDpiAwarenessContext(hwnd); - - if ( s_pfnAreDpiAwarenessContextsEqual(dpiAwarenessContext, WXDPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) == TRUE ) - { - dpiAware = true; - } - } -#endif // wxUSE_DYNLIB_CLASS - - return dpiAware; -} - -} - bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate, const wxString& title, const wxPoint& pos, @@ -559,9 +483,7 @@ bool wxTopLevelWindowMSW::Create(wxWindow *parent, EnableCloseButton(false); } - m_activeDPI = GetDPI(); - - m_perMonitorDPIaware = IsPerMonitorDPIAware(GetHwnd()); + InheritAttributes(); // for standard dialogs the dialog manager generates WM_CHANGEUISTATE // itself but for custom windows we have to do it ourselves in order to diff --git a/src/msw/window.cpp b/src/msw/window.cpp index eeeb4f3793..2e5be999d9 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -3696,6 +3696,7 @@ wxWindowMSW::MSWHandleMessage(WXLRESULT *result, } break; +#if wxUSE_POPUPWIN case WM_NCACTIVATE: // When we're losing activation to our own popup window, we want to // retain the "active" appearance of the title bar, as dropping @@ -3712,6 +3713,7 @@ wxWindowMSW::MSWHandleMessage(WXLRESULT *result, processed = true; } break; +#endif #if wxUSE_UXTHEME // If we want the default themed border then we need to draw it ourselves diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 359b5c4383..ce4e7e2bff 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -103,6 +103,8 @@ wxColour wxColourFromCDandAlpha(ColourDesired& cd, int alpha) { namespace { +inline wxWindow* GETWIN(WindowID id) { return (wxWindow*)id; } + // wxFont with ascent cached, a pointer to this type is stored in Font::fid. class wxFontWithAscent : public wxFont { @@ -291,21 +293,21 @@ void SurfaceImpl::Init(SurfaceID hdc_, WindowID) { void SurfaceImpl::InitPixMap(int width, int height, Surface *surface, WindowID winid) { Release(); - if (surface) - hdc = new wxMemoryDC(static_cast(surface)->hdc); - else - hdc = new wxMemoryDC(); + wxMemoryDC* mdc = surface + ? new wxMemoryDC(static_cast(surface)->hdc) + : new wxMemoryDC(); + mdc->GetImpl()->SetWindow(GETWIN(winid)); + hdc = mdc; hdcOwned = true; if (width < 1) width = 1; if (height < 1) height = 1; #ifdef __WXMSW__ bitmap = new wxBitmap(width, height); - wxUnusedVar(winid); #else bitmap = new wxBitmap(); - bitmap->CreateScaled(width, height,wxBITMAP_SCREEN_DEPTH,((wxWindow*)winid)->GetContentScaleFactor()); + bitmap->CreateScaled(width, height,wxBITMAP_SCREEN_DEPTH,(GETWIN(winid))->GetContentScaleFactor()); #endif - ((wxMemoryDC*)hdc)->SelectObject(*bitmap); + mdc->SelectObject(*bitmap); } @@ -999,7 +1001,6 @@ public: // helpers void SetFont(Font &font_); - void SetScale(wxDC* dc); HRESULT FlushDrawing(); void D2DPenColour(ColourDesired fore, int alpha=255); void DrawTextCommon(PRectangle rc, Font &font_, XYPOSITION ybase, @@ -1057,19 +1058,18 @@ SurfaceD2D::~SurfaceD2D() Release(); } -void SurfaceD2D::Init(WindowID WXUNUSED(wid)) +void SurfaceD2D::Init(WindowID wid) { Release(); - wxScreenDC sdc; - SetScale(&sdc); + m_logPixelsY = GETWIN(wid)->GetDPI().GetY(); } void SurfaceD2D::Init(SurfaceID sid, WindowID wid) { Release(); - wxWindow* win = wxDynamicCast(wid,wxWindow); + wxWindow* win = GETWIN(wid); if ( win && win->GetName() == "wxSTCCallTip" ) win = win->GetParent(); @@ -1078,7 +1078,7 @@ void SurfaceD2D::Init(SurfaceID sid, WindowID wid) { wxDC* const dc = static_cast(sid); const wxSize sz = dc->GetSize(); - SetScale(dc); + m_logPixelsY = win->GetDPI().GetY(); ScintillaWX* const sciwx = reinterpret_cast(stc->GetDirectPointer()); m_surfaceData = static_cast(sciwx->GetSurfaceData()); @@ -1773,12 +1773,6 @@ void SurfaceD2D::SetFont(Font &font_) } } -void SurfaceD2D::SetScale(wxDC* dc) -{ - wxSize sz = dc->GetPPI(); - m_logPixelsY = sz.GetY(); -} - HRESULT SurfaceD2D::FlushDrawing() { return m_pRenderTarget->Flush(); @@ -1861,8 +1855,6 @@ Surface *Surface::Allocate(int technology) { //---------------------------------------------------------------------- -inline wxWindow* GETWIN(WindowID id) { return (wxWindow*)id; } - Window::~Window() { } @@ -1914,7 +1906,6 @@ void Window::SetPositionRelative(PRectangle rc, Window relativeTo) { if (position.y + height > displayRect.GetBottom()) position.y = displayRect.GetBottom() - height; - position = relativeWin->ScreenToClient(position); wxWindow *window = GETWIN(wid); window->SetSize(position.x, position.y, width, height); } @@ -1975,9 +1966,9 @@ void Window::SetCursor(Cursor curs) { break; } - wxCursor wc = wxCursor(cursorId); if(curs != cursorLast) { + wxCursor wc = wxCursor(cursorId); GETWIN(wid)->SetCursor(wc); cursorLast = curs; } @@ -2170,7 +2161,7 @@ PRectangle Window::GetMonitorRect(Point pt) { #ifdef __WXMSW__ // Use ShowWithoutActivating instead of show. - bool wxSTCPopupBase::Show(bool show) wxOVERRIDE + bool wxSTCPopupBase::Show(bool show) { if ( show ) { @@ -2188,7 +2179,7 @@ PRectangle Window::GetMonitorRect(Point pt) { // Do not activate in response to mouse clicks on this window. bool wxSTCPopupBase::MSWHandleMessage(WXLRESULT *res, WXUINT msg, - WXWPARAM wParam, WXLPARAM lParam) wxOVERRIDE + WXWPARAM wParam, WXLPARAM lParam) { if ( msg == WM_MOUSEACTIVATE ) { @@ -2227,7 +2218,9 @@ PRectangle Window::GetMonitorRect(Point pt) { #endif // __WXOSX_COCOA__ wxSTCPopupWindow::wxSTCPopupWindow(wxWindow* parent) - :wxSTCPopupBase(parent), m_lastKnownPosition(wxDefaultPosition) + : wxSTCPopupBase(parent) + , m_relPos(wxDefaultPosition) + , m_absPos(wxDefaultPosition) { #if !wxSTC_POPUP_IS_CUSTOM Bind(wxEVT_SET_FOCUS, &wxSTCPopupWindow::OnFocus, this); @@ -2278,22 +2271,20 @@ bool wxSTCPopupWindow::AcceptsFocus() const void wxSTCPopupWindow::DoSetSize(int x, int y, int width, int height, int flags) { - m_lastKnownPosition = wxPoint(x, y); + wxPoint pos(x, y); + if ( pos.IsFullySpecified() && !m_relPos.IsFullySpecified() ) + { + m_relPos = GetParent()->ScreenToClient(pos); + } - // convert coords to screen coords since we're a top-level window - if (x != wxDefaultCoord) - GetParent()->ClientToScreen(&x, NULL); + m_absPos = GetParent()->ClientToScreen(m_relPos); - if (y != wxDefaultCoord) - GetParent()->ClientToScreen(NULL, &y); - - wxSTCPopupBase::DoSetSize(x, y, width, height, flags); + wxSTCPopupBase::DoSetSize(m_absPos.x, m_absPos.y, width, height, flags); } void wxSTCPopupWindow::OnParentMove(wxMoveEvent& event) { - if ( m_lastKnownPosition.IsFullySpecified() ) - SetPosition(m_lastKnownPosition); + SetPosition(m_absPos); event.Skip(); } @@ -2657,6 +2648,7 @@ protected: void OnSelection(wxCommandEvent&); void OnDClick(wxCommandEvent&); void OnSysColourChanged(wxSysColourChangedEvent& event); + void OnDPIChanged(wxDPIChangedEvent& event); void OnMouseMotion(wxMouseEvent& event); void OnMouseLeaveWindow(wxMouseEvent& event); @@ -2712,6 +2704,7 @@ wxSTCListBox::wxSTCListBox(wxWindow* parent, wxSTCListBoxVisualData* v, int ht) Bind(wxEVT_LISTBOX, &wxSTCListBox::OnSelection, this); Bind(wxEVT_LISTBOX_DCLICK, &wxSTCListBox::OnDClick, this); Bind(wxEVT_SYS_COLOUR_CHANGED, &wxSTCListBox::OnSysColourChanged, this); + Bind(wxEVT_DPI_CHANGED, &wxSTCListBox::OnDPIChanged, this); if ( m_visualData->HasListCtrlAppearance() ) { @@ -2951,6 +2944,18 @@ void wxSTCListBox::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event)) GetParent()->Refresh(); } +void wxSTCListBox::OnDPIChanged(wxDPIChangedEvent& WXUNUSED(event)) +{ + m_imagePadding = FromDIP(1); + m_textBoxToTextGap = FromDIP(3); + m_textExtraVerticalPadding = FromDIP(1); + + int w; + GetTextExtent(EXTENT_TEST, &w, &m_textHeight); + + RecalculateItemHeight(); +} + void wxSTCListBox::OnMouseLeaveWindow(wxMouseEvent& event) { const int old = m_currentRow; diff --git a/src/stc/PlatWX.h b/src/stc/PlatWX.h index 31a11dbf4d..bdaf7fef4b 100644 --- a/src/stc/PlatWX.h +++ b/src/stc/PlatWX.h @@ -150,7 +150,8 @@ protected: #endif private: - wxPoint m_lastKnownPosition; + wxPoint m_relPos; + wxPoint m_absPos; wxWindow* m_tlw; }; diff --git a/src/stc/ScintillaWX.cpp b/src/stc/ScintillaWX.cpp index 74f446229d..7b7a7ef033 100644 --- a/src/stc/ScintillaWX.cpp +++ b/src/stc/ScintillaWX.cpp @@ -1039,7 +1039,7 @@ void ScintillaWX::DoGainFocus(){ CreateSystemCaret(); } -void ScintillaWX::DoSysColourChange() { +void ScintillaWX::DoInvalidateStyleData() { InvalidateStyleData(); } diff --git a/src/stc/ScintillaWX.h b/src/stc/ScintillaWX.h index dfe97e1d4f..cee2409998 100644 --- a/src/stc/ScintillaWX.h +++ b/src/stc/ScintillaWX.h @@ -161,7 +161,7 @@ public: void DoSize(int width, int height); void DoLoseFocus(); void DoGainFocus(); - void DoSysColourChange(); + void DoInvalidateStyleData(); void DoLeftButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt); void DoRightButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt); void DoLeftButtonUp(Point pt, unsigned int curTime, bool ctrl); diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index 2ae931b4e1..8e3820d162 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -240,18 +240,6 @@ bool wxStyledTextCtrl::Create(wxWindow *parent, SetFontQuality(wxSTC_EFF_QUALITY_DEFAULT); #endif -#ifdef __WXMSW__ - // Set initial zoom for active DPI - const HDC hdc = ::GetDC(parent->GetHWND()); - const int baseDPI = ::GetDeviceCaps(hdc, LOGPIXELSY); - const int activeDPI = parent->GetDPI().y; - ::ReleaseDC(parent->GetHWND(), hdc); - - const int ptSizeOld = StyleGetSize(wxSTC_STYLE_DEFAULT); - const int ptSizeNew = (int)wxMulDivInt32(ptSizeOld, activeDPI, baseDPI); - SetZoom(GetZoom() + (ptSizeNew - ptSizeOld)); -#endif - return true; } @@ -5445,21 +5433,31 @@ void wxStyledTextCtrl::OnGainFocus(wxFocusEvent& evt) { } -void wxStyledTextCtrl::OnDPIChanged(wxDPIChangedEvent& evt) -{ - int ptSizeOld = StyleGetSize(wxSTC_STYLE_DEFAULT); - int ptSizeNew = (int)wxMulDivInt32(ptSizeOld, evt.GetNewDPI().y, evt.GetOldDPI().y); - SetZoom(GetZoom() + (ptSizeNew - ptSizeOld)); +void wxStyledTextCtrl::OnDPIChanged(wxDPIChangedEvent& evt) { + m_swx->DoInvalidateStyleData(); + // trigger a cursor change, so any cursors created by wxWidgets (like reverse arrow) will be recreated + const int oldCursor = GetSTCCursor(); + SetSTCCursor(-1); + SetSTCCursor(oldCursor); + + // adjust the margins to the new DPI for ( int i = 0; i < SC_MAX_MARGIN; ++i ) { SetMarginWidth(i, (int)wxMulDivInt32(GetMarginWidth(i), evt.GetNewDPI().y, evt.GetOldDPI().y)); } + + // Hide auto-complete popup, there is no (easy) way to set it to the correct size + // and position + if ( AutoCompActive() ) + { + AutoCompCancel(); + } } void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(evt)) { - m_swx->DoSysColourChange(); + m_swx->DoInvalidateStyleData(); } diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in index 63db3db362..a3987c47fe 100644 --- a/src/stc/stc.cpp.in +++ b/src/stc/stc.cpp.in @@ -240,18 +240,6 @@ bool wxStyledTextCtrl::Create(wxWindow *parent, SetFontQuality(wxSTC_EFF_QUALITY_DEFAULT); #endif -#ifdef __WXMSW__ - // Set initial zoom for active DPI - const HDC hdc = ::GetDC(parent->GetHWND()); - const int baseDPI = ::GetDeviceCaps(hdc, LOGPIXELSY); - const int activeDPI = parent->GetDPI().y; - ::ReleaseDC(parent->GetHWND(), hdc); - - const int ptSizeOld = StyleGetSize(wxSTC_STYLE_DEFAULT); - const int ptSizeNew = (int)wxMulDivInt32(ptSizeOld, activeDPI, baseDPI); - SetZoom(GetZoom() + (ptSizeNew - ptSizeOld)); -#endif - return true; } @@ -972,21 +960,31 @@ void wxStyledTextCtrl::OnGainFocus(wxFocusEvent& evt) { } -void wxStyledTextCtrl::OnDPIChanged(wxDPIChangedEvent& evt) -{ - int ptSizeOld = StyleGetSize(wxSTC_STYLE_DEFAULT); - int ptSizeNew = (int)wxMulDivInt32(ptSizeOld, evt.GetNewDPI().y, evt.GetOldDPI().y); - SetZoom(GetZoom() + (ptSizeNew - ptSizeOld)); +void wxStyledTextCtrl::OnDPIChanged(wxDPIChangedEvent& evt) { + m_swx->DoInvalidateStyleData(); + // trigger a cursor change, so any cursors created by wxWidgets (like reverse arrow) will be recreated + const int oldCursor = GetSTCCursor(); + SetSTCCursor(-1); + SetSTCCursor(oldCursor); + + // adjust the margins to the new DPI for ( int i = 0; i < SC_MAX_MARGIN; ++i ) { SetMarginWidth(i, (int)wxMulDivInt32(GetMarginWidth(i), evt.GetNewDPI().y, evt.GetOldDPI().y)); } + + // Hide auto-complete popup, there is no (easy) way to set it to the correct size + // and position + if ( AutoCompActive() ) + { + AutoCompCancel(); + } } void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(evt)) { - m_swx->DoSysColourChange(); + m_swx->DoInvalidateStyleData(); }