Remove pre-wxWidgets 3.1.3 DPI fallback code

Since we now target wxWidgets 3.3, the custom DPI change event
workaround (DpiChangedEvent, EVT_DPI_CHANGED_SLICER,
register_win32_dpi_event) is dead code. wxWidgets 3.1.3+ provides
native wxEVT_DPI_CHANGED / wxDPIChangedEvent which is already
wired up in the "true" branch of the version guards.

Removes:
- DpiChangedEvent struct and EVT_DPI_CHANGED_SLICER declaration/definition
- register_win32_dpi_event() function and its call site
- All associated #if !wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3) guards
This commit is contained in:
SoftFever
2026-03-24 20:28:12 +08:00
parent 2d7e26292b
commit 195d22d5cb
5 changed files with 152 additions and 57 deletions

148
plan.md Normal file
View File

@@ -0,0 +1,148 @@
# wxWidgets Upgrade Plan: 3.1.5 → 3.3.2
## Context
OrcaSlicer currently uses wxWidgets 3.1.5 via a custom fork (`https://github.com/SoftFever/Orca-deps-wxWidgets`). The goal is to upgrade to 3.3.2 from the same fork's `v3.3.2` branch. The codebase has several version-gated workarounds and compatibility shims that can be removed, and the 3.2/3.3 releases introduce breaking API changes that must be addressed.
## Branch / Fork Policy
- Use the floating `v3.3.2` **branch** from the SoftFever fork (no pinned tag for now). Set `GIT_TAG v3.3.2` in CMake so ExternalProject tracks the branch head.
- If a wx-side fix is needed, patch the SoftFever `v3.3.2` branch directly rather than adding Orca-side vendored diffs.
- Do **not** proactively port old `master` patches (dark theme, DataView, WebView ARM64, libwebkit2gtk, GLX/XWayland, GTK). Only reintroduce if a regression is reproduced against `v3.3.2`.
---
## Phase 1: Build System Changes
### 1.1 Update `deps/wxWidgets/wxWidgets.cmake`
- Add `GIT_TAG v3.3.2` (branch name) to the `orcaslicer_add_cmake_project` call — this tracks the floating branch head, not a fixed tag
- Remove `-DwxUSE_UNICODE=ON` (unicode-only in 3.3, option removed)
- Review `-DwxUSE_GLCANVAS_EGL=OFF` — still valid but verify
- Keep `-DwxUSE_WEBVIEW_IE=OFF` — the option still exists in 3.3.2 and IE backend is still present; removing it would re-enable IE on Windows
- All other cmake args should remain valid
### 1.2 Update `src/CMakeLists.txt` (lines 31-40)
- **Keep `adv` in `find_package` COMPONENTS lists** — wxWidgets 3.3.2 still ships `wxadv` as a backward-compatible empty shell (all classes moved to `core`, but the component remains findable). Removing it is safe but unnecessary churn; keeping it avoids breaking the build for no benefit.
- Change minimum version from `3.1` / `3.0` to `3.3`
- Remove the `SLIC3R_WX_STABLE` conditional path (3.0 no longer supported)
### 1.3 Update Flatpak manifest
- `scripts/flatpak/com.orcaslicer.OrcaSlicer.yml` — update wxWidgets source URL/tag and sha256
---
## Phase 2: Remove Outdated Workarounds
These are mechanical changes — the workarounds are already dead code on 3.1.5 or explicitly marked with FIXME comments for removal on upgrade.
### 2.1 Remove DPI fallback code (pre-3.1.3 workaround)
- **`src/slic3r/GUI/GUI_Utils.hpp:84-100`** — Remove `DpiChangedEvent` struct and `EVT_DPI_CHANGED_SLICER` declaration (guarded by `#if !wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)`)
- **`src/slic3r/GUI/GUI_Utils.cpp`** — Remove corresponding `EVT_DPI_CHANGED_SLICER` definition
- **`src/slic3r/GUI/GUI_App.cpp`** — Remove `register_win32_dpi_event()` function and its call (guarded by same version check)
### 2.2 Remove const_cast workarounds for wxExecute
- **`src/slic3r/GUI/GUI.cpp`** (2 instances) — FIXME says "not needed in wxWidgets 3.1"
- **`src/slic3r/GUI/NotificationManager.cpp`**
- **`src/slic3r/GUI/Downloader.cpp`**
### 2.3 Remove OSX 10.9.5 crash workaround
- **`src/slic3r/GUI/OpenGLManager.cpp:22-26, 240-256, 416-419`** — wxWidgets 3.3 requires macOS 10.11+, so 10.9.5 is unsupported. Remove the version check and always clean up wxGLContext normally.
### 2.4 Simplify version-check guards
Remove `#if wxCHECK_VERSION(...)` guards, keeping only the "true" branch:
- **`src/slic3r/GUI/I18N.hpp:67`** — `wxCHECK_VERSION(3, 1, 1)`
- **`src/slic3r/GUI/ExtraRenderers.hpp:8`** — `wxCHECK_VERSION(3, 1, 1)` for `SUPPORTS_MARKUP`
- **`src/slic3r/GUI/ConfigWizard.cpp:906`** — `wxCHECK_VERSION(3, 1, 1)`
- **`src/slic3r/GUI/SendSystemInfoDialog.cpp:484`** — `wxCHECK_VERSION(3, 1, 2)`
- **`src/slic3r/GUI/GUI_Utils.cpp:250`** — `wxCHECK_VERSION(3, 1, 3)`
### 2.5 Clean up wxinit.h
- **`src/slic3r/GUI/wxinit.h:17-23`** — The `#ifndef wxEVT_BUTTON` / `#ifndef wxEVT_HTML_LINK_CLICKED` guards are unnecessary (these macros have existed since 3.0). Can keep for safety since they're harmless, or remove.
---
## Phase 3: Fix Breaking API Changes
These require actual code modifications to compile against wxWidgets 3.3.
### 3.1 Sizer flag conflicts — `wxEXPAND | wxALIGN_*` (~115 occurrences, ~23 files)
wxWidgets 3.2+ asserts on invalid flag combos. `wxEXPAND` fills entire space, making alignment meaningless.
- Search for all `wxEXPAND` combined with `wxALIGN_CENTER`, `wxALIGN_RIGHT`, `wxALIGN_CENTRE`, `wxALIGN_CENTER_VERTICAL`, `wxALIGN_CENTER_HORIZONTAL`, `wxALIGN_BOTTOM`, `wxALIGN_TOP`
- Remove the conflicting alignment flag in each case
- Alternatively, call `wxSizerFlags::DisableConsistencyChecks()` as a temporary measure
### 3.2 `wxTRANSPARENT_WINDOW` removal
- **`src/slic3r/GUI/MainFrame.cpp:121`** — Used in `ResizeEdgePanel` constructor. Remove the flag; the `wxBG_STYLE_TRANSPARENT` on line 125 already handles transparency.
### 3.3 wxGLCanvas multi-sampling (3.3 change)
- Multi-sampling is no longer the default. **`src/slic3r/GUI/OpenGLManager.cpp`** and **GLCanvas3D** — verify that explicit `wxGLAttributes` are used to request multi-sampling where needed.
### 3.4 Global operator scope changes (3.3 change)
- Operators on wx types moved from global to class scope. Code relying on implicit conversions will fail.
- Fix on a case-by-case basis during compilation — likely a small number of actual failures
### 3.5 wxUSE_STD_CONTAINERS default ON (3.3 change)
- wxList/wxArray now behave like std containers. `wxArrayString`, `wxArrayInt` used throughout.
- Test thoroughly. If problems arise, set `-DwxUSE_STD_CONTAINERS=0` in cmake args as fallback.
### 3.6 Missing header includes
- `wx/cursor.h` no longer transitively includes `wx/utils.h` — add explicit `#include <wx/utils.h>` where needed
### 3.7 wxWindow::Raise() no longer implies Show() (3.3 change)
- `Raise()` no longer shows a hidden window. Callers that relied on `Raise()` to both show and raise must add explicit `Show()`.
- 9 files use `->Raise()`: `WebViewDialog.cpp`, `StatusPanel.cpp`, `ReleaseNote.cpp`, `PrinterWebView.cpp`, `Plater.cpp`, `ObjColorDialog.cpp`, `MainFrame.cpp`, `ImageDPIFrame.cpp`, `BaseTransparentDPIFrame.cpp`
- Audit each call: if the window may be hidden when `Raise()` is called, add `Show()` before it.
### 3.8 wxToolTip::GetToolTipCtrl() accessibility (Windows dark tooltips)
- **`src/slic3r/GUI/GUI_App.cpp:4316`** — Uses `wxToolTip::GetToolTipCtrl()` for dark tooltip styling on Windows.
- If this API is no longer accessible in 3.3, either patch the fork branch to keep it or refactor Orca's dark tooltip code.
---
## Phase 4: Build, Fix, Iterate
1. Rebuild deps with the new wxWidgets version: `cmake --build deps/build`
2. Attempt main build: `cmake --build build/arm64 --config RelWithDebInfo`
3. Fix compilation errors iteratively — expect 50-200 errors on first pass
4. Most errors will be from Phase 3 issues; fix in order of H1-H7 priority
---
## Phase 5: Runtime Verification
- **Layout testing** — verify all dialogs/panels render correctly (sizer flag changes)
- **Dark mode** — wxWidgets 3.3 adds MSW dark mode support; test for conflicts with OrcaSlicer's custom dark mode. Verify dark tooltips (`wxToolTip::GetToolTipCtrl()` in `GUI_App.cpp:4316`).
- **OpenGL** — verify 3D canvas rendering on all platforms (multi-sampling change)
- **Media playback** — test wxMediaCtrl2 (custom implementation). On Linux, wxMediaCtrl2 depends on legacy GStreamer backend internals (`wxMediaCtrl2.cpp`); if playback breaks, patch fork to set `wxUSE_GSTREAMER_PLAYER OFF`.
- **Locale/language** — test language switching
- **High DPI** — test on high DPI displays. Verify wxImageList sizing (now physical pixels) in `Tab.cpp:471,1332,1366` and `TabCtrl.hpp`.
- **wxClientDC double buffering** (Windows) — wxMSW now double-buffers by default, changing wxClientDC behavior. Test custom drawing in `wxExtensions.cpp`, `OG_CustomCtrl.cpp`, and `Widgets/*.cpp` for rendering artifacts or flickering.
- **Window activation** — `wxWindow::Raise()` no longer implies `Show()`. Test dialogs and transient frames in 9 files that call `Raise()`.
- **wxBitmapBundle** — 3.2+ bitmap API changes may affect custom bitmap combo wrappers and controls. Not a required migration but test for regressions.
---
## Critical Files to Modify
| File | Change |
|------|--------|
| `deps/wxWidgets/wxWidgets.cmake` | Add GIT_TAG, remove obsolete cmake args |
| `src/CMakeLists.txt` | Bump version to 3.3, remove `SLIC3R_WX_STABLE` path |
| `src/slic3r/GUI/GUI_Utils.hpp` | Remove DpiChangedEvent fallback |
| `src/slic3r/GUI/GUI_Utils.cpp` | Remove DPI event definition, simplify version checks |
| `src/slic3r/GUI/GUI_App.cpp` | Remove register_win32_dpi_event, version guards |
| `src/slic3r/GUI/OpenGLManager.cpp` | Remove OSX 10.9.5 hack, verify GL attributes |
| `src/slic3r/GUI/MainFrame.cpp` | Remove wxTRANSPARENT_WINDOW |
| `src/slic3r/GUI/GUI.cpp` | Remove const_cast workarounds |
| `src/slic3r/GUI/NotificationManager.cpp` | Remove const_cast workaround |
| `src/slic3r/GUI/Downloader.cpp` | Remove const_cast workaround |
| `src/slic3r/GUI/wxinit.h` | Optional cleanup of compat shims |
| `src/slic3r/GUI/I18N.hpp` | Remove version guard |
| `src/slic3r/GUI/ConfigWizard.cpp` | Remove version guard |
| `src/slic3r/GUI/SendSystemInfoDialog.cpp` | Remove version guard |
| ~23 files with sizer flags | Remove conflicting `wxALIGN_*` from `wxEXPAND` calls |
| 9 files with `->Raise()` | Audit for missing `Show()` before `Raise()` |
## Approach
Work in order: Phase 1 → 2 → 3 → 4 → 5. Phases 2 and 3 can be partially interleaved during the compilation fix pass. The strategy is to make minimal, targeted changes — not a broad refactor — to get the build working, then verify at runtime.

View File

@@ -633,24 +633,6 @@ wxString file_wildcards(FileType file_type, const std::string &custom_extension)
static std::string libslic3r_translate_callback(const char *s) { return wxGetTranslation(wxString(s, wxConvUTF8)).utf8_str().data(); }
#ifdef WIN32
#if !wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
static void register_win32_dpi_event()
{
enum { WM_DPICHANGED_ = 0x02e0 };
wxWindow::MSWRegisterMessageHandler(WM_DPICHANGED_, [](wxWindow *win, WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) {
const int dpi = wParam & 0xffff;
const auto rect = reinterpret_cast<PRECT>(lParam);
const wxRect wxrect(wxPoint(rect->top, rect->left), wxPoint(rect->bottom, rect->right));
DpiChangedEvent evt(EVT_DPI_CHANGED_SLICER, dpi, wxrect);
win->GetEventHandler()->AddPendingEvent(evt);
return true;
});
}
#endif // !wxVERSION_EQUAL_OR_GREATER_THAN
static GUID GUID_DEVINTERFACE_HID = { 0x4D1E55B2, 0xF16F, 0x11CF, 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 };
static void register_win32_device_notification_event()
@@ -3094,9 +3076,6 @@ bool GUI_App::on_init_inner()
//}
#ifdef WIN32
#if !wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
register_win32_dpi_event();
#endif // !wxVERSION_EQUAL_OR_GREATER_THAN
register_win32_device_notification_event();
#endif // WIN32

View File

@@ -148,10 +148,6 @@ void on_window_geometry(wxTopLevelWindow *tlw, std::function<void()> callback)
#endif
}
#if !wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
wxDEFINE_EVENT(EVT_DPI_CHANGED_SLICER, DpiChangedEvent);
#endif // !wxVERSION_EQUAL_OR_GREATER_THAN
#ifdef _WIN32
template<class F> typename F::FN winapi_get_function(const wchar_t *dll, const char *fn_name) {
static HINSTANCE dll_handle = LoadLibraryExW(dll, nullptr, 0);

View File

@@ -81,24 +81,6 @@ void update_dark_config();
void update_dark_ui(wxWindow* window);
#endif
#if !wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
struct DpiChangedEvent : public wxEvent {
int dpi;
wxRect rect;
DpiChangedEvent(wxEventType eventType, int dpi, wxRect rect)
: wxEvent(0, eventType), dpi(dpi), rect(rect)
{}
virtual wxEvent *Clone() const
{
return new DpiChangedEvent(*this);
}
};
wxDECLARE_EVENT(EVT_DPI_CHANGED_SLICER, DpiChangedEvent);
#endif // !wxVERSION_EQUAL_OR_GREATER_THAN
extern std::deque<wxDialog*> dialogStack;
template<class P> class DPIAware : public P
@@ -136,26 +118,12 @@ public:
// recalc_font();
#ifndef __WXOSX__
#if wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
this->Bind(wxEVT_DPI_CHANGED, [this](wxDPIChangedEvent& evt) {
m_scale_factor = (float)evt.GetNewDPI().x / (float)DPI_DEFAULT;
m_new_font_point_size = get_default_font_for_dpi(this, evt.GetNewDPI().x).GetPointSize();
if (m_can_rescale && (m_force_rescale || is_new_scale_factor()))
rescale(wxRect());
});
#else
this->Bind(EVT_DPI_CHANGED_SLICER, [this](const DpiChangedEvent& evt) {
m_scale_factor = (float)evt.dpi / (float)DPI_DEFAULT;
m_new_font_point_size = get_default_font_for_dpi(this, evt.dpi).GetPointSize();
if (!m_can_rescale)
return;
if (m_force_rescale || is_new_scale_factor())
rescale(evt.rect);
});
#endif // wxVERSION_EQUAL_OR_GREATER_THAN
#endif // no __WXOSX__
this->Bind(wxEVT_MOVE_START, [this](wxMoveEvent& event)

4
task.md Normal file
View File

@@ -0,0 +1,4 @@
Upgrade wxwidgets to latest 3.3.2 from https://github.com/SoftFever/Orca-deps-wxWidgets/tree/v3.3.2
our current version is quite old(3.1.5) with some custom patches which we expect are not needed anymore for latest wxwidgets version.
1. check wxwidgets's document to figure out what API have changed from 3.1.5 to 3.3.2
2. plan the upgrade and use practical approaches, avoid making excessive changes.