From bd660400cc714a24df7dcaac6d31520dafb07ec6 Mon Sep 17 00:00:00 2001 From: cxl Date: Tue, 19 Nov 2013 20:07:19 +0000 Subject: [PATCH] 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 --- uppsrc/Core/Color.cpp | 2 ++ uppsrc/CtrlLib/ColorPopup.cpp | 32 +++++++++++++++++++++++++++++++- uppsrc/CtrlLib/ColorPusher.cpp | 19 +++++++++++-------- uppsrc/CtrlLib/DlgColor.h | 7 +++++++ uppsrc/Draw/Draw.h | 2 +- uppsrc/RichEdit/Table.cpp | 4 ++-- uppsrc/RichText/RichText.h | 2 ++ uppsrc/RichText/TableData.cpp | 8 ++++---- 8 files changed, 60 insertions(+), 16 deletions(-) diff --git a/uppsrc/Core/Color.cpp b/uppsrc/Core/Color.cpp index 7c92a0a4b..020ad7e57 100644 --- a/uppsrc/Core/Color.cpp +++ b/uppsrc/Core/Color.cpp @@ -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()); } diff --git a/uppsrc/CtrlLib/ColorPopup.cpp b/uppsrc/CtrlLib/ColorPopup.cpp index ac8e38d5d..0820f8c20 100644 --- a/uppsrc/CtrlLib/ColorPopup.cpp +++ b/uppsrc/CtrlLib/ColorPopup.cpp @@ -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 diff --git a/uppsrc/CtrlLib/ColorPusher.cpp b/uppsrc/CtrlLib/ColorPusher.cpp index 130ceaac8..8fdaffd88 100644 --- a/uppsrc/CtrlLib/ColorPusher.cpp +++ b/uppsrc/CtrlLib/ColorPusher.cpp @@ -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); diff --git a/uppsrc/CtrlLib/DlgColor.h b/uppsrc/CtrlLib/DlgColor.h index e6b4325aa..f6eb05832 100644 --- a/uppsrc/CtrlLib/DlgColor.h +++ b/uppsrc/CtrlLib/DlgColor.h @@ -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; } diff --git a/uppsrc/Draw/Draw.h b/uppsrc/Draw/Draw.h index c60065f8d..b545f60f0 100644 --- a/uppsrc/Draw/Draw.h +++ b/uppsrc/Draw/Draw.h @@ -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); diff --git a/uppsrc/RichEdit/Table.cpp b/uppsrc/RichEdit/Table.cpp index 0e5c6080d..dd3b2e081 100644 --- a/uppsrc/RichEdit/Table.cpp +++ b/uppsrc/RichEdit/Table.cpp @@ -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(); diff --git a/uppsrc/RichText/RichText.h b/uppsrc/RichText/RichText.h index 013dcb2d7..a906a4ab7 100644 --- a/uppsrc/RichText/RichText.h +++ b/uppsrc/RichText/RichText.h @@ -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; diff --git a/uppsrc/RichText/TableData.cpp b/uppsrc/RichText/TableData.cpp index 1c54ca6cd..780d5c34b 100644 --- a/uppsrc/RichText/TableData.cpp +++ b/uppsrc/RichText/TableData.cpp @@ -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;