Core: VoidColor, CtrlLib: VoidColor in ColorPusher, RichEdit: Support for Null color in cell background

git-svn-id: svn://ultimatepp.org/upp/trunk@6587 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2013-11-19 20:07:19 +00:00
parent b79f1e3bdf
commit bd660400cc
8 changed files with 60 additions and 16 deletions

View file

@ -149,6 +149,8 @@ template<>
String AsString(const Color& c) {
if(IsNull(c))
return "Color(Null)";
if(c.GetRaw() & 0x80000000)
return Format("Color(%d, 0)", int(c.GetRaw() & ~0x80000000));
return Format("Color(%d, %d, %d)", c.GetR(), c.GetG(), c.GetB());
}

View file

@ -61,6 +61,8 @@ INITBLOCK {
void ColorPopUp::Hint(Color c)
{
if(IsNull(c) || c == VoidColor)
return;
for(int i = 0; i < 17; i++)
if(hint[i] == c) {
memmove(&hint[i], &hint[i + 1], (17 - i) * sizeof(Color));
@ -158,7 +160,8 @@ int ColorPopUp::GetCy()
{
return ((GetColorCount() + 17) / 18) * 16 +
(norampwheel ? 0 : 2) +
(notnull ? 0 : StdFont().Info().GetHeight() + 3 + 2);
(notnull ? 0 : StdFont().Info().GetHeight() + 3 + 2) +
(withvoid ? StdFont().Info().GetHeight() + 3 + 2 : 0);
}
void ColorPopUp::DrawFilledFrame(Draw &w, int x, int y, int cx, int cy, Color fcol, Color bcol)
@ -182,6 +185,22 @@ void ColorPopUp::Paint(Draw& w)
int y = 1;
if(withvoid) {
Size fsz = GetTextSize(nulltext, StdFont());
Rect r(1, y, sz.cx - 1, fsz.cy + y + 2);
DrawFrame(w, r, SColorText);
w.DrawText((sz.cx - fsz.cx) / 2, y, voidtext, StdFont(), SColorText());
y = r.bottom + 3;
if(colori == 997)
{
r.Inflate(1);
if(GetMouseLeft())
DrawFrame(w, r, SColorShadow, SColorLight);
else
DrawFrame(w, r, GUI_GlobalStyle() >= GUISTYLE_XP ? SColorText : SColorHighlight);
}
}
if(!notnull) {
Size fsz = GetTextSize(nulltext, StdFont());
Rect r(1, y, sz.cx - 1, fsz.cy + y + 2);
@ -235,6 +254,12 @@ int ColorPopUp::Get(Point p)
{
if(p.y >= GetCy())
return 999;
if(withvoid) {
int y0 = StdFont().Info().GetHeight() + 4;
if(p.y < y0)
return 997;
p.y -= y0;
}
if(!notnull) {
int y0 = StdFont().Info().GetHeight() + 4;
if(p.y < y0)
@ -312,6 +337,9 @@ Color ColorPopUp::Get() const
else
if(colori == 999)
return color;
else
if(colori == 997)
return VoidColor();
else
return Null;
}
@ -388,6 +416,7 @@ ColorPopUp::ColorPopUp()
{
norampwheel = false;
notnull = false;
withvoid = false;
scolors = false;
animating = false;
hints = false;
@ -400,6 +429,7 @@ ColorPopUp::ColorPopUp()
ramp.WhenLeftDouble = wheel.WhenLeftDouble = THISBACK(Select);
BackPaint();
nulltext = t_("(transparent)");
voidtext = t_("(none)");
}
END_UPP_NAMESPACE

View file

@ -9,20 +9,22 @@ void ColorPusher::Paint(Draw& w)
Size sz = GetSize();
w.DrawRect(sz, push ? SColorHighlight : SColorPaper);
int ty = (sz.cy - StdFont().Info().GetHeight()) / 2;
if(IsNull(color))
w.DrawText(max(2, (sz.cx - GetTextSize(nulltext, StdFont()).cx) / 2), ty,
nulltext, StdFont(), SColorText());
else
if(color == VoidColor)
w.DrawText(max(2, (sz.cx - GetTextSize(nulltext, StdFont()).cx) / 2), ty,
voidtext, StdFont(), SColorText());
else
if(withtext) {
w.DrawRect(2, 2, sz.cy - 4, sz.cy - 4, color);
DrawFrame(w, 1, 1, sz.cy - 2, sz.cy - 2, SColorText);
w.DrawText(sz.cy + 2, ty, FormatColor(color), StdFont(), SColorText());
}
else {
if(!IsNull(color)) {
w.DrawRect(2, 2, sz.cx - 4, sz.cy - 4, color);
DrawFrame(w, 1, 1, sz.cx - 2, sz.cy - 2, SColorText);
}
else
if(!withtext)
w.DrawText(max(2, (sz.cx - GetTextSize(nulltext, StdFont()).cx) / 2), ty,
nulltext, StdFont(), SColorText());
w.DrawRect(2, 2, sz.cx - 4, sz.cy - 4, color);
DrawFrame(w, 1, 1, sz.cx - 2, sz.cy - 2, SColorText);
}
if(HasFocus())
DrawFocus(w, GetSize());
@ -97,6 +99,7 @@ void ColorPusher::NewColor()
ColorPusher::ColorPusher()
{
nulltext = t_("(transparent)");
voidtext = t_("(none)");
color = Null;
track = push = withtext = false;
colors.WhenSelect = THISBACK(AcceptColors);

View file

@ -170,7 +170,9 @@ private:
bool animating;
bool hints;
bool open;
bool withvoid;
String nulltext;
String voidtext;
Color color;
ColorRampCtrl ramp;
@ -195,6 +197,8 @@ public:
ColorPopUp& NotNull(bool b = true) { notnull = b; return *this; }
ColorPopUp& SColors(bool b = true) { scolors = b; return *this; }//Deprecated
ColorPopUp& NullText(const char *s) { nulltext = s; Refresh(); return *this; }
ColorPopUp& VoidText(const char *s) { voidtext = s; Refresh(); return *this; }
ColorPopUp& WithVoid(bool b = true) { withvoid = b; Refresh(); return *this; }
ColorPopUp& NoRampWheel(bool b = true) { norampwheel = b; return *this; }
ColorPopUp& Hints(bool b = true) { hints = b; return *this; }
@ -219,6 +223,7 @@ protected:
Color color, saved_color;
ColorPopUp colors;
String nulltext;
String voidtext;
void AcceptColors();
void CloseColors();
@ -230,6 +235,8 @@ public:
ColorPusher& NullText(const char *s) { nulltext = s; colors.NullText(s); Refresh(); return *this; }
ColorPusher& NotNull(bool b = true) { colors.NotNull(b); return *this; }
ColorPusher& VoidText(const char *s) { voidtext = s; colors.VoidText(s); Refresh(); return *this; }
ColorPusher& WithVoid(bool b = true) { colors.WithVoid(b); return *this; }
ColorPusher& SColors(bool b = true) { colors.SColors(b); return *this; }
ColorPusher& WithText() { withtext = true; return *this; }
ColorPusher& Track(bool b = true) { track = b; return *this; }

View file

@ -361,7 +361,7 @@ void SColorDkShadow_Write(Color c);
inline Color InvertColor() { return Color(255, 0); }
inline Color DefaultInk() { return Black(); } //TODO!
inline Color DefaultInk() { return Black(); } //TODO?
Drawing AsDrawing(const Painting& pw);

View file

@ -316,8 +316,8 @@ void RichEdit::CellProperties()
dlg.align.Set(0, ALIGN_TOP);
dlg.align.Set(1, ALIGN_CENTER);
dlg.align.Set(2, ALIGN_BOTTOM);
dlg.color.NullText("");
dlg.border.NullText("");
dlg.color.WithVoid().VoidText("(no change)");
dlg.border.WithVoid().VoidText("(no change)");
if(dlg.Run() != IDOK)
return;
r.Retrieve();

View file

@ -11,6 +11,8 @@ struct RichPara;
class RichTable;
class RichTxt;
inline Color VoidColor() { return Color(223, 0); } // Used for mixed/no change in Get/SetCellFormat
struct Zoom {
int m, d;

View file

@ -485,9 +485,9 @@ RichCell::Format RichTable::GetCellFormat(const Rect& sel) const
if(fmt.align != f.align)
fmt.align = Null;
if(fmt.color != f.color)
fmt.color = Null;
fmt.color = VoidColor;
if(fmt.bordercolor != f.bordercolor)
fmt.bordercolor = Null;
fmt.bordercolor = VoidColor;
}
return fmt;
}
@ -514,9 +514,9 @@ void RichTable::SetCellFormat(const Rect& sel, const RichCell::Format& fmt, boo
sSetRect(f.margin, fmt.margin);
if(!IsNull(fmt.align))
f.align = fmt.align;
if(!IsNull(fmt.color))
if(fmt.color != VoidColor)
f.color = fmt.color;
if(!IsNull(fmt.bordercolor))
if(fmt.bordercolor != VoidColor)
f.bordercolor = fmt.bordercolor;
if(!IsNull(fmt.minheight))
f.minheight = fmt.minheight;