summaryrefslogtreecommitdiff
path: root/Widgets/WindowManager.h
blob: 074558105ca383effe817aa83cc3f97f59a235ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once

#include "Object.h"
#include "Rect.h"
#include "Color.h"
#include <AK/HashTable.h>
#include <AK/InlineLinkedList.h>
#include <AK/WeakPtr.h>

class MouseEvent;
class PaintEvent;
class Widget;
class Window;

class WindowManager : public Object {
public:
    static WindowManager& the(); 
    void addWindow(Window&);
    void removeWindow(Window&);

    void notifyTitleChanged(Window&);
    void notifyRectChanged(Window&, const Rect& oldRect, const Rect& newRect);

    Widget* rootWidget() { return m_rootWidget; }
    void setRootWidget(Widget*);

    Window* activeWindow() { return m_activeWindow.ptr(); }
    void setActiveWindow(Window*);

    bool isVisible(Window&) const;

    void did_paint(Window&);

    void repaint();
    void move_to_front(Window&);

private:
    WindowManager();
    ~WindowManager();

    void processMouseEvent(MouseEvent&);
    void handleTitleBarMouseEvent(Window&, MouseEvent&);
    void handlePaintEvent(PaintEvent&);
    
    virtual void event(Event&) override;

    Color m_activeWindowBorderColor;
    Color m_activeWindowTitleColor;

    Color m_inactiveWindowBorderColor;
    Color m_inactiveWindowTitleColor;

    void recompose();
    void paintWindowFrame(Window&);
    HashTable<Window*> m_windows;
    InlineLinkedList<Window> m_windows_in_order;
    Widget* m_rootWidget { nullptr };

    WeakPtr<Window> m_activeWindow;

    WeakPtr<Window> m_dragWindow;

    Point m_dragOrigin;
    Point m_dragWindowOrigin;
    Rect m_lastDragRect;
    Rect m_dragStartRect;
    Rect m_dragEndRect;

    unsigned m_recompose_count { 0 };
    unsigned m_frontmost_only_compose_count { 0 };
};