From fc9ccf92ee30b5af730f03c8d5a3c4871cc72d56 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 22 Feb 2025 15:15:24 +0100 Subject: [PATCH 01/31] Declare loop variable inside the loop in wxAuiDefaultDockArt No real changes, just a small clean up. --- src/aui/dockart.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/aui/dockart.cpp b/src/aui/dockart.cpp index a588563a3db9..d9b6399960c0 100644 --- a/src/aui/dockart.cpp +++ b/src/aui/dockart.cpp @@ -518,11 +518,11 @@ void wxAuiDefaultDockArt::DrawBorder(wxDC& dc, wxWindow* window, const wxRect& _ dc.SetBrush(*wxTRANSPARENT_BRUSH); wxRect rect = _rect; - int i, border_width = window->FromDIP(GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE)); + const int border_width = window->FromDIP(GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE)); if (pane.IsToolbar()) { - for (i = 0; i < border_width; ++i) + for (int i = 0; i < border_width; ++i) { dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW))); dc.DrawLine(rect.x, rect.y, rect.x+rect.width, rect.y); @@ -547,7 +547,7 @@ void wxAuiDefaultDockArt::DrawBorder(wxDC& dc, wxWindow* window, const wxRect& _ art->DrawBorder(dc, window, rect); else { - for (i = 0; i < border_width; ++i) + for (int i = 0; i < border_width; ++i) { dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height); rect.Deflate(1); From 43b55cf0db22835e1879b7a101eac0b97f3157d0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 22 Feb 2025 15:22:56 +0100 Subject: [PATCH 02/31] Avoid scaling small metrics by DPI in wxAuiDockArt Since the changes of 6f463d1376 (Make sizes in wxAuiDockArt metrics DPI independent, 2024-09-28) all metrics used by wxAuiDockArt were scaled by the DPI factor, but this could be undesirable for the metrics using small values, such as the border size, which is just 1px by default, but became 2px when using 200% DPI scaling, or even sash size, which also became visually too thick at 8px instead of the default 4px. Revert to the old behaviour for just these metrics by adding a new virtual GetMetricForWindow() function to wxAuiDockArt which decides whether the given metric should or not be scaled by the DPI and don't do it by default for these two metrics. Document that this -- admittedly, rather arbitrary -- logic can be changed by overriding GetMetricForWindow() in the derived classes. See #24844. Closes #25006. --- include/wx/aui/dockart.h | 7 ++++++ interface/wx/aui/dockart.h | 31 +++++++++++++++++++++++++-- samples/aui/auidemo.cpp | 2 +- src/aui/dockart.cpp | 44 ++++++++++++++++++++++++++++++++++---- src/aui/floatpane.cpp | 5 +++-- src/aui/framemanager.cpp | 28 ++++++++++++------------ src/aui/tabart.cpp | 4 ++-- 7 files changed, 96 insertions(+), 25 deletions(-) diff --git a/include/wx/aui/dockart.h b/include/wx/aui/dockart.h index c73b7f3be0d1..7a5dc8e8d3f7 100644 --- a/include/wx/aui/dockart.h +++ b/include/wx/aui/dockart.h @@ -38,6 +38,13 @@ class WXDLLIMPEXP_AUI wxAuiDockArt virtual ~wxAuiDockArt() = default; virtual wxAuiDockArt* Clone() = 0; + + // This function should be used for querying metrics in the new code, as it + // will scale them by the DPI of the provided window if necessary. The + // older GetMetric() function is kept for compatibility and shouldn't be + // used outside of this class itself. + virtual int GetMetricForWindow(int id, wxWindow* window); + virtual int GetMetric(int id) = 0; virtual void SetMetric(int id, int newVal) = 0; virtual void SetFont(int id, const wxFont& font) = 0; diff --git a/interface/wx/aui/dockart.h b/interface/wx/aui/dockart.h index ec87f89fe1bc..c3b13ce4c315 100644 --- a/interface/wx/aui/dockart.h +++ b/interface/wx/aui/dockart.h @@ -265,10 +265,34 @@ class wxAuiDockArt /** Get the value of a certain setting. @a id can be one of the size values of @b wxAuiPaneDockArtSetting. - Sizes are in DPI-independent pixel values. + + This function returns the same value that was set by SetMetric(), use + GetMetricForWindow() to get the value appropriate for the given window + for metrics that express sizes. */ virtual int GetMetric(int id) = 0; + /** + Get metric value scaled by the DPI of the given window if appropriate. + + Call this function instead of GetMetric() to get the metric value + scaled by the window DPI for the metrics that are expressed in pixels + and must be scaled. + + The default implementation doesn't scale ::wxAUI_DOCKART_SASH_SIZE and + ::wxAUI_DOCKART_PANE_BORDER_SIZE metrics in order to allow setting them + to just a single pixel (which is the default value for the latter in + wxAuiDefaultDockArt) even in high DPI. You may override this function + in your custom art implementation to scale these metrics too if you + prefer to have thicker borders in high DPI. + + Note that values of ::wxAUI_DOCKART_GRADIENT_TYPE are not expressed in + pixels and so should never be scaled by this function. + + @since 3.3.0 + */ + virtual int GetMetricForWindow(int id, wxWindow* window); + /** Set a certain setting with the value @e colour. @a id can be one of the colour values of @b wxAuiPaneDockArtSetting. @@ -282,8 +306,11 @@ class wxAuiDockArt /** Set a certain setting with the value @e new_val. + @a id can be one of the size values of @b wxAuiPaneDockArtSetting. - Sizes should be in DPI-independent pixel values. + + The interpretation of @a new_val depends on the metric being set, see + GetMetricForWindow(). */ virtual void SetMetric(int id, int new_val) = 0; }; diff --git a/samples/aui/auidemo.cpp b/samples/aui/auidemo.cpp index cb8c69c4fa5a..0ec6adb27724 100644 --- a/samples/aui/auidemo.cpp +++ b/samples/aui/auidemo.cpp @@ -1014,7 +1014,7 @@ MyFrame::MyFrame(wxWindow* parent, wxWindow* wnd10 = CreateTextCtrl("This pane will prompt the user before hiding."); // Give this pane an icon, too, just for testing. - int iconSize = FromDIP(m_mgr.GetArtProvider()->GetMetric(wxAUI_DOCKART_CAPTION_SIZE)); + int iconSize = m_mgr.GetArtProvider()->GetMetricForWindow(wxAUI_DOCKART_CAPTION_SIZE, this); // Make it even to use 16 pixel icons with default 17 caption height. iconSize &= ~1; diff --git a/src/aui/dockart.cpp b/src/aui/dockart.cpp index d9b6399960c0..37ca65718ddd 100644 --- a/src/aui/dockart.cpp +++ b/src/aui/dockart.cpp @@ -179,6 +179,40 @@ wxString wxAuiChopText(wxDC& dc, const wxString& text, int max_size) return ret; } +// ---------------------------------------------------------------------------- +// wxAuiDockArt +// ---------------------------------------------------------------------------- + +int wxAuiDockArt::GetMetricForWindow(int id, wxWindow* window) +{ + // Most, but not all, metrics are adjusted to the window DPI. + bool scale = false; + switch (id) + { + case wxAUI_DOCKART_SASH_SIZE: + case wxAUI_DOCKART_PANE_BORDER_SIZE: + // These sizes are typically small values and we don't scale them + // by default to allow setting them to 1 pixel even in high DPI. + break; + + case wxAUI_DOCKART_CAPTION_SIZE: + case wxAUI_DOCKART_GRIPPER_SIZE: + case wxAUI_DOCKART_PANE_BUTTON_SIZE: + scale = true; + break; + + case wxAUI_DOCKART_GRADIENT_TYPE: + // This value is not in pixels at all and is never scaled. + break; + } + + int value = GetMetric(id); + if ( scale ) + value = wxWindow::FromDIP(value, window); + + return value; +} + // -- wxAuiDefaultDockArt class implementation -- // wxAuiDefaultDockArt is an art provider class which does all of the drawing for @@ -518,7 +552,7 @@ void wxAuiDefaultDockArt::DrawBorder(wxDC& dc, wxWindow* window, const wxRect& _ dc.SetBrush(*wxTRANSPARENT_BRUSH); wxRect rect = _rect; - const int border_width = window->FromDIP(GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE)); + const int border_width = GetMetricForWindow(wxAUI_DOCKART_PANE_BORDER_SIZE, window); if (pane.IsToolbar()) { @@ -639,12 +673,14 @@ void wxAuiDefaultDockArt::DrawCaption(wxDC& dc, wxRect clip_rect = rect; clip_rect.width -= window->FromDIP(3); // text offset clip_rect.width -= window->FromDIP(2); // button padding + + const int buttonSize = GetMetricForWindow(wxAUI_DOCKART_PANE_BUTTON_SIZE, window); if (pane.HasCloseButton()) - clip_rect.width -= window->FromDIP(m_buttonSize); + clip_rect.width -= buttonSize; if (pane.HasPinButton()) - clip_rect.width -= window->FromDIP(m_buttonSize); + clip_rect.width -= buttonSize; if (pane.HasMaximizeButton()) - clip_rect.width -= window->FromDIP(m_buttonSize); + clip_rect.width -= buttonSize; wxString draw_text = wxAuiChopText(dc, text, clip_rect.width); diff --git a/src/aui/floatpane.cpp b/src/aui/floatpane.cpp index f9e38fad0502..a32c38f9d8fc 100644 --- a/src/aui/floatpane.cpp +++ b/src/aui/floatpane.cpp @@ -147,10 +147,11 @@ void wxAuiFloatingFrame::SetPaneWindow(const wxAuiPaneInfo& pane) size = m_paneWindow->GetSize(); if (m_ownerMgr && pane.HasGripper()) { + const int gripperSize = m_ownerMgr->m_art->GetMetricForWindow(wxAUI_DOCKART_GRIPPER_SIZE, m_paneWindow); if (pane.HasGripperTop()) - size.y += m_paneWindow->FromDIP(m_ownerMgr->m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE)); + size.y += gripperSize; else - size.x += m_paneWindow->FromDIP(m_ownerMgr->m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE)); + size.x += gripperSize; } SetClientSize(size); diff --git a/src/aui/framemanager.cpp b/src/aui/framemanager.cpp index f01753db322f..f4d91503cf45 100644 --- a/src/aui/framemanager.cpp +++ b/src/aui/framemanager.cpp @@ -1612,9 +1612,9 @@ void wxAuiManager::GetPanePositionsAndSizes(wxAuiDockInfo& dock, for ( auto* p : dock.panes ) { wxAuiPaneInfo& pane = *p; - int caption_size = pane.window->FromDIP(m_art->GetMetric(wxAUI_DOCKART_CAPTION_SIZE)); - int pane_borderSize = pane.window->FromDIP(m_art->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE)); - int gripperSize = pane.window->FromDIP(m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE)); + int caption_size = m_art->GetMetricForWindow(wxAUI_DOCKART_CAPTION_SIZE, pane.window); + int pane_borderSize = m_art->GetMetricForWindow(wxAUI_DOCKART_PANE_BORDER_SIZE, pane.window); + int gripperSize = m_art->GetMetricForWindow(wxAUI_DOCKART_GRIPPER_SIZE, pane.window); positions.Add(pane.dock_pos); int size = 0; @@ -1681,10 +1681,10 @@ void wxAuiManager::LayoutAddPane(wxSizer* cont, wxAuiDockUIPart part; wxSizerItem* sizer_item; - int caption_size = pane.window->FromDIP(m_art->GetMetric(wxAUI_DOCKART_CAPTION_SIZE)); - int gripperSize = pane.window->FromDIP(m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE)); - int pane_borderSize = pane.window->FromDIP(m_art->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE)); - int pane_button_size = pane.window->FromDIP(m_art->GetMetric(wxAUI_DOCKART_PANE_BUTTON_SIZE)); + int caption_size = m_art->GetMetricForWindow(wxAUI_DOCKART_CAPTION_SIZE, pane.window); + int gripperSize = m_art->GetMetricForWindow(wxAUI_DOCKART_GRIPPER_SIZE, pane.window); + int pane_borderSize = m_art->GetMetricForWindow(wxAUI_DOCKART_PANE_BORDER_SIZE, pane.window); + int pane_button_size = m_art->GetMetricForWindow(wxAUI_DOCKART_PANE_BUTTON_SIZE, pane.window); // find out the orientation of the item (orientation for panes // is the same as the dock's orientation) @@ -1863,7 +1863,7 @@ void wxAuiManager::LayoutAddDock(wxSizer* cont, wxSizerItem* sizer_item; wxAuiDockUIPart part; - int sashSize = m_frame->FromDIP(m_art->GetMetric(wxAUI_DOCKART_SASH_SIZE)); + int sashSize = m_art->GetMetricForWindow(wxAUI_DOCKART_SASH_SIZE, m_frame); int orientation = dock.IsHorizontal() ? wxHORIZONTAL : wxVERTICAL; // resizable bottom and right docks have a sash before them @@ -2019,8 +2019,8 @@ wxSizer* wxAuiManager::LayoutAll(wxAuiPaneInfoArray& panes, wxAuiDockUIPartArray& uiparts, bool spacer_only) { - int pane_borderSize = m_frame->FromDIP(m_art->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE)); - int caption_size = m_frame->FromDIP(m_art->GetMetric(wxAUI_DOCKART_CAPTION_SIZE)); + int pane_borderSize = m_art->GetMetricForWindow(wxAUI_DOCKART_PANE_BORDER_SIZE, m_frame); + int caption_size = m_art->GetMetricForWindow(wxAUI_DOCKART_CAPTION_SIZE, m_frame); wxSize cli_size = m_frame->GetClientSize(); @@ -4107,7 +4107,7 @@ bool wxAuiManager::DoEndResizeAction(wxMouseEvent& event) if (m_actionPart && m_actionPart->type==wxAuiDockUIPart::typeDockSizer) { // first, we must calculate the maximum size the dock may be - int sashSize = m_frame->FromDIP(m_art->GetMetric(wxAUI_DOCKART_SASH_SIZE)); + int sashSize = m_art->GetMetricForWindow(wxAUI_DOCKART_SASH_SIZE, m_frame); int used_width = 0, used_height = 0; @@ -4197,9 +4197,9 @@ bool wxAuiManager::DoEndResizeAction(wxMouseEvent& event) int dock_pixels = 0; int new_pixsize = 0; - int caption_size = pane.window->FromDIP(m_art->GetMetric(wxAUI_DOCKART_CAPTION_SIZE)); - int pane_borderSize = pane.window->FromDIP(m_art->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE)); - int sashSize = pane.window->FromDIP(m_art->GetMetric(wxAUI_DOCKART_SASH_SIZE)); + int caption_size = m_art->GetMetricForWindow(wxAUI_DOCKART_CAPTION_SIZE, pane.window); + int pane_borderSize = m_art->GetMetricForWindow(wxAUI_DOCKART_PANE_BORDER_SIZE, pane.window); + int sashSize = m_art->GetMetricForWindow(wxAUI_DOCKART_SASH_SIZE, pane.window); wxPoint new_pos(event.m_x - m_actionOffset.x, event.m_y - m_actionOffset.y); diff --git a/src/aui/tabart.cpp b/src/aui/tabart.cpp index 6260f9ebbcc7..259501f940b6 100644 --- a/src/aui/tabart.cpp +++ b/src/aui/tabart.cpp @@ -658,7 +658,7 @@ int wxAuiGenericTabArt::GetBorderWidth(wxWindow* wnd) { wxAuiDockArt* art = mgr->GetArtProvider(); if (art) - return wnd->FromDIP(art->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE)); + return art->GetMetricForWindow(wxAUI_DOCKART_PANE_BORDER_SIZE, wnd); } return 1; } @@ -1253,7 +1253,7 @@ int wxAuiSimpleTabArt::GetBorderWidth(wxWindow* wnd) { wxAuiDockArt* art = mgr->GetArtProvider(); if (art) - return wnd->FromDIP(art->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE)); + return art->GetMetricForWindow(wxAUI_DOCKART_PANE_BORDER_SIZE, wnd); } return 1; } From 46ff95c84e13db014589982c7399373dd521f6a3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 24 Feb 2025 15:07:48 +0100 Subject: [PATCH 03/31] Fix showing labels of newly added wxNotebook pages in wxOSX The existing code added new tabs before setting their label, which resulted in them being shown initially truncated. Fix this by adding new tabs with their correct label (and image), as this seems to make more sense and also fixes the problem. Also don't override SetMaximum() in wxCocoaTabView, this doesn't make sense as wxNotebook doesn't have a "maximum" property unlike wxSpinCtrl or wxGauge, for which this function (and the associated SetMinimum()) exists, and just do what this function did in SetupTabs() itself, which is the function explicitly intended to be overridden in wxNotebook. See #25196. Closes #25194. --- src/osx/cocoa/notebook.mm | 55 +++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/src/osx/cocoa/notebook.mm b/src/osx/cocoa/notebook.mm index 53c65aa53004..2afbe8af7b80 100644 --- a/src/osx/cocoa/notebook.mm +++ b/src/osx/cocoa/notebook.mm @@ -224,7 +224,7 @@ wxInt32 GetValue() const override return [slf indexOfTabViewItem:selectedItem]+1; } - void SetMaximum( wxInt32 maximum ) override + void SetupTabs( const wxNotebook& notebook) override { wxNSTabView* slf = (wxNSTabView*) m_osxView; int cocoacount = [slf numberOfTabViewItems ]; @@ -232,11 +232,42 @@ void SetMaximum( wxInt32 maximum ) override wxTabViewController* controller = [slf delegate]; [slf setDelegate:nil]; + // Update the existing pages in case their label or image changed. + const int maximum = notebook.GetPageCount(); + for ( int i = 0; i < wxMin(maximum, cocoacount); ++i ) + { + NSTabViewItem* item = [(wxNSTabView*) m_osxView tabViewItemAtIndex:i]; + + wxNotebookPage* page = notebook.GetPage(i); + [item setView:page->GetHandle() ]; + wxCFStringRef cf( page->GetLabel() ); + [item setLabel:cf.AsNSString()]; + + const wxBitmapBundle bitmap = notebook.GetPageBitmapBundle(i); + if ( bitmap.IsOk() ) + { + [(WXCTabViewImageItem*) item setImage: wxOSXGetImageFromBundle(bitmap)]; + } + } + + // Next also add new pages or delete the no more existing ones. if ( maximum > cocoacount ) { for ( int i = cocoacount ; i < maximum ; ++i ) { NSTabViewItem* item = [[WXCTabViewImageItem alloc] init]; + + wxNotebookPage* page = notebook.GetPage(i); + [item setView:page->GetHandle() ]; + wxCFStringRef cf( page->GetLabel() ); + [item setLabel:cf.AsNSString()]; + + const wxBitmapBundle bitmap = notebook.GetPageBitmapBundle(i); + if ( bitmap.IsOk() ) + { + [(WXCTabViewImageItem*) item setImage: wxOSXGetImageFromBundle(bitmap)]; + } + [slf addTabViewItem:item]; [item release]; } @@ -252,28 +283,6 @@ void SetMaximum( wxInt32 maximum ) override [slf setDelegate:controller]; } - void SetupTabs( const wxNotebook& notebook) override - { - int pcount = notebook.GetPageCount(); - - SetMaximum( pcount ); - - for ( int i = 0 ; i < pcount ; ++i ) - { - wxNotebookPage* page = notebook.GetPage(i); - NSTabViewItem* item = [(wxNSTabView*) m_osxView tabViewItemAtIndex:i]; - [item setView:page->GetHandle() ]; - wxCFStringRef cf( page->GetLabel() ); - [item setLabel:cf.AsNSString()]; - - const wxBitmapBundle bitmap = notebook.GetPageBitmapBundle(i); - if ( bitmap.IsOk() ) - { - [(WXCTabViewImageItem*) item setImage: wxOSXGetImageFromBundle(bitmap)]; - } - } - } - int TabHitTest(const wxPoint & pt, long* flags) override { int retval = wxNOT_FOUND; From 08976f9687ab302965e12deeb6205d32960fcdc4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 24 Feb 2025 16:12:51 +0100 Subject: [PATCH 04/31] Fix wxBookCtrl::GetPageText() test to really use multiline strings This test was added back in 232fdc630c (Merge the new GUI tests from SOC2010_GUI_TEST branch., 2010-08-22) but didn't use actual line break to an apparent confusion between slash and backslash. --- tests/controls/bookctrlbasetest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/controls/bookctrlbasetest.cpp b/tests/controls/bookctrlbasetest.cpp index 37cb50520ece..c4930130924a 100644 --- a/tests/controls/bookctrlbasetest.cpp +++ b/tests/controls/bookctrlbasetest.cpp @@ -80,9 +80,9 @@ void BookCtrlBaseTestCase::Text() CPPUNIT_ASSERT_EQUAL("Some other string", base->GetPageText(1)); - base->SetPageText(2, "string with /nline break"); + base->SetPageText(2, "string with\nline break"); - CPPUNIT_ASSERT_EQUAL("string with /nline break", base->GetPageText(2)); + CPPUNIT_ASSERT_EQUAL("string with\nline break", base->GetPageText(2)); } void BookCtrlBaseTestCase::PageManagement() From 568bc1461e218ae1c20482079fa1adbfc4ed17aa Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 24 Feb 2025 16:32:19 +0100 Subject: [PATCH 05/31] Use RemoveMnemonics() not wxStripMenuCodes() in wxGTK wxNotebook No real changes, just use a more clearly named function and remove the unnecessary inclusion of wx/utils.h (where wxStripMenuCodes() is declared). --- src/gtk/notebook.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index eae490c0fe2e..ed716fa20236 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -16,7 +16,6 @@ #ifndef WX_PRECOMP #include "wx/intl.h" #include "wx/log.h" - #include "wx/utils.h" #include "wx/msgdlg.h" #include "wx/bitmap.h" #endif @@ -500,8 +499,9 @@ bool wxNotebook::InsertPage( size_t position, pageData->m_image = nullptr; } - /* set the label text */ - pageData->m_label = gtk_label_new(wxStripMenuCodes(text).utf8_str()); + // Set the label text: we don't support mnemonics here, but we still need + // to strip them if there are any. + pageData->m_label = gtk_label_new(RemoveMnemonics(text).utf8_str()); if (m_windowStyle & wxBK_LEFT) gtk_label_set_angle(GTK_LABEL(pageData->m_label), 90); From 3835619d766989cb41d3be8bd1702f14b9bb23df Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 24 Feb 2025 16:34:31 +0100 Subject: [PATCH 06/31] Store the original page text in wxGTK wxNotebook It may be different from the GtkLabel text if we had stripped any mnemonics from it. --- src/gtk/notebook.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index ed716fa20236..1a3897d30087 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -46,6 +46,7 @@ class wxGtkNotebookPage GtkWidget* m_label; GtkWidget* m_image; int m_imageIndex; + wxString m_text; }; @@ -214,8 +215,7 @@ wxString wxNotebook::GetPageText( size_t page ) const { wxCHECK_MSG(page < GetPageCount(), wxEmptyString, "invalid notebook index"); - GtkLabel* label = GTK_LABEL(GetNotebookPage(page)->m_label); - return wxString::FromUTF8(gtk_label_get_text(label)); + return GetNotebookPage(page)->m_text; } int wxNotebook::GetPageImage( size_t page ) const @@ -268,8 +268,11 @@ bool wxNotebook::SetPageText( size_t page, const wxString &text ) { wxCHECK_MSG(page < GetPageCount(), false, "invalid notebook index"); - GtkLabel* label = GTK_LABEL(GetNotebookPage(page)->m_label); - gtk_label_set_text(label, text.utf8_str()); + wxGtkNotebookPage* const pageData = GetNotebookPage(page); + pageData->m_text = text; + + GtkLabel* label = GTK_LABEL(pageData->m_label); + gtk_label_set_text(label, RemoveMnemonics(text).utf8_str()); return true; } @@ -500,7 +503,9 @@ bool wxNotebook::InsertPage( size_t position, } // Set the label text: we don't support mnemonics here, but we still need - // to strip them if there are any. + // to strip them if there are any. Also store the original text to be able + // to return it from GetPageText() later. + pageData->m_text = text; pageData->m_label = gtk_label_new(RemoveMnemonics(text).utf8_str()); if (m_windowStyle & wxBK_LEFT) From 65c26e52db279e603280461e537ad366e4520ced Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 24 Feb 2025 16:47:52 +0100 Subject: [PATCH 07/31] Factor out wxCocoaTabView::SetupTabItem() Avoid duplicating the same code, extract it into a helper function. No real changes. --- src/osx/cocoa/notebook.mm | 40 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/osx/cocoa/notebook.mm b/src/osx/cocoa/notebook.mm index 2afbe8af7b80..13c8dff79c14 100644 --- a/src/osx/cocoa/notebook.mm +++ b/src/osx/cocoa/notebook.mm @@ -236,18 +236,9 @@ void SetupTabs( const wxNotebook& notebook) override const int maximum = notebook.GetPageCount(); for ( int i = 0; i < wxMin(maximum, cocoacount); ++i ) { - NSTabViewItem* item = [(wxNSTabView*) m_osxView tabViewItemAtIndex:i]; + SetupTabItem(notebook, i, + [(wxNSTabView*) m_osxView tabViewItemAtIndex:i]); - wxNotebookPage* page = notebook.GetPage(i); - [item setView:page->GetHandle() ]; - wxCFStringRef cf( page->GetLabel() ); - [item setLabel:cf.AsNSString()]; - - const wxBitmapBundle bitmap = notebook.GetPageBitmapBundle(i); - if ( bitmap.IsOk() ) - { - [(WXCTabViewImageItem*) item setImage: wxOSXGetImageFromBundle(bitmap)]; - } } // Next also add new pages or delete the no more existing ones. @@ -256,17 +247,7 @@ void SetupTabs( const wxNotebook& notebook) override for ( int i = cocoacount ; i < maximum ; ++i ) { NSTabViewItem* item = [[WXCTabViewImageItem alloc] init]; - - wxNotebookPage* page = notebook.GetPage(i); - [item setView:page->GetHandle() ]; - wxCFStringRef cf( page->GetLabel() ); - [item setLabel:cf.AsNSString()]; - - const wxBitmapBundle bitmap = notebook.GetPageBitmapBundle(i); - if ( bitmap.IsOk() ) - { - [(WXCTabViewImageItem*) item setImage: wxOSXGetImageFromBundle(bitmap)]; - } + SetupTabItem(notebook, i, item); [slf addTabViewItem:item]; [item release]; @@ -304,6 +285,21 @@ int TabHitTest(const wxPoint & pt, long* flags) override return retval; } + +private: + void SetupTabItem(const wxNotebook& notebook, int i, NSTabViewItem* item) + { + wxNotebookPage* page = notebook.GetPage(i); + [item setView:page->GetHandle() ]; + wxCFStringRef cf( page->GetLabel() ); + [item setLabel:cf.AsNSString()]; + + const wxBitmapBundle bitmap = notebook.GetPageBitmapBundle(i); + if ( bitmap.IsOk() ) + { + [(WXCTabViewImageItem*) item setImage: wxOSXGetImageFromBundle(bitmap)]; + } + } }; From 00f5bbbab7bed1cc29d761e57848127da0802f49 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 24 Feb 2025 16:49:07 +0100 Subject: [PATCH 08/31] Avoid using wxWindow::SetLabel() in wxOSX wxNotebook code This function doesn't work for all windows, notably it doesn't do anything and triggers an assert for wxTextCtrl since the changes of 79f06970a8 (Make wxTextCtrl::SetLabel() consistently do nothing everywhere, 2024-11-28), so don't use it to store the notebook page title and store it separately, just as we already do for the page images and as was done for wxGTK in the recent 3835619d76 (Store the original page text in wxGTK wxNotebook, 2025-02-24). Incidentally, this also makes GetPageText() return the same string that was passed to SetPageText() instead of returning the string with the mnemonics stripped, as it did before. Closes #25195. --- include/wx/osx/notebook.h | 23 +++++++++++++++++++++-- src/osx/cocoa/notebook.mm | 2 +- src/osx/notebook_osx.cpp | 26 ++++++++++++-------------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/include/wx/osx/notebook.h b/include/wx/osx/notebook.h index 3d52ad4cdee2..89e3b5214968 100644 --- a/include/wx/osx/notebook.h +++ b/include/wx/osx/notebook.h @@ -14,6 +14,8 @@ // ---------------------------------------------------------------------------- #include "wx/event.h" +#include + // ---------------------------------------------------------------------------- // types // ---------------------------------------------------------------------------- @@ -128,8 +130,25 @@ class WXDLLIMPEXP_CORE wxNotebook : public wxNotebookBase int DoSetSelection(size_t nPage, int flags = 0) override; - // the icon indices - wxArrayInt m_images; +private: + // this vector is synchronized with m_pages in the base class + struct PageData + { + PageData(const wxString& text_, int image_) + : text{text_}, image{image_} + { + } + + PageData(const PageData&) = default; + PageData& operator=(const PageData&) = default; + + PageData(PageData&&) = default; + PageData& operator=(PageData&&) = default; + + wxString text; + int image = wxNOT_FOUND; + }; + std::vector m_pagesData; wxDECLARE_DYNAMIC_CLASS(wxNotebook); wxDECLARE_EVENT_TABLE(); diff --git a/src/osx/cocoa/notebook.mm b/src/osx/cocoa/notebook.mm index 13c8dff79c14..a0a455478f8e 100644 --- a/src/osx/cocoa/notebook.mm +++ b/src/osx/cocoa/notebook.mm @@ -291,7 +291,7 @@ void SetupTabItem(const wxNotebook& notebook, int i, NSTabViewItem* item) { wxNotebookPage* page = notebook.GetPage(i); [item setView:page->GetHandle() ]; - wxCFStringRef cf( page->GetLabel() ); + wxCFStringRef cf( wxControl::RemoveMnemonics(notebook.GetPageText(i)) ); [item setLabel:cf.AsNSString()]; const wxBitmapBundle bitmap = notebook.GetPageBitmapBundle(i); diff --git a/src/osx/notebook_osx.cpp b/src/osx/notebook_osx.cpp index c0aebcf9494b..0f5dbb851fd1 100644 --- a/src/osx/notebook_osx.cpp +++ b/src/osx/notebook_osx.cpp @@ -118,9 +118,11 @@ bool wxNotebook::SetPageText(size_t nPage, const wxString& strText) { wxCHECK_MSG( IS_VALID_PAGE(nPage), false, wxT("SetPageText: invalid notebook page") ); - wxNotebookPage *page = m_pages[nPage]; - page->SetLabel(wxStripMenuCodes(strText)); - MacSetupTabs(); + if ( m_pagesData[nPage].text != strText ) + { + m_pagesData[nPage].text = strText; + MacSetupTabs(); + } return true; } @@ -129,16 +131,14 @@ wxString wxNotebook::GetPageText(size_t nPage) const { wxCHECK_MSG( IS_VALID_PAGE(nPage), wxEmptyString, wxT("GetPageText: invalid notebook page") ); - wxNotebookPage *page = m_pages[nPage]; - - return page->GetLabel(); + return m_pagesData[nPage].text; } int wxNotebook::GetPageImage(size_t nPage) const { wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("GetPageImage: invalid notebook page") ); - return m_images[nPage]; + return m_pagesData[nPage].image; } bool wxNotebook::SetPageImage(size_t nPage, int nImage) @@ -148,12 +148,12 @@ bool wxNotebook::SetPageImage(size_t nPage, int nImage) wxCHECK_MSG( HasImageList() && nImage < GetImageList()->GetImageCount(), false, wxT("SetPageImage: invalid image index") ); - if ( nImage != m_images[nPage] ) + if ( nImage != m_pagesData[nPage].image ) { // if the item didn't have an icon before or, on the contrary, did have // it but has lost it now, its size will change - but if the icon just // changes, it won't - m_images[nPage] = nImage; + m_pagesData[nPage].image = nImage; MacSetupTabs() ; } @@ -173,7 +173,7 @@ wxNotebookPage* wxNotebook::DoRemovePage(size_t nPage) wxNotebookPage* page = m_pages[nPage] ; m_pages.erase(m_pages.begin() + nPage); - m_images.RemoveAt(nPage); + m_pagesData.erase(m_pagesData.begin() + nPage); MacSetupTabs(); @@ -200,7 +200,7 @@ bool wxNotebook::DeleteAllPages() { wxBookCtrlBase::DeleteAllPages(); - m_images.clear(); + m_pagesData.clear(); MacSetupTabs(); return true; @@ -221,9 +221,7 @@ bool wxNotebook::InsertPage(size_t nPage, // don't show pages by default (we'll need to adjust their size first) pPage->Show( false ) ; - pPage->SetLabel( wxStripMenuCodes(strText) ); - - m_images.Insert( imageId, nPage ); + m_pagesData.insert( m_pagesData.begin() + nPage, {strText, imageId} ); MacSetupTabs(); From b40585c2e334de7ec1cbed30e22565ba559ab71c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 24 Feb 2025 17:27:05 +0100 Subject: [PATCH 09/31] Fix documentation of wxAUI_TBART_DROPDOWN_SIZE Due to a missing comma in wxAuiToolBarArtSetting, this enum element didn't appear in the generated documentation. This should have been part of 7a8e314736 (Fix clicking on drop down button in wxAuiToolBar on wxMSW, 2018-09-20), see #939. --- interface/wx/aui/auibar.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/wx/aui/auibar.h b/interface/wx/aui/auibar.h index a820a0311a39..184fdd8c231f 100644 --- a/interface/wx/aui/auibar.h +++ b/interface/wx/aui/auibar.h @@ -102,7 +102,7 @@ enum wxAuiToolBarArtSetting /** Overflow button size in wxAuiToolBar. */ - wxAUI_TBART_OVERFLOW_SIZE = 2 + wxAUI_TBART_OVERFLOW_SIZE = 2, /** Drop down button size in wxAuiToolBar. From ee0b03929f1a22dbd3f13144d14c09695c1fd509 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 24 Feb 2025 17:44:37 +0100 Subject: [PATCH 10/31] Remove useless overrides from wxAuiMSWToolBarArt Don't override virtual functions only to forward to the base class versions. No real changes. --- include/wx/aui/barartmsw.h | 3 --- src/aui/barartmsw.cpp | 14 +++----------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/include/wx/aui/barartmsw.h b/include/wx/aui/barartmsw.h index 9e5b201a366e..6cea1bc611b7 100644 --- a/include/wx/aui/barartmsw.h +++ b/include/wx/aui/barartmsw.h @@ -76,9 +76,6 @@ class WXDLLIMPEXP_AUI wxAuiMSWToolBarArt : public wxAuiGenericToolBarArt wxWindow* wnd, const wxAuiToolBarItem& item) override; - virtual int GetElementSize(int element) override; - virtual void SetElementSize(int elementId, int size) override; - virtual int ShowDropDown(wxWindow* wnd, const wxAuiToolBarItemArray& items) override; diff --git a/src/aui/barartmsw.cpp b/src/aui/barartmsw.cpp index 0782b090b503..a894b583e74f 100644 --- a/src/aui/barartmsw.cpp +++ b/src/aui/barartmsw.cpp @@ -45,7 +45,9 @@ wxAuiMSWToolBarArt::wxAuiMSWToolBarArt() // TP_DROPDOWNBUTTON is only 7px, too small to fit the dropdown arrow, // use 14px instead. - m_dropdownSize = window->FromDIP(14); + // + // Note that this value is intentionally in DIPs. + m_dropdownSize = 14; m_buttonSize = hThemeToolbar.GetTrueSize(TP_BUTTON); } @@ -396,16 +398,6 @@ wxSize wxAuiMSWToolBarArt::GetToolSize( return wxAuiGenericToolBarArt::GetToolSize(dc, wnd, item); } -int wxAuiMSWToolBarArt::GetElementSize(int element) -{ - return wxAuiGenericToolBarArt::GetElementSize(element); -} - -void wxAuiMSWToolBarArt::SetElementSize(int elementId, int size) -{ - wxAuiGenericToolBarArt::SetElementSize(elementId, size); -} - int wxAuiMSWToolBarArt::ShowDropDown(wxWindow* wnd, const wxAuiToolBarItemArray& items) { From 0e7420fd8b25fdf7aea9e0fc4c90340a3dfc2e9d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 24 Feb 2025 17:45:24 +0100 Subject: [PATCH 11/31] Fix per-monitor DPI handling of wxAuiToolBarArt element sizes Store them in DIPs internally and apply the window-dependent scale factor when actually using them to ensure that they can have different values for windows on the monitors using different DPI. This mirrors what was done to wxAuiDockArt previously. See #25191. --- include/wx/aui/auibar.h | 6 +++ interface/wx/aui/auibar.h | 84 +++++++++++++++++++++++++++++++++++++-- src/aui/auibar.cpp | 39 ++++++++++-------- 3 files changed, 109 insertions(+), 20 deletions(-) diff --git a/include/wx/aui/auibar.h b/include/wx/aui/auibar.h index 9b25ede41db3..70a6a100f1e9 100644 --- a/include/wx/aui/auibar.h +++ b/include/wx/aui/auibar.h @@ -337,6 +337,12 @@ class WXDLLIMPEXP_AUI wxAuiToolBarArt wxWindow* wnd, const wxAuiToolBarItem& item) = 0; + // This function should be used for querying element sizes in the new code, + // as it scales them by the DPI of the provided window. GetElementSize() + // still exists (and is simpler to override), but is usually _not_ what you + // need. + virtual int GetElementSizeForWindow(int elementId, const wxWindow* window); + // Note that these functions work with the size in DIPs, not physical // pixels. virtual int GetElementSize(int elementId) = 0; diff --git a/interface/wx/aui/auibar.h b/interface/wx/aui/auibar.h index 184fdd8c231f..2a3c456465e0 100644 --- a/interface/wx/aui/auibar.h +++ b/interface/wx/aui/auibar.h @@ -547,8 +547,56 @@ class wxAuiToolBarArt wxWindow* wnd, const wxAuiToolBarItem& item) = 0; - virtual int GetElementSize(int element_id) = 0; - virtual void SetElementSize(int element_id, int size) = 0; + /** + Get the element size scaled by the DPI of the given window. + + This function should be used to get the size of the element in pixels. + + The default version delegates to GetElementSize(), override this + function if a different behaviour (e.g. to use some smarter algorithm + for scaling instead of just multiplying by the DPI factor) is needed. + + @param elementId + One of ::wxAuiToolBarArtSetting elements. + @param window + A valid window, typically wxAuiToolBar itself. + @return + The size of the element in pixels. + + @see SetElementSize() + + @since 3.3.0 + */ + virtual int GetElementSizeForWindow(int elementId, const wxWindow* window); + + /** + Returns the size of the given element in DIPs. + + This function is typically more convenient to override, as it can just + return the same value as was passed to SetElementSize(), but it + shouldn't usually be called, use GetElementSizeForWindow() instead. + + @param elementId + One of ::wxAuiToolBarArtSetting elements. + @return + The size of the element in DIPs. + */ + virtual int GetElementSize(int elementId) = 0; + + /** + Sets the size of the given element in DIPs. + + Note that this function takes the size in DPI-independent pixels and + this size will be scaled by the factor depending on the DPI being + actually used by GetElementSizeForWindow(). In particular, do _not_ use + wxWindow::FromDIP() for the @a size argument passed to this function. + + @param elementId + One of ::wxAuiToolBarArtSetting elements. + @param size + The size of the element in DIPs. + */ + virtual void SetElementSize(int elementId, int size) = 0; virtual int ShowDropDown( wxWindow* wnd, @@ -638,8 +686,24 @@ class wxAuiDefaultToolBarArt : public wxAuiToolBarArt wxWindow* wnd, const wxAuiToolBarItem& item); - virtual int GetElementSize(int element); - virtual void SetElementSize(int element_id, int size); + /** + Return the size of the element. + + Implement the base class pure virtual function by returning the default + element size or the last value passed to SetElementSize(). + */ + virtual int GetElementSize(int elementId); + + /** + Change the size of the element. + + Implements the base class pure virtual function by storing the value to + be returned by GetElementSize() and used by GetElementSizeForWindow(). + + As for the base class function, @a size is in DIPs, _not_ pixels, so + wxWindow::FromDIP() should _not_ be used for it. + */ + virtual void SetElementSize(int elementId, int size); virtual int ShowDropDown(wxWindow* wnd, const wxAuiToolBarItemArray& items); @@ -925,7 +989,19 @@ class wxAuiToolBar : public wxControl void SetToolProportion(int toolId, int proportion); int GetToolProportion(int toolId) const; + /** + Set the tool separation in DIPs. + + Please note that because this function passes @a separation to + wxAuiToolBarArt::SetElementSize() it should be given in DIPs, not in + (logical) pixels. I.e. do _not_ use wxWindow::FromDIP() for this + function argument. + */ void SetToolSeparation(int separation); + + /** + Returns the separation between tools in logical pixels. + */ int GetToolSeparation() const; void SetToolSticky(int toolId, bool sticky); diff --git a/src/aui/auibar.cpp b/src/aui/auibar.cpp index 64793f30fc97..6c76354fa2dc 100644 --- a/src/aui/auibar.cpp +++ b/src/aui/auibar.cpp @@ -130,6 +130,12 @@ wxBitmap wxAuiToolBarItem::GetCurrentBitmapFor(wxWindow* wnd) const return m_bitmap.GetBitmapFor(wnd); } +int +wxAuiToolBarArt::GetElementSizeForWindow(int elementId, const wxWindow* window) +{ + return wxWindow::FromDIP(GetElementSize(elementId), window); +} + wxAuiGenericToolBarArt::wxAuiGenericToolBarArt() { UpdateColoursFromSystem(); @@ -137,10 +143,11 @@ wxAuiGenericToolBarArt::wxAuiGenericToolBarArt() m_flags = 0; m_textOrientation = wxAUI_TBTOOL_TEXT_BOTTOM; - m_separatorSize = wxWindow::FromDIP( 7, nullptr); - m_gripperSize = wxWindow::FromDIP( 7, nullptr); - m_overflowSize = wxWindow::FromDIP(16, nullptr); - m_dropdownSize = wxWindow::FromDIP(10, nullptr); + // Note that these values are intentionally in DIPs. + m_separatorSize = 7; + m_gripperSize = 7; + m_overflowSize = 16; + m_dropdownSize = 10; m_font = *wxNORMAL_FONT; @@ -380,7 +387,7 @@ void wxAuiGenericToolBarArt::DrawDropDownButton( const wxAuiToolBarItem& item, const wxRect& rect) { - int dropdownWidth = GetElementSize(wxAUI_TBART_DROPDOWN_SIZE); + int dropdownWidth = GetElementSizeForWindow(wxAUI_TBART_DROPDOWN_SIZE, wnd); int textWidth = 0, textHeight = 0, textX = 0, textY = 0; int bmpX = 0, bmpY = 0, dropBmpX = 0, dropBmpY = 0; @@ -615,7 +622,7 @@ wxSize wxAuiGenericToolBarArt::GetToolSize( // and add some extra space in front of the drop down button if (item.HasDropDown()) { - int dropdownWidth = GetElementSize(wxAUI_TBART_DROPDOWN_SIZE); + int dropdownWidth = GetElementSizeForWindow(wxAUI_TBART_DROPDOWN_SIZE, wnd); width += dropdownWidth + wnd->FromDIP(4); } @@ -1333,7 +1340,7 @@ void wxAuiToolBar::SetToolSeparation(int separation) int wxAuiToolBar::GetToolSeparation() const { if (m_art) - return m_art->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE); + return m_art->GetElementSizeForWindow(wxAUI_TBART_SEPARATOR_SIZE, this); else return FromDIP(5); } @@ -1961,8 +1968,8 @@ wxSize wxAuiToolBar::RealizeHelper(wxReadOnlyDC& dc, wxOrientation orientation) wxBoxSizer* sizer = new wxBoxSizer(orientation); // add gripper area - int separatorSize = m_art->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE); - int gripperSize = m_art->GetElementSize(wxAUI_TBART_GRIPPER_SIZE); + int separatorSize = m_art->GetElementSizeForWindow(wxAUI_TBART_SEPARATOR_SIZE, this); + int gripperSize = m_art->GetElementSizeForWindow(wxAUI_TBART_GRIPPER_SIZE, this); if (gripperSize > 0 && m_gripperVisible) { m_gripperSizerItem = sizer->AddSpacer(gripperSize); @@ -2098,7 +2105,7 @@ wxSize wxAuiToolBar::RealizeHelper(wxReadOnlyDC& dc, wxOrientation orientation) if (m_windowStyle & wxAUI_TB_OVERFLOW) { - int overflow_size = m_art->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE); + int overflow_size = m_art->GetElementSizeForWindow(wxAUI_TBART_OVERFLOW_SIZE, this); if (overflow_size > 0 && m_overflowVisible) { m_overflowSizerItem = sizer->AddSpacer(overflow_size); @@ -2169,7 +2176,7 @@ wxRect wxAuiToolBar::GetOverflowRect() const { wxRect cli_rect(wxPoint(0,0), GetClientSize()); wxRect overflow_rect = m_overflowSizerItem->GetRect(); - int overflow_size = m_art->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE); + int overflow_size = m_art->GetElementSizeForWindow(wxAUI_TBART_OVERFLOW_SIZE, this); if (m_orientation == wxVERTICAL) { @@ -2472,8 +2479,8 @@ void wxAuiToolBar::OnPaint(wxPaintEvent& WXUNUSED(evt)) bool horizontal = m_orientation == wxHORIZONTAL; - int gripperSize = m_art->GetElementSize(wxAUI_TBART_GRIPPER_SIZE); - int overflowSize = m_art->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE); + int gripperSize = m_art->GetElementSizeForWindow(wxAUI_TBART_GRIPPER_SIZE, this); + int overflowSize = m_art->GetElementSizeForWindow(wxAUI_TBART_OVERFLOW_SIZE, this); // paint the gripper if (gripperSize > 0 && m_gripperSizerItem) @@ -2655,7 +2662,7 @@ void wxAuiToolBar::OnLeftDown(wxMouseEvent& evt) int mouse_x = evt.GetX(); wxRect rect = m_actionItem->m_sizerItem->GetRect(); - int dropdownWidth = m_art->GetElementSize(wxAUI_TBART_DROPDOWN_SIZE); + int dropdownWidth = m_art->GetElementSizeForWindow(wxAUI_TBART_DROPDOWN_SIZE, this); const bool dropDownHit = m_actionItem->m_dropDown && mouse_x >= (rect.x+rect.width-dropdownWidth) && mouse_x < (rect.x+rect.width); @@ -2765,7 +2772,7 @@ void wxAuiToolBar::OnRightDown(wxMouseEvent& evt) if (m_overflowSizerItem && m_art) { - int overflowSize = m_art->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE); + int overflowSize = m_art->GetElementSizeForWindow(wxAUI_TBART_OVERFLOW_SIZE, this); if (overflowSize > 0 && evt.m_x > cli_rect.width - overflowSize && evt.m_y >= 0 && @@ -2837,7 +2844,7 @@ void wxAuiToolBar::OnMiddleDown(wxMouseEvent& evt) if (m_overflowSizerItem && m_art) { - int overflowSize = m_art->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE); + int overflowSize = m_art->GetElementSizeForWindow(wxAUI_TBART_OVERFLOW_SIZE, this); if (overflowSize > 0 && evt.m_x > cli_rect.width - overflowSize && evt.m_y >= 0 && From 26d2a667b3d52345f90bacc3b38ecbf70eb9fc0b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 24 Feb 2025 18:07:11 +0100 Subject: [PATCH 12/31] Remove mnemonics from page text in wxChoicebook and wxListbook Do it for consistency with the other wxBookCtrl-derived classes. Document this behaviour. --- docs/changes.txt | 4 ++++ interface/wx/bookctrl.h | 10 ++++++++-- src/generic/choicbkg.cpp | 4 ++-- src/generic/listbkg.cpp | 4 ++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 3ffbd29f8aa6..f3a08c9d9bff 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -127,6 +127,10 @@ Changes in behaviour not resulting in compilation errors the page on screen, which doesn't make sense without reference to the tab control containing it, use GetPagePosition() to retrieve both of them. +- wxListbook and wxChoicebook now interpret (but ignore) mnemonics in their + page titles, just as the other wx*book classes already did. Double "&" + in the page text if it should be interpreted as a literal "&". + Changes in behaviour which may result in build errors ----------------------------------------------------- diff --git a/interface/wx/bookctrl.h b/interface/wx/bookctrl.h index 739609049b65..75248b64700a 100644 --- a/interface/wx/bookctrl.h +++ b/interface/wx/bookctrl.h @@ -139,6 +139,10 @@ class wxBookCtrlBase : public wxControl, public wxWithImages /** Sets the text for the given page. + + The text may contain mnemonics, i.e. accelerator characters preceded by + the ampersand (`&`) character. If you need to include a literal + ampersand in the text, you need to double it, i.e. use `&&`. */ virtual bool SetPageText(size_t page, const wxString& text) = 0; ///@} @@ -257,7 +261,8 @@ class wxBookCtrlBase : public wxControl, public wxWithImages @param page Specifies the new page. @param text - Specifies the text for the new page. + Specifies the text of the new page. Note that it may contain + mnemonic characters, see SetPageText() for more information. @param select Specifies whether the page should be selected. @param imageId @@ -297,7 +302,8 @@ class wxBookCtrlBase : public wxControl, public wxWithImages @param page Specifies the new page. @param text - Specifies the text for the new page. + Specifies the text of the new page. Note that it may contain + mnemonic characters, see SetPageText() for more information. @param select Specifies whether the page should be selected. @param imageId diff --git a/src/generic/choicbkg.cpp b/src/generic/choicbkg.cpp index 8400fc1e3191..6d02c1848aaa 100644 --- a/src/generic/choicbkg.cpp +++ b/src/generic/choicbkg.cpp @@ -106,7 +106,7 @@ wxChoicebook::Create(wxWindow *parent, bool wxChoicebook::SetPageText(size_t n, const wxString& strText) { - GetChoiceCtrl()->SetString(n, strText); + GetChoiceCtrl()->SetString(n, RemoveMnemonics(strText)); return true; } @@ -178,7 +178,7 @@ wxChoicebook::InsertPage(size_t n, if ( !wxBookCtrlBase::InsertPage(n, page, text, bSelect, imageId) ) return false; - GetChoiceCtrl()->Insert(text, n); + GetChoiceCtrl()->Insert(RemoveMnemonics(text), n); // if the inserted page is before the selected one, we must update the // index of the selected page diff --git a/src/generic/listbkg.cpp b/src/generic/listbkg.cpp index 22891be71125..ea146dbc5dba 100644 --- a/src/generic/listbkg.cpp +++ b/src/generic/listbkg.cpp @@ -219,7 +219,7 @@ void wxListbook::UpdateSize() bool wxListbook::SetPageText(size_t n, const wxString& strText) { - GetListView()->SetItemText(n, strText); + GetListView()->SetItemText(n, RemoveMnemonics(strText)); return true; } @@ -320,7 +320,7 @@ wxListbook::InsertPage(size_t n, if ( !wxBookCtrlBase::InsertPage(n, page, text, bSelect, imageId) ) return false; - GetListView()->InsertItem(n, text, imageId); + GetListView()->InsertItem(n, RemoveMnemonics(text), imageId); // if the inserted page is before the selected one, we must update the // index of the selected page From 59b1fafe1a4705dd849bf59f9b09b88d7ab6b99b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 24 Feb 2025 16:35:17 +0100 Subject: [PATCH 13/31] Update wxBookCtrl unit test to cover mnemonics in page text This passes now, after the recent changes. Also update the sample to use a mnemonic for one of the pages to be able to check that it appears correctly visually too. --- samples/notebook/notebook.h | 2 +- tests/controls/bookctrlbasetest.cpp | 11 +++++++++-- tests/controls/bookctrlbasetest.h | 4 ++++ tests/controls/choicebooktest.cpp | 2 ++ tests/controls/listbooktest.cpp | 2 ++ 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/samples/notebook/notebook.h b/samples/notebook/notebook.h index 9ee628c5bab3..763e85583edb 100644 --- a/samples/notebook/notebook.h +++ b/samples/notebook/notebook.h @@ -187,7 +187,7 @@ enum ID_COMMANDS */ #define I_WAS_INSERTED_PAGE_NAME "Inserted" -#define RADIOBUTTONS_PAGE_NAME "Radiobuttons" +#define RADIOBUTTONS_PAGE_NAME "Radio &buttons" #define VETO_PAGE_NAME "Veto" #define TEXT_PAGE_NAME "Text" diff --git a/tests/controls/bookctrlbasetest.cpp b/tests/controls/bookctrlbasetest.cpp index c4930130924a..cd06fd2da67e 100644 --- a/tests/controls/bookctrlbasetest.cpp +++ b/tests/controls/bookctrlbasetest.cpp @@ -40,7 +40,7 @@ void BookCtrlBaseTestCase::AddPanels() m_panel2 = new wxPanel(base); m_panel3 = new wxPanel(base); - base->AddPage(m_panel1, "Panel 1", false, 0); + base->AddPage(m_panel1, "Panel &1", false, 0); base->AddPage(m_panel2, "Panel 2", false, 1); base->AddPage(m_panel3, "Panel 3", false, 2); } @@ -74,7 +74,8 @@ void BookCtrlBaseTestCase::Text() { wxBookCtrlBase * const base = GetBase(); - CPPUNIT_ASSERT_EQUAL("Panel 1", base->GetPageText(0)); + const wxString expected(HasBrokenMnemonics() ? "Panel 1" : "Panel &1"); + CPPUNIT_ASSERT_EQUAL(expected, base->GetPageText(0)); base->SetPageText(1, "Some other string"); @@ -83,6 +84,12 @@ void BookCtrlBaseTestCase::Text() base->SetPageText(2, "string with\nline break"); CPPUNIT_ASSERT_EQUAL("string with\nline break", base->GetPageText(2)); + + if ( !HasBrokenMnemonics() ) + { + base->SetPageText(0, "With &mnemonic"); + CPPUNIT_ASSERT_EQUAL("With &mnemonic", base->GetPageText(0)); + } } void BookCtrlBaseTestCase::PageManagement() diff --git a/tests/controls/bookctrlbasetest.h b/tests/controls/bookctrlbasetest.h index 6fb3ed1476d8..07e07f034e72 100644 --- a/tests/controls/bookctrlbasetest.h +++ b/tests/controls/bookctrlbasetest.h @@ -26,6 +26,10 @@ class BookCtrlBaseTestCase virtual wxEventType GetChangingEvent() const = 0; + // Some wxBookCtrlBase-derived classes strip mnemonics and don't return + // them from their GetPageText(), allow them to just return true from here. + virtual bool HasBrokenMnemonics() const { return false; } + // this should be inserted in the derived class CPPUNIT_TEST_SUITE // definition to run all wxBookCtrlBase tests as part of it #define wxBOOK_CTRL_BASE_TESTS() \ diff --git a/tests/controls/choicebooktest.cpp b/tests/controls/choicebooktest.cpp index 7bf72a3d622b..c7866cd031d2 100644 --- a/tests/controls/choicebooktest.cpp +++ b/tests/controls/choicebooktest.cpp @@ -36,6 +36,8 @@ class ChoicebookTestCase : public BookCtrlBaseTestCase, public CppUnit::TestCase virtual wxEventType GetChangingEvent() const override { return wxEVT_CHOICEBOOK_PAGE_CHANGING; } + virtual bool HasBrokenMnemonics() const override { return true; } + CPPUNIT_TEST_SUITE( ChoicebookTestCase ); wxBOOK_CTRL_BASE_TESTS(); CPPUNIT_TEST( Choice ); diff --git a/tests/controls/listbooktest.cpp b/tests/controls/listbooktest.cpp index e8a8ddb1e5cc..c9c7e22a1ae8 100644 --- a/tests/controls/listbooktest.cpp +++ b/tests/controls/listbooktest.cpp @@ -37,6 +37,8 @@ class ListbookTestCase : public BookCtrlBaseTestCase, public CppUnit::TestCase virtual wxEventType GetChangingEvent() const override { return wxEVT_LISTBOOK_PAGE_CHANGING; } + virtual bool HasBrokenMnemonics() const override { return true; } + CPPUNIT_TEST_SUITE( ListbookTestCase ); wxBOOK_CTRL_BASE_TESTS(); CPPUNIT_TEST( ListView ); From 380cf411bc7c1e5b3ec82d01656d3ec61e50bf49 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 25 Feb 2025 15:02:06 +0100 Subject: [PATCH 14/31] Ignore unknown events read from IOCP in wxMSW wxFileSystemWatcher We can get events with unknown (and, arguably, invalid) values, at least when using Samba, so don't assert if this happens but just ignore them. This extends the changes of 83c75a439d (Ignore invalid file notification events, 2020-10-30) to cover all unknown events and not just those with "Action" field set to 0. Closes #18953. --- src/msw/fswatcher.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/msw/fswatcher.cpp b/src/msw/fswatcher.cpp index 11fd4a9652f0..6d14014f5d30 100644 --- a/src/msw/fswatcher.cpp +++ b/src/msw/fswatcher.cpp @@ -387,8 +387,6 @@ int wxIOCPThread::Native2WatcherFlags(int flags) // ignored as it should always be matched with ***_OLD_NAME { FILE_ACTION_RENAMED_NEW_NAME, 0 }, - // ignore invalid event - { 0, 0 }, }; for (unsigned int i=0; i < WXSIZEOF(flag_mapping); ++i) { @@ -396,9 +394,9 @@ int wxIOCPThread::Native2WatcherFlags(int flags) return flag_mapping[i][1]; } - // never reached - wxFAIL_MSG(wxString::Format("Unknown file notify change %u", flags)); - return -1; + // We can get unknown values here, see #18953, just ignore them because we + // don't know what else to do with them. + return 0; } wxString wxIOCPThread::FileNotifyInformationToString( From 3754077d923390ad5b5531147eca8d92be7b3675 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 25 Feb 2025 15:06:34 +0100 Subject: [PATCH 15/31] Minor cleanup in wxMSW wxFileSystemWatcher code Get rid of an unnecessary temporary variable, make another local variable const. No real changes. --- src/msw/fswatcher.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/msw/fswatcher.cpp b/src/msw/fswatcher.cpp index 6d14014f5d30..772bf95784c0 100644 --- a/src/msw/fswatcher.cpp +++ b/src/msw/fswatcher.cpp @@ -319,8 +319,7 @@ void wxIOCPThread::ProcessNativeEvents(wxVector& events) wxLogTrace( wxTRACE_FSWATCHER, "[iocp] %s", FileNotifyInformationToString(e)); - int nativeFlags = e.Action; - int flags = Native2WatcherFlags(nativeFlags); + const int flags = Native2WatcherFlags(e.Action); if (flags & wxFSW_EVENT_WARNING || flags & wxFSW_EVENT_ERROR) { wxFileSystemWatcherEvent @@ -336,7 +335,7 @@ void wxIOCPThread::ProcessNativeEvents(wxVector& events) return; } // rename case - else if (nativeFlags == FILE_ACTION_RENAMED_OLD_NAME) + else if (e.Action == FILE_ACTION_RENAMED_OLD_NAME) { wxFileName oldpath = GetEventPath(*watch, e); wxFileName newpath; From 55d8e8d49bdbd9f06185dfad9ff790e50e7bd521 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 25 Feb 2025 15:08:04 +0100 Subject: [PATCH 16/31] Remove code that couldn't be executed from wxFileSystemWatcher The return value of Native2WatcherFlags() never includes wxFSW_EVENT_WARNING or wxFSW_EVENT_ERROR, so don't test for them. Also don't compare flags with 0 needlessly as the other half of comparison catches this case too. No changes in behaviour. --- src/msw/fswatcher.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/msw/fswatcher.cpp b/src/msw/fswatcher.cpp index 772bf95784c0..1e3dc8ba658b 100644 --- a/src/msw/fswatcher.cpp +++ b/src/msw/fswatcher.cpp @@ -320,17 +320,8 @@ void wxIOCPThread::ProcessNativeEvents(wxVector& events) FileNotifyInformationToString(e)); const int flags = Native2WatcherFlags(e.Action); - if (flags & wxFSW_EVENT_WARNING || flags & wxFSW_EVENT_ERROR) - { - wxFileSystemWatcherEvent - event(flags, - flags & wxFSW_EVENT_ERROR ? wxFSW_WARNING_NONE - : wxFSW_WARNING_GENERAL); - SendEvent(event); - } - // filter out ignored events and those not asked for. - // we never filter out warnings or exceptions - else if ((flags == 0) || !(flags & watch->GetFlags())) + // filter out ignored events (with flags == 0) and those not asked for. + if (!(flags & watch->GetFlags())) { return; } From ef8508a989ee39b6fc7eaa90ed737ee24230ea5a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 25 Feb 2025 15:10:20 +0100 Subject: [PATCH 17/31] Don't use "else" after "return" No real changes, just another bit of minor cleanup in MSW wxFileSystemWatcher code. --- src/msw/fswatcher.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/msw/fswatcher.cpp b/src/msw/fswatcher.cpp index 1e3dc8ba658b..3db4632204c6 100644 --- a/src/msw/fswatcher.cpp +++ b/src/msw/fswatcher.cpp @@ -325,8 +325,9 @@ void wxIOCPThread::ProcessNativeEvents(wxVector& events) { return; } + // rename case - else if (e.Action == FILE_ACTION_RENAMED_OLD_NAME) + if (e.Action == FILE_ACTION_RENAMED_OLD_NAME) { wxFileName oldpath = GetEventPath(*watch, e); wxFileName newpath; From f5d238a7d162eff187cc0a3cacd5a7c9c3916dca Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 21 Feb 2025 01:33:18 +0100 Subject: [PATCH 18/31] Serialize and restore wxAUI pane visibility too Panes may be hidden by user, so it makes sense to store their visibility as part of the serialized representation to be able to restore the same visual layout later. See #25186. --- include/wx/aui/serializer.h | 11 ++++++++--- interface/wx/aui/serializer.h | 8 ++++++-- samples/aui/auidemo.cpp | 8 ++++++++ src/aui/framemanager.cpp | 2 ++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/include/wx/aui/serializer.h b/include/wx/aui/serializer.h index cacc5e2733af..a19aae6891b9 100644 --- a/include/wx/aui/serializer.h +++ b/include/wx/aui/serializer.h @@ -65,11 +65,16 @@ struct wxAuiPaneLayoutInfo : wxAuiDockLayoutInfo wxSize floating_size = wxDefaultSize; + // The remaining fields correspond to individual bits of the pane state + // flags instead of corresponding to wxAuiPaneInfo fields directly because + // we prefer not storing the entire state -- this would be less readable + // and extensible. + // True if the pane is currently maximized. - // - // Note that it's the only field of this struct which doesn't directly - // correspond to a field of wxAuiPaneInfo. bool is_maximized = false; + + // True if the pane is currently hidden. + bool is_hidden = false; }; // wxAuiBookSerializer is used for serializing wxAuiNotebook layout. diff --git a/interface/wx/aui/serializer.h b/interface/wx/aui/serializer.h index a8c0d248d3f3..c5fb652a966c 100644 --- a/interface/wx/aui/serializer.h +++ b/interface/wx/aui/serializer.h @@ -67,8 +67,9 @@ struct wxAuiTabLayoutInfo : wxAuiDockLayoutInfo This struct is used with wxAuiSerializer and wxAuiDeserializer to store the pane layout. Its fields, including the inherited ones from wxAuiDockLayoutInfo, have the same meaning as the corresponding fields in - wxAuiPaneInfo (with the exception of `is_maximized`), but it doesn't - contain the fields that it wouldn't make sense to serialize. + wxAuiPaneInfo (with the exception of `is_maximized` and `is_hidden`, which + rather correspond to the individual bits of its state field), but it + doesn't contain the fields that it wouldn't make sense to serialize. @since 3.3.0 */ @@ -91,6 +92,9 @@ struct wxAuiPaneLayoutInfo : wxAuiDockLayoutInfo /// True if the pane is currently maximized. bool is_maximized = false; + + /// True if the pane is currently hidden. + bool is_hidden = false; }; /** diff --git a/samples/aui/auidemo.cpp b/samples/aui/auidemo.cpp index 0ec6adb27724..beb1bde10394 100644 --- a/samples/aui/auidemo.cpp +++ b/samples/aui/auidemo.cpp @@ -1587,6 +1587,10 @@ class MyXmlSerializer : public wxAuiSerializer if ( pane.is_maximized ) AddChild(node, "maximized", 1); + // Also don't mark visible pages (as most of them are) as being so. + if ( pane.is_hidden ) + AddChild(node, "hidden", 1); + m_panes->AddChild(node); } @@ -1779,6 +1783,10 @@ class MyXmlDeserializer : public wxAuiDeserializer { pane.is_maximized = GetInt(content) != 0; } + else if ( name == "hidden" ) + { + pane.is_hidden = GetInt(content) != 0; + } else { throw std::runtime_error("Unexpected pane child node name"); diff --git a/src/aui/framemanager.cpp b/src/aui/framemanager.cpp index f4d91503cf45..71d7544a5554 100644 --- a/src/aui/framemanager.cpp +++ b/src/aui/framemanager.cpp @@ -1438,6 +1438,7 @@ wxAuiManager::CopyLayoutFrom(wxAuiPaneLayoutInfo& layoutInfo, layoutInfo.floating_size = pane.floating_size; layoutInfo.is_maximized = pane.HasFlag(wxAuiPaneInfo::optionMaximized); + layoutInfo.is_hidden = pane.HasFlag(wxAuiPaneInfo::optionHidden); } void @@ -1450,6 +1451,7 @@ wxAuiManager::CopyLayoutTo(const wxAuiPaneLayoutInfo& layoutInfo, pane.floating_size = layoutInfo.floating_size; pane.SetFlag(wxAuiPaneInfo::optionMaximized, layoutInfo.is_maximized); + pane.SetFlag(wxAuiPaneInfo::optionHidden, layoutInfo.is_hidden); } void wxAuiManager::SaveLayout(wxAuiSerializer& serializer) const From cc42b23b1d8e7fa76fa619e2589f13f3d3b3e780 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Wed, 26 Feb 2025 16:58:18 -0800 Subject: [PATCH 19/31] Avoid shadowed-variable warnings --- src/common/webrequest_curl.cpp | 4 ++-- src/generic/buttonbar.cpp | 8 ++++---- src/gtk/bitmap.cpp | 4 ++-- src/gtk/dataview.cpp | 4 ++-- src/osx/carbon/dcprint.cpp | 6 +++--- src/osx/combobox_osx.cpp | 14 +++++++------- src/osx/core/bitmap.cpp | 2 +- src/osx/textctrl_osx.cpp | 14 +++++++------- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/common/webrequest_curl.cpp b/src/common/webrequest_curl.cpp index adba405fc4bb..3c475c4a1f4e 100644 --- a/src/common/webrequest_curl.cpp +++ b/src/common/webrequest_curl.cpp @@ -1026,9 +1026,9 @@ void SourceSocketPoller::SendEvent(curl_socket_t sock, int result) { // Check if we have any sockets to clean up and do it now, it should be // safe. - for ( auto sock : m_socketsToCleanUp ) + for ( auto sck : m_socketsToCleanUp ) { - StopPolling(sock); + StopPolling(sck); } m_socketsToCleanUp.clear(); diff --git a/src/generic/buttonbar.cpp b/src/generic/buttonbar.cpp index dfca3fe452e4..d4d46b180a31 100644 --- a/src/generic/buttonbar.cpp +++ b/src/generic/buttonbar.cpp @@ -543,10 +543,10 @@ void wxButtonToolBar::OnLeftUp(wxMouseEvent& event) wxButtonToolBarTool* tool = (wxButtonToolBarTool*) FindToolForPosition(event.GetX(), event.GetY()); if (tool && tool->GetButton() && (event.GetY() > (tool->m_y + tool->GetButton()->GetSize().y))) { - wxCommandEvent event(wxEVT_BUTTON, tool->GetId()); - event.SetEventObject(tool->GetButton()); - if (!GetEventHandler()->ProcessEvent(event)) - event.Skip(); + wxCommandEvent evt(wxEVT_BUTTON, tool->GetId()); + evt.SetEventObject(tool->GetButton()); + if (!GetEventHandler()->ProcessEvent(evt)) + evt.Skip(); } } } diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index 5f82496ed285..1a14d4c9129b 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -757,12 +757,12 @@ bool wxBitmap::CreateFromImageAsPixbuf(const wxImage& image) if ( image.HasMask() ) { const size_t out_size = size_t((width + 7) / 8) * unsigned(height); - wxByte* out = new wxByte[out_size]; + out = new wxByte[out_size]; memset(out, 0xff, out_size); const wxByte r_mask = image.GetMaskRed(); const wxByte g_mask = image.GetMaskGreen(); const wxByte b_mask = image.GetMaskBlue(); - const wxByte* in = image.GetData(); + in = image.GetData(); unsigned bit_index = 0; for (int y = 0; y < height; y++) { diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 8a901e88cf88..4e41c4fa570b 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -4354,12 +4354,12 @@ wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( const wxDataViewItem &item } wxGtkTreeModelNode * node = m_root; - for ( const auto& item : list ) + for ( const auto& itm : list ) { wxGtkTreeModelNode* next = nullptr; for (auto child : node->GetNodes()) { - if (child->GetItem() == item) + if (child->GetItem() == itm) { next = child; break; diff --git a/src/osx/carbon/dcprint.cpp b/src/osx/carbon/dcprint.cpp index 2b50d799ec14..3dc808fcc9c0 100644 --- a/src/osx/carbon/dcprint.cpp +++ b/src/osx/carbon/dcprint.cpp @@ -307,9 +307,9 @@ bool wxPrinterDCImpl::StartDoc( const wxString& message ) m_ok = m_nativePrinterDC->IsOk() ; if ( !m_ok ) { - wxString message ; - message.Printf( wxT("Print Error %u"), m_nativePrinterDC->GetStatus() ) ; - wxMessageDialog dialog( nullptr , message , wxEmptyString, wxICON_HAND | wxOK) ; + wxString msg; + msg.Printf("Print Error %u", m_nativePrinterDC->GetStatus()); + wxMessageDialog dialog(nullptr, msg, wxString(), wxICON_HAND | wxOK); dialog.ShowModal(); } diff --git a/src/osx/combobox_osx.cpp b/src/osx/combobox_osx.cpp index 2fc1b35da5e8..96d40380d824 100644 --- a/src/osx/combobox_osx.cpp +++ b/src/osx/combobox_osx.cpp @@ -260,10 +260,10 @@ void wxComboBox::OnChar(wxKeyEvent& event) case WXK_NUMPAD_ENTER: if (m_windowStyle & wxTE_PROCESS_ENTER) { - wxCommandEvent event(wxEVT_TEXT_ENTER, m_windowId); - event.SetEventObject(this); - event.SetString(GetValue()); - if (HandleWindowEvent(event)) + wxCommandEvent evt(wxEVT_TEXT_ENTER, m_windowId); + evt.SetEventObject(this); + evt.SetString(GetValue()); + if (HandleWindowEvent(evt)) return; } @@ -274,9 +274,9 @@ void wxComboBox::OnChar(wxKeyEvent& event) wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton); if (def && def->IsEnabled()) { - wxCommandEvent event(wxEVT_BUTTON, def->GetId()); - event.SetEventObject(def); - def->Command(event); + wxCommandEvent evt(wxEVT_BUTTON, def->GetId()); + evt.SetEventObject(def); + def->Command(evt); return; } } diff --git a/src/osx/core/bitmap.cpp b/src/osx/core/bitmap.cpp index 7b21bc189343..a696714196b9 100644 --- a/src/osx/core/bitmap.cpp +++ b/src/osx/core/bitmap.cpp @@ -1198,7 +1198,7 @@ void wxBitmap::InitFromImage(const wxImage& image, int depth, double scale) y++) { unsigned char * destination = destinationRowStart; - unsigned char * destinationMask = destinationMaskRowStart; + destinationMask = destinationMaskRowStart; for (int x = 0; x < width; x++) { if ( hasMask ) diff --git a/src/osx/textctrl_osx.cpp b/src/osx/textctrl_osx.cpp index 463f6fd620a5..3f455a3deb49 100644 --- a/src/osx/textctrl_osx.cpp +++ b/src/osx/textctrl_osx.cpp @@ -471,10 +471,10 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) case WXK_NUMPAD_ENTER: if (m_windowStyle & wxTE_PROCESS_ENTER) { - wxCommandEvent event(wxEVT_TEXT_ENTER, m_windowId); - event.SetEventObject( this ); - event.SetString( GetValue() ); - if ( HandleWindowEvent(event) ) + wxCommandEvent evt(wxEVT_TEXT_ENTER, m_windowId); + evt.SetEventObject(this); + evt.SetString(GetValue()); + if (HandleWindowEvent(evt)) return; } @@ -486,9 +486,9 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton); if ( def && def->IsEnabled() ) { - wxCommandEvent event(wxEVT_BUTTON, def->GetId() ); - event.SetEventObject(def); - def->Command(event); + wxCommandEvent evt(wxEVT_BUTTON, def->GetId()); + evt.SetEventObject(def); + def->Command(evt); return ; } From 889d458e45a4b16e086886999b6c2c7cb01421fd Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Wed, 26 Feb 2025 17:01:43 -0800 Subject: [PATCH 20/31] Suppress some -Wunused-member-function warnings --- include/wx/hashmap.h | 4 +++- include/wx/unix/private/uilocale.h | 2 ++ src/common/quantize.cpp | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/wx/hashmap.h b/include/wx/hashmap.h index d32466dd1566..a58faa3742b4 100644 --- a/include/wx/hashmap.h +++ b/include/wx/hashmap.h @@ -569,6 +569,7 @@ struct WXDLLIMPEXP_BASE wxStringEqual #define wxPTROP_NOP(pointer) #define _WX_DECLARE_HASH_MAP( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP ) \ +wxCLANG_WARNING_SUPPRESS(unused-member-function) \ _WX_DECLARE_PAIR( KEY_T, VALUE_T, CLASSNAME##_wxImplementation_Pair, CLASSEXP ) \ _WX_DECLARE_HASH_MAP_KEY_EX( KEY_T, CLASSNAME##_wxImplementation_Pair, CLASSNAME##_wxImplementation_KeyEx, CLASSEXP ) \ _WX_DECLARE_HASHTABLE( CLASSNAME##_wxImplementation_Pair, KEY_T, HASH_T, \ @@ -621,7 +622,8 @@ public: \ { \ return GetNode( key ) ? 1u : 0u; \ } \ -} +} \ +wxCLANG_WARNING_RESTORE(unused-member-function) #endif // wxNEEDS_WX_HASH_MAP diff --git a/include/wx/unix/private/uilocale.h b/include/wx/unix/private/uilocale.h index 10e6b3a90fd7..6accc495c518 100644 --- a/include/wx/unix/private/uilocale.h +++ b/include/wx/unix/private/uilocale.h @@ -41,6 +41,7 @@ namespace class TempLocaleSetter { public: + wxCLANG_WARNING_SUPPRESS(unused-member-function) explicit TempLocaleSetter(int localeCategory, const wxString& localeId = wxString()) : m_localeCategory(localeCategory), @@ -54,6 +55,7 @@ class TempLocaleSetter setlocale(m_localeCategory, m_localeOrig); free(m_localeOrig); } + wxCLANG_WARNING_RESTORE(unused-member-function) private: const int m_localeCategory; diff --git a/src/common/quantize.cpp b/src/common/quantize.cpp index bce83e102f77..89d3f481db12 100644 --- a/src/common/quantize.cpp +++ b/src/common/quantize.cpp @@ -83,12 +83,14 @@ typedef struct { typedef j_decompress *j_decompress_ptr; struct jpeg_color_quantizer { + wxCLANG_WARNING_SUPPRESS(unused-member-function) JMETHOD(void, start_pass, (j_decompress_ptr cinfo, bool is_pre_scan)); JMETHOD(void, color_quantize, (j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)); JMETHOD(void, finish_pass, (j_decompress_ptr cinfo)); JMETHOD(void, new_color_map, (j_decompress_ptr cinfo)); + wxCLANG_WARNING_RESTORE(unused-member-function) }; From 28a499a891eda231bc0996e8d754558202e4c0dd Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Wed, 26 Feb 2025 17:06:07 -0800 Subject: [PATCH 21/31] Use g_object_set() to avoid deprecated gtk_settings_set_long_property() --- src/gtk/tooltip.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/gtk/tooltip.cpp b/src/gtk/tooltip.cpp index 20555e18171a..4d9f716771c5 100644 --- a/src/gtk/tooltip.cpp +++ b/src/gtk/tooltip.cpp @@ -80,10 +80,8 @@ void wxToolTip::Enable( bool flag ) if (wx_is_at_least_gtk2(12)) { GtkSettings* settings = gtk_settings_get_default(); - wxGCC_WARNING_SUPPRESS(deprecated-declarations) if (settings) - gtk_settings_set_long_property(settings, "gtk-enable-tooltips", flag, nullptr); - wxGCC_WARNING_RESTORE() + g_object_set(settings, "gtk-enable-tooltips", flag, nullptr); } else #endif @@ -110,10 +108,8 @@ void wxToolTip::SetDelay( long msecs ) if (wx_is_at_least_gtk2(12)) { GtkSettings* settings = gtk_settings_get_default(); - wxGCC_WARNING_SUPPRESS(deprecated-declarations) if (settings) - gtk_settings_set_long_property(settings, "gtk-tooltip-timeout", msecs, nullptr); - wxGCC_WARNING_RESTORE() + g_object_set(settings, "gtk-tooltip-timeout", int(msecs), nullptr); } else #endif From 0f7652cede4a4609fd0ec5f5fc854cefcdd260e0 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Wed, 26 Feb 2025 17:16:12 -0800 Subject: [PATCH 22/31] Avoid some -Wcomma warnings --- src/msw/volume.cpp | 13 ++++++------- src/qt/treectrl.cpp | 13 ++++--------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/msw/volume.cpp b/src/msw/volume.cpp index 05f834a00927..5b4f14ca685c 100644 --- a/src/msw/volume.cpp +++ b/src/msw/volume.cpp @@ -235,7 +235,6 @@ static void BuildListFromNN(wxArrayString& list, NETRESOURCE* pResSrc, unsigned flagsSet, unsigned flagsUnset) { HANDLE hEnum; - int rc; //----------------------------------------------- // Scope may be all drives or all mounted drives. @@ -249,13 +248,14 @@ static void BuildListFromNN(wxArrayString& list, NETRESOURCE* pResSrc, // Containers cause a recursive call to this function for their own // enumeration. //---------------------------------------------------------------------- - if (rc = s_pWNetOpenEnum(scope, RESOURCETYPE_DISK, 0, pResSrc, &hEnum), rc == NO_ERROR) + if (s_pWNetOpenEnum(scope, RESOURCETYPE_DISK, 0, pResSrc, &hEnum) == NO_ERROR) { DWORD count = 1; DWORD size = 256; NETRESOURCE* pRes = (NETRESOURCE*)malloc(size); memset(pRes, 0, sizeof(NETRESOURCE)); - while (rc = s_pWNetEnumResource(hEnum, &count, pRes, &size), rc == NO_ERROR || rc == ERROR_MORE_DATA) + int rc; + while ((rc = s_pWNetEnumResource(hEnum, &count, pRes, &size)) == NO_ERROR || rc == ERROR_MORE_DATA) { if (s_cancelSearch) break; @@ -366,9 +366,8 @@ static bool BuildRemoteList(wxArrayString& list, NETRESOURCE* pResSrc, { int compare; - while (compare = - wxStricmp(list[iList].c_str(), mounted[iMounted].c_str()), - compare > 0 && iList >= 0) + while ((compare = wxStricmp(list[iList].c_str(), mounted[iMounted].c_str())) > 0 + && iList >= 0) { iList--; } @@ -447,7 +446,7 @@ wxArrayString wxFSVolumeBase::GetVolumes(int flagsSet, int flagsUnset) // The returned list will be sorted alphabetically. We don't pass // our in since we don't want to change to order of the local drives. wxArrayString nn; - if (BuildRemoteList(nn, 0, flagsSet, flagsUnset)) + if (BuildRemoteList(nn, nullptr, flagsSet, flagsUnset)) { for (size_t idx = 0; idx < nn.GetCount(); idx++) list.Add(nn[idx]); diff --git a/src/qt/treectrl.cpp b/src/qt/treectrl.cpp index 510b75a61c57..5a09ff5b3d34 100644 --- a/src/qt/treectrl.cpp +++ b/src/qt/treectrl.cpp @@ -1131,15 +1131,10 @@ wxTreeItemId wxTreeCtrl::GetNextVisible(const wxTreeItemId& item) const wxASSERT_MSG(IsVisible(item), "this item itself should be visible"); wxTreeItemId id = item; - if ( id.IsOk() ) - { - while ( id = GetNext(id), id.IsOk() ) - { - if ( IsVisible(id) ) - return id; - } - } - return wxTreeItemId(); + do + id = GetNext(id); + while (id.IsOk() && !IsVisible(id)); + return id; } wxTreeItemId wxTreeCtrl::GetPrevVisible(const wxTreeItemId& item) const From 77eaa7a5abed70cf86d96a6ee17ef23904f8ec8e Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Wed, 26 Feb 2025 17:18:59 -0800 Subject: [PATCH 23/31] Remove unused member variable --- src/qt/textentry.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/qt/textentry.cpp b/src/qt/textentry.cpp index ae3752b714c0..f38f3695303c 100644 --- a/src/qt/textentry.cpp +++ b/src/qt/textentry.cpp @@ -176,8 +176,7 @@ class wxTextAutoCompleteData // The constructor associates us with the given text entry. explicit wxTextAutoCompleteData(wxTextEntry* entry, CompleterType type = CompleterType::StringCompleter) - : m_entry(entry), - m_win(entry->GetEditableWindow()) + : m_win(entry->GetEditableWindow()) { if ( m_win ) { @@ -314,9 +313,6 @@ class wxTextAutoCompleteData event.Skip(); } - // The text entry we're associated with. - wxTextEntry* const m_entry; - // The window of this text entry. wxWindow* const m_win; From abdc4935e5de5bc3977e1bb0e886af8bb9581603 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Wed, 26 Feb 2025 17:24:07 -0800 Subject: [PATCH 24/31] Avoid -Wdeprecated-this-capture warning --- src/qt/treectrl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/treectrl.cpp b/src/qt/treectrl.cpp index 5a09ff5b3d34..51f9b52475f3 100644 --- a/src/qt/treectrl.cpp +++ b/src/qt/treectrl.cpp @@ -453,7 +453,7 @@ class wxQTreeWidget : public wxQtEventSignalHandler // QT doesn't update the selection until this signal has been processed. // Deferring this event ensures that wxTreeCtrl::GetSelections() returns // the new selection in the wx event handler. - GetHandler()->CallAfter([=]() + GetHandler()->CallAfter([this]() { EmitSelectChangeEvent(wxEVT_TREE_SEL_CHANGED); }); From 025413543743daed27f29e2b6446ab8ec74ced11 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Thu, 27 Feb 2025 16:42:13 -0800 Subject: [PATCH 25/31] Avoid -Wunused-member-function warnings --- src/common/datavcmn.cpp | 4 +++- src/generic/preferencesg.cpp | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index b5580d432106..98a1edcc5513 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -52,11 +52,13 @@ class wxDataViewEditorCtrlEvtHandler: public wxEvtHandler { m_editorCtrl = editor; m_owner = owner; - m_finished = false; + m_focusOnIdle = false; } +#if defined(__WXGTK__) && !defined(wxHAS_GENERIC_DATAVIEWCTRL) void SetFocusOnIdle( bool focus = true ) { m_focusOnIdle = focus; } +#endif protected: void OnChar( wxKeyEvent &event ); diff --git a/src/generic/preferencesg.cpp b/src/generic/preferencesg.cpp index 77a548672834..895070b5239b 100644 --- a/src/generic/preferencesg.cpp +++ b/src/generic/preferencesg.cpp @@ -67,6 +67,7 @@ class wxGenericPrefsDialog : public wxDialog m_notebook->AddPage(win, page->GetName()); } +#ifndef wxHAS_PREF_EDITOR_MODELESS int GetSelectedPage() const { return m_notebook->GetSelection(); @@ -76,6 +77,7 @@ class wxGenericPrefsDialog : public wxDialog { m_notebook->ChangeSelection(page); } +#endif // !wxHAS_PREF_EDITOR_MODELESS bool ShouldPreventAppExit() const override { From 7c909d47d5f869551fca7f896a90536cd99384d9 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Thu, 27 Feb 2025 16:45:16 -0800 Subject: [PATCH 26/31] Avoid -Wunused-template warnings --- src/common/wxcrt.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/common/wxcrt.cpp b/src/common/wxcrt.cpp index 3c319b0c6f95..087a228257e4 100644 --- a/src/common/wxcrt.cpp +++ b/src/common/wxcrt.cpp @@ -810,6 +810,7 @@ wxCRT_StrftimeW(wchar_t *s, size_t maxsize, const wchar_t *fmt, const struct tm } #endif // !wxCRT_StrftimeW +#if !defined(wxCRT_StrtoullA) || !defined(wxCRT_StrtoullW) template static wxULongLong_t wxCRT_StrtoullBase(const T* nptr, T** endptr, int base, T* sign) @@ -923,7 +924,9 @@ static wxULongLong_t wxCRT_DoStrtoull(const T* nptr, T** endptr, int base) return uval; } +#endif // !defined(wxCRT_StrtoullA) || !defined(wxCRT_StrtoullW) +#if !defined(wxCRT_StrtollA) || !defined(wxCRT_StrtollW) template static wxLongLong_t wxCRT_DoStrtoll(const T* nptr, T** endptr, int base) { @@ -953,6 +956,7 @@ static wxLongLong_t wxCRT_DoStrtoll(const T* nptr, T** endptr, int base) return val; } +#endif // !defined(wxCRT_StrtollA) || !defined(wxCRT_StrtollW) #ifndef wxCRT_StrtollA wxLongLong_t wxCRT_StrtollA(const char* nptr, char** endptr, int base) From 14f5690396da1e8b97dce04e19d02d12b4e47390 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Thu, 27 Feb 2025 16:46:48 -0800 Subject: [PATCH 27/31] Avoid -Wshadow warning --- src/common/wxcrt.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/common/wxcrt.cpp b/src/common/wxcrt.cpp index 087a228257e4..eeba6267bf1f 100644 --- a/src/common/wxcrt.cpp +++ b/src/common/wxcrt.cpp @@ -1063,10 +1063,11 @@ static bool wxIsLocaleUtf8() // because a) it may be unavailable in some builds and b) has slightly // different semantics (default locale instead of current) + const char* charset; #if defined(HAVE_LANGINFO_H) && defined(CODESET) // GNU libc provides current character set this way (this conforms to // Unix98) - const char *charset = nl_langinfo(CODESET); + charset = nl_langinfo(CODESET); if ( charset && wxIsCharsetUtf8(charset) ) return true; #endif // HAVE_LANGINFO_H @@ -1083,7 +1084,7 @@ static bool wxIsLocaleUtf8() // any other locale can also use UTF-8 encoding if it's explicitly // specified - const char* charset = strrchr(lc_ctype, '.'); + charset = strrchr(lc_ctype, '.'); if ( charset && wxIsCharsetUtf8(charset + 1) ) return true; } From afdada7cd4f81f76f3764a5465eb256ef9152e9b Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Thu, 27 Feb 2025 17:03:37 -0800 Subject: [PATCH 28/31] Avoid unreachable code warnings --- src/common/intl.cpp | 7 ++++--- src/osx/carbon/graphics.cpp | 6 ++++-- src/qt/brush.cpp | 1 - src/unix/dlunix.cpp | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 6dfc24d10893..b96c11b527de 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -621,6 +621,7 @@ wxFontEncoding wxLocale::GetSystemEncoding() case 65001: return wxFONTENCODING_UTF8; } + return wxFONTENCODING_SYSTEM; #elif defined(__WXMAC__) CFStringEncoding encoding = 0; encoding = CFStringGetSystemEncoding(); @@ -645,11 +646,11 @@ wxFontEncoding wxLocale::GetSystemEncoding() { return enc; } - //else: return wxFONTENCODING_SYSTEM below } -#endif // Win32/Unix - return wxFONTENCODING_SYSTEM; +#else + return wxFONTENCODING_SYSTEM; +#endif } /* static */ diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index 453d5737ccfb..3a93aa75f408 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -2965,8 +2965,9 @@ wxGraphicsContext * wxMacCoreGraphicsRenderer::CreateContext( const wxMemoryDC& { #ifdef __WXMAC__ return new wxMacCoreGraphicsContext(this, dc); -#endif +#else return nullptr; +#endif } #if wxUSE_PRINTING_ARCHITECTURE @@ -2974,8 +2975,9 @@ wxGraphicsContext * wxMacCoreGraphicsRenderer::CreateContext( const wxPrinterDC& { #ifdef __WXMAC__ return new wxMacCoreGraphicsContext(this, dc); -#endif +#else return nullptr; +#endif } #endif diff --git a/src/qt/brush.cpp b/src/qt/brush.cpp index 53877420a2c8..8b7494980abd 100644 --- a/src/qt/brush.cpp +++ b/src/qt/brush.cpp @@ -51,7 +51,6 @@ static Qt::BrushStyle ConvertBrushStyle(wxBrushStyle style) case wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE: case wxBRUSHSTYLE_STIPPLE_MASK: return Qt::TexturePattern; - break; } return Qt::SolidPattern; } diff --git a/src/unix/dlunix.cpp b/src/unix/dlunix.cpp index e55db5273c4a..5869d7192e29 100644 --- a/src/unix/dlunix.cpp +++ b/src/unix/dlunix.cpp @@ -222,9 +222,9 @@ void* wxDynamicLibrary::GetModuleFromAddress(const void* addr, wxString* path) #else wxUnusedVar(addr); wxUnusedVar(path); -#endif // HAVE_DLADDR return nullptr; +#endif // HAVE_DLADDR } From 318e97efa141e5815f950bbf1f0e18f1c50cbd0a Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Thu, 27 Feb 2025 17:15:47 -0800 Subject: [PATCH 29/31] Avoid -Wcast-qual warnings --- src/qt/accel.cpp | 2 +- src/qt/brush.cpp | 2 +- src/qt/cursor.cpp | 2 +- src/qt/font.cpp | 2 +- src/qt/pen.cpp | 4 ++-- src/qt/region.cpp | 2 +- src/qt/textctrl.cpp | 4 ++-- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/qt/accel.cpp b/src/qt/accel.cpp index 05af3ad575c5..afdfdecf6b6e 100644 --- a/src/qt/accel.cpp +++ b/src/qt/accel.cpp @@ -89,7 +89,7 @@ wxObjectRefData *wxAcceleratorTable::CreateRefData() const wxObjectRefData *wxAcceleratorTable::CloneRefData(const wxObjectRefData *data) const { - return new wxAccelRefData(*(wxAccelRefData *)data); + return new wxAccelRefData(*static_cast(data)); } bool wxAcceleratorTable::IsOk() const diff --git a/src/qt/brush.cpp b/src/qt/brush.cpp index 8b7494980abd..082341e060cb 100644 --- a/src/qt/brush.cpp +++ b/src/qt/brush.cpp @@ -225,5 +225,5 @@ wxGDIRefData *wxBrush::CreateGDIRefData() const wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const { - return new wxBrushRefData(*(wxBrushRefData *)data); + return new wxBrushRefData(*static_cast(data)); } diff --git a/src/qt/cursor.cpp b/src/qt/cursor.cpp index 9a69c45d57f8..5d81e2386da7 100644 --- a/src/qt/cursor.cpp +++ b/src/qt/cursor.cpp @@ -179,5 +179,5 @@ wxGDIRefData *wxCursor::CreateGDIRefData() const wxGDIRefData *wxCursor::CloneGDIRefData(const wxGDIRefData *data) const { - return new wxCursorRefData(*(wxCursorRefData *)data); + return new wxCursorRefData(*static_cast(data)); } diff --git a/src/qt/font.cpp b/src/qt/font.cpp index 768a1955d1ed..6b979a5b33fa 100644 --- a/src/qt/font.cpp +++ b/src/qt/font.cpp @@ -366,7 +366,7 @@ wxGDIRefData *wxFont::CreateGDIRefData() const wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const { - return new wxFontRefData(*(wxFontRefData *)data); + return new wxFontRefData(*static_cast(data)); } QFont wxFont::GetHandle() const diff --git a/src/qt/pen.cpp b/src/qt/pen.cpp index 7fee1726182c..ba9ed56c5050 100644 --- a/src/qt/pen.cpp +++ b/src/qt/pen.cpp @@ -407,7 +407,7 @@ int wxPen::GetDashes(wxDash **ptr) const { wxCHECK_MSG( IsOk(), -1, "invalid pen" ); - *ptr = (wxDash *)((wxPenRefData *)m_refData)->m_dashes; + *ptr = const_cast(((wxPenRefData*)m_refData)->m_dashes); return ((wxPenRefData *)m_refData)->m_dashesSize; } @@ -423,5 +423,5 @@ wxGDIRefData *wxPen::CreateGDIRefData() const wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const { - return new wxPenRefData(*(wxPenRefData *)data); + return new wxPenRefData(*static_cast(data)); } diff --git a/src/qt/region.cpp b/src/qt/region.cpp index d529c97d1101..9f7d62becfed 100644 --- a/src/qt/region.cpp +++ b/src/qt/region.cpp @@ -186,7 +186,7 @@ wxGDIRefData *wxRegion::CreateGDIRefData() const wxGDIRefData *wxRegion::CloneGDIRefData(const wxGDIRefData *data) const { - return new wxRegionRefData(*(wxRegionRefData *)data); + return new wxRegionRefData(*static_cast(data)); } bool wxRegion::DoIsEqual(const wxRegion& region) const diff --git a/src/qt/textctrl.cpp b/src/qt/textctrl.cpp index 626a9da54891..445a78847d32 100644 --- a/src/qt/textctrl.cpp +++ b/src/qt/textctrl.cpp @@ -263,7 +263,7 @@ class wxQtMultiLineEdit : public wxQtEdit virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long* pos) const override { - auto qtEdit = static_cast(m_edit); + const auto qtEdit = static_cast(m_edit); auto cursor = qtEdit->cursorForPosition( wxQtConvertPoint(pt) ); auto curRect = qtEdit->cursorRect(cursor); @@ -589,7 +589,7 @@ class wxQtSingleLineEdit : public wxQtEdit virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const override { - auto qtEdit = static_cast(m_edit); + const auto qtEdit = static_cast(m_edit); auto curPos = qtEdit->cursorPositionAt( wxQtConvertPoint(pt) ); auto curRect = qtEdit->cursorRect(); From 2034ac4d87c6e280fdea3c141b96688b0920529f Mon Sep 17 00:00:00 2001 From: Lauri Nurmi Date: Mon, 24 Feb 2025 14:07:35 +0200 Subject: [PATCH 30/31] Remove unused C #includes in headers Don't include standard C headers that aren't used for anything by the wx headers. --- include/wx/datetime.h | 2 -- include/wx/strconv.h | 2 -- include/wx/stream.h | 1 - include/wx/string.h | 3 --- include/wx/utils.h | 2 -- 5 files changed, 10 deletions(-) diff --git a/include/wx/datetime.h b/include/wx/datetime.h index 65bda23164c6..eaf02e1f05b8 100644 --- a/include/wx/datetime.h +++ b/include/wx/datetime.h @@ -19,8 +19,6 @@ #include -#include // for INT_MIN - #include "wx/longlong.h" #include "wx/anystr.h" diff --git a/include/wx/strconv.h b/include/wx/strconv.h index ce7022aaff3a..3b332a65be62 100644 --- a/include/wx/strconv.h +++ b/include/wx/strconv.h @@ -15,8 +15,6 @@ #include "wx/chartype.h" #include "wx/buffer.h" -#include - class WXDLLIMPEXP_FWD_BASE wxString; // the error value returned by wxMBConv methods diff --git a/include/wx/stream.h b/include/wx/stream.h index 668a1d19fd3a..a1209b73ebda 100644 --- a/include/wx/stream.h +++ b/include/wx/stream.h @@ -14,7 +14,6 @@ #if wxUSE_STREAMS -#include #include "wx/object.h" #include "wx/string.h" #include "wx/filefn.h" // for wxFileOffset, wxInvalidOffset and wxSeekMode diff --git a/include/wx/string.h b/include/wx/string.h index 0efdf20aebd2..274e7cac48ab 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -27,10 +27,7 @@ #endif #include -#include #include -#include -#include #include "wx/chartype.h" // for wxChar #include "wx/wxcrtbase.h" // for wxChar, wxStrlen() etc. diff --git a/include/wx/utils.h b/include/wx/utils.h index c51f1453096b..55b08a7f1763 100644 --- a/include/wx/utils.h +++ b/include/wx/utils.h @@ -48,8 +48,6 @@ class WXDLLIMPEXP_FWD_BASE wxArrayInt; #include #endif -#include - #include // ---------------------------------------------------------------------------- From f222eda6aa6f6e8e32e964f766b2b83c1b87cbb4 Mon Sep 17 00:00:00 2001 From: Lauri Nurmi Date: Mon, 24 Feb 2025 14:30:21 +0200 Subject: [PATCH 31/31] Do not #include "wx/list.h" for no reason in various headers --- include/wx/filefn.h | 1 - include/wx/filesys.h | 1 + include/wx/statusbr.h | 1 - include/wx/utils.h | 1 - include/wx/xml/xml.h | 1 - include/wx/xrc/xmlres.h | 1 - 6 files changed, 1 insertion(+), 5 deletions(-) diff --git a/include/wx/filefn.h b/include/wx/filefn.h index 6279cf62155f..0abd2abe0cb6 100644 --- a/include/wx/filefn.h +++ b/include/wx/filefn.h @@ -10,7 +10,6 @@ #ifndef _FILEFN_H_ #define _FILEFN_H_ -#include "wx/list.h" #include "wx/arrstr.h" #include diff --git a/include/wx/filesys.h b/include/wx/filesys.h index ea46f691392a..95208dfdc435 100644 --- a/include/wx/filesys.h +++ b/include/wx/filesys.h @@ -16,6 +16,7 @@ #include "wx/stream.h" #include "wx/datetime.h" #include "wx/filename.h" +#include "wx/list.h" #include diff --git a/include/wx/statusbr.h b/include/wx/statusbr.h index 8a4506a8d41f..e311a5580b4e 100644 --- a/include/wx/statusbr.h +++ b/include/wx/statusbr.h @@ -15,7 +15,6 @@ #if wxUSE_STATUSBAR #include "wx/control.h" -#include "wx/list.h" #include "wx/dynarray.h" #include "wx/weakref.h" diff --git a/include/wx/utils.h b/include/wx/utils.h index 55b08a7f1763..c3bed00b7e08 100644 --- a/include/wx/utils.h +++ b/include/wx/utils.h @@ -15,7 +15,6 @@ // ---------------------------------------------------------------------------- #include "wx/object.h" -#include "wx/list.h" #include "wx/filefn.h" #include "wx/versioninfo.h" #include "wx/meta/implicitconversion.h" diff --git a/include/wx/xml/xml.h b/include/wx/xml/xml.h index 023337ce33ff..f17ecb58ea9a 100644 --- a/include/wx/xml/xml.h +++ b/include/wx/xml/xml.h @@ -17,7 +17,6 @@ #include "wx/string.h" #include "wx/object.h" -#include "wx/list.h" #include "wx/textbuf.h" #include "wx/versioninfo.h" #include "wx/filefn.h" diff --git a/include/wx/xrc/xmlres.h b/include/wx/xrc/xmlres.h index f6ccad05a13e..b0827da04e6b 100644 --- a/include/wx/xrc/xmlres.h +++ b/include/wx/xrc/xmlres.h @@ -18,7 +18,6 @@ #include "wx/dynarray.h" #include "wx/arrstr.h" #include "wx/datetime.h" -#include "wx/list.h" #include "wx/gdicmn.h" #include "wx/filesys.h" #include "wx/bitmap.h"