ladybird/Userland/Services/WindowServer/Menubar.h
Andreas Kling b91c49364d AK: Rename adopt() to adopt_ref()
This makes it more symmetrical with adopt_own() (which is used to
create a NonnullOwnPtr from the result of a naked new.)
2021-04-23 16:46:57 +02:00

46 lines
1.0 KiB
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include "Menu.h"
#include <AK/Vector.h>
#include <AK/WeakPtr.h>
#include <AK/Weakable.h>
namespace WindowServer {
class Menubar
: public RefCounted<Menubar>
, public Weakable<Menubar> {
public:
static NonnullRefPtr<Menubar> create(ClientConnection& client, int menubar_id) { return adopt_ref(*new Menubar(client, menubar_id)); }
~Menubar();
ClientConnection& client() { return m_client; }
const ClientConnection& client() const { return m_client; }
int menubar_id() const { return m_menubar_id; }
void add_menu(Menu&);
template<typename Callback>
void for_each_menu(Callback callback)
{
for (auto& menu : m_menus) {
if (callback(*menu) == IterationDecision::Break)
return;
}
}
private:
Menubar(ClientConnection&, int menubar_id);
ClientConnection& m_client;
int m_menubar_id { 0 };
Vector<Menu*> m_menus;
};
}