wxMaxima
Loading...
Searching...
No Matches
Styles.h
Go to the documentation of this file.
1// -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2//
3// Copyright (C) 2026 Gunter Königsmann <wxMaxima@physikbuch.de>
4//
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15//
16// You should have received a copy of the GNU General Public License
17// along with this program; if not, write to the Free Software
18// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19//
20// SPDX-License-Identifier: GPL-2.0+
21
26#ifndef WXMAXIMA_STYLES_H
27#define WXMAXIMA_STYLES_H
28
29#include "cells/TextStyle.h"
30#include <utility>
31#include <vector>
32
33class wxConfigBase;
34
41class Styles
42{
43public:
49 Style &operator[](int textStyle) { return active()[textStyle]; }
50 const Style &operator[](int textStyle) const { return active()[textStyle]; }
51 Style *begin() { return active(); }
52 Style *end() { return active() + NUMBEROFSTYLES; }
53 const Style *begin() const { return active(); }
54 const Style *end() const { return active() + NUMBEROFSTYLES; }
55
57 void SetUseDark(bool dark) { m_useDark = dark; }
58 bool UsingDark() const { return m_useDark; }
60 void ClearCaches();
61
63 void SetDefaults();
64
67 void SetDarkDefaults();
68
70 void Read(wxConfigBase *config);
72 void Write(wxConfigBase *config) const;
73
81 static const std::vector<std::pair<TextStyle, wxString>> &ConfigKeys();
82
85 static const wxString &Name(TextStyle textStyle);
86
87 // Defined inline so the lightweight unit tests (which include this header but do
88 // not link Styles.cpp) can still construct a Styles / Configuration.
89 Styles()
90 : m_codeStyles{TS_CODE_VARIABLE, TS_CODE_FUNCTION, TS_CODE_COMMENT,
91 TS_CODE_NUMBER, TS_CODE_STRING, TS_CODE_OPERATOR,
92 TS_CODE_LISP, TS_CODE_ENDOFLINE, TS_EQUALSSELECTION},
93 m_2dMathStyles{TS_VARIABLE, TS_OPERATOR, TS_NUMBER,
94 TS_FUNCTION, TS_SPECIAL_CONSTANT, TS_GREEK_CONSTANT,
95 TS_STRING, TS_MAIN_PROMPT, TS_OTHER_PROMPT,
96 TS_LABEL, TS_USERLABEL, TS_HIGHLIGHT,
97 TS_WARNING, TS_ERROR, TS_ASCIIMATHS, TS_TEXT},
98 m_colorOnlyStyles{TS_TEXT_BACKGROUND, TS_DOCUMENT_BACKGROUND, TS_CELL_BRACKET,
99 TS_ACTIVE_CELL_BRACKET, TS_CURSOR, TS_SELECTION,
100 TS_EQUALSSELECTION, TS_OUTDATED} {}
101
103 const std::vector<TextStyle> &CodeStylesList() const { return m_codeStyles; }
105 const std::vector<TextStyle> &MathStylesList() const { return m_2dMathStyles; }
107 const std::vector<TextStyle> &ColorOnlyStylesList() const { return m_colorOnlyStyles; }
108 bool AffectsCode(TextStyle style) const;
109 bool AffectsMathOut(TextStyle style) const;
110 bool AffectsColorOnly(TextStyle style) const;
112 void MakeConsistent();
113
114private:
115 Style *active() { return m_useDark ? m_stylesDark : m_styles; }
116 const Style *active() const { return m_useDark ? m_stylesDark : m_styles; }
119 void SetLightDefaultsInto(Style *styles);
120
122 Style m_styles[NUMBEROFSTYLES];
124 Style m_stylesDark[NUMBEROFSTYLES];
126 bool m_useDark = false;
128 std::vector<TextStyle> m_codeStyles;
130 std::vector<TextStyle> m_2dMathStyles;
132 std::vector<TextStyle> m_colorOnlyStyles;
133};
134
135#endif // WXMAXIMA_STYLES_H
This file declares everything needed for the text style system used to style all the elements on the ...
TextStyle
All text styles known to wxMaxima.
Definition: TextStyle.h:231
@ NUMBEROFSTYLES
This is not a style, but its value tells us how many styles are defined.
Definition: TextStyle.h:272
Text Style Definition.
Definition: TextStyle.h:63
Storage for the worksheet's per-TextStyle text styles.
Definition: Styles.h:42
static const std::vector< std::pair< TextStyle, wxString > > & ConfigKeys()
The single source of truth mapping each persisted text style to its config-key prefix.
Definition: Styles.cpp:261
void Read(wxConfigBase *config)
Read every persisted style from config.
Definition: Styles.cpp:247
static const wxString & Name(TextStyle textStyle)
The human-readable, translated name of a style (used by the config dialog). Returns an empty string f...
Definition: Styles.cpp:95
const std::vector< TextStyle > & ColorOnlyStylesList() const
The styles where only the color is configurable.
Definition: Styles.h:107
const std::vector< TextStyle > & MathStylesList() const
The styles that share the 2d-math font.
Definition: Styles.h:105
const std::vector< TextStyle > & CodeStylesList() const
The styles that share the code-default font/attributes.
Definition: Styles.h:103
void MakeConsistent()
Propagate the code-default / math fonts to the styles that must share them.
Definition: Styles.cpp:55
void SetDefaults()
Reset every style to wxMaxima's built-in (light) defaults.
Definition: Styles.cpp:144
void Write(wxConfigBase *config) const
Write every persisted style to config.
Definition: Styles.cpp:254
void ClearCaches()
Invalidate the font caches of every style in BOTH sets.
Definition: Styles.cpp:232
Style & operator[](int textStyle)
The style used for a given TextStyle. Indexed like the old raw array, so both TextStyle enumerators a...
Definition: Styles.h:49
void SetDarkDefaults()
Reset every style to wxMaxima's built-in dark-mode defaults (a curated palette for a dark background;...
Definition: Styles.cpp:192
void SetUseDark(bool dark)
Select which set indexing/iteration return.
Definition: Styles.h:57