diff --git a/src/FileListPage.cxx b/src/FileListPage.cxx index 481b2484..4baeb522 100644 --- a/src/FileListPage.cxx +++ b/src/FileListPage.cxx @@ -553,8 +553,6 @@ FileListPage::PaintStatusBarOverride(const Window window) const noexcept if (!lw.HasRangeSelection()) return false; - WINDOW *const w = window.w; - window.MoveCursor({0, 0}); window.ClearToEol(); @@ -576,7 +574,7 @@ FileListPage::PaintStatusBarOverride(const Window window) const noexcept duration); const unsigned duration_width = strlen(duration_string); - SelectStyle(w, Style::STATUS_TIME); + SelectStyle(window, Style::STATUS_TIME); window.String({0, (int)window.GetWidth() - (int)duration_width}, duration_string); window.RefreshNoOut(); diff --git a/src/ProgressBar.cxx b/src/ProgressBar.cxx index 9b900e6a..33d63c6b 100644 --- a/src/ProgressBar.cxx +++ b/src/ProgressBar.cxx @@ -26,7 +26,7 @@ ProgressBar::Paint() const noexcept if (max > 0) { assert(width < window_width); - SelectStyle(window.w, Style::PROGRESSBAR); + SelectStyle(window, Style::PROGRESSBAR); if (width > 0) window.HLine({0, 0}, width, '='); @@ -35,12 +35,12 @@ ProgressBar::Paint() const noexcept unsigned x = width + 1; if (x < window_width) { - SelectStyle(window.w, Style::PROGRESSBAR_BACKGROUND); + SelectStyle(window, Style::PROGRESSBAR_BACKGROUND); window.HLine({(int)x, 0}, window_width - x, ACS_HLINE); } } else { /* no progress bar, just a simple horizontal line */ - SelectStyle(window.w, Style::LINE); + SelectStyle(window, Style::LINE); window.HLine({0, 0}, window_width, ACS_HLINE); } diff --git a/src/QueuePage.cxx b/src/QueuePage.cxx index a5989c98..f52939a6 100644 --- a/src/QueuePage.cxx +++ b/src/QueuePage.cxx @@ -423,8 +423,6 @@ QueuePage::PaintStatusBarOverride(const Window window) const noexcept if (!lw.HasRangeSelection()) return false; - WINDOW *const w = window.w; - window.MoveCursor({0, 0}); window.ClearToEol(); @@ -443,7 +441,7 @@ QueuePage::PaintStatusBarOverride(const Window window) const noexcept duration); const unsigned duration_width = strlen(duration_string); - SelectStyle(w, Style::STATUS_TIME); + SelectStyle(window, Style::STATUS_TIME); window.String({(int)window.GetWidth() - (int)duration_width, 0}, duration_string); window.RefreshNoOut(); diff --git a/src/StatusBar.cxx b/src/StatusBar.cxx index b039be7f..046f8e0e 100644 --- a/src/StatusBar.cxx +++ b/src/StatusBar.cxx @@ -209,20 +209,19 @@ StatusBar::Update(const struct mpd_status *status, void StatusBar::Paint() const noexcept { - WINDOW *w = window.w; const unsigned window_width = window.GetWidth(); window.MoveCursor({0, 0}); window.ClearToEol(); if (!message.empty()) { - SelectStyle(w, Style::STATUS_ALERT); + SelectStyle(window, Style::STATUS_ALERT); window.String(message); window.RefreshNoOut(); return; } - SelectStyle(w, Style::STATUS_BOLD); + SelectStyle(window, Style::STATUS_BOLD); if (left_text != nullptr) /* display state */ @@ -231,14 +230,14 @@ StatusBar::Paint() const noexcept if (right_width > 0) { /* display time string */ int x = window_width - right_width; - SelectStyle(w, Style::STATUS_TIME); + SelectStyle(window, Style::STATUS_TIME); window.String({x, 0}, right_text); } if (!center_text.empty()) { /* display song name */ - SelectStyle(w, Style::STATUS); + SelectStyle(window, Style::STATUS); /* scroll if the song name is to long */ #ifndef NCMPC_MINI @@ -251,7 +250,7 @@ StatusBar::Paint() const noexcept /* display time string */ int x = window_width - right_width; - SelectStyle(w, Style::STATUS_TIME); + SelectStyle(window, Style::STATUS_TIME); window.String({x, 0}, right_text); window.RefreshNoOut(); diff --git a/src/Styles.cxx b/src/Styles.cxx index 60ac80df..c2f706e4 100644 --- a/src/Styles.cxx +++ b/src/Styles.cxx @@ -8,6 +8,7 @@ #include "util/RuntimeError.hxx" #include "util/StringAPI.hxx" #include "util/StringStrip.hxx" +#include "Window.hxx" #ifdef ENABLE_COLORS #include "Options.hxx" @@ -342,18 +343,18 @@ ApplyStyles() noexcept #endif void -SelectStyle(WINDOW *w, Style style) noexcept +SelectStyle(const Window window, Style style) noexcept { const auto &data = GetStyle(style); #ifdef ENABLE_COLORS if (options.enable_colors) { /* color mode */ - wattr_set(w, data.attr, short(style), nullptr); + wattr_set(window.w, data.attr, short(style), nullptr); } else { #endif /* mono mode */ - (void)wattrset(w, data.mono); + (void)wattrset(window.w, data.mono); #ifdef ENABLE_COLORS } #endif diff --git a/src/Styles.hxx b/src/Styles.hxx index 5516ae14..c3ed3bc1 100644 --- a/src/Styles.hxx +++ b/src/Styles.hxx @@ -1,12 +1,11 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Copyright The Music Player Daemon Project -#ifndef STYLES_HXX -#define STYLES_HXX +#pragma once #include "config.h" -#include +struct Window; enum class Style : unsigned { /** @@ -49,6 +48,4 @@ ApplyStyles() noexcept; #endif void -SelectStyle(WINDOW *w, Style style) noexcept; - -#endif +SelectStyle(Window window, Style style) noexcept; diff --git a/src/TabBar.cxx b/src/TabBar.cxx index b803bb5d..1434636c 100644 --- a/src/TabBar.cxx +++ b/src/TabBar.cxx @@ -13,7 +13,7 @@ static void PaintPageTab(const Window window, Command cmd, const char *label, bool selected) noexcept { - SelectStyle(window.w, selected ? Style::TITLE : Style::TITLE_BOLD); + SelectStyle(window, selected ? Style::TITLE : Style::TITLE_BOLD); if (selected) window.AttributeOn(A_REVERSE); @@ -23,7 +23,7 @@ PaintPageTab(const Window window, Command cmd, const char *label, bool selected) if (key != nullptr) window.String(key); - SelectStyle(window.w, Style::TITLE); + SelectStyle(window, Style::TITLE); if (selected) window.AttributeOn(A_REVERSE); diff --git a/src/TablePaint.cxx b/src/TablePaint.cxx index 1d2eb528..bfa17638 100644 --- a/src/TablePaint.cxx +++ b/src/TablePaint.cxx @@ -32,7 +32,7 @@ PaintTableRow(const Window window, unsigned width, break; if (i > 0) { - SelectStyle(window.w, Style::LINE); + SelectStyle(window, Style::LINE); window.Char(ACS_VLINE); row_color(window, color, selected); } diff --git a/src/TitleBar.cxx b/src/TitleBar.cxx index 20bb7445..07cc41b5 100644 --- a/src/TitleBar.cxx +++ b/src/TitleBar.cxx @@ -61,8 +61,6 @@ void TitleBar::Paint(const PageMeta ¤t_page_meta, const char *title) const noexcept { - WINDOW *w = window.w; - window.MoveCursor({0, 0}); window.ClearToEol(); @@ -73,7 +71,7 @@ TitleBar::Paint(const PageMeta ¤t_page_meta, #else (void)current_page_meta; #endif - SelectStyle(w, Style::TITLE_BOLD); + SelectStyle(window, Style::TITLE_BOLD); window.String({0, 0}, title); #ifndef NCMPC_MINI } @@ -88,19 +86,19 @@ TitleBar::Paint(const PageMeta ¤t_page_meta, volume_string = buf; } - SelectStyle(w, Style::TITLE); + SelectStyle(window, Style::TITLE); const int window_width = window.GetWidth(); window.String({window_width - (int)StringWidthMB(volume_string), 0}, volume_string); - SelectStyle(w, Style::LINE); + SelectStyle(window, Style::LINE); window.HLine({0, 1}, window_width, ACS_HLINE); if (flags[0]) { window.MoveCursor({window_width - (int)strlen(flags) - 3, 1}); window.Char('['); - SelectStyle(w, Style::LINE_FLAGS); + SelectStyle(window, Style::LINE_FLAGS); window.String(flags); - SelectStyle(w, Style::LINE); + SelectStyle(window, Style::LINE); window.Char(']'); } diff --git a/src/hscroll.cxx b/src/hscroll.cxx index 0f1883ce..1e565c8d 100644 --- a/src/hscroll.cxx +++ b/src/hscroll.cxx @@ -43,7 +43,7 @@ hscroll::Paint() const noexcept { assert(basic.IsDefined()); - SelectStyle(window.w, style); + SelectStyle(window, style); if (attr != 0) window.AttributeOn(attr); diff --git a/src/paint.hxx b/src/paint.hxx index a6bc19a7..1ae94a79 100644 --- a/src/paint.hxx +++ b/src/paint.hxx @@ -14,7 +14,7 @@ static inline void row_color(const Window window, Style style, bool selected) noexcept { - SelectStyle(window.w, style); + SelectStyle(window, style); if (selected) window.AttributeOn(A_REVERSE); diff --git a/src/screen_utils.cxx b/src/screen_utils.cxx index ccc521c2..130ffe7b 100644 --- a/src/screen_utils.cxx +++ b/src/screen_utils.cxx @@ -43,9 +43,8 @@ int screen_getch(ScreenManager &screen, const char *prompt) noexcept { const auto &window = screen.status_bar.GetWindow(); - WINDOW *w = window.w; - SelectStyle(w, Style::STATUS_ALERT); + SelectStyle(window, Style::STATUS_ALERT); window.Erase(); window.MoveCursor({0, 0}); window.String(prompt); @@ -103,18 +102,17 @@ screen_readln(ScreenManager &screen, const char *prompt, Completion *completion) noexcept { const auto &window = screen.status_bar.GetWindow(); - WINDOW *w = window.w; window.MoveCursor({0, 0}); curs_set(1); if (prompt != nullptr) { - SelectStyle(w, Style::STATUS_ALERT); + SelectStyle(window, Style::STATUS_ALERT); window.String(prompt); window.String(": "sv); } - SelectStyle(w, Style::STATUS); + SelectStyle(window, Style::STATUS); window.AttributeOn(A_REVERSE); auto result = wreadln(window, value, window.GetWidth(), @@ -127,11 +125,10 @@ std::string screen_read_password(ScreenManager &screen, const char *prompt) noexcept { const auto &window = screen.status_bar.GetWindow(); - WINDOW *w = window.w; window.MoveCursor({0, 0}); curs_set(1); - SelectStyle(w, Style::STATUS_ALERT); + SelectStyle(window, Style::STATUS_ALERT); if (prompt == nullptr) prompt = _("Password"); @@ -139,7 +136,7 @@ screen_read_password(ScreenManager &screen, const char *prompt) noexcept window.String(prompt); window.String(": "sv); - SelectStyle(w, Style::STATUS); + SelectStyle(window, Style::STATUS); window.AttributeOn(A_REVERSE); auto result = wreadln_masked(window, nullptr, window.GetWidth()); @@ -176,7 +173,6 @@ screen_display_completion_list(ScreenManager &screen, Completion::Range range) n static size_t prev_length = 0; static unsigned offset = 0; const Window window = screen.main_window; - WINDOW *w = window.w; const unsigned height = screen.main_window.GetHeight(); size_t length = std::distance(range.begin(), range.end()); @@ -190,7 +186,7 @@ screen_display_completion_list(ScreenManager &screen, Completion::Range range) n offset = 0; } - SelectStyle(w, Style::STATUS_ALERT); + SelectStyle(window, Style::STATUS_ALERT); auto i = std::next(range.begin(), offset); for (unsigned y = 0; y < height; ++y, ++i) { @@ -206,5 +202,5 @@ screen_display_completion_list(ScreenManager &screen, Completion::Range range) n window.ClearToBottom(); window.Refresh(); - SelectStyle(w, Style::LIST); + SelectStyle(window, Style::LIST); }