1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-29 14:05:11 +00:00
serenity/Userland/Services/WindowServer/MenuManager.h
creator1creeper1 19d9d5bfe1 Everywhere: Mark Vector of mutable references as mutable
The point of a reference type is to behave just like the referred-to
type. So, a Foo& should behave just like a Foo.

In these cases, we had a const Vector. If it was a const Vector of Foo,
iterating over the Vector would only permit taking const references to
the individual Foos.

However, we had a const Vector of Foo&. The behavior should not
change. We should still only be permitted to take const references to
the individual Foos. Otherwise, we would be allowed to mutate the
individual Foos, which would mutate the elements of the const Vector.
This wouldn't modify the stored pointers, but it would modify the
objects that the references refer to. Since references should be
transparent, this should not be legal.

So it should be impossible to get mutable references into a const
Vector. Since we need mutable references in these cases to call the
mutating member functions, we need to mark the Vector as mutable as
well.
2022-01-16 00:38:21 +03:30

68 lines
1.5 KiB
C++

/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include "Menu.h"
#include "Menubar.h"
#include "Window.h"
#include <AK/HashMap.h>
#include <AK/StringBuilder.h>
namespace WindowServer {
class MenuManager final : public Core::Object {
C_OBJECT(MenuManager);
public:
static MenuManager& the();
virtual ~MenuManager() override;
bool is_open(const Menu&) const;
bool has_open_menu() const { return !m_open_menu_stack.is_empty(); }
Menu* current_menu() { return m_current_menu.ptr(); }
void set_current_menu(Menu*);
void clear_current_menu();
void open_menu(Menu&, bool as_current_menu = true);
void close_everyone();
void close_everyone_not_in_lineage(Menu&);
void close_menu_and_descendants(Menu&);
void close_all_menus_from_client(Badge<ClientConnection>, ClientConnection&);
int theme_index() const { return m_theme_index; }
Menu* previous_menu(Menu* current);
Menu* next_menu(Menu* current);
void did_change_theme();
void set_hovered_menu(Menu*);
Menu* hovered_menu() { return m_hovered_menu; }
private:
MenuManager();
void close_menus(Vector<Menu&>&);
virtual void event(Core::Event&) override;
void handle_mouse_event(MouseEvent&);
void refresh();
WeakPtr<Menu> m_current_menu;
WeakPtr<Window> m_previous_input_window;
Vector<WeakPtr<Menu>> m_open_menu_stack;
int m_theme_index { 0 };
WeakPtr<Menu> m_hovered_menu;
};
}