From e655aebd70bb7d248c2f7be4a12d695ceec707a5 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 16 Jan 2019 13:49:44 +0100 Subject: [PATCH] Window: Update coding style. --- Kernel/ProcessGUI.cpp | 4 ++-- Widgets/Widget.cpp | 4 ++-- Widgets/Window.cpp | 17 +++-------------- Widgets/Window.h | 24 +++++++++--------------- Widgets/WindowManager.cpp | 6 +++--- Widgets/test.cpp | 8 ++++---- 6 files changed, 23 insertions(+), 40 deletions(-) diff --git a/Kernel/ProcessGUI.cpp b/Kernel/ProcessGUI.cpp index f4ba4748d86..6801a9e86b8 100644 --- a/Kernel/ProcessGUI.cpp +++ b/Kernel/ProcessGUI.cpp @@ -63,8 +63,8 @@ int Process::gui$create_window(const GUI_CreateWindowParameters* user_params) if (!window) return -ENOMEM; - window->setTitle(params.title); - window->setRect(rect); + window->set_title(params.title); + window->set_rect(rect); m_windows.set(window_id, move(window)); dbgprintf("%s<%u> gui$create_window: %d with rect {%d,%d %dx%d}\n", name().characters(), pid(), window_id, rect.x(), rect.y(), rect.width(), rect.height()); diff --git a/Widgets/Widget.cpp b/Widgets/Widget.cpp index 3a2dea77e7d..66d5b0cf011 100644 --- a/Widgets/Widget.cpp +++ b/Widgets/Widget.cpp @@ -38,9 +38,9 @@ void Widget::event(Event& event) case Event::Paint: m_hasPendingPaintEvent = false; if (auto* win = window()) { - if (win->isBeingDragged()) + if (win->is_being_dragged()) return; - if (!win->isVisible()) + if (!win->is_visible()) return; } return paintEvent(static_cast(event)); diff --git a/Widgets/Window.cpp b/Widgets/Window.cpp index f70dcee59ef..29db30eb746 100644 --- a/Widgets/Window.cpp +++ b/Widgets/Window.cpp @@ -2,7 +2,6 @@ #include "WindowManager.h" #include "Event.h" #include "EventLoop.h" -#include "Widget.h" #include "Process.h" Window::Window(Process& process, int window_id) @@ -17,7 +16,7 @@ Window::~Window() WindowManager::the().removeWindow(*this); } -void Window::setTitle(String&& title) +void Window::set_title(String&& title) { if (m_title == title) return; @@ -26,7 +25,7 @@ void Window::setTitle(String&& title) WindowManager::the().notifyTitleChanged(*this); } -void Window::setRect(const Rect& rect) +void Window::set_rect(const Rect& rect) { if (m_rect == rect) return; @@ -87,17 +86,7 @@ void Window::event(Event& event) } } -void Window::did_paint() -{ - WindowManager::the().did_paint(*this); -} - -bool Window::isActive() const -{ - return WindowManager::the().activeWindow() == this; -} - -bool Window::isVisible() const +bool Window::is_visible() const { return WindowManager::the().isVisible(const_cast(*this)); } diff --git a/Widgets/Window.h b/Widgets/Window.h index 3376e6926ab..3da05c3c97e 100644 --- a/Widgets/Window.h +++ b/Widgets/Window.h @@ -5,10 +5,8 @@ #include "GraphicsBitmap.h" #include #include -#include class Process; -class Widget; class Window final : public Object, public InlineLinkedListNode { public: @@ -18,7 +16,7 @@ public: int window_id() const { return m_window_id; } String title() const { return m_title; } - void setTitle(String&&); + void set_title(String&&); int x() const { return m_rect.x(); } int y() const { return m_rect.y(); } @@ -26,28 +24,24 @@ public: int height() const { return m_rect.height(); } const Rect& rect() const { return m_rect; } - void setRect(const Rect&); - void setRectWithoutRepaint(const Rect& rect) { m_rect = rect; } + void set_rect(const Rect&); + void set_rect_without_repaint(const Rect& rect) { m_rect = rect; } Point position() const { return m_rect.location(); } - void setPosition(const Point& position) { setRect({ position.x(), position.y(), width(), height() }); } - void setPositionWithoutRepaint(const Point& position) { setRectWithoutRepaint({ position.x(), position.y(), width(), height() }); } + void set_position(const Point& position) { set_rect({ position.x(), position.y(), width(), height() }); } + void set_position_without_repaint(const Point& position) { set_rect_without_repaint({ position.x(), position.y(), width(), height() }); } virtual void event(Event&) override; - bool isBeingDragged() const { return m_isBeingDragged; } - void setIsBeingDragged(bool b) { m_isBeingDragged = b; } + bool is_being_dragged() const { return m_is_being_dragged; } + void set_is_being_dragged(bool b) { m_is_being_dragged = b; } - bool isActive() const; - - bool isVisible() const; + bool is_visible() const; void close(); GraphicsBitmap* backing() { return m_backing.ptr(); } - void did_paint(); - // For InlineLinkedList. // FIXME: Maybe make a ListHashSet and then WindowManager can just use that. Window* m_next { nullptr }; @@ -56,7 +50,7 @@ public: private: String m_title; Rect m_rect; - bool m_isBeingDragged { false }; + bool m_is_being_dragged { false }; RetainPtr m_backing; Process& m_process; diff --git a/Widgets/WindowManager.cpp b/Widgets/WindowManager.cpp index febf64fe57e..2b779122772 100644 --- a/Widgets/WindowManager.cpp +++ b/Widgets/WindowManager.cpp @@ -210,7 +210,7 @@ void WindowManager::handleTitleBarMouseEvent(Window& window, MouseEvent& event) m_dragOrigin = event.position(); m_dragWindowOrigin = window.position(); m_dragStartRect = outerRectForWindow(window.rect()); - window.setIsBeingDragged(true); + window.set_is_being_dragged(true); return; } } @@ -222,7 +222,7 @@ void WindowManager::processMouseEvent(MouseEvent& event) printf("[WM] Finish dragging Window{%p}\n", m_dragWindow.ptr()); invalidate(m_dragStartRect); invalidate(*m_dragWindow); - m_dragWindow->setIsBeingDragged(false); + m_dragWindow->set_is_being_dragged(false); m_dragEndRect = outerRectForWindow(m_dragWindow->rect()); m_dragWindow = nullptr; return; @@ -235,7 +235,7 @@ void WindowManager::processMouseEvent(MouseEvent& event) Point pos = m_dragWindowOrigin; printf("[WM] Dragging [origin: %d,%d] now: %d,%d\n", m_dragOrigin.x(), m_dragOrigin.y(), event.x(), event.y()); pos.moveBy(event.x() - m_dragOrigin.x(), event.y() - m_dragOrigin.y()); - m_dragWindow->setPositionWithoutRepaint(pos); + m_dragWindow->set_position_without_repaint(pos); invalidate(outerRectForWindow(old_window_rect)); invalidate(outerRectForWindow(m_dragWindow->rect())); return; diff --git a/Widgets/test.cpp b/Widgets/test.cpp index 762b8191e0a..c25c5879a85 100644 --- a/Widgets/test.cpp +++ b/Widgets/test.cpp @@ -19,8 +19,8 @@ int main(int argc, char** argv) EventLoop loop; auto* fontTestWindow = new Window; - fontTestWindow->setTitle("Font test"); - fontTestWindow->setRect({ 140, 100, 300, 80 }); + fontTestWindow->set_title("Font test"); + fontTestWindow->set_rect({ 140, 100, 300, 80 }); auto* fontTestWindowWidget = new Widget; fontTestWindow->setMainWidget(fontTestWindowWidget); @@ -44,8 +44,8 @@ int main(int argc, char** argv) { auto* widgetTestWindow = new Window; - widgetTestWindow->setTitle("Widget test"); - widgetTestWindow->setRect({ 20, 40, 100, 180 }); + widgetTestWindow->set_title("Widget test"); + widgetTestWindow->set_rect({ 20, 40, 100, 180 }); auto* widgetTestWindowWidget = new Widget; widgetTestWindowWidget->setWindowRelativeRect({ 0, 0, 100, 100 });