mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-09-23 23:13:12 +08:00
Add wxSizer::DetachItem()
Unix builds / Ubuntu 18.04 wxGTK 3 compatible 3.0 (push) Has been cancelled
Unix builds / Ubuntu 24.04 wxGTK ASAN not compatible (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxGTK UTF-8 (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxQt (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxX11 (push) Has been cancelled
Unix builds / Ubuntu 20.04 wxGTK 3 with clang (push) Has been cancelled
Unix builds / Ubuntu 22.04 wxGTK with wx containers (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxDFB (push) Has been cancelled
Unix builds / Ubuntu 24.04 wxGTK UBSAN (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxGTK 3 static with gcc 4.8 (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxGTK 2 (push) Has been cancelled
CMake builds / Ubuntu 22.04 wxGTK 3 (push) Has been cancelled
CMake builds / macOS latest wxGTK 3 Unix Makefiles (push) Has been cancelled
CMake builds / MSW/MSVC wxMSW (push) Has been cancelled
CMake builds / MSW/Clang wxMSW (push) Has been cancelled
CMake builds / macOS latest wxOSX Ninja (push) Has been cancelled
CMake builds / macOS 14 wxOSX Xcode (push) Has been cancelled
CMake builds / macOS 14 wxIOS (push) Has been cancelled
CMake builds / MSW/MSVC wxQt 5.15 (push) Has been cancelled
CMake builds / MSW/MSVC wxQt 6.10 (push) Has been cancelled
Mac builds / wxMac ARM ASAN not compatible (push) Has been cancelled
Mac builds / wxMac Universal C++14 (push) Has been cancelled
Mac builds / wxiOS Simulator on Silicon Mac (push) Has been cancelled
Mac builds / wxiOS (push) Has been cancelled
Mac builds / wxMac Intel C++17 (push) Has been cancelled
Mac Xcode builds / iOS Simulator static (push) Has been cancelled
Mac Xcode builds / macOS dynamic Release (push) Has been cancelled
Mac Xcode builds / iOS static Debug (push) Has been cancelled
MSW builds / wxMSW vs2022 DLL Debug x64 (push) Has been cancelled
MSW builds / wxMSW vs2022 DLL Release x64 (push) Has been cancelled
MSW builds / wxMSW vs2022 Debug Win32 (push) Has been cancelled
MSW builds / wxMSW vs2022 Release arm64 (push) Has been cancelled
MSW builds / wxMSW vs2026 DLL Release x64 (push) Has been cancelled
MSW cross-builds / wxMSW 64 bits not compatible (push) Has been cancelled
MSW cross-builds / wxMSW/Univ (push) Has been cancelled
MSW cross-builds / wxMSW 32 bits (push) Has been cancelled
Code Checks / Check Spelling (push) Has been cancelled
Code Checks / Check Whitespace (push) Has been cancelled
Code Checks / Check Mixed EOL (push) Has been cancelled
Code Checks / Check C++ Style (push) Has been cancelled
Code Checks / Check All Headers In allheaders.h (push) Has been cancelled
Update Documentation / Update Online Documentation (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxGTK 3 compatible 3.0 (push) Has been cancelled
Unix builds / Ubuntu 24.04 wxGTK ASAN not compatible (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxGTK UTF-8 (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxQt (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxX11 (push) Has been cancelled
Unix builds / Ubuntu 20.04 wxGTK 3 with clang (push) Has been cancelled
Unix builds / Ubuntu 22.04 wxGTK with wx containers (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxDFB (push) Has been cancelled
Unix builds / Ubuntu 24.04 wxGTK UBSAN (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxGTK 3 static with gcc 4.8 (push) Has been cancelled
Unix builds / Ubuntu 18.04 wxGTK 2 (push) Has been cancelled
CMake builds / Ubuntu 22.04 wxGTK 3 (push) Has been cancelled
CMake builds / macOS latest wxGTK 3 Unix Makefiles (push) Has been cancelled
CMake builds / MSW/MSVC wxMSW (push) Has been cancelled
CMake builds / MSW/Clang wxMSW (push) Has been cancelled
CMake builds / macOS latest wxOSX Ninja (push) Has been cancelled
CMake builds / macOS 14 wxOSX Xcode (push) Has been cancelled
CMake builds / macOS 14 wxIOS (push) Has been cancelled
CMake builds / MSW/MSVC wxQt 5.15 (push) Has been cancelled
CMake builds / MSW/MSVC wxQt 6.10 (push) Has been cancelled
Mac builds / wxMac ARM ASAN not compatible (push) Has been cancelled
Mac builds / wxMac Universal C++14 (push) Has been cancelled
Mac builds / wxiOS Simulator on Silicon Mac (push) Has been cancelled
Mac builds / wxiOS (push) Has been cancelled
Mac builds / wxMac Intel C++17 (push) Has been cancelled
Mac Xcode builds / iOS Simulator static (push) Has been cancelled
Mac Xcode builds / macOS dynamic Release (push) Has been cancelled
Mac Xcode builds / iOS static Debug (push) Has been cancelled
MSW builds / wxMSW vs2022 DLL Debug x64 (push) Has been cancelled
MSW builds / wxMSW vs2022 DLL Release x64 (push) Has been cancelled
MSW builds / wxMSW vs2022 Debug Win32 (push) Has been cancelled
MSW builds / wxMSW vs2022 Release arm64 (push) Has been cancelled
MSW builds / wxMSW vs2026 DLL Release x64 (push) Has been cancelled
MSW cross-builds / wxMSW 64 bits not compatible (push) Has been cancelled
MSW cross-builds / wxMSW/Univ (push) Has been cancelled
MSW cross-builds / wxMSW 32 bits (push) Has been cancelled
Code Checks / Check Spelling (push) Has been cancelled
Code Checks / Check Whitespace (push) Has been cancelled
Code Checks / Check Mixed EOL (push) Has been cancelled
Code Checks / Check C++ Style (push) Has been cancelled
Code Checks / Check All Headers In allheaders.h (push) Has been cancelled
Update Documentation / Update Online Documentation (push) Has been cancelled
Unlike the existing Detach(), this function doesn't delete wxSizerItem itself, allowing to add it back to this or another sizer later. Closes #26512.
This commit is contained in:
@@ -617,6 +617,8 @@ public:
|
||||
virtual bool Detach( wxSizer *sizer );
|
||||
virtual bool Detach( int index );
|
||||
|
||||
wxNODISCARD virtual wxSizerItem *DetachItem(size_t index);
|
||||
|
||||
virtual bool Replace( wxWindow *oldwin, wxWindow *newwin, bool recursive = false );
|
||||
virtual bool Replace( wxSizer *oldsz, wxSizer *newsz, bool recursive = false );
|
||||
virtual bool Replace( size_t index, wxSizerItem *newitem );
|
||||
|
||||
+24
-1
@@ -440,16 +440,39 @@ public:
|
||||
virtual bool Detach(wxSizer* sizer);
|
||||
|
||||
/**
|
||||
Detach an item at position @a index from the sizer without destroying it.
|
||||
Detach the child sizer or window in item at position @a index without
|
||||
destroying the child object.
|
||||
|
||||
This method does not cause any layout or resizing to take place, call Layout()
|
||||
to update the layout "on screen" after detaching a child from the sizer.
|
||||
|
||||
Returns @true if the child item was found and detached, @false otherwise.
|
||||
|
||||
Note that the sizer item containing the child sizer or window is
|
||||
deleted by this function, see DetachItem() if you want to prevent this
|
||||
from happening.
|
||||
|
||||
@see Remove()
|
||||
*/
|
||||
virtual bool Detach(int index);
|
||||
|
||||
/**
|
||||
Detach the item at position @a index without destroying it.
|
||||
|
||||
This method does not cause any layout or resizing to take place, call Layout()
|
||||
to update the layout "on screen" after detaching a child from the sizer.
|
||||
|
||||
Returns the item if it was found and detached, @nullptr otherwise.
|
||||
|
||||
The caller takes ownership of the returned pointer, i.e. must either
|
||||
delete it or add it back to this or another sizer later.
|
||||
|
||||
@see Remove(), Add()
|
||||
|
||||
@since 3.3.3
|
||||
*/
|
||||
virtual wxSizerItem *DetachItem(size_t index);
|
||||
|
||||
/**
|
||||
Tell the sizer to resize the @a window so that its client area matches the
|
||||
sizer's minimal size (ComputeFittingClientSize() is called to determine it).
|
||||
|
||||
@@ -1099,6 +1099,23 @@ bool wxSizer::Detach( int index )
|
||||
return true;
|
||||
}
|
||||
|
||||
wxSizerItem *wxSizer::DetachItem(size_t index)
|
||||
{
|
||||
const auto node = GetChildNode(index);
|
||||
if ( !node )
|
||||
return nullptr;
|
||||
|
||||
wxSizerItem *item = node->GetData();
|
||||
|
||||
wxWindow *window = item->GetWindow();
|
||||
if ( window != nullptr )
|
||||
window->SetContainingSizer(nullptr);
|
||||
|
||||
m_children.Erase( node );
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
bool wxSizer::Replace( wxWindow *oldwin, wxWindow *newwin, bool recursive )
|
||||
{
|
||||
wxASSERT_MSG( oldwin, wxT("Replacing null window") );
|
||||
|
||||
@@ -448,6 +448,40 @@ TEST_CASE_METHOD(BoxSizerTestCase, "BoxSizer::Replace", "[sizer]")
|
||||
m_sizer->Replace(0, new wxSizerItem(new wxWindow(m_win, wxID_ANY)));
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(BoxSizerTestCase, "Sizer::DetachItem", "[sizer]")
|
||||
{
|
||||
wxSizerItem *item = nullptr;
|
||||
|
||||
SECTION("Spacer")
|
||||
{
|
||||
item = new wxSizerItem(0, 0);
|
||||
}
|
||||
|
||||
SECTION("Sizer")
|
||||
{
|
||||
item = new wxSizerItem(new wxBoxSizer(wxVERTICAL));
|
||||
}
|
||||
|
||||
SECTION("Window")
|
||||
{
|
||||
item = new wxSizerItem(new wxWindow(m_win, wxID_ANY));
|
||||
}
|
||||
|
||||
m_sizer->Add(item);
|
||||
|
||||
// Test re-insertion
|
||||
auto *detached = m_sizer->DetachItem(0);
|
||||
CHECK( item == detached );
|
||||
|
||||
m_sizer->Insert(0, detached);
|
||||
|
||||
// Test deletion after detach.
|
||||
detached = m_sizer->DetachItem(0);
|
||||
CHECK( item == detached );
|
||||
|
||||
delete detached;
|
||||
}
|
||||
|
||||
TEST_CASE("Sizer::CombineFlags", "[sizer]")
|
||||
{
|
||||
// This is a compile-time test which simply verifies that we can combine
|
||||
|
||||
Reference in New Issue
Block a user