mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 17:52:26 -05:00
bc319d9e88
Okay, I've spent a whole day on this now, and it finally kinda works! With this patch, CObject and all of its derived classes are reference counted instead of tree-owned. The previous, Qt-like model was nice and familiar, but ultimately also outdated and difficult to reason about. CObject-derived types should now be stored in RefPtr/NonnullRefPtr and each class can be constructed using the forwarding construct() helper: auto widget = GWidget::construct(parent_widget); Note that construct() simply forwards all arguments to an existing constructor. It is inserted into each class by the C_OBJECT macro, see CObject.h to understand how that works. CObject::delete_later() disappears in this patch, as there is no longer a single logical owner of a CObject.
68 lines
1.7 KiB
C++
68 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include "WindowIdentifier.h"
|
|
#include <AK/String.h>
|
|
#include <AK/HashMap.h>
|
|
#include <LibGUI/GButton.h>
|
|
#include <LibDraw/Rect.h>
|
|
|
|
class Window {
|
|
public:
|
|
explicit Window(const WindowIdentifier& identifier)
|
|
: m_identifier(identifier)
|
|
{
|
|
}
|
|
|
|
~Window()
|
|
{
|
|
}
|
|
|
|
WindowIdentifier identifier() const { return m_identifier; }
|
|
|
|
String title() const { return m_title; }
|
|
void set_title(const String& title) { m_title = title; }
|
|
|
|
Rect rect() const { return m_rect; }
|
|
void set_rect(const Rect& rect) { m_rect = rect; }
|
|
|
|
GButton* button() { return m_button; }
|
|
void set_button(GButton* button) { m_button = button; }
|
|
|
|
void set_active(bool active) { m_active = active; }
|
|
bool is_active() const { return m_active; }
|
|
|
|
void set_minimized(bool minimized) { m_minimized = minimized; }
|
|
bool is_minimized() const { return m_minimized; }
|
|
|
|
const GraphicsBitmap* icon() const { return m_icon.ptr(); }
|
|
|
|
private:
|
|
WindowIdentifier m_identifier;
|
|
String m_title;
|
|
Rect m_rect;
|
|
RefPtr<GButton> m_button;
|
|
RefPtr<GraphicsBitmap> m_icon;
|
|
bool m_active { false };
|
|
bool m_minimized { false };
|
|
};
|
|
|
|
class WindowList {
|
|
public:
|
|
static WindowList& the();
|
|
|
|
template<typename Callback>
|
|
void for_each_window(Callback callback)
|
|
{
|
|
for (auto& it : m_windows)
|
|
callback(*it.value);
|
|
}
|
|
|
|
Window* window(const WindowIdentifier&);
|
|
Window& ensure_window(const WindowIdentifier&);
|
|
void remove_window(const WindowIdentifier&);
|
|
|
|
Function<NonnullRefPtr<GButton>(const WindowIdentifier&)> aid_create_button;
|
|
|
|
private:
|
|
HashMap<WindowIdentifier, NonnullOwnPtr<Window>> m_windows;
|
|
};
|