WSWindow.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #pragma once
  2. #include <SharedGraphics/Rect.h>
  3. #include <SharedGraphics/GraphicsBitmap.h>
  4. #include <AK/AKString.h>
  5. #include <AK/InlineLinkedList.h>
  6. #include <LibCore/CObject.h>
  7. #include <WindowServer/WSWindowType.h>
  8. #include <WindowServer/WSWindowFrame.h>
  9. #include <SharedGraphics/DisjointRectSet.h>
  10. class WSClientConnection;
  11. class WSCursor;
  12. class WSMenu;
  13. class WSMouseEvent;
  14. class WSWindow final : public CObject, public InlineLinkedListNode<WSWindow> {
  15. public:
  16. WSWindow(WSClientConnection&, WSWindowType, int window_id, bool modal, bool resizable, bool fullscreen);
  17. WSWindow(CObject&, WSWindowType);
  18. virtual ~WSWindow() override;
  19. unsigned wm_event_mask() const { return m_wm_event_mask; }
  20. void set_wm_event_mask(unsigned mask) { m_wm_event_mask = mask; }
  21. Color background_color() const { return m_background_color; }
  22. void set_background_color(Color color) { m_background_color = color; }
  23. bool is_minimized() const { return m_minimized; }
  24. void set_minimized(bool);
  25. bool is_maximized() const { return m_maximized; }
  26. void set_maximized(bool);
  27. bool is_fullscreen() const { return m_fullscreen; }
  28. WSWindowFrame& frame() { return m_frame; }
  29. const WSWindowFrame& frame() const { return m_frame; }
  30. bool is_blocked_by_modal_window() const;
  31. bool listens_to_wm_events() const { return m_listens_to_wm_events; }
  32. WSClientConnection* client() { return m_client; }
  33. const WSClientConnection* client() const { return m_client; }
  34. WSWindowType type() const { return m_type; }
  35. int window_id() const { return m_window_id; }
  36. String title() const { return m_title; }
  37. void set_title(const String&);
  38. float opacity() const { return m_opacity; }
  39. void set_opacity(float opacity) { m_opacity = opacity; }
  40. int x() const { return m_rect.x(); }
  41. int y() const { return m_rect.y(); }
  42. int width() const { return m_rect.width(); }
  43. int height() const { return m_rect.height(); }
  44. bool is_active() const;
  45. bool is_visible() const { return m_visible; }
  46. void set_visible(bool);
  47. bool is_modal() const { return m_modal; }
  48. bool is_resizable() const { return m_resizable && !m_fullscreen; }
  49. Rect rect() const { return m_rect; }
  50. void set_rect(const Rect&);
  51. void set_rect(int x, int y, int width, int height) { set_rect({ x, y, width, height }); }
  52. void set_rect_without_repaint(const Rect& rect)
  53. {
  54. if (m_rect == rect)
  55. return;
  56. auto old_rect = m_rect;
  57. m_rect = rect;
  58. m_frame.notify_window_rect_changed(old_rect, rect);
  59. }
  60. void set_rect_from_window_manager_resize(const Rect&);
  61. void move_to(const Point& position) { set_rect({ position, size() }); }
  62. void move_to(int x, int y) { move_to({ x, y }); }
  63. Point position() const { return m_rect.location(); }
  64. void set_position(const Point& position) { set_rect({ position.x(), position.y(), width(), height() }); }
  65. void set_position_without_repaint(const Point& position) { set_rect_without_repaint({ position.x(), position.y(), width(), height() }); }
  66. Size size() const { return m_rect.size(); }
  67. void invalidate();
  68. virtual void event(CEvent&) override;
  69. GraphicsBitmap* backing_store() { return m_backing_store.ptr(); }
  70. void set_backing_store(RetainPtr<GraphicsBitmap>&& backing_store)
  71. {
  72. m_last_backing_store = move(m_backing_store);
  73. m_backing_store = move(backing_store);
  74. }
  75. void swap_backing_stores()
  76. {
  77. swap(m_backing_store, m_last_backing_store);
  78. }
  79. GraphicsBitmap* last_backing_store() { return m_last_backing_store.ptr(); }
  80. void set_global_cursor_tracking_enabled(bool);
  81. void set_automatic_cursor_tracking_enabled(bool enabled) { m_automatic_cursor_tracking_enabled = enabled; }
  82. bool global_cursor_tracking() const { return m_global_cursor_tracking_enabled || m_automatic_cursor_tracking_enabled; }
  83. bool has_alpha_channel() const { return m_has_alpha_channel; }
  84. void set_has_alpha_channel(bool value) { m_has_alpha_channel = value; }
  85. Size size_increment() const { return m_size_increment; }
  86. void set_size_increment(const Size& increment) { m_size_increment = increment; }
  87. Size base_size() const { return m_base_size; }
  88. void set_base_size(const Size& size) { m_base_size = size; }
  89. const GraphicsBitmap& icon() const { return *m_icon; }
  90. String icon_path() const { return m_icon_path; }
  91. void set_icon(const String& path, Retained<GraphicsBitmap>&& icon)
  92. {
  93. m_icon_path = path;
  94. m_icon = move(icon);
  95. }
  96. void set_default_icon();
  97. const WSCursor* override_cursor() const { return m_override_cursor.ptr(); }
  98. void set_override_cursor(RetainPtr<WSCursor>&& cursor) { m_override_cursor = move(cursor); }
  99. void request_update(const Rect&);
  100. DisjointRectSet take_pending_paint_rects() { return move(m_pending_paint_rects); }
  101. // For InlineLinkedList.
  102. // FIXME: Maybe make a ListHashSet and then WSWindowManager can just use that.
  103. WSWindow* m_next { nullptr };
  104. WSWindow* m_prev { nullptr };
  105. private:
  106. void handle_mouse_event(const WSMouseEvent&);
  107. WSClientConnection* m_client { nullptr };
  108. CObject* m_internal_owner { nullptr };
  109. String m_title;
  110. Rect m_rect;
  111. WSWindowType m_type { WSWindowType::Normal };
  112. bool m_global_cursor_tracking_enabled { false };
  113. bool m_automatic_cursor_tracking_enabled { false };
  114. bool m_visible { true };
  115. bool m_has_alpha_channel { false };
  116. bool m_modal { false };
  117. bool m_resizable { false };
  118. bool m_listens_to_wm_events { false };
  119. bool m_minimized { false };
  120. bool m_maximized { false };
  121. bool m_fullscreen { false };
  122. RetainPtr<GraphicsBitmap> m_backing_store;
  123. RetainPtr<GraphicsBitmap> m_last_backing_store;
  124. int m_window_id { -1 };
  125. float m_opacity { 1 };
  126. Size m_size_increment;
  127. Size m_base_size;
  128. Retained<GraphicsBitmap> m_icon;
  129. String m_icon_path;
  130. RetainPtr<WSCursor> m_override_cursor;
  131. WSWindowFrame m_frame;
  132. Color m_background_color { Color::LightGray };
  133. unsigned m_wm_event_mask { 0 };
  134. DisjointRectSet m_pending_paint_rects;
  135. Rect m_unmaximized_rect;
  136. };