From 7a5f22cfe87f938ef58f92b48ac379dc1c4c81c7 Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Fri, 10 May 2024 11:21:56 -0400 Subject: add upstream 13.6 --- wx+/app_main.h | 2 +- wx+/async_task.h | 2 +- wx+/context_menu.h | 2 +- wx+/dc.h | 4 ++-- wx+/file_drop.h | 2 +- wx+/graph.cpp | 4 ++-- wx+/grid.cpp | 18 +++++++++--------- wx+/grid.h | 4 ++-- wx+/image_resources.cpp | 2 +- wx+/image_tools.cpp | 6 ++++-- wx+/image_tools.h | 3 +-- wx+/popup_dlg.cpp | 4 ++-- wx+/popup_dlg.h | 2 +- wx+/std_button_layout.h | 2 +- wx+/tooltip.cpp | 15 ++++++++------- wx+/window_layout.h | 4 ++-- wx+/window_tools.h | 13 ++++++++++--- 17 files changed, 49 insertions(+), 40 deletions(-) (limited to 'wx+') diff --git a/wx+/app_main.h b/wx+/app_main.h index 17a59d7b..c1fd2441 100644 --- a/wx+/app_main.h +++ b/wx+/app_main.h @@ -7,7 +7,7 @@ #ifndef APP_MAIN_H_08215601837818347575856 #define APP_MAIN_H_08215601837818347575856 -#include +//#include #include diff --git a/wx+/async_task.h b/wx+/async_task.h index 5a3e7caa..85f0d9d0 100644 --- a/wx+/async_task.h +++ b/wx+/async_task.h @@ -7,7 +7,7 @@ #ifndef ASYNC_TASK_H_839147839170432143214321 #define ASYNC_TASK_H_839147839170432143214321 -#include +//#include #include #include #include diff --git a/wx+/context_menu.h b/wx+/context_menu.h index 92d8504c..1e2d4d69 100644 --- a/wx+/context_menu.h +++ b/wx+/context_menu.h @@ -7,7 +7,7 @@ #ifndef CONTEXT_MENU_H_18047302153418174632141234 #define CONTEXT_MENU_H_18047302153418174632141234 -#include +//#include #include #include #include diff --git a/wx+/dc.h b/wx+/dc.h index 522e3bc8..161765a0 100644 --- a/wx+/dc.h +++ b/wx+/dc.h @@ -9,10 +9,10 @@ #include #include -#include +//#include #include //for macro: wxALWAYS_NATIVE_DOUBLE_BUFFER #include -#include +//#include // #include diff --git a/wx+/file_drop.h b/wx+/file_drop.h index 16c2b519..e9cb9e72 100644 --- a/wx+/file_drop.h +++ b/wx+/file_drop.h @@ -8,7 +8,7 @@ #define FILE_DROP_H_09457802957842560325626 #include -#include +//#include #include #include #include diff --git a/wx+/graph.cpp b/wx+/graph.cpp index ad7fd3ec..da5c1d98 100644 --- a/wx+/graph.cpp +++ b/wx+/graph.cpp @@ -7,10 +7,10 @@ #include "graph.h" #include #include -#include +//#include #include #include -#include +//#include using namespace zen; diff --git a/wx+/grid.cpp b/wx+/grid.cpp index 07196eaf..1c8897a1 100644 --- a/wx+/grid.cpp +++ b/wx+/grid.cpp @@ -6,13 +6,13 @@ #include "grid.h" #include -#include +//#include #include #include -#include +//#include #include #include -#include +//#include #include #include #include @@ -142,7 +142,7 @@ wxRect GridData::drawCellBorder(wxDC& dc, const wxRect& rect) //returns remainin } -void GridData::drawCellText(wxDC& dc, const wxRect& rect, const std::wstring& text, int alignment, const wxSize* textExtentHint) +void GridData::drawCellText(wxDC& dc, const wxRect& rect, const std::wstring_view text, int alignment, const wxSize* textExtentHint) { /* Performance Notes (Windows): - wxDC::GetTextExtent() is by far the most expensive call (20x more expensive than wxDC::DrawText()) @@ -157,9 +157,9 @@ void GridData::drawCellText(wxDC& dc, const wxRect& rect, const std::wstring& te return; //truncate large texts and add ellipsis - wxString textTrunc = text; - wxSize extentTrunc = textExtentHint ? *textExtentHint : dc.GetTextExtent(text); - assert(!textExtentHint || *textExtentHint == dc.GetTextExtent(text)); //"trust, but verify" :> + wxString textTrunc(&text[0], text.size()); + wxSize extentTrunc = textExtentHint ? *textExtentHint : dc.GetTextExtent(textTrunc); + assert(!textExtentHint || *textExtentHint == dc.GetTextExtent(textTrunc)); //"trust, but verify" :> if (extentTrunc.GetWidth() > rect.width) { @@ -180,13 +180,13 @@ void GridData::drawCellText(wxDC& dc, const wxRect& rect, const std::wstring& te } const size_t middle = (low + high) / 2; //=> never 0 when "high - low > 1" - const wxString candidate = getUnicodeSubstring(text, 0, middle) + ELLIPSIS; + /*const*/ wxString candidate = getUnicodeSubstring(text, 0, middle) + ELLIPSIS; const wxSize extentCand = dc.GetTextExtent(candidate); //perf: most expensive call of this routine! if (extentCand.GetWidth() <= rect.width) { low = middle; - textTrunc = candidate; + textTrunc = std::move(candidate); extentTrunc = extentCand; } else diff --git a/wx+/grid.h b/wx+/grid.h index 471ba31b..57a8ffe3 100644 --- a/wx+/grid.h +++ b/wx+/grid.h @@ -8,7 +8,7 @@ #define GRID_H_834702134831734869987 #include -#include +//#include #include #include #include @@ -122,7 +122,7 @@ public: static wxColor getColorSelectionGradientFrom(); static wxColor getColorSelectionGradientTo(); - static void drawCellText(wxDC& dc, const wxRect& rect, const std::wstring& text, + static void drawCellText(wxDC& dc, const wxRect& rect, const std::wstring_view text, int alignment = wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, const wxSize* textExtentHint = nullptr); static wxRect drawCellBorder(wxDC& dc, const wxRect& rect); //returns inner rectangle diff --git a/wx+/image_resources.cpp b/wx+/image_resources.cpp index 6157f381..3e162651 100644 --- a/wx+/image_resources.cpp +++ b/wx+/image_resources.cpp @@ -5,7 +5,7 @@ // ***************************************************************************** #include "image_resources.h" -#include +//#include #include #include #include diff --git a/wx+/image_tools.cpp b/wx+/image_tools.cpp index e95797ca..4dfa7b30 100644 --- a/wx+/image_tools.cpp +++ b/wx+/image_tools.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include using namespace zen; @@ -173,7 +175,7 @@ wxImage zen::createImageFromText(const wxString& text, const wxFont& font, const std::vector> lineInfo; //text + extent for (const wxString& line : splitCpy(text, L'\n', SplitOnEmpty::allow)) - lineInfo.emplace_back(line, line.empty() ? wxSize() : dc.GetTextExtent(line)); + lineInfo.emplace_back(line, dc.GetTextExtent(line)); //GetTextExtent() returns (0, 0) for empty string! //------------------------------------------------------------------------------------------------ int maxWidth = 0; @@ -181,7 +183,7 @@ wxImage zen::createImageFromText(const wxString& text, const wxFont& font, const for (const auto& [lineText, lineSize] : lineInfo) { maxWidth = std::max(maxWidth, lineSize.GetWidth()); - lineHeight = std::max(lineHeight, lineSize.GetHeight()); //wxWidgets comment "GetTextExtent will return 0 for empty string" + lineHeight = std::max(lineHeight, lineSize.GetHeight()); } if (maxWidth == 0 || lineHeight == 0) return wxNullImage; diff --git a/wx+/image_tools.h b/wx+/image_tools.h index 79b15e3a..8374a26f 100644 --- a/wx+/image_tools.h +++ b/wx+/image_tools.h @@ -9,9 +9,8 @@ #include #include -#include #include -#include +#include namespace zen diff --git a/wx+/popup_dlg.cpp b/wx+/popup_dlg.cpp index 5ab17564..d6c25fc8 100644 --- a/wx+/popup_dlg.cpp +++ b/wx+/popup_dlg.cpp @@ -10,7 +10,7 @@ #include #include #include -#include "app_main.h" +//#include "app_main.h" #include "bitmap_button.h" #include "no_flicker.h" #include "window_layout.h" @@ -36,7 +36,7 @@ void setBestInitialSize(wxRichTextCtrl& ctrl, const wxString& text, wxSize maxSi const int rowGap = 0; int maxLineWidth = 0; - int rowHeight = 0; + int rowHeight = 0; //alternative: just call ctrl.GetCharHeight()!? int rowCount = 0; bool haveLineWrap = false; diff --git a/wx+/popup_dlg.h b/wx+/popup_dlg.h index cabf13f5..92a60b42 100644 --- a/wx+/popup_dlg.h +++ b/wx+/popup_dlg.h @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include diff --git a/wx+/std_button_layout.h b/wx+/std_button_layout.h index 86558026..9a38ec1b 100644 --- a/wx+/std_button_layout.h +++ b/wx+/std_button_layout.h @@ -7,7 +7,7 @@ #ifndef STD_BUTTON_LAYOUT_H_183470321478317214 #define STD_BUTTON_LAYOUT_H_183470321478317214 -#include +//#include #include #include #include "dc.h" diff --git a/wx+/tooltip.cpp b/wx+/tooltip.cpp index 14df955c..5b6b5f45 100644 --- a/wx+/tooltip.cpp +++ b/wx+/tooltip.cpp @@ -8,10 +8,10 @@ #include #include #include -#include +//#include #include #include -#include "image_tools.h" +//#include "image_tools.h" #include "bitmap_button.h" #include "dc.h" #include @@ -21,7 +21,7 @@ using namespace zen; namespace { -const int TIP_WINDOW_OFFSET_DIP = 30; +const int TIP_WINDOW_OFFSET_DIP = 20; } @@ -88,13 +88,14 @@ void Tooltip::show(const wxString& text, wxPoint mousePos, const wxImage* img) //=> call wxWindow::Show() to "execute" #endif - const wxPoint newPos = wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ? - mousePos - wxPoint(dipToWxsize(TIP_WINDOW_OFFSET_DIP) + tipWindow_->GetSize().GetWidth(), 0) : - mousePos + wxPoint(dipToWxsize(TIP_WINDOW_OFFSET_DIP), 0); + const wxPoint newPos = mousePos + wxPoint(wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ? + - dipToWxsize(TIP_WINDOW_OFFSET_DIP) - tipWindow_->GetSize().GetWidth() : + dipToWxsize(TIP_WINDOW_OFFSET_DIP), + dipToWxsize(TIP_WINDOW_OFFSET_DIP)); if (newPos != tipWindow_->GetScreenPosition()) tipWindow_->Move(newPos); - //attention!!! possible endless loop: mouse pointer must NOT be within tipWindow! + //caveat: possible endless loop! mouse pointer must NOT be within tipWindow! //else it will trigger a wxEVT_LEAVE_WINDOW on middle grid which will hide the window, causing the window to be shown again via this method, etc. if (!tipWindow_->IsShown()) diff --git a/wx+/window_layout.h b/wx+/window_layout.h index 553485bd..05b9316e 100644 --- a/wx+/window_layout.h +++ b/wx+/window_layout.h @@ -7,8 +7,8 @@ #ifndef WINDOW_LAYOUT_H_23849632846734343234532 #define WINDOW_LAYOUT_H_23849632846734343234532 -#include -#include +//#include +//#include #include #include #include diff --git a/wx+/window_tools.h b/wx+/window_tools.h index 19b89176..94cb2c32 100644 --- a/wx+/window_tools.h +++ b/wx+/window_tools.h @@ -54,6 +54,15 @@ wxTopLevelWindow* getTopLevelWindow(wxWindow* child) even if the user is currently busy using a different app! More curiosity: this foreground focus stealing happens only during the *first* SetFocus() after app start! It also can be avoided by changing focus back and forth with some other app after start => wxWidgets bug or Win32 feature??? */ +inline +void setFocusIfActive(wxWindow& win) //don't steal keyboard focus when currently using a different foreground application +{ + if (wxTopLevelWindow* topWin = getTopLevelWindow(&win)) + if (topWin->IsActive()) //Linux/macOS: already behaves just like ::GetForegroundWindow() on Windows! + win.SetFocus(); +} + + struct FocusPreserver { FocusPreserver() @@ -70,9 +79,7 @@ struct FocusPreserver if (oldFocusId_ != wxID_ANY) if (wxWindow* oldFocusWin = wxWindow::FindWindowById(oldFocusId_)) - if (wxTopLevelWindow* topWin = getTopLevelWindow(oldFocusWin)) - if (topWin->IsActive()) //Linux/macOS: already behaves just like ::GetForegroundWindow() on Windows! - oldFocusWin->SetFocus(); + setFocusIfActive(*oldFocusWin); } wxWindowID getFocusId() const { return oldFocusId_; } -- cgit