diff --git a/docs/API.md b/docs/API.md
index 6555d5cc..dc3a5b67 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -228,6 +228,7 @@ build instructions.
- [`GetMouseFoci()`](#getmousefoci)
- [`frame:SetShown(shown)`](#framesetshownshown)
- [A frame moved to a new parent takes its children along](#a-frame-moved-to-a-new-parent-takes-its-children-along)
+ - [A ScrollFrame keeps clipping its content when it moves](#a-scrollframe-keeps-clipping-its-content-when-it-moves)
- [`fontstring:GetStringHeight()`](#fontstringgetstringheight)
- [`fontstring:GetUnboundedStringWidth()`](#fontstringgetunboundedstringwidth)
- [`fontstring:GetWrappedWidth()`](#fontstringgetwrappedwidth)
@@ -5647,6 +5648,22 @@ child:GetFrameLevel() -- 22
`frame:SetFrameLevel(level)` moves only `frame`. The frames under it keep
the levels they have.
+### A ScrollFrame keeps clipping its content when it moves
+
+A ScrollFrame's scroll child, and all the frames in it, stay clipped to the
+ScrollFrame. This is also true when the ScrollFrame, or a frame above it,
+gets a new parent. As a result, a ScrollFrame that an addon builds in one
+place and then moves into a window still clips its content to its edges.
+AceGUI-3.0 widgets work this way.
+
+```lua
+local holder = CreateFrame("Frame", nil, UIParent)
+local scroll = CreateFrame("ScrollFrame", nil, holder)
+local content = CreateFrame("Frame", nil, scroll)
+scroll:SetScrollChild(content)
+holder:SetParent(SomeWindow) -- content stays clipped to scroll
+```
+
### `fontstring:GetStringHeight()`
This is the companion to `GetStringWidth`. It returns the height of the
diff --git a/src/Offsets.h b/src/Offsets.h
index 9ec89b0b..f12e684d 100644
--- a/src/Offsets.h
+++ b/src/Offsets.h
@@ -2869,6 +2869,32 @@ enum Offsets {
// 0x0076AAB0, never through SetParent or the alpha setter. `Frame::Alpha`
// hooks it to forget the frame's own alpha.
FUN_FRAME_DESTRUCTOR = 0x007693B0,
+
+ // Scroll clipping. A frame a ScrollFrame draws carries FRAME_FLAG_SCROLLED
+ // in its flags (OFF_FRAME_FLAGS): the strata pass leaves it out when it
+ // builds a level's layers (`test ah, 0x20` at 0x007659DF), and the
+ // ScrollFrame draws it instead, from the render callback it queues after
+ // its last layer (0x007871C0 -> 0x00787220). That callback narrows the
+ // viewport to the ScrollFrame's rect and calls the scroll child's
+ // vtable+0x40 (0x0076B3F0), which draws the frame's layers and then each
+ // shown child frame without FRAME_FLAG_SCROLL_CHILD, recursively.
+ //
+ // FUN_FRAME_SET_SCROLLED — `void __thiscall(frame, int scrolled, int
+ // scrollChild)`, `ret 8` — sets or clears FRAME_FLAG_SCROLLED, sets or
+ // clears FRAME_FLAG_SCROLL_CHILD when `scrollChild` >= 0, marks the
+ // frame's five layers for a rebuild when scrolled (0x0076B530), and calls
+ // itself on each child frame with (scrolled, -1). Its only callers:
+ // SetScrollChild (0x00786CE0: the old child (0, 0), the new one (1, 1)),
+ // SetParent (0x0076ABCB: the new parent's FRAME_FLAG_SCROLLED bit, or 0
+ // with no parent, and -1) and its own recursion (0x0076A45F). So a value
+ // SetParent passes down reaches a scroll child and everything in it.
+ // 3.3.5's setter (0x00490F60) skips child frames that carry
+ // FRAME_FLAG_SCROLL_CHILD; `Frame::ScrollChildren` hooks this one to do
+ // the same.
+ FUN_FRAME_SET_SCROLLED = 0x0076A400,
+ OFF_FRAME_FLAGS = 0xB4,
+ FRAME_FLAG_SCROLLED = 0x2000,
+ FRAME_FLAG_SCROLL_CHILD = 0x4000,
FUN_SCRIPT_TEXTURE_SHOW = 0x0079B770,
FUN_SCRIPT_TEXTURE_HIDE = 0x0079B830,
FUN_SCRIPT_FONTSTRING_SHOW = 0x0079CDB0,
diff --git a/src/frame/ScrollChildren.cpp b/src/frame/ScrollChildren.cpp
new file mode 100644
index 00000000..bd626232
--- /dev/null
+++ b/src/frame/ScrollChildren.cpp
@@ -0,0 +1,78 @@
+// This file is part of ClassicAPI.
+//
+// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
+// of the GNU General Public License as published by the Free Software Foundation, either
+// version 3 of the License, or (at your option) any later version.
+//
+// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+// PURPOSE. See the GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// ClassicAPI. If not, see .
+
+// A ScrollFrame keeps clipping its scroll child when the ScrollFrame, or any
+// frame above it, moves to a new parent.
+//
+// A frame a ScrollFrame draws carries a "scrolled" flag: the strata pass
+// leaves it out, and the ScrollFrame draws it inside a viewport cut to its
+// own rect. SetScrollChild sets the flag on the child and everything under
+// it, and marks the child itself as the scroll child. SetParent sets a moved
+// frame's flag from its new parent through the same setter, which passes the
+// value on down to every child frame. It doesn't stop at a ScrollFrame, so a
+// frame holding a ScrollFrame, moved under a parent that isn't scrolled,
+// clears the flag on the ScrollFrame's scroll child and everything in it.
+// The strata pass then draws them whole, past the ScrollFrame's edges.
+//
+// AceGUI-3.0 builds each widget under UIParent and then moves it into its
+// container, so the content of every AceGUI ScrollFrame lost its clipping
+// the moment it was used. AceConfigDialog-3.0's option pages in the
+// Interface Options window drew their widgets below the window, off the
+// bottom of the screen: on Zygor Guides Viewer 2.0's "Display" page, 61
+// frames under the scroll child had lost the flag. 3.3.5 draws the same
+// pages clipped to their box.
+//
+// 3.3.5's setter (CSimpleFrame::SetBeingScrolled, 0x00490F60) doesn't pass
+// the value into a child frame marked as the scroll child, so a scroll child
+// and everything in it keep the flag their ScrollFrame gave them. The direct
+// call is not gated there: a scroll child that is itself given a new parent
+// takes the new parent's value. The hook mirrors that. It skips a scroll
+// child only when the setter reaches it through its own recursion, which
+// comes back through the hooked entry, so a scroll child at any depth is
+// skipped. SetParent's and SetScrollChild's direct calls go through
+// unchanged.
+
+#include "Game.h"
+#include "Offsets.h"
+
+#include
+
+namespace Frame::ScrollChildren {
+
+namespace {
+
+// `scrollChild`: 1 / 0 set or clear the scroll-child mark (SetScrollChild);
+// -1 leaves it as it is (SetParent and the recursion).
+using SetScrolled_t = void(__thiscall *)(void *frame, int scrolled, int scrollChild);
+SetScrolled_t g_origSetScrolled = nullptr;
+
+// Nonzero while the original runs, so a nested call is the setter's own
+// recursion into a child frame (its only caller from inside).
+int g_depth = 0;
+
+void __fastcall SetScrolled_h(void *frame, void * /*edx*/, int scrolled, int scrollChild) {
+ if (g_depth > 0 &&
+ (Game::Read(frame, Offsets::OFF_FRAME_FLAGS) & Offsets::FRAME_FLAG_SCROLL_CHILD) != 0)
+ return; // its ScrollFrame draws it, whatever its ancestors are
+ ++g_depth;
+ g_origSetScrolled(frame, scrolled, scrollChild);
+ --g_depth;
+}
+
+const Game::HookAutoRegister _hook{Offsets::FUN_FRAME_SET_SCROLLED,
+ reinterpret_cast(&SetScrolled_h),
+ reinterpret_cast(&g_origSetScrolled)};
+
+} // namespace
+
+} // namespace Frame::ScrollChildren