Martin Vermeer wrote:

> On Fri, Aug 01, 2003 at 07:02:29AM +0300, Martin Vermeer spake
> thusly:
> 
> ...
>   
>> One remaining problem: the place where the colour is used in
>> insets/insetbranch.C where we have
>> 
>> setBackgroundColor(lc.getFromGUIName(color));
>> 
>> 'color' being the string name. So, an LColor is being generated.
>> Can the colour picker handle that (i.e. add a legit LColor and name
>> to the database, where the above will find it) for an arbitrary RGB
>> triplet? I seem to remember this mentioned somewhere.
> 
> Having analyzed this proble a little further, it looks pretty bad.
> The need by setBackgroundColor for an LColor can be traced back to
> fillRectangle in Painter and in XPainter, which calls XFillRectangle
> that takes a Graphics Context as argument... produced by (file
> ColorHandler.C)

Well, take heart! I don't think it is too bad myself.

The problem stems from the fact that 'class LColor' uses entries of 
type 'enum LColor::color' to access the various functions. This 
necessarily means that the number of colors is hardcoded at compile 
time. Ultimately the data is stored in
        std::map<LColor::color, information> infotab;

Now, my suggestion to you is to change this store to
        std::map<int, information> infotab;
and to ADD more accessor methods
        string const getGUIName(string const & some_id) const;
        string const getX11Name(string const & some_id) const;
        string const getLaTeXName(string const & some_id) const;

Internal to LColor.C you would have an additional 
        std::map(string, int) transform;
that mapped this string id to the identifier used in 'infotab'.

Voilą! You are able to prescribe new colors dynamically.

> Do I really have to start tinkering with this deep stuff, e.g.,
> define a LyXColorHandler::getGCForeground() that takes an RGB
> argument? It would shortcircuit part of the code and
> would call XAllocColor directly.
> 
> Am I on a wild goose chase?

This is definitely NOT the way to go.

> Why not use XAllocColor directly as it was made for this?

Think of Qt running on a Windows box...

-- 
Angus

Reply via email to