opuntiaOS - an operating system targeting x86 and ARMv7
at master 84 lines 3.3 kB view raw
1/* 2 * Copyright (C) 2020-2022 The opuntiaOS Project Authors. 3 * + Contributed by Nikita Melekhin <nimelehin@gmail.com> 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9#include "Window.h" 10#include "../../Managers/WindowManager.h" 11#include <utility> 12 13namespace WinServer::Desktop { 14 15Window::Window(int connection_id, int id, CreateWindowMessage& msg) 16 : BaseWindow(connection_id, id, msg) 17 , m_frame(*this) 18{ 19 m_bounds = LG::Rect(0, 0, msg.width() + frame().left_border_size() + frame().right_border_size(), msg.height() + frame().top_border_size() + frame().bottom_border_size()); 20 m_content_bounds = LG::Rect(m_frame.left_border_size(), m_frame.top_border_size(), msg.width(), msg.height()); 21 m_content_bitmap = LG::PixelBitmap(m_buffer.data(), content_bounds().width(), content_bounds().height()); 22 23 // Creating standard menubar directory entry. 24 m_menubar_content.push_back(MenuDir(m_app_name, 0)); 25 m_menubar_content[0].add_item(PopupItem { PopupItem::InternalId, "Minimize others", [this](int) { WindowManager::the().minimize_windows([this](Window* win) { return win != this; }); } }); 26 m_menubar_content[0].add_item(PopupItem { PopupItem::InternalId, "Minimize", [this](int) { WindowManager::the().minimize_window(*this); } }); 27 m_menubar_content[0].add_item(PopupItem { PopupItem::InternalId, "Close", [this](int) { WindowManager::the().close_window(*this); } }); 28} 29 30Window::Window(Window&& win) 31 : BaseWindow(std::move(win)) 32 , m_frame(*this, std::move(win.m_frame.control_panel_buttons()), std::move(win.m_frame.window_control_buttons())) 33 , m_corner_mask(std::move(win.m_corner_mask)) 34 , m_menubar_content(std::move(win.m_menubar_content)) 35{ 36} 37 38void Window::make_frame() 39{ 40 uint32_t x = m_bounds.min_x(); 41 uint32_t y = m_bounds.min_y(); 42 uint32_t content_width = m_content_bounds.width(); 43 uint32_t content_height = m_content_bounds.height(); 44 m_bounds = LG::Rect(x, y, content_width + frame().left_border_size() + frame().right_border_size(), content_height + frame().top_border_size() + frame().bottom_border_size()); 45 m_content_bounds = LG::Rect(x + m_frame.left_border_size(), y + m_frame.top_border_size(), content_width, content_height); 46 m_frame.set_visible(true); 47} 48 49void Window::make_frameless() 50{ 51 uint32_t x = m_bounds.min_x(); 52 uint32_t y = m_bounds.min_y(); 53 uint32_t content_width = m_content_bounds.width(); 54 uint32_t content_height = m_content_bounds.height(); 55 m_bounds = LG::Rect(x, y, content_width, content_height); 56 m_content_bounds = LG::Rect(x, y, content_width, content_height); 57 m_frame.set_visible(false); 58} 59 60void Window::recalc_bounds(const LG::Size& size) 61{ 62 m_content_bounds.set_width(size.width()); 63 m_content_bounds.set_height(size.height()); 64 65 m_bounds.set_width(size.width() + frame().left_border_size() + frame().right_border_size()); 66 m_bounds.set_height(size.height() + frame().top_border_size() + frame().bottom_border_size()); 67} 68 69void Window::did_size_change(const LG::Size& size) 70{ 71 recalc_bounds(size); 72} 73 74void Window::on_style_change() 75{ 76 WindowManager::the().on_window_style_change(*this); 77} 78 79void Window::on_menubar_change() 80{ 81 WindowManager::the().on_window_menubar_change(*this); 82} 83 84} // namespace WinServer