commit af933dde24f1a6e79fe1f19f69cbe0a41f9a95ac
Author: Juergen Spitzmueller <sp...@lyx.org>
Date:   Sat Feb 22 18:28:33 2025 +0100

    A bit more color to the world, part IV
    
    Use the new colors and UI in the Box dialog.
    
    Now all color settings are done.
---
 development/FORMAT               |   9 ++-
 lib/doc/EmbeddedObjects.lyx      |  37 +++++++++++-
 lib/doc/de/EmbeddedObjects.lyx   | 125 +++------------------------------------
 lib/lyx2lyx/lyx_2_5.py           | 120 +++++++++++++++++++++++++++++++++++--
 src/frontends/qt/ColorsCombo.cpp |   5 +-
 src/frontends/qt/ColorsCombo.h   |   4 ++
 src/frontends/qt/GuiBox.cpp      |  80 ++++++-------------------
 src/frontends/qt/GuiBox.h        |   4 +-
 src/frontends/qt/ui/BoxUi.ui     |  55 +++++++++++------
 src/insets/InsetBox.cpp          |  41 +++++++++----
 src/insets/InsetBox.h            |   4 +-
 11 files changed, 261 insertions(+), 223 deletions(-)

diff --git a/development/FORMAT b/development/FORMAT
index d0830f8600..4af5d7f1ff 100644
--- a/development/FORMAT
+++ b/development/FORMAT
@@ -8,9 +8,12 @@ changes happened in particular if possible. A good example 
would be
 -----------------------
 
 2025-02-22 Jürgen Spitzmüller <sp...@lyx.org>
-       * Format incremented to 633: \fontcolor, \backgroundcolor, 
\notefontcolor"
-         and \boxbgcolor now take a lyxcolor as a (string) value, no longer
-         a color hexname. 
+       * Format incremented to 633: 
+        1. \fontcolor, \backgroundcolor, \notefontcolor"
+           and \boxbgcolor now take a lyxcolor as a (string) value, no longer
+           a color hexname.
+        2. The framecolor and backgroundcolor parameter of InsetBox can
+           take all supported latexcolors and cusom colors as argument.
 
 2025-02-20 Jürgen Spitzmüller <sp...@lyx.org>
        * Format incremented to 632:
diff --git a/lib/doc/EmbeddedObjects.lyx b/lib/doc/EmbeddedObjects.lyx
index 9c6dcc2e7b..14408a4401 100644
--- a/lib/doc/EmbeddedObjects.lyx
+++ b/lib/doc/EmbeddedObjects.lyx
@@ -38557,7 +38557,9 @@ This is colored text within a colored,
 
 \begin_layout Standard
 If you need another color than the predefined ones,
- you can define your own color as described in section
+ you
+\change_deleted -712698321 1740244776
+ can define your own color as described in section
 \begin_inset space ~
 \end_inset
 
@@ -38570,10 +38572,25 @@ nolink "false"
 \end_inset
 
 .
- To use your own color you must typeset the box by using TeX code:
+ 
+\change_inserted -712698321 1740244787
+can define your own color in 
+\family sans
+Document\SpecialChar menuseparator
+Settings\SpecialChar ldots
+\SpecialChar menuseparator
+Colors\SpecialChar menuseparator
+Custom Colors
+\family default
+ and use that.
+ 
+\change_deleted -712698321 1740244798
+To use your own color you must typeset the box by using TeX code:
 \end_layout
 
 \begin_layout Standard
+
+\change_deleted -712698321 1740244798
 Colored boxes without frame are created with the command 
 \series bold
 
@@ -38586,6 +38603,8 @@ colorbox
 
 \begin_layout Standard
 
+\change_deleted -712698321 1740244798
+
 \series bold
 
 \backslash
@@ -38593,6 +38612,8 @@ colorbox{color}{box content}
 \end_layout
 
 \begin_layout Standard
+
+\change_deleted -712698321 1740244798
 The box content can also be a box and colored boxes can also be within other 
boxes.
  To have e.
 \begin_inset space \thinspace{}
@@ -38608,6 +38629,8 @@ a darkgreen background for a word,
 
 \begin_layout Standard
 
+\change_deleted -712698321 1740244798
+
 \series bold
 
 \backslash
@@ -38615,6 +38638,8 @@ colorbox{darkgreen}{
 \end_layout
 
 \begin_layout Standard
+
+\change_deleted -712698321 1740244798
 before the word in \SpecialChar TeX
  Code.
  After the word insert a closing brace 
@@ -38638,6 +38663,8 @@ This is the result:
 \end_layout
 
 \begin_layout Standard
+
+\change_deleted -712698321 1740244798
 This is a line where the word 
 \begin_inset ERT
 status collapsed
@@ -38674,6 +38701,8 @@ status collapsed
 \end_layout
 
 \begin_layout Standard
+
+\change_deleted -712698321 1740244798
 Framed,
  colored boxes are created with the command 
 \series bold
@@ -38687,10 +38716,14 @@ fcolorbox
 
 \begin_layout Standard
 
+\change_deleted -712698321 1740244798
+
 \series bold
 
 \backslash
 fcolorbox{frame color}{box color}{box content}
+\change_unchanged
+
 \end_layout
 
 \begin_layout Section
diff --git a/lib/doc/de/EmbeddedObjects.lyx b/lib/doc/de/EmbeddedObjects.lyx
index 7fc8973e3a..78e1001036 100644
--- a/lib/doc/de/EmbeddedObjects.lyx
+++ b/lib/doc/de/EmbeddedObjects.lyx
@@ -38720,123 +38720,14 @@ Dies ist farbiger Text in einer farbigen,
 
 \begin_layout Standard
 Falls sie andere als die voreingestellten Farben benötigen,
- können Ihre eigenen Farben definieren,
- wie in Abschnitt
-\begin_inset space ~
-\end_inset
-
-
-\begin_inset CommandInset ref
-LatexCommand ref
-reference "abs:Farbige-Tabellen"
-nolink "false"
-
-\end_inset
-
- beschrieben.
- Um selbstdefinierte Farben zu verwenden,
- muss die Box mittels TeX-Code gesetzt werden:
-\end_layout
-
-\begin_layout Standard
-Farbige Boxen ohne Rahmen werden mit dem Befehl 
-\series bold
-
-\backslash
-colorbox
-\series default
- erzeugt.
- Er hat folgendes Schema:
-\end_layout
-
-\begin_layout Standard
-
-\series bold
-
-\backslash
-colorbox{Farbe}{Boxinhalt}
-\end_layout
-
-\begin_layout Standard
-Der Boxinhalt kann auch eine Box sein,
- und farbige Boxen können in anderen Boxen sein.
- Um zum Beispiel ein Wort auf einem dunkelgrünen Hintergrund zu drucken,
- fügen sie den \SpecialChar TeX
--Code-Befehl
-\end_layout
-
-\begin_layout Standard
-
-\series bold
-
-\backslash
-colorbox{dunkelgruen}{
-\end_layout
-
-\begin_layout Standard
-vor dem Wort ein.
- Hinter dem Wort fügen Sie 
-\series bold
-
-\begin_inset Quotes gld
-\end_inset
-
-}
-\series default
-
-\begin_inset Quotes grd
-\end_inset
-
- als \SpecialChar TeX
--Code ein.
- Hier ist das Ergebnis:
-\end_layout
-
-\begin_layout Standard
-In dieser Zeile hat 
-\begin_inset ERT
-status collapsed
-
-\begin_layout Plain Layout
-
-
-\backslash
-colorbox{dunkelgruen}{
-\end_layout
-
-\end_inset
-
-Achtung!
-\begin_inset ERT
-status collapsed
-
-\begin_layout Plain Layout
-
-}
-\end_layout
-
-\end_inset
-
- einen dunkelgrünen Hintergrund.
-\end_layout
-
-\begin_layout Standard
-Farbige Boxen mit Rahmen werden mit dem Befehl
-\series bold
- 
-\backslash
-fcolorbox
-\series default
- erzeugt.
- Er hat folgendes Schema:
-\end_layout
-
-\begin_layout Standard
-
-\series bold
-
-\backslash
-fcolorbox{Rahmenfarbe}{Boxfarbe}{Boxinhalt}
+ können Sie in 
+\family sans
+Dokument\SpecialChar menuseparator
+Einstellungen\SpecialChar menuseparator
+Farben\SpecialChar menuseparator
+Benutzerdefinierte Farben
+\family default
+ eigene Farben definieren und verwenden.
 \end_layout
 
 \begin_layout Section
diff --git a/lib/lyx2lyx/lyx_2_5.py b/lib/lyx2lyx/lyx_2_5.py
index 9b7fa6994e..9919f953a2 100644
--- a/lib/lyx2lyx/lyx_2_5.py
+++ b/lib/lyx2lyx/lyx_2_5.py
@@ -39,7 +39,7 @@ from lyx2lyx_tools import (
 #    find_re, find_token_backwards, find_token_exact,
 #    find_tokens,
 #    get_containing_layout, get_option_value,
-#    is_in_inset, set_bool_value
+#    is_in_inset
 from parser_tools import (
     del_token,
     find_end_of_inset,
@@ -50,7 +50,8 @@ from parser_tools import (
     get_containing_inset,
     get_bool_value,
     get_quoted_value,
-    get_value
+    get_value,
+    set_bool_value
 )
 
 ####################################################################
@@ -1768,7 +1769,9 @@ def revert_doc_col(document, color, default_value, 
xcolor, x11, svg, dvips):
             del document.header[i]
             return
         # check whether it is a color also otherwise used
-        color_used = find_token(document.body, "\\color " + value, i) != -1
+        color_used = find_token(document.body, "\\color " + value, i) != -1 \
+        or find_token(document.body, "framecolor \"" + value, i) \
+        or find_token(document.body, "backgroundcolor \"" + value, i)
         # check whether it is a known latexcolor
         if value in list(xcolor_names):
             if color_used == False and value.find(":") != -1:
@@ -1823,6 +1826,115 @@ def revert_doc_colors(document):
              options]
         )
 
+
+basic_box_colors = [
+    "default",
+    "none",
+    "black",
+    "white",
+    "blue",
+    "brown",
+    "cyan",
+    "darkgray",
+    "gray",
+    "green",
+    "lightgray",
+    "lime",
+    "magenta",
+    "orange",
+    "olive",
+    "pink",
+    "purple",
+    "red",
+    "teal",
+    "violet",
+    "white",
+    "yellow"
+]
+
+
+def revert_colorbox(document):
+    """Change box color settings to LaTeX code for new colors."""
+
+    i = 0
+    while True:
+        i = find_token(document.body, "\\begin_inset Box", i)
+        if i == -1:
+            return
+
+        j = find_end_of_inset(document.body, i)
+        k = find_token(document.body, "\\begin_layout", i, j)
+        if k == -1:
+            document.warning("Malformed LyX document: no layout in Box inset!")
+            i += 1
+            continue
+
+        # Get colour settings:
+        framecolor = get_quoted_value(document.body, "framecolor", i, k)
+        backcolor = get_quoted_value(document.body, "backgroundcolor", i, k + 
1)
+        if not framecolor or not backcolor:
+            document.warning("Malformed LyX document: color options not found 
in Box inset!")
+            i += 1
+            continue
+        if framecolor in list(basic_box_colors) and backcolor in 
list(basic_box_colors):
+            i += 1
+            continue
+
+        # Set params to default
+        p1 = find_token(document.body, "framecolor", i, j)
+        if p1 != -1:
+            document.body[p1] = "framecolor \"default\""
+        p2 = find_token(document.body, "backgroundcolor", i, j)
+        if p2 != -1:
+            document.body[p2] = "backgroundcolor \"none\""
+        
+        if "Box Boxed" not in document.body[i]:
+            i += 1
+            continue
+
+        # framed box, use \fcolorbox
+        # Emulate new colors with LaTeX code
+        einset = find_end_of_inset(document.body, i)
+        if einset == -1:
+            document.warning("Malformed LyX document: Can't find end of box 
inset!")
+            i += 1
+            continue
+
+        bothcolors = framecolor + backcolor
+        opts = []
+        if bothcolors.find("X11:") != -1:
+            opts.append("x11names")
+        if bothcolors.find("SVG:") != -1:
+            opts.append("svgnames")
+        if bothcolors.find("DVIPS:") != -1:
+            opts.append("dvipsnames")
+        options = "\\SetKeys[xcolor]{" + ",".join(opts) + "}"
+        for color in list(xcolor_names):
+            if framecolor == color.lower():
+               framecolor = color.split(":")[1]
+            if backcolor == color.lower():
+               backcolor = color.split(":")[1]
+        
+        add_to_preamble(document, 
["\\@ifundefined{rangeHsb}{\\usepackage{xcolor}}{}", options])
+        # insert the closing brace first (keeps indices 'i' and 'einset' valid)
+        document.body[einset + 1 : einset + 1] = put_cmd_in_ert("}")
+        # now insert the (f)color box command
+        # change the box type (frame added by \fcolorbox)
+        document.body[i] = "\\begin_inset Box Frameless"
+        # ensure an inner box:
+        try:
+            if not set_bool_value(document.body, "has_inner_box", True, i + 3, 
i + 4):
+                set_bool_value(document.body, "use_makebox", True, i + 6, i + 
7)
+        except ValueError:
+            document.warning(
+                "Malformed LyX document: 'has_inner_box' or "
+                "'use_makebox' option not found in box inset!"
+            )
+        ertinset = 
put_cmd_in_ert(f"\\fcolorbox{{{framecolor}}}{{{backcolor}}}{{")
+        document.body[i:i] = ertinset + [""]
+        i += 13
+
+
 ##
 # Conversion hub
 #
@@ -1846,7 +1958,7 @@ convert = [
 
 
 revert = [
-    [632, [revert_doc_colors]],
+    [632, [revert_doc_colors, revert_colorbox]],
     [631, [revert_textcolor, revert_custom_colors]],
     [630, [revert_mathml_version]],
     [629, [revert_new_polyglossia_languages, revert_new_babel_languages]],
diff --git a/src/frontends/qt/ColorsCombo.cpp b/src/frontends/qt/ColorsCombo.cpp
index 9086f797c2..2a50440354 100644
--- a/src/frontends/qt/ColorsCombo.cpp
+++ b/src/frontends/qt/ColorsCombo.cpp
@@ -29,7 +29,8 @@ namespace frontend {
 
 ColorsCombo::ColorsCombo(QWidget * parent)
        : CategorizedCombo(parent),
-         has_ignore_(false), has_inherit_(false)
+         has_ignore_(false), has_inherit_(false),
+         default_value_("none")
 {
        setLeftMargin(32);
        fillComboColor();
@@ -117,7 +118,7 @@ void ColorsCombo::fillComboColor()
                addItemSort(QString("ignore"), qt_("No change"),
                            QString());
        if (default_color_.isEmpty())
-               addItemSort(QString("none"), qt_("Default"),
+               addItemSort(default_value_, qt_("Default"),
                            QString());
        if (has_inherit_)
                addItemSort(QString("inherit"), qt_("(Without)[[color]]"),
diff --git a/src/frontends/qt/ColorsCombo.h b/src/frontends/qt/ColorsCombo.h
index e4345b6329..f801b0ae57 100644
--- a/src/frontends/qt/ColorsCombo.h
+++ b/src/frontends/qt/ColorsCombo.h
@@ -46,6 +46,8 @@ public:
        void hasInherit(bool const b) { has_inherit_ = b; }
        /// Flag a color as default. This will also omit the "none" entry
        void setDefaultColor(std::string const & col) { default_color_ = 
toqstr(col); }
+       /// Set the value of the default entry. Preset is "none"
+       void setDefaultValue(std::string const & val) { default_value_ = 
toqstr(val); }
 
 private:
        ///
@@ -60,6 +62,8 @@ private:
        bool has_inherit_;
        ///
        QString default_color_;
+       ///
+       QString default_value_;
 };
 
 
diff --git a/src/frontends/qt/GuiBox.cpp b/src/frontends/qt/GuiBox.cpp
index c7c8dc9027..9ea2244798 100644
--- a/src/frontends/qt/GuiBox.cpp
+++ b/src/frontends/qt/GuiBox.cpp
@@ -15,18 +15,18 @@
 
 #include "GuiBox.h"
 
-#include "GuiApplication.h"
-#include "ColorCache.h"
-#include "ColorSet.h"
+#include "Buffer.h"
+#include "BufferParams.h"
+
+#include "ColorsCombo.h"
+
 #include "LengthCombo.h"
 #include "qt_helpers.h"
 #include "Validator.h"
 
 #include "insets/InsetBox.h"
 
-#include "support/gettext.h"
 #include "support/Length.h"
-#include "support/lstrings.h"
 
 #include <QComboBox>
 #include <QLineEdit>
@@ -72,32 +72,6 @@ static QStringList boxGuiSpecialLengthNames()
 }
 
 
-static QList<ColorCode> colors()
-{
-       QList<ColorCode> colors;
-       colors << Color_black;
-       colors << Color_white;
-       colors << Color_blue;
-       colors << Color_brown;
-       colors << Color_cyan;
-       colors << Color_darkgray;
-       colors << Color_gray;
-       colors << Color_green;
-       colors << Color_lightgray;
-       colors << Color_lime;
-       colors << Color_magenta;
-       colors << Color_olive;
-       colors << Color_orange;
-       colors << Color_pink;
-       colors << Color_purple;
-       colors << Color_red;
-       colors << Color_teal;
-       colors << Color_violet;
-       colors << Color_yellow;
-       return colors;
-}
-
-
 GuiBox::GuiBox(QWidget * parent) : InsetParamsWidget(parent)
 {
        setupUi(this);
@@ -138,6 +112,11 @@ GuiBox::GuiBox(QWidget * parent) : 
InsetParamsWidget(parent)
        connect(backgroundColorCO, SIGNAL(currentIndexChanged(int)),
                this, SIGNAL(changed()));
 
+       // frame color has "default" as default value, background has "none"
+       frameColorCO->setDefaultValue("default");
+       frameColorCO->setToolTip(qt_("You can also directly type on the list to 
filter on color names."));
+       backgroundColorCO->setToolTip(qt_("You can also directly type on the 
list to filter on color names."));
+
        heightED->setValidator(unsignedLengthValidator(heightED));
        widthED->setValidator(unsignedLengthValidator(widthED));
        thicknessED->setValidator(unsignedLengthValidator(thicknessED));
@@ -151,38 +130,10 @@ GuiBox::GuiBox(QWidget * parent) : 
InsetParamsWidget(parent)
        addCheckedWidget(separationED, separationLA);
        addCheckedWidget(shadowsizeED, shadowsizeLA);
 
-       // the background can be uncolored while the frame cannot
-       color_codes_ = colors();
-       sort(color_codes_.begin(), color_codes_.end(), ColorSorter);
-       fillComboColor(backgroundColorCO, true);
-       fillComboColor(frameColorCO, false);
-
        initDialog();
 }
 
 
-void GuiBox::fillComboColor(QComboBox * combo, bool const is_background)
-{
-       combo->clear();
-       QPixmap coloritem(32, 32);
-       QColor color;
-       // condition on the two possible types
-       if (is_background)
-               
combo->addItem(toqstr(translateIfPossible(lcolor.getGUIName(Color_none))),
-                              toqstr(lcolor.getLaTeXName(Color_none)));
-       else
-               combo->addItem(qt_("Default"), toqstr("default"));
-       QList<ColorCode>::const_iterator cit = color_codes_.begin();
-       for (; cit != color_codes_.end(); ++cit) {
-               QString const latexname = toqstr(lcolor.getLaTeXName(*cit));
-               QString const guiname = 
toqstr(translateIfPossible(lcolor.getGUIName(*cit)));
-               color = guiApp->colorCache().get(*cit, false);
-               coloritem.fill(color);
-               combo->addItem(QIcon(coloritem), guiname, latexname);
-       }
-}
-
-
 void GuiBox::on_innerBoxCO_activated(int index)
 {
        QString itype = innerBoxCO->itemData(index).toString();
@@ -274,6 +225,9 @@ void GuiBox::paramsToDialog(Inset const * inset)
 {
        InsetBox const * box = static_cast<InsetBox const *>(inset);
        InsetBoxParams const & params = box->params();
+       custom_colors_cache_ = inset->buffer().masterParams().custom_colors;
+       frameColorCO->setCustomColors(custom_colors_cache_);
+       backgroundColorCO->setCustomColors(custom_colors_cache_);
        QString type = toqstr(params.type);
        if (type == "Framed") {
                pagebreakCB->setChecked(true);
@@ -377,8 +331,8 @@ void GuiBox::paramsToDialog(Inset const * inset)
        lengthToWidgets(shadowsizeED, shadowsizeUnitsLC,
                (params.shadowsize).asString(), default_unit);
        // set color
-       
frameColorCO->setCurrentIndex(frameColorCO->findData(toqstr(params.framecolor)));
-       
backgroundColorCO->setCurrentIndex(backgroundColorCO->findData(toqstr(params.backgroundcolor)));
+       frameColorCO->set(toqstr(params.framecolor));
+       backgroundColorCO->set(toqstr(params.backgroundcolor));
 }
 
 
@@ -462,12 +416,12 @@ docstring GuiBox::dialogToParams() const
                params.shadowsize = Length("4pt");
        if (frameColorCO->isEnabled())
                params.framecolor =
-                       
fromqstr(frameColorCO->itemData(frameColorCO->currentIndex()).toString());
+                       
fromqstr(frameColorCO->getData(frameColorCO->currentIndex()));
        else
                params.framecolor = "foreground";
        if (backgroundColorCO->isEnabled())
                params.backgroundcolor =
-                       
fromqstr(backgroundColorCO->itemData(backgroundColorCO->currentIndex()).toString());
+                       
fromqstr(backgroundColorCO->getData(backgroundColorCO->currentIndex()));
        else
                params.backgroundcolor = "none";
 
diff --git a/src/frontends/qt/GuiBox.h b/src/frontends/qt/GuiBox.h
index 79a9b91e3b..a63d0cae7e 100644
--- a/src/frontends/qt/GuiBox.h
+++ b/src/frontends/qt/GuiBox.h
@@ -46,8 +46,6 @@ private:
        bool checkWidgets(bool readonly) const override;
        //@}
 
-       /// Fill the color combos
-       void fillComboColor(QComboBox * combo, bool const is_background);
        /// add and remove special lengths
        void setSpecial(bool ibox);
        /// only show valid inner box items
@@ -61,7 +59,7 @@ private:
        ///
        QStringList gui_names_spec_;
        ///
-       QList<ColorCode> color_codes_;
+       std::map<std::string, std::string> custom_colors_cache_;
 };
 
 } // namespace frontend
diff --git a/src/frontends/qt/ui/BoxUi.ui b/src/frontends/qt/ui/BoxUi.ui
index 52208b0d75..c70e6e7521 100644
--- a/src/frontends/qt/ui/BoxUi.ui
+++ b/src/frontends/qt/ui/BoxUi.ui
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>579</width>
-    <height>381</height>
+    <height>397</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -434,19 +434,6 @@
       <bool>true</bool>
      </property>
      <layout class="QGridLayout" name="gridLayout_4">
-      <item row="2" column="2">
-       <spacer name="verticalSpacer">
-        <property name="orientation">
-         <enum>Qt::Vertical</enum>
-        </property>
-        <property name="sizeHint" stdset="0">
-         <size>
-          <width>20</width>
-          <height>40</height>
-         </size>
-        </property>
-       </spacer>
-      </item>
       <item row="1" column="0">
        <widget class="QLabel" name="backgroundColorLA">
         <property name="text">
@@ -457,6 +444,16 @@
         </property>
        </widget>
       </item>
+      <item row="0" column="1">
+       <widget class="lyx::frontend::ColorsCombo" name="frameColorCO">
+        <property name="inputMethodHints">
+         <set>Qt::ImhDigitsOnly|Qt::ImhLatinOnly</set>
+        </property>
+        <property name="maxVisibleItems">
+         <number>20</number>
+        </property>
+       </widget>
+      </item>
       <item row="0" column="0">
        <widget class="QLabel" name="frameColorLA">
         <property name="text">
@@ -467,11 +464,28 @@
         </property>
        </widget>
       </item>
-      <item row="1" column="1" colspan="2">
-       <widget class="QComboBox" name="backgroundColorCO"/>
+      <item row="2" column="1">
+       <spacer name="verticalSpacer">
+        <property name="orientation">
+         <enum>Qt::Vertical</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>20</width>
+          <height>40</height>
+         </size>
+        </property>
+       </spacer>
       </item>
-      <item row="0" column="1" colspan="2">
-       <widget class="QComboBox" name="frameColorCO"/>
+      <item row="1" column="1">
+       <widget class="lyx::frontend::ColorsCombo" name="backgroundColorCO">
+        <property name="inputMethodHints">
+         <set>Qt::ImhDigitsOnly|Qt::ImhLatinOnly</set>
+        </property>
+        <property name="maxVisibleItems">
+         <number>20</number>
+        </property>
+       </widget>
       </item>
      </layout>
     </widget>
@@ -479,6 +493,11 @@
   </layout>
  </widget>
  <customwidgets>
+  <customwidget>
+   <class>lyx::frontend::ColorsCombo</class>
+   <extends>QComboBox</extends>
+   <header>ColorsCombo.h</header>
+  </customwidget>
   <customwidget>
    <class>lyx::frontend::LengthCombo</class>
    <extends>QComboBox</extends>
diff --git a/src/insets/InsetBox.cpp b/src/insets/InsetBox.cpp
index de217bc9e2..5c11fc2886 100644
--- a/src/insets/InsetBox.cpp
+++ b/src/insets/InsetBox.cpp
@@ -20,7 +20,6 @@
 #include "BufferView.h"
 #include "ColorSet.h"
 #include "Cursor.h"
-#include "DispatchResult.h"
 #include "FuncStatus.h"
 #include "FuncRequest.h"
 #include "LaTeXFeatures.h"
@@ -32,7 +31,6 @@
 #include "TextClass.h"
 
 #include "support/debug.h"
-#include "support/docstream.h"
 #include "support/FileName.h"
 #include "support/gettext.h"
 #include "support/Lexer.h"
@@ -165,7 +163,7 @@ void InsetBox::setButtonLabel()
 
        // set the frame color for the inset if the type is Boxed
        if (btype == Boxed)
-               setFrameColor(lcolor.getFromLaTeXName(getFrameColor(true)));
+               setFrameColor(lcolor.getFromLyXName(getFrameColor(true)));
        else
                setFrameColor(Color_collapsibleframe);
 }
@@ -228,7 +226,7 @@ ColorCode InsetBox::backgroundColor(PainterInfo const &) 
const
        }
 
        if (params_.backgroundcolor != "none")
-               return lcolor.getFromLaTeXName(params_.backgroundcolor);
+               return lcolor.getFromLyXName(getBackgroundColor(true));
 
        return getLayout().bgcolor();
 }
@@ -884,21 +882,44 @@ void InsetBox::string2params(string const & in, 
InsetBoxParams & params)
 }
 
 
+void InsetBox::registerLyXColor(string const & value) const
+{
+       if (!lcolor.isKnownLyXName(value)) {
+               if (theLaTeXColors().isLaTeXColor(value)) {
+                       LaTeXColor const lc = 
theLaTeXColors().getLaTeXColor(value);
+                       string const lyxname = lc.name();
+                       lcolor.setColor(lyxname, lc.hexname());
+                       lcolor.setLaTeXName(lyxname, lc.latex());
+                       lcolor.setGUIName(lyxname, to_ascii(lc.guiname()));
+               }
+       }
+}
+
+
 string const InsetBox::getFrameColor(bool const gui) const
 {
        if (params_.framecolor == "default")
                return gui ? "foreground" : "black";
-       return params_.framecolor;
+       
+       registerLyXColor(params_.framecolor);
+       if (!lcolor.isKnownLyXName(params_.framecolor))
+               return gui ? "foreground" : "black";
+       return gui ? params_.framecolor
+                  : 
lcolor.getLaTeXName(lcolor.getFromLyXName(params_.framecolor));
 }
 
 
-string const InsetBox::getBackgroundColor() const
+string const InsetBox::getBackgroundColor(bool const gui) const
 {
        if (params_.backgroundcolor == "none")
-               return (buffer().params().backgroundcolor == "none")
-                               ? "white"
-                               : "page_backgroundcolor";
-       return params_.backgroundcolor;
+               return (gui) ? "white"
+                            : "page_backgroundcolor";
+       registerLyXColor(params_.backgroundcolor);
+       if (!lcolor.isKnownLyXName(params_.backgroundcolor))
+               return (gui) ? "white"
+                            : "page_backgroundcolor";
+       return gui ? params_.backgroundcolor
+                  : 
lcolor.getLaTeXName(lcolor.getFromLyXName(params_.backgroundcolor));
 }
 
 
diff --git a/src/insets/InsetBox.h b/src/insets/InsetBox.h
index a5b71e5cda..5281da8b4c 100644
--- a/src/insets/InsetBox.h
+++ b/src/insets/InsetBox.h
@@ -166,7 +166,9 @@ private:
        ///
        std::string const getFrameColor(bool const gui = false) const;
        ///
-       std::string const getBackgroundColor() const;
+       std::string const getBackgroundColor(bool const gui = false) const;
+       ///
+       void registerLyXColor(std::string const & value) const;
        ///
        bool useFColorBox() const;
 
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to