1/*
2 * Copyright (C) 2020-2022 The opuntiaOS Project Authors.
3 * + Contributed by Nikita Melekhin <nimelehin@gmail.com>
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#pragma once
10#include "../../../shared/MessageContent/MenuBar.h"
11#include "../../../shared/MessageContent/Window.h"
12#include "../../IPC/Connection.h"
13#include "../MenuBar/MenuItem.h"
14#include <libfoundation/SharedBuffer.h>
15#include <libg/PixelBitmap.h>
16#include <libg/Rect.h>
17#include <libg/Size.h>
18#include <sys/types.h>
19#include <utility>
20
21namespace WinServer {
22
23typedef uint32_t WindowEventMask;
24enum WindowEvent {
25 WindowStatus = (1 << 0),
26 WindowCreation = (1 << 1),
27 IconChange = (1 << 2),
28 TitleChange = (1 << 3),
29};
30
31class BaseWindow {
32public:
33 BaseWindow(int connection_id, int id, CreateWindowMessage& msg);
34 BaseWindow(BaseWindow&& win);
35 ~BaseWindow() = default;
36
37 void set_buffer(int buffer_id, LG::Size sz, LG::PixelBitmapFormat fmt);
38
39 inline int id() const { return m_id; }
40 inline int connection_id() const { return m_connection_id; }
41 inline WindowType type() const { return m_type; }
42 inline WindowEventMask event_mask() const { return m_event_mask; }
43 inline void set_event_mask(WindowEventMask mask) { m_event_mask = mask; }
44
45 inline LFoundation::SharedBuffer<LG::Color>& buffer() { return m_buffer; }
46 inline LG::PixelBitmap& content_bitmap() { return m_content_bitmap; }
47 inline const LG::PixelBitmap& content_bitmap() const { return m_content_bitmap; }
48
49 inline LG::Rect& content_bounds() { return m_content_bounds; }
50 inline const LG::Rect& content_bounds() const { return m_content_bounds; }
51
52 inline LG::Rect& bounds() { return m_bounds; }
53 inline const LG::Rect& bounds() const { return m_bounds; }
54
55 inline const std::string& app_name() const { return m_app_name; }
56 inline const std::string& bundle_id() const { return m_bundle_id; }
57
58 inline const std::string& app_title() const { return m_app_title; }
59 inline void set_app_title(const std::string& title) { m_app_title = title, did_app_title_change(); }
60 virtual void did_app_title_change() { }
61
62 inline const std::string& icon_path() const { return m_icon_path; }
63 inline void set_icon_path(std::string&& name) { m_icon_path = std::move(name), did_icon_path_change(); }
64 inline void set_icon_path(const std::string& name) { m_icon_path = name, did_icon_path_change(); }
65 virtual void did_icon_path_change() { }
66
67 inline bool visible() const { return m_visible; }
68 inline void set_visible(bool vis) { m_visible = vis; }
69
70 inline void set_needs_display(const LG::Rect& rect) const
71 {
72 DisplayMessage msg(connection_id(), rect);
73 Connection::the().send_async_message(msg);
74 }
75
76 inline void offset_by(int x_offset, int y_offset)
77 {
78 bounds().offset_by(x_offset, y_offset);
79 content_bounds().offset_by(x_offset, y_offset);
80 }
81
82 virtual void did_size_change(const LG::Size& size) { }
83
84protected:
85 int m_id { -1 };
86 int m_connection_id { -1 };
87 bool m_visible { true };
88 WindowType m_type { WindowType::Standard };
89 WindowEventMask m_event_mask { 0 };
90 LG::Rect m_bounds;
91 LG::Rect m_content_bounds;
92 LG::PixelBitmap m_content_bitmap;
93 std::string m_app_name {};
94 std::string m_app_title {};
95 std::string m_icon_path {};
96 std::string m_bundle_id {};
97 LFoundation::SharedBuffer<LG::Color> m_buffer;
98};
99
100} // namespace WinServer