diff --git a/docs/API.md b/docs/API.md
index f75de25e..1176f304 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -8262,6 +8262,13 @@ f:SetWordWrap(false)
f:SetText("one two three four five six") -- draws "one two three four fi..."
```
+You can also set the value in XML with the `wordwrap` attribute on a
+`FontString`. The default is `true`.
+
+```xml
+
+```
+
### `fontstring:GetFieldSize()`
Returns the number of bytes of text that the string can hold. A string
@@ -10006,6 +10013,16 @@ unknown names makes the button respond to no click at all. `Button:Click()`
ignores the click types, so a button in that state still responds to
`Click()`.
+You can also set the click types in XML with the `registerForClicks`
+attribute on a `Button` or `CheckButton`. Put spaces or commas between the
+names. The attribute replaces the click types of an inherited template, and
+a `RegisterForClicks` call in `OnLoad` replaces the attribute.
+
+```xml
+
+
+```
+
### `button:RegisterForMouse(...)`
Sets which mouse buttons run the `OnMouseDown` and `OnMouseUp` scripts of the
diff --git a/src/Offsets.h b/src/Offsets.h
index 7ad15da9..1dc5cd1b 100644
--- a/src/Offsets.h
+++ b/src/Offsets.h
@@ -3713,9 +3713,10 @@ enum Offsets {
SITE_SCRIPT_CLICK_RIGHT = 0x00782811,
SITE_SCRIPT_CLICK_DEFAULT = 0x00782826,
BUTTON_DOUBLE_CLICK_MS = 300,
- // Button::SetClickMask — __thiscall(button, mask): writes +0x330. The
- // ctors call it with the type default (Button 0x100 = LeftButtonUp;
- // hyperlink button 0x500). Reference only.
+ // Button::SetClickMask — __thiscall(button, mask), `ret 4`: writes +0x330
+ // and nothing else (Ghidra). The ctors call it with the type default
+ // (Button 0x100 = LeftButtonUp; hyperlink button 0x500). Frame::ClickMask
+ // calls it for the XML `registerForClicks` attribute.
FUN_BUTTON_SET_CLICK_MASK = 0x00779730,
// EditBox — 48 methods (table 0x0087BB68), ctx per
// docs/BlizzardScriptAPI.md. Backs `EditBox:SetCursorPosition` /
diff --git a/src/fontstring/WordWrap.cpp b/src/fontstring/WordWrap.cpp
index 6f2ab390..f549bbfd 100644
--- a/src/fontstring/WordWrap.cpp
+++ b/src/fontstring/WordWrap.cpp
@@ -21,6 +21,12 @@
// out again as SetText does, not only rebuilds it: a string sized by its text
// would keep its old height, and the engine's fit would then neither
// ellipsize the one line (wrap off) nor make room for the others (wrap on).
+//
+// The FontString node's `wordwrap` attribute is 3.3.5's loader: when present
+// and non-empty it goes through the same setter (Xml::ParentKey's font string
+// loader hook calls Set). 1.12's loader reads only `nonspacewrap`.
+
+#include "fontstring/WordWrap.h"
#include "Game.h"
#include "Offsets.h"
@@ -32,21 +38,13 @@ namespace FontString::WordWrap {
namespace {
-
constexpr uint32_t kNoWrap = Offsets::FONT_STYLE_NO_WORD_WRAP;
int __fastcall Script_SetWordWrap(void *L) {
void *fontString = Game::Lua::ResolveFontString(L);
if (fontString == nullptr)
return 0;
- const bool wrap = Game::Lua::ToFlag(L, 2, true);
- Game::Ref(fontString, Offsets::OFF_FONTSTRING_SETTABLE_STYLE) &= ~kNoWrap;
- const uint32_t flags = Game::Read(fontString, Offsets::OFF_FONTSTRING_FLAGS);
- const uint32_t wanted = wrap ? flags & ~kNoWrap : flags | kNoWrap;
- if (wanted != flags) {
- Game::Ref(fontString, Offsets::OFF_FONTSTRING_FLAGS) = wanted;
- FontString::Layout::Invalidate(fontString);
- }
+ Set(fontString, Game::Lua::ToFlag(L, 2, true));
return 0;
}
@@ -89,4 +87,14 @@ const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
} // namespace
+void Set(void *fontString, bool wrap) {
+ Game::Ref(fontString, Offsets::OFF_FONTSTRING_SETTABLE_STYLE) &= ~kNoWrap;
+ const uint32_t flags = Game::Read(fontString, Offsets::OFF_FONTSTRING_FLAGS);
+ const uint32_t wanted = wrap ? flags & ~kNoWrap : flags | kNoWrap;
+ if (wanted != flags) {
+ Game::Ref(fontString, Offsets::OFF_FONTSTRING_FLAGS) = wanted;
+ FontString::Layout::Invalidate(fontString);
+ }
+}
+
} // namespace FontString::WordWrap
diff --git a/src/fontstring/WordWrap.h b/src/fontstring/WordWrap.h
new file mode 100644
index 00000000..056e4a3e
--- /dev/null
+++ b/src/fontstring/WordWrap.h
@@ -0,0 +1,23 @@
+// 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 .
+
+#pragma once
+
+namespace FontString::WordWrap {
+
+// fontstring:SetWordWrap(wrap). Also the FontString node's `wordwrap`
+// attribute, which Xml::ParentKey's font string loader hook applies when it
+// is present and non-empty, as 3.3.5's loader does.
+void Set(void *fontString, bool wrap);
+
+} // namespace FontString::WordWrap
diff --git a/src/frame/ClickMask.cpp b/src/frame/ClickMask.cpp
index 9a13ba49..62660b55 100644
--- a/src/frame/ClickMask.cpp
+++ b/src/frame/ClickMask.cpp
@@ -42,15 +42,32 @@
// can silently displace, so it is reserved for names nobody else contends —
// unlike TargetUnit (see CLAUDE.md), no loaded DLL or addon has cause to
// replace RegisterForClicks.
+//
+// The XML attribute `registerForClicks` is 3.3.5's CSimpleButton::LoadXML:
+// Storm's tokenizer (FUN_STORM_STR_TOKENIZE, the one 3.3.5 calls) splits the
+// value on spaces and commas, each name ORs in its bits
+// (Frame::MouseRegistration::MaskForName, 3.3.5's MouseButtonStringToBitmask,
+// which knows AnyUp / AnyDown), and the result REPLACES the mask through the
+// engine's setter, as RegisterForClicks does. 1.12's Button loader has no such
+// attribute.
+
+#include "frame/ClickMask.h"
#include "Game.h"
#include "Offsets.h"
#include "baselib/Ascii.h"
+#include "frame/MouseRegistration.h"
+
+#include
namespace Frame::ClickMask {
namespace {
+using Tokenize_t = void(__stdcall *)(const char **cursor, char *out, unsigned outSize,
+ const char *delims, int *outQuoted);
+using SetClickMask_t = void(__thiscall *)(void *button, uint32_t mask);
+
// The engine's own click-type names, in mask-bit order.
constexpr const char *kUpNames[] = {"LeftButtonUp", "MiddleButtonUp", "RightButtonUp",
"Button4Up", "Button5Up"};
@@ -93,4 +110,17 @@ const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
} // namespace
+void SetFromXml(void *button, const char *value) {
+ auto tokenize = reinterpret_cast(Offsets::FUN_STORM_STR_TOKENIZE);
+ uint32_t mask = 0;
+ char token[1024];
+ const char *cursor = value;
+ while (cursor != nullptr && *cursor != '\0') {
+ token[0] = '\0';
+ tokenize(&cursor, token, sizeof token, " ,", nullptr);
+ mask |= Frame::MouseRegistration::MaskForName(token);
+ }
+ reinterpret_cast(Offsets::FUN_BUTTON_SET_CLICK_MASK)(button, mask);
+}
+
} // namespace Frame::ClickMask
diff --git a/src/frame/ClickMask.h b/src/frame/ClickMask.h
new file mode 100644
index 00000000..51fc30cd
--- /dev/null
+++ b/src/frame/ClickMask.h
@@ -0,0 +1,23 @@
+// 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 .
+
+#pragma once
+
+namespace Frame::ClickMask {
+
+// A Button node's `registerForClicks="AnyUp RightButtonDown"` (spaces or
+// commas between names) on `button`. Xml::ParentKey's Button loader hook
+// calls it when the attribute is present and non-empty.
+void SetFromXml(void *button, const char *value);
+
+} // namespace Frame::ClickMask
diff --git a/src/frame/MouseRegistration.cpp b/src/frame/MouseRegistration.cpp
index 06815747..ecb00c09 100644
--- a/src/frame/MouseRegistration.cpp
+++ b/src/frame/MouseRegistration.cpp
@@ -33,6 +33,7 @@
// insensitive, unknown names add nothing, the scan stops at the first
// non-string. Only buttons that called RegisterForMouse with something other
// than the default get an entry; Frame::Destruction drops it with the button.
+// MaskForName also parses the XML `registerForClicks` names (Frame::ClickMask).
#include "frame/MouseRegistration.h"
@@ -83,12 +84,8 @@ int __fastcall Script_RegisterForMouse(void *L) {
return 0;
uint32_t mask = 0;
const int top = GetTop(L);
- for (int i = 2; i <= top && IsString(L, i); ++i) {
- const char *arg = ToString(L, i);
- for (const Name &n : kNames)
- if (Ascii::EqualCI(arg, n.name))
- mask |= n.bits;
- }
+ for (int i = 2; i <= top && IsString(L, i); ++i)
+ mask |= MaskForName(ToString(L, i));
if (mask == kDefault)
g_masks.erase(button);
else
@@ -119,6 +116,13 @@ const Frame::Destruction::AutoSubscribe _destructionSub{&OnFrameDestroyed};
} // namespace
+uint32_t MaskForName(const char *name) {
+ for (const Name &n : kNames)
+ if (Ascii::EqualCI(name, n.name))
+ return n.bits;
+ return 0;
+}
+
bool Accepts(void *frame, bool down, const char *name) {
if (g_masks.empty())
return true;
diff --git a/src/frame/MouseRegistration.h b/src/frame/MouseRegistration.h
index 85c30640..fdaabce1 100644
--- a/src/frame/MouseRegistration.h
+++ b/src/frame/MouseRegistration.h
@@ -13,8 +13,15 @@
#pragma once
+#include
+
namespace Frame::MouseRegistration {
+// The click-mask bits for one click name ("LeftButtonUp", "AnyDown", ...),
+// matched case-insensitively; 0 for an unknown name. 3.3.5's
+// MouseButtonStringToBitmask.
+uint32_t MaskForName(const char *name);
+
// Whether `frame`'s OnMouseDown (`down`) or OnMouseUp fire for the mouse
// button `name` (one of the engine's name literals, as the fire passes it)
// may run under the frame's `RegisterForMouse` registration. True for every
diff --git a/src/xml/ParentKey.cpp b/src/xml/ParentKey.cpp
index c0cda91d..3d3e9c0e 100644
--- a/src/xml/ParentKey.cpp
+++ b/src/xml/ParentKey.cpp
@@ -72,7 +72,9 @@
// and, with no `inherits`, leaves it empty. After that loader, a font element
// with `style` and no `inherits` is applied through the engine's own setter
// for that state (SetTextFontObject / SetHighlightFontObject /
-// SetDisabledFontObject) with `_G[style]`.
+// SetDisabledFontObject) with `_G[style]`. The Button loader also reads
+// `registerForClicks` (Frame::ClickMask) and the font string loader
+// `wordwrap` (FontString::WordWrap), the 3.3.5 attributes 1.12 lacks.
//
// `parentArray="Name"` appends the object to `parent.Name` (created on first
// use) in load order, the same way.
@@ -96,6 +98,8 @@
#include "Game.h"
#include "Offsets.h"
#include "animation/Xml.h"
+#include "fontstring/WordWrap.h"
+#include "frame/ClickMask.h"
#include "texture/Atlas.h"
#include "texture/Mask.h"
#include "xml/Anchors.h"
@@ -298,6 +302,9 @@ void BindButtonFontStyles(void *self, const void *node) {
uintptr_t __fastcall ButtonLoad_h(void *self, void *edx, const void *node, void *status) {
const uintptr_t r = g_origButtonLoad(self, edx, node, status);
BindButtonFontStyles(self, node);
+ if (self != nullptr && node != nullptr)
+ if (const char *clicks = Xml::Attr(node, "registerForClicks"); clicks != nullptr && *clicks != '\0')
+ Frame::ClickMask::SetFromXml(static_cast(self) - Offsets::OFF_XML_LOADER_SUBOBJECT, clicks);
return r;
}
@@ -353,6 +360,8 @@ uintptr_t __fastcall FontStringLoad_h(void *self, void *edx, const void *node, v
Xml::Anchors::Apply(RegionObject(self), node, status);
Xml::KeyValues::ApplyToRegion(RegionObject(self), node, status);
Animation::Xml::LoadAnimations(RegionObject(self), node, status);
+ if (const char *wordwrap = Xml::Attr(node, "wordwrap"); wordwrap != nullptr && *wordwrap != '\0')
+ FontString::WordWrap::Set(RegionObject(self), Game::StringToFlag(wordwrap));
}
return r;
}