mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
Everywhere: Stop using NonnullOwnPtrVector
Same as NonnullRefPtrVector: weird semantics, questionable benefits.
This commit is contained in:
parent
689ca370d4
commit
359d6e7b0b
111 changed files with 517 additions and 503 deletions
|
@ -73,14 +73,14 @@ int Menu::content_width() const
|
|||
int widest_text = 0;
|
||||
int widest_shortcut = 0;
|
||||
for (auto& item : m_items) {
|
||||
if (!item.is_visible())
|
||||
if (!item->is_visible())
|
||||
continue;
|
||||
if (item.type() != MenuItem::Text)
|
||||
if (item->type() != MenuItem::Text)
|
||||
continue;
|
||||
auto& use_font = item.is_default() ? font().bold_variant() : font();
|
||||
int text_width = use_font.width(Gfx::parse_ampersand_string(item.text()));
|
||||
if (!item.shortcut_text().is_empty()) {
|
||||
int shortcut_width = use_font.width(item.shortcut_text());
|
||||
auto& use_font = item->is_default() ? font().bold_variant() : font();
|
||||
int text_width = use_font.width(Gfx::parse_ampersand_string(item->text()));
|
||||
if (!item->shortcut_text().is_empty()) {
|
||||
int shortcut_width = use_font.width(item->shortcut_text());
|
||||
widest_shortcut = max(shortcut_width, widest_shortcut);
|
||||
}
|
||||
widest_text = max(widest_text, text_width);
|
||||
|
@ -129,7 +129,7 @@ Window& Menu::ensure_menu_window(Gfx::IntPoint position)
|
|||
auto calculate_window_rect = [&]() -> Gfx::IntRect {
|
||||
int window_height_available = screen.height() - frame_thickness() * 2;
|
||||
int max_window_height = (window_height_available / item_height()) * item_height() + frame_thickness() * 2;
|
||||
int content_height = m_items.is_empty() ? 0 : (m_items.last().rect().bottom() + 1) + frame_thickness();
|
||||
int content_height = m_items.is_empty() ? 0 : (m_items.last()->rect().bottom() + 1) + frame_thickness();
|
||||
int window_height = min(max_window_height, content_height);
|
||||
if (window_height < content_height) {
|
||||
m_scrollable = true;
|
||||
|
@ -140,14 +140,14 @@ Window& Menu::ensure_menu_window(Gfx::IntPoint position)
|
|||
|
||||
Gfx::IntPoint next_item_location(frame_thickness(), frame_thickness());
|
||||
for (auto& item : m_items) {
|
||||
if (!item.is_visible())
|
||||
if (!item->is_visible())
|
||||
continue;
|
||||
int height = 0;
|
||||
if (item.type() == MenuItem::Text)
|
||||
if (item->type() == MenuItem::Text)
|
||||
height = item_height();
|
||||
else if (item.type() == MenuItem::Separator)
|
||||
else if (item->type() == MenuItem::Separator)
|
||||
height = 8;
|
||||
item.set_rect({ next_item_location, { width - frame_thickness() * 2, height } });
|
||||
item->set_rect({ next_item_location, { width - frame_thickness() * 2, height } });
|
||||
next_item_location.translate_by(0, height);
|
||||
}
|
||||
|
||||
|
@ -217,7 +217,7 @@ void Menu::draw()
|
|||
|
||||
int visible_item_count = this->visible_item_count();
|
||||
for (int i = 0; i < visible_item_count; ++i)
|
||||
draw(m_items.at(m_scroll_offset + i), true);
|
||||
draw(*m_items[m_scroll_offset + i], true);
|
||||
}
|
||||
|
||||
void Menu::draw(MenuItem const& item, bool is_drawing_all)
|
||||
|
@ -407,9 +407,9 @@ void Menu::event(Core::Event& event)
|
|||
// Default to the last enabled, non-separator item on key press if one has not been selected yet
|
||||
for (auto i = static_cast<int>(m_items.size()) - 1; i >= 0; i--) {
|
||||
auto& item = m_items.at(i);
|
||||
if (!item.is_visible())
|
||||
if (!item->is_visible())
|
||||
continue;
|
||||
if (item.type() != MenuItem::Separator && item.is_enabled()) {
|
||||
if (item->type() != MenuItem::Separator && item->is_enabled()) {
|
||||
set_hovered_index(i, key == Key_Right);
|
||||
break;
|
||||
}
|
||||
|
@ -418,9 +418,9 @@ void Menu::event(Core::Event& event)
|
|||
// Default to the first enabled, non-separator item on key press if one has not been selected yet
|
||||
int counter = 0;
|
||||
for (auto const& item : m_items) {
|
||||
if (!item.is_visible())
|
||||
if (!item->is_visible())
|
||||
continue;
|
||||
if (item.type() != MenuItem::Separator && item.is_enabled()) {
|
||||
if (item->type() != MenuItem::Separator && item->is_enabled()) {
|
||||
set_hovered_index(counter, key == Key_Right);
|
||||
break;
|
||||
}
|
||||
|
@ -562,12 +562,12 @@ void Menu::did_activate(MenuItem& item, bool leave_menu_open)
|
|||
bool Menu::activate_default()
|
||||
{
|
||||
for (auto& item : m_items) {
|
||||
if (!item.is_visible())
|
||||
if (!item->is_visible())
|
||||
continue;
|
||||
if (item.type() == MenuItem::Type::Separator)
|
||||
if (item->type() == MenuItem::Type::Separator)
|
||||
continue;
|
||||
if (item.is_enabled() && item.is_default()) {
|
||||
did_activate(item, false);
|
||||
if (item->is_enabled() && item->is_default()) {
|
||||
did_activate(*item, false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -577,8 +577,8 @@ bool Menu::activate_default()
|
|||
MenuItem* Menu::item_with_identifier(unsigned identifier)
|
||||
{
|
||||
for (auto& item : m_items) {
|
||||
if (item.identifier() == identifier)
|
||||
return &item;
|
||||
if (item->identifier() == identifier)
|
||||
return item;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -592,9 +592,9 @@ int Menu::item_index_at(Gfx::IntPoint position)
|
|||
{
|
||||
for (int i = 0; i < static_cast<int>(m_items.size()); ++i) {
|
||||
auto const& item = m_items[i];
|
||||
if (!item.is_visible())
|
||||
if (!item->is_visible())
|
||||
continue;
|
||||
if (item.rect().contains(position))
|
||||
if (item->rect().contains(position))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
|
@ -684,9 +684,9 @@ void Menu::do_popup(Gfx::IntPoint position, bool make_input, bool as_submenu)
|
|||
bool Menu::is_menu_ancestor_of(Menu const& other) const
|
||||
{
|
||||
for (auto& item : m_items) {
|
||||
if (!item.is_submenu())
|
||||
if (!item->is_submenu())
|
||||
continue;
|
||||
auto& submenu = *item.submenu();
|
||||
auto& submenu = *item->submenu();
|
||||
if (&submenu == &other)
|
||||
return true;
|
||||
if (submenu.is_menu_ancestor_of(other))
|
||||
|
@ -711,7 +711,7 @@ void Menu::update_alt_shortcuts_for_items()
|
|||
m_alt_shortcut_character_to_item_indices.clear();
|
||||
int i = 0;
|
||||
for (auto& item : m_items) {
|
||||
if (auto alt_shortcut = find_ampersand_shortcut_character(item.text())) {
|
||||
if (auto alt_shortcut = find_ampersand_shortcut_character(item->text())) {
|
||||
m_alt_shortcut_character_to_item_indices.ensure(to_ascii_lowercase(alt_shortcut)).append(i);
|
||||
}
|
||||
++i;
|
||||
|
|
|
@ -40,8 +40,8 @@ public:
|
|||
|
||||
bool is_empty() const { return m_items.is_empty(); }
|
||||
size_t item_count() const { return m_items.size(); }
|
||||
MenuItem const& item(size_t index) const { return m_items.at(index); }
|
||||
MenuItem& item(size_t index) { return m_items.at(index); }
|
||||
MenuItem const& item(size_t index) const { return *m_items.at(index); }
|
||||
MenuItem& item(size_t index) { return *m_items.at(index); }
|
||||
|
||||
MenuItem* item_by_identifier(unsigned identifier)
|
||||
{
|
||||
|
@ -65,7 +65,7 @@ public:
|
|||
IterationDecision for_each_item(Callback callback)
|
||||
{
|
||||
for (auto& item : m_items) {
|
||||
IterationDecision decision = callback(item);
|
||||
IterationDecision decision = callback(*item);
|
||||
if (decision != IterationDecision::Continue)
|
||||
return decision;
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ private:
|
|||
u32 m_alt_shortcut_character { 0 };
|
||||
Gfx::IntRect m_rect_in_window_menubar;
|
||||
Gfx::IntPoint m_unadjusted_position;
|
||||
NonnullOwnPtrVector<MenuItem> m_items;
|
||||
Vector<NonnullOwnPtr<MenuItem>> m_items;
|
||||
RefPtr<Window> m_menu_window;
|
||||
|
||||
WeakPtr<Window> m_window_menu_of;
|
||||
|
|
|
@ -294,7 +294,7 @@ Gfx::WindowTheme::WindowState WindowFrame::window_state_for_theme() const
|
|||
void WindowFrame::paint_notification_frame(Gfx::Painter& painter)
|
||||
{
|
||||
auto palette = WindowManager::the().palette();
|
||||
Gfx::WindowTheme::current().paint_notification_frame(painter, to_theme_window_mode(m_window.mode()), m_window.rect(), palette, m_buttons.last().relative_rect());
|
||||
Gfx::WindowTheme::current().paint_notification_frame(painter, to_theme_window_mode(m_window.mode()), m_window.rect(), palette, m_buttons.last()->relative_rect());
|
||||
}
|
||||
|
||||
void WindowFrame::paint_menubar(Gfx::Painter& painter)
|
||||
|
@ -401,7 +401,7 @@ void WindowFrame::render(Screen& screen, Gfx::Painter& painter)
|
|||
return;
|
||||
|
||||
for (auto& button : m_buttons)
|
||||
button.paint(screen, painter);
|
||||
button->paint(screen, painter);
|
||||
}
|
||||
|
||||
void WindowFrame::theme_changed()
|
||||
|
@ -585,7 +585,7 @@ Gfx::IntRect WindowFrame::constrained_render_rect_to_screen(Gfx::IntRect const&
|
|||
Gfx::IntRect WindowFrame::leftmost_titlebar_button_rect() const
|
||||
{
|
||||
if (!m_buttons.is_empty())
|
||||
return m_buttons.last().relative_rect();
|
||||
return m_buttons.last()->relative_rect();
|
||||
|
||||
auto rect = titlebar_rect();
|
||||
rect.translate_by(rect.width(), 0);
|
||||
|
@ -677,7 +677,7 @@ void WindowFrame::layout_buttons()
|
|||
{
|
||||
auto button_rects = Gfx::WindowTheme::current().layout_buttons(to_theme_window_type(m_window.type()), to_theme_window_mode(m_window.mode()), m_window.rect(), WindowManager::the().palette(), m_buttons.size());
|
||||
for (size_t i = 0; i < m_buttons.size(); i++)
|
||||
m_buttons[i].set_relative_rect(button_rects[i]);
|
||||
m_buttons[i]->set_relative_rect(button_rects[i]);
|
||||
}
|
||||
|
||||
Optional<HitTestResult> WindowFrame::hit_test(Gfx::IntPoint position)
|
||||
|
@ -795,8 +795,8 @@ void WindowFrame::handle_titlebar_mouse_event(MouseEvent const& event)
|
|||
}
|
||||
|
||||
for (auto& button : m_buttons) {
|
||||
if (button.relative_rect().contains(event.position()))
|
||||
return button.on_mouse_event(event.translated(-button.relative_rect().location()));
|
||||
if (button->relative_rect().contains(event.position()))
|
||||
return button->on_mouse_event(event.translated(-button->relative_rect().location()));
|
||||
}
|
||||
|
||||
if (event.type() == Event::MouseDown) {
|
||||
|
|
|
@ -138,7 +138,7 @@ private:
|
|||
Gfx::IntRect leftmost_titlebar_button_rect() const;
|
||||
|
||||
Window& m_window;
|
||||
NonnullOwnPtrVector<Button> m_buttons;
|
||||
Vector<NonnullOwnPtr<Button>> m_buttons;
|
||||
Button* m_close_button { nullptr };
|
||||
Button* m_maximize_button { nullptr };
|
||||
Button* m_minimize_button { nullptr };
|
||||
|
|
|
@ -44,7 +44,7 @@ WindowManager::WindowManager(Gfx::PaletteImpl& palette)
|
|||
|
||||
{
|
||||
// If we haven't created any window stacks, at least create the stationary/main window stack
|
||||
auto row = adopt_own(*new RemoveReference<decltype(m_window_stacks[0])>());
|
||||
auto row = adopt_own(*new RemoveReference<decltype(*m_window_stacks[0])>());
|
||||
auto main_window_stack = adopt_own(*new WindowStack(0, 0));
|
||||
main_window_stack->set_stationary_window_stack(*main_window_stack);
|
||||
m_current_window_stack = main_window_stack.ptr();
|
||||
|
@ -191,9 +191,9 @@ bool WindowManager::apply_workspace_settings(unsigned rows, unsigned columns, bo
|
|||
|
||||
// While we have too many rows, merge each row too many into the new bottom row
|
||||
while (current_rows > rows) {
|
||||
auto& row = m_window_stacks[rows];
|
||||
auto& row = *m_window_stacks[rows];
|
||||
for (size_t column_index = 0; column_index < row.size(); column_index++) {
|
||||
merge_window_stack(row[column_index], m_window_stacks[rows - 1][column_index]);
|
||||
merge_window_stack(*row[column_index], *(*m_window_stacks[rows - 1])[column_index]);
|
||||
if (rows - 1 == current_stack_row && column_index == current_stack_column)
|
||||
need_rerender = true;
|
||||
}
|
||||
|
@ -203,8 +203,8 @@ bool WindowManager::apply_workspace_settings(unsigned rows, unsigned columns, bo
|
|||
// While we have too many columns, merge each column too many into the new right most column
|
||||
while (current_columns > columns) {
|
||||
for (size_t row_index = 0; row_index < current_rows; row_index++) {
|
||||
auto& row = m_window_stacks[row_index];
|
||||
merge_window_stack(row[columns], row[columns - 1]);
|
||||
auto& row = *m_window_stacks[row_index];
|
||||
merge_window_stack(*row[columns], *row[columns - 1]);
|
||||
if (row_index == current_stack_row && columns - 1 == current_stack_column)
|
||||
need_rerender = true;
|
||||
row.remove(columns);
|
||||
|
@ -213,10 +213,10 @@ bool WindowManager::apply_workspace_settings(unsigned rows, unsigned columns, bo
|
|||
}
|
||||
// Add more rows if necessary
|
||||
while (rows > current_rows) {
|
||||
auto row = adopt_own(*new RemoveReference<decltype(m_window_stacks[0])>());
|
||||
auto row = adopt_own(*new RemoveReference<decltype(*m_window_stacks[0])>());
|
||||
for (size_t column_index = 0; column_index < columns; column_index++) {
|
||||
auto window_stack = adopt_own(*new WindowStack(current_rows, column_index));
|
||||
window_stack->set_stationary_window_stack(m_window_stacks[0][0]);
|
||||
window_stack->set_stationary_window_stack(*(*m_window_stacks[0])[0]);
|
||||
row->append(move(window_stack));
|
||||
}
|
||||
m_window_stacks.append(move(row));
|
||||
|
@ -226,10 +226,10 @@ bool WindowManager::apply_workspace_settings(unsigned rows, unsigned columns, bo
|
|||
while (columns > current_columns) {
|
||||
for (size_t row_index = 0; row_index < current_rows; row_index++) {
|
||||
auto& row = m_window_stacks[row_index];
|
||||
while (row.size() < columns) {
|
||||
auto window_stack = adopt_own(*new WindowStack(row_index, row.size()));
|
||||
window_stack->set_stationary_window_stack(m_window_stacks[0][0]);
|
||||
row.append(move(window_stack));
|
||||
while (row->size() < columns) {
|
||||
auto window_stack = adopt_own(*new WindowStack(row_index, row->size()));
|
||||
window_stack->set_stationary_window_stack(*(*m_window_stacks[0])[0]);
|
||||
row->append(move(window_stack));
|
||||
}
|
||||
}
|
||||
current_columns++;
|
||||
|
@ -237,7 +237,7 @@ bool WindowManager::apply_workspace_settings(unsigned rows, unsigned columns, bo
|
|||
|
||||
if (removing_current_stack) {
|
||||
// If we're on a window stack that was removed, we need to move...
|
||||
m_current_window_stack = &m_window_stacks[new_current_row][new_current_column];
|
||||
m_current_window_stack = (*m_window_stacks[new_current_row])[new_current_column];
|
||||
Compositor::the().set_current_window_stack_no_transition(*m_current_window_stack);
|
||||
need_rerender = false; // The compositor already called invalidate_for_window_stack_merge_or_change for us
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ bool WindowManager::is_natural_scroll() const
|
|||
WindowStack& WindowManager::window_stack_for_window(Window& window)
|
||||
{
|
||||
if (is_stationary_window_type(window.type()))
|
||||
return m_window_stacks[0][0];
|
||||
return *(*m_window_stacks[0])[0];
|
||||
if (auto* parent = window.parent_window(); parent && !is_stationary_window_type(parent->type()))
|
||||
return parent->window_stack();
|
||||
return current_window_stack();
|
||||
|
@ -1657,7 +1657,7 @@ void WindowManager::process_key_event(KeyEvent& event)
|
|||
column--;
|
||||
return true;
|
||||
case Key_Right:
|
||||
if (column + 1 >= m_window_stacks[0].size())
|
||||
if (column + 1 >= m_window_stacks[0]->size())
|
||||
return true;
|
||||
column++;
|
||||
return true;
|
||||
|
@ -1678,7 +1678,7 @@ void WindowManager::process_key_event(KeyEvent& event)
|
|||
if (handle_window_stack_switch_key()) {
|
||||
request_close_fragile_windows();
|
||||
Window* carry_window = nullptr;
|
||||
auto& new_window_stack = m_window_stacks[row][column];
|
||||
auto& new_window_stack = *(*m_window_stacks[row])[column];
|
||||
if (&new_window_stack != ¤t_stack) {
|
||||
if (event.modifiers() == (Mod_Ctrl | Mod_Shift | Mod_Alt))
|
||||
carry_window = this->active_window();
|
||||
|
|
|
@ -259,11 +259,11 @@ public:
|
|||
void switch_to_window_stack(u32 row, u32 col, Window* carry = nullptr, bool show_overlay = true)
|
||||
{
|
||||
if (row < window_stack_rows() && col < window_stack_columns())
|
||||
switch_to_window_stack(m_window_stacks[row][col], carry, show_overlay);
|
||||
switch_to_window_stack(*(*m_window_stacks[row])[col], carry, show_overlay);
|
||||
}
|
||||
|
||||
size_t window_stack_rows() const { return m_window_stacks.size(); }
|
||||
size_t window_stack_columns() const { return m_window_stacks[0].size(); }
|
||||
size_t window_stack_columns() const { return m_window_stacks[0]->size(); }
|
||||
|
||||
bool apply_workspace_settings(unsigned rows, unsigned columns, bool save);
|
||||
|
||||
|
@ -277,8 +277,8 @@ public:
|
|||
IterationDecision for_each_window_stack(F f)
|
||||
{
|
||||
for (auto& row : m_window_stacks) {
|
||||
for (auto& stack : row) {
|
||||
IterationDecision decision = f(stack);
|
||||
for (auto& stack : *row) {
|
||||
IterationDecision decision = f(*stack);
|
||||
if (decision != IterationDecision::Continue)
|
||||
return decision;
|
||||
}
|
||||
|
@ -397,7 +397,7 @@ private:
|
|||
RefPtr<MultiScaleBitmaps> m_overlay_rect_shadow;
|
||||
|
||||
// Setup 2 rows 1 column by default
|
||||
NonnullOwnPtrVector<NonnullOwnPtrVector<WindowStack, default_window_stack_columns>, default_window_stack_rows> m_window_stacks;
|
||||
Vector<NonnullOwnPtr<Vector<NonnullOwnPtr<WindowStack>, default_window_stack_columns>>, default_window_stack_rows> m_window_stacks;
|
||||
WindowStack* m_current_window_stack { nullptr };
|
||||
|
||||
struct DoubleClickInfo {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue