mirror of
https://github.com/RGBCube/serenity
synced 2025-10-13 17:42:19 +00:00
Start using WeakPtr for some of the WindowManager window pointers.
This commit is contained in:
parent
16fff6dff7
commit
560405667e
5 changed files with 29 additions and 8 deletions
|
@ -1,11 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Vector.h>
|
||||
#include <AK/Weakable.h>
|
||||
|
||||
class Event;
|
||||
class TimerEvent;
|
||||
|
||||
class Object {
|
||||
class Object : public Weakable<Object> {
|
||||
public:
|
||||
Object(Object* parent = nullptr);
|
||||
virtual ~Object();
|
||||
|
|
|
@ -96,7 +96,7 @@ void WindowManager::paintWindowFrame(Window& window)
|
|||
m_lastDragRect = Rect();
|
||||
}
|
||||
|
||||
if (m_dragWindow == &window) {
|
||||
if (m_dragWindow.ptr() == &window) {
|
||||
p.xorRect(outerRect, Color::Red);
|
||||
m_lastDragRect = outerRect;
|
||||
return;
|
||||
|
@ -138,7 +138,7 @@ void WindowManager::handleTitleBarMouseEvent(Window& window, MouseEvent& event)
|
|||
{
|
||||
if (event.type() == Event::MouseDown) {
|
||||
printf("[WM] Begin dragging Window{%p}\n", &window);
|
||||
m_dragWindow = &window;
|
||||
m_dragWindow = window.makeWeakPtr();;
|
||||
m_dragOrigin = event.position();
|
||||
m_dragWindowOrigin = window.position();
|
||||
m_dragStartRect = outerRectForWindow(window);
|
||||
|
@ -180,7 +180,7 @@ void WindowManager::processMouseEvent(MouseEvent& event)
|
|||
{
|
||||
if (event.type() == Event::MouseUp) {
|
||||
if (m_dragWindow) {
|
||||
printf("[WM] Finish dragging Window{%p}\n", m_dragWindow);
|
||||
printf("[WM] Finish dragging Window{%p}\n", m_dragWindow.ptr());
|
||||
m_dragWindow->setIsBeingDragged(false);
|
||||
m_dragEndRect = outerRectForWindow(*m_dragWindow);
|
||||
m_dragWindow = nullptr;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "Rect.h"
|
||||
#include "Color.h"
|
||||
#include <AK/HashTable.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
|
||||
class MouseEvent;
|
||||
class PaintEvent;
|
||||
|
@ -41,7 +42,8 @@ private:
|
|||
HashTable<Window*> m_windows;
|
||||
Widget* m_rootWidget { nullptr };
|
||||
|
||||
Window* m_dragWindow { nullptr };
|
||||
WeakPtr<Window> m_dragWindow;
|
||||
|
||||
Point m_dragOrigin;
|
||||
Point m_dragWindowOrigin;
|
||||
Rect m_lastDragRect;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue