diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-03-20 04:34:14 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-03-20 04:34:14 +0100 |
commit | d17a91f1851e8f0b3a3353d677ad8d1f51e921b7 (patch) | |
tree | 30316253f23ab99c106832deeb6c7d36adab27fc /Servers/WindowServer/WSMenu.h | |
parent | 9120b05a4044b346be397b0ae5b9b7e9a8cbd0b1 (diff) | |
download | serenity-d17a91f1851e8f0b3a3353d677ad8d1f51e921b7.zip |
Move WindowServer into Servers.
Diffstat (limited to 'Servers/WindowServer/WSMenu.h')
-rw-r--r-- | Servers/WindowServer/WSMenu.h | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/Servers/WindowServer/WSMenu.h b/Servers/WindowServer/WSMenu.h new file mode 100644 index 0000000000..e7e6c34ef0 --- /dev/null +++ b/Servers/WindowServer/WSMenu.h @@ -0,0 +1,90 @@ +#pragma once + +#include <AK/AKString.h> +#include <AK/Vector.h> +#include <AK/WeakPtr.h> +#include <SharedGraphics/Rect.h> +#include <WindowServer/WSMenuItem.h> +#include <WindowServer/WSMessageReceiver.h> + +class WSClientConnection; +class WSMenuBar; +class WSMessage; +class WSWindow; +class Font; + +class WSMenu final : public WSMessageReceiver { +public: + WSMenu(WSClientConnection*, int menu_id, String&& name); + virtual ~WSMenu() override; + + WSClientConnection* client() { return m_client; } + const WSClientConnection* client() const { return m_client; } + int menu_id() const { return m_menu_id; } + + WSMenuBar* menu_bar() { return m_menubar; } + const WSMenuBar* menu_bar() const { return m_menubar; } + + bool is_empty() const { return m_items.is_empty(); } + int item_count() const { return m_items.size(); } + WSMenuItem* item(int i) { return m_items[i].ptr(); } + const WSMenuItem* item(int i) const { return m_items[i].ptr(); } + + void add_item(OwnPtr<WSMenuItem>&& item) { m_items.append(move(item)); } + + String name() const { return m_name; } + + template<typename Callback> + void for_each_item(Callback callback) const + { + for (auto& item : m_items) + callback(*item); + } + + Rect text_rect_in_menubar() const { return m_text_rect_in_menubar; } + void set_text_rect_in_menubar(const Rect& rect) { m_text_rect_in_menubar = rect; } + + Rect rect_in_menubar() const { return m_rect_in_menubar; } + void set_rect_in_menubar(const Rect& rect) { m_rect_in_menubar = rect; } + + WSWindow* menu_window() { return m_menu_window.ptr(); } + WSWindow& ensure_menu_window(); + + int width() const; + int height() const; + + int item_height() const { return 18; } + int vertical_padding() const { return 4; } + int horizontal_padding() const { return left_padding() + right_padding(); } + int left_padding() const { return 14; } + int right_padding() const { return 14; } + + void draw(); + const Font& font() const; + + WSMenuItem* item_at(const Point&); + void redraw(); + + const WSMenuItem* hovered_item() const { return m_hovered_item; } + void clear_hovered_item(); + + Function<void(WSMenuItem&)> on_item_activation; + + void close(); + +private: + virtual void on_message(WSMessage&) override; + + int padding_between_text_and_shortcut() const { return 50; } + void did_activate(WSMenuItem&); + WSClientConnection* m_client { nullptr }; + int m_menu_id { 0 }; + String m_name; + Rect m_rect_in_menubar; + Rect m_text_rect_in_menubar; + WSMenuBar* m_menubar { nullptr }; + WSMenuItem* m_hovered_item { nullptr }; + Vector<OwnPtr<WSMenuItem>> m_items; + OwnPtr<WSWindow> m_menu_window; +}; + |