diff options
-rw-r--r-- | Base/res/icons/16x16/window-close.png | bin | 0 -> 115 bytes | |||
-rw-r--r-- | Base/res/icons/16x16/window-maximize.png | bin | 0 -> 90 bytes | |||
-rw-r--r-- | Base/res/icons/16x16/window-minimize.png | bin | 0 -> 92 bytes | |||
-rw-r--r-- | Base/res/icons/16x16/window-restore.png | bin | 0 -> 100 bytes | |||
-rw-r--r-- | Servers/WindowServer/MenuItem.cpp | 8 | ||||
-rw-r--r-- | Servers/WindowServer/MenuItem.h | 2 | ||||
-rw-r--r-- | Servers/WindowServer/Window.cpp | 52 | ||||
-rw-r--r-- | Servers/WindowServer/Window.h | 3 |
8 files changed, 60 insertions, 5 deletions
diff --git a/Base/res/icons/16x16/window-close.png b/Base/res/icons/16x16/window-close.png Binary files differnew file mode 100644 index 0000000000..61ddee97cc --- /dev/null +++ b/Base/res/icons/16x16/window-close.png diff --git a/Base/res/icons/16x16/window-maximize.png b/Base/res/icons/16x16/window-maximize.png Binary files differnew file mode 100644 index 0000000000..ef1fd57578 --- /dev/null +++ b/Base/res/icons/16x16/window-maximize.png diff --git a/Base/res/icons/16x16/window-minimize.png b/Base/res/icons/16x16/window-minimize.png Binary files differnew file mode 100644 index 0000000000..72ddab9fc5 --- /dev/null +++ b/Base/res/icons/16x16/window-minimize.png diff --git a/Base/res/icons/16x16/window-restore.png b/Base/res/icons/16x16/window-restore.png Binary files differnew file mode 100644 index 0000000000..cd305dbd6c --- /dev/null +++ b/Base/res/icons/16x16/window-restore.png diff --git a/Servers/WindowServer/MenuItem.cpp b/Servers/WindowServer/MenuItem.cpp index b062a47d9d..eba593c136 100644 --- a/Servers/WindowServer/MenuItem.cpp +++ b/Servers/WindowServer/MenuItem.cpp @@ -85,4 +85,12 @@ Gfx::Rect MenuItem::rect() const return m_rect.translated(0, m_menu.item_height() - (m_menu.scroll_offset() * m_menu.item_height())); } +void MenuItem::set_icon(const Gfx::Bitmap* icon) +{ + if (m_icon == icon) + return; + m_icon = icon; + m_menu.redraw(); +} + } diff --git a/Servers/WindowServer/MenuItem.h b/Servers/WindowServer/MenuItem.h index 297c751848..3f297adb43 100644 --- a/Servers/WindowServer/MenuItem.h +++ b/Servers/WindowServer/MenuItem.h @@ -70,7 +70,7 @@ public: unsigned identifier() const { return m_identifier; } const Gfx::Bitmap* icon() const { return m_icon; } - void set_icon(const Gfx::Bitmap* icon) { m_icon = icon; } + void set_icon(const Gfx::Bitmap*); bool is_submenu() const { return m_submenu_id != -1; } int submenu_id() const { return m_submenu_id; } diff --git a/Servers/WindowServer/Window.cpp b/Servers/WindowServer/Window.cpp index 550c067e13..2bc92c35b3 100644 --- a/Servers/WindowServer/Window.cpp +++ b/Servers/WindowServer/Window.cpp @@ -48,6 +48,38 @@ static Gfx::Bitmap& default_window_icon() return *s_icon; } +static Gfx::Bitmap& minimize_icon() +{ + static Gfx::Bitmap* s_icon; + if (!s_icon) + s_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/window-minimize.png").leak_ref(); + return *s_icon; +} + +static Gfx::Bitmap& maximize_icon() +{ + static Gfx::Bitmap* s_icon; + if (!s_icon) + s_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/window-maximize.png").leak_ref(); + return *s_icon; +} + +static Gfx::Bitmap& restore_icon() +{ + static Gfx::Bitmap* s_icon; + if (!s_icon) + s_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/window-restore.png").leak_ref(); + return *s_icon; +} + +static Gfx::Bitmap& close_icon() +{ + static Gfx::Bitmap* s_icon; + if (!s_icon) + s_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/window-close.png").leak_ref(); + return *s_icon; +} + Window::Window(Core::Object& parent, WindowType type) : Core::Object(&parent) , m_type(type) @@ -334,10 +366,19 @@ void Window::popup_window_menu(const Gfx::Point& position) m_window_menu = Menu::construct(nullptr, -1, "(Window Menu)"); m_window_menu->set_window_menu_of(*this); - m_window_menu->add_item(make<MenuItem>(*m_window_menu, 1, m_minimized ? "Unminimize" : "Minimize")); - m_window_menu->add_item(make<MenuItem>(*m_window_menu, 2, m_maximized ? "Restore" : "Maximize")); + auto minimize_item = make<MenuItem>(*m_window_menu, 1, m_minimized ? "Unminimize" : "Minimize"); + m_window_menu_minimize_item = minimize_item.ptr(); + m_window_menu->add_item(move(minimize_item)); + + auto maximize_item = make<MenuItem>(*m_window_menu, 2, m_maximized ? "Restore" : "Maximize"); + m_window_menu_maximize_item = maximize_item.ptr(); + m_window_menu->add_item(move(maximize_item)); + m_window_menu->add_item(make<MenuItem>(*m_window_menu, MenuItem::Type::Separator)); - m_window_menu->add_item(make<MenuItem>(*m_window_menu, 3, "Close")); + + auto close_item = make<MenuItem>(*m_window_menu, 3, "Close"); + close_item->set_icon(&close_icon()); + m_window_menu->add_item(move(close_item)); m_window_menu->item((int)PopupMenuItem::Minimize).set_enabled(m_minimizable); m_window_menu->item((int)PopupMenuItem::Maximize).set_enabled(m_resizable); @@ -361,6 +402,9 @@ void Window::popup_window_menu(const Gfx::Point& position) } }; } + m_window_menu_minimize_item->set_icon(m_minimized ? nullptr : &minimize_icon()); + m_window_menu_maximize_item->set_icon(m_maximized ? &restore_icon() : &maximize_icon()); + m_window_menu->popup(position); } @@ -402,7 +446,7 @@ Gfx::Rect Window::tiled_rect(WindowTileType tiled) const WindowManager::the().maximized_window_rect(*this).y(), Screen::the().width() / 2 - frame_width, WindowManager::the().maximized_window_rect(*this).height()); - default : + default: ASSERT_NOT_REACHED(); } } diff --git a/Servers/WindowServer/Window.h b/Servers/WindowServer/Window.h index 31f05c76b8..ce796b602f 100644 --- a/Servers/WindowServer/Window.h +++ b/Servers/WindowServer/Window.h @@ -40,6 +40,7 @@ namespace WindowServer { class ClientConnection; class Cursor; class Menu; +class MenuItem; class MouseEvent; enum WMEventMask { @@ -269,6 +270,8 @@ private: Gfx::Rect m_unmaximized_rect; Gfx::Rect m_rect_in_menubar; RefPtr<Menu> m_window_menu; + MenuItem* m_window_menu_minimize_item { nullptr }; + MenuItem* m_window_menu_maximize_item { nullptr }; int m_minimize_animation_step { -1 }; }; |