New ui::FocusMessage with oldFocus/newFocus fields

This commit is contained in:
David Capello 2024-03-20 20:22:11 -03:00
parent 73b23c3830
commit 1d9f14665f
2 changed files with 23 additions and 3 deletions

View File

@ -964,10 +964,13 @@ void Manager::setFocus(Widget* widget)
&& !(widget->hasFlags(DECORATIVE))
&& someParentIsFocusStop(widget)))) {
Widget* commonAncestor = findLowestCommonAncestor(focus_widget, widget);
Widget* oldFocus = focus_widget;
// Fetch the focus
if (focus_widget && focus_widget != commonAncestor) {
auto msg = new Message(kFocusLeaveMessage);
auto* msg = new FocusMessage(kFocusLeaveMessage,
oldFocus,
widget);
msg->setRecipient(focus_widget);
msg->setPropagateToParent(true);
msg->setCommonAncestor(commonAncestor);
@ -984,7 +987,9 @@ void Manager::setFocus(Widget* widget)
// Put the focus
focus_widget = widget;
if (widget) {
auto msg = new Message(kFocusEnterMessage);
auto* msg = new FocusMessage(kFocusEnterMessage,
oldFocus,
widget);
msg->setRecipient(widget);
msg->setPropagateToParent(true);
msg->setCommonAncestor(commonAncestor);

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2018-2023 Igara Studio S.A.
// Copyright (C) 2018-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
@ -96,6 +96,21 @@ namespace ui {
std::function<void()> m_callback;
};
class FocusMessage : public Message {
public:
FocusMessage(MessageType type,
Widget* oldFocus,
Widget* newFocus)
: Message(type)
, m_oldFocus(oldFocus)
, m_newFocus(newFocus) { }
Widget* oldFocus() { return m_oldFocus; }
Widget* newFocus() { return m_newFocus; }
private:
Widget* m_oldFocus;
Widget* m_newFocus;
};
class KeyMessage : public Message {
public:
KeyMessage(MessageType type,