2019-01-16 16:03:50 +01:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-19 23:22:46 +01:00
|
|
|
#include <SharedGraphics/Rect.h>
|
|
|
|
#include <SharedGraphics/GraphicsBitmap.h>
|
2019-01-16 16:03:50 +01:00
|
|
|
#include <AK/AKString.h>
|
|
|
|
#include <AK/InlineLinkedList.h>
|
2019-01-26 05:28:02 +01:00
|
|
|
#include "WSMessageReceiver.h"
|
2019-02-12 11:53:45 +01:00
|
|
|
#include <WindowServer/WSWindowType.h>
|
2019-04-05 15:54:56 +02:00
|
|
|
#include <WindowServer/WSWindowFrame.h>
|
2019-01-16 16:03:50 +01:00
|
|
|
|
2019-02-17 08:54:57 +01:00
|
|
|
class WSClientConnection;
|
2019-03-31 23:52:02 +02:00
|
|
|
class WSCursor;
|
2019-02-11 09:47:10 +01:00
|
|
|
class WSMenu;
|
2019-03-24 15:01:56 +01:00
|
|
|
class WSMouseEvent;
|
2019-01-16 16:03:50 +01:00
|
|
|
|
2019-01-26 05:28:02 +01:00
|
|
|
class WSWindow final : public WSMessageReceiver, public InlineLinkedListNode<WSWindow> {
|
2019-01-16 16:03:50 +01:00
|
|
|
public:
|
2019-04-03 19:38:44 +02:00
|
|
|
WSWindow(WSClientConnection&, WSWindowType, int window_id, bool modal);
|
2019-03-06 10:03:10 +01:00
|
|
|
WSWindow(WSMessageReceiver&, WSWindowType);
|
2019-01-16 16:03:50 +01:00
|
|
|
virtual ~WSWindow() override;
|
|
|
|
|
2019-04-05 15:54:56 +02:00
|
|
|
WSWindowFrame& frame() { return m_frame; }
|
|
|
|
const WSWindowFrame& frame() const { return m_frame; }
|
|
|
|
|
2019-03-19 00:52:39 +01:00
|
|
|
bool is_blocked_by_modal_window() const;
|
|
|
|
|
2019-04-04 01:44:35 +02:00
|
|
|
bool listens_to_wm_events() const { return m_listens_to_wm_events; }
|
|
|
|
|
2019-02-17 08:54:57 +01:00
|
|
|
WSClientConnection* client() { return m_client; }
|
|
|
|
const WSClientConnection* client() const { return m_client; }
|
2019-02-13 00:19:21 +01:00
|
|
|
|
2019-02-12 11:53:45 +01:00
|
|
|
WSWindowType type() const { return m_type; }
|
2019-01-16 16:03:50 +01:00
|
|
|
int window_id() const { return m_window_id; }
|
|
|
|
|
|
|
|
String title() const { return m_title; }
|
|
|
|
void set_title(String&&);
|
|
|
|
|
2019-02-19 01:42:53 +01:00
|
|
|
float opacity() const { return m_opacity; }
|
|
|
|
void set_opacity(float opacity) { m_opacity = opacity; }
|
|
|
|
|
2019-01-16 16:03:50 +01:00
|
|
|
int x() const { return m_rect.x(); }
|
|
|
|
int y() const { return m_rect.y(); }
|
|
|
|
int width() const { return m_rect.width(); }
|
|
|
|
int height() const { return m_rect.height(); }
|
|
|
|
|
2019-03-03 15:17:05 +01:00
|
|
|
bool is_active() const;
|
|
|
|
|
2019-02-11 09:47:10 +01:00
|
|
|
bool is_visible() const { return m_visible; }
|
|
|
|
void set_visible(bool);
|
|
|
|
|
2019-03-19 00:52:39 +01:00
|
|
|
bool is_modal() const { return m_modal; }
|
|
|
|
|
|
|
|
bool is_resizable() const { return m_resizable; }
|
|
|
|
void set_resizable(bool);
|
|
|
|
|
2019-02-11 09:47:10 +01:00
|
|
|
Rect rect() const { return m_rect; }
|
2019-01-16 16:03:50 +01:00
|
|
|
void set_rect(const Rect&);
|
2019-02-11 09:47:10 +01:00
|
|
|
void set_rect(int x, int y, int width, int height) { set_rect({ x, y, width, height }); }
|
2019-04-05 15:54:56 +02:00
|
|
|
void set_rect_without_repaint(const Rect& rect)
|
|
|
|
{
|
|
|
|
if (m_rect == rect)
|
|
|
|
return;
|
|
|
|
auto old_rect = m_rect;
|
|
|
|
m_rect = rect;
|
|
|
|
m_frame.notify_window_rect_changed(old_rect, rect);
|
|
|
|
}
|
|
|
|
|
2019-02-20 15:34:55 +01:00
|
|
|
void set_rect_from_window_manager_resize(const Rect&);
|
2019-01-16 16:03:50 +01:00
|
|
|
|
2019-02-11 09:47:10 +01:00
|
|
|
void move_to(const Point& position) { set_rect({ position, size() }); }
|
|
|
|
void move_to(int x, int y) { move_to({ x, y }); }
|
|
|
|
|
2019-01-16 16:03:50 +01:00
|
|
|
Point position() const { return m_rect.location(); }
|
|
|
|
void set_position(const Point& position) { set_rect({ position.x(), position.y(), width(), height() }); }
|
|
|
|
void set_position_without_repaint(const Point& position) { set_rect_without_repaint({ position.x(), position.y(), width(), height() }); }
|
|
|
|
|
2019-02-11 09:47:10 +01:00
|
|
|
Size size() const { return m_rect.size(); }
|
|
|
|
|
|
|
|
void invalidate();
|
|
|
|
|
2019-04-01 19:14:57 +02:00
|
|
|
virtual void on_message(const WSMessage&) override;
|
2019-01-16 16:03:50 +01:00
|
|
|
|
2019-02-20 21:59:13 +01:00
|
|
|
GraphicsBitmap* backing_store() { return m_backing_store.ptr(); }
|
2019-03-18 20:52:23 +01:00
|
|
|
void set_backing_store(RetainPtr<GraphicsBitmap>&& backing_store)
|
|
|
|
{
|
|
|
|
m_last_backing_store = move(m_backing_store);
|
|
|
|
m_backing_store = move(backing_store);
|
|
|
|
}
|
|
|
|
void swap_backing_stores()
|
|
|
|
{
|
|
|
|
swap(m_backing_store, m_last_backing_store);
|
|
|
|
}
|
|
|
|
|
|
|
|
GraphicsBitmap* last_backing_store() { return m_last_backing_store.ptr(); }
|
2019-01-16 16:03:50 +01:00
|
|
|
|
2019-01-27 08:48:34 +01:00
|
|
|
void set_global_cursor_tracking_enabled(bool);
|
2019-03-24 15:01:56 +01:00
|
|
|
void set_automatic_cursor_tracking_enabled(bool enabled) { m_automatic_cursor_tracking_enabled = enabled; }
|
|
|
|
bool global_cursor_tracking() const { return m_global_cursor_tracking_enabled || m_automatic_cursor_tracking_enabled; }
|
2019-01-27 08:48:34 +01:00
|
|
|
|
2019-02-19 01:42:53 +01:00
|
|
|
bool has_alpha_channel() const { return m_has_alpha_channel; }
|
|
|
|
void set_has_alpha_channel(bool value) { m_has_alpha_channel = value; }
|
|
|
|
|
2019-02-20 21:59:13 +01:00
|
|
|
void set_last_lazy_resize_rect(const Rect& rect) { m_last_lazy_resize_rect = rect; }
|
|
|
|
Rect last_lazy_resize_rect() const { return m_last_lazy_resize_rect; }
|
|
|
|
|
2019-02-20 15:50:05 +01:00
|
|
|
bool has_painted_since_last_resize() const { return m_has_painted_since_last_resize; }
|
2019-02-20 21:59:13 +01:00
|
|
|
void set_has_painted_since_last_resize(bool b) { m_has_painted_since_last_resize = b; }
|
2019-02-20 15:50:05 +01:00
|
|
|
|
2019-02-21 00:21:23 +01:00
|
|
|
Size size_increment() const { return m_size_increment; }
|
|
|
|
void set_size_increment(const Size& increment) { m_size_increment = increment; }
|
|
|
|
|
|
|
|
Size base_size() const { return m_base_size; }
|
|
|
|
void set_base_size(const Size& size) { m_base_size = size; }
|
|
|
|
|
2019-03-06 23:03:36 +01:00
|
|
|
const GraphicsBitmap& icon() const { return *m_icon; }
|
|
|
|
void set_icon(Retained<GraphicsBitmap>&& icon) { m_icon = move(icon); }
|
|
|
|
|
2019-03-31 23:52:02 +02:00
|
|
|
const WSCursor* override_cursor() const { return m_override_cursor.ptr(); }
|
|
|
|
void set_override_cursor(RetainPtr<WSCursor>&& cursor) { m_override_cursor = move(cursor); }
|
|
|
|
|
2019-01-16 16:03:50 +01:00
|
|
|
// For InlineLinkedList.
|
|
|
|
// FIXME: Maybe make a ListHashSet and then WSWindowManager can just use that.
|
|
|
|
WSWindow* m_next { nullptr };
|
|
|
|
WSWindow* m_prev { nullptr };
|
|
|
|
|
|
|
|
private:
|
2019-03-24 15:01:56 +01:00
|
|
|
void handle_mouse_event(const WSMouseEvent&);
|
|
|
|
|
2019-02-17 08:54:57 +01:00
|
|
|
WSClientConnection* m_client { nullptr };
|
2019-03-06 10:03:10 +01:00
|
|
|
WSMessageReceiver* m_internal_owner { nullptr };
|
2019-01-16 16:03:50 +01:00
|
|
|
String m_title;
|
|
|
|
Rect m_rect;
|
2019-02-12 11:53:45 +01:00
|
|
|
WSWindowType m_type { WSWindowType::Normal };
|
2019-01-27 08:48:34 +01:00
|
|
|
bool m_global_cursor_tracking_enabled { false };
|
2019-03-24 15:01:56 +01:00
|
|
|
bool m_automatic_cursor_tracking_enabled { false };
|
2019-02-11 09:47:10 +01:00
|
|
|
bool m_visible { true };
|
2019-02-19 01:42:53 +01:00
|
|
|
bool m_has_alpha_channel { false };
|
2019-02-20 15:50:05 +01:00
|
|
|
bool m_has_painted_since_last_resize { false };
|
2019-03-19 00:52:39 +01:00
|
|
|
bool m_modal { false };
|
|
|
|
bool m_resizable { false };
|
2019-04-04 01:44:35 +02:00
|
|
|
bool m_listens_to_wm_events { false };
|
2019-02-20 21:59:13 +01:00
|
|
|
RetainPtr<GraphicsBitmap> m_backing_store;
|
2019-03-18 20:52:23 +01:00
|
|
|
RetainPtr<GraphicsBitmap> m_last_backing_store;
|
2019-01-16 16:03:50 +01:00
|
|
|
int m_window_id { -1 };
|
2019-02-19 01:42:53 +01:00
|
|
|
float m_opacity { 1 };
|
2019-02-20 21:59:13 +01:00
|
|
|
Rect m_last_lazy_resize_rect;
|
2019-02-21 00:21:23 +01:00
|
|
|
Size m_size_increment;
|
|
|
|
Size m_base_size;
|
2019-03-06 23:03:36 +01:00
|
|
|
Retained<GraphicsBitmap> m_icon;
|
2019-03-31 23:52:02 +02:00
|
|
|
RetainPtr<WSCursor> m_override_cursor;
|
2019-04-05 15:54:56 +02:00
|
|
|
WSWindowFrame m_frame;
|
2019-01-16 16:03:50 +01:00
|
|
|
};
|