From ff1ec91efb514902b3ec29696d53262936a868b1 Mon Sep 17 00:00:00 2001 From: cxl Date: Thu, 2 Oct 2008 15:25:38 +0000 Subject: [PATCH] Changed RichText/RichEdit apply-style operation git-svn-id: svn://ultimatepp.org/upp/trunk@503 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/RichText/Format.cpp | 4 ++-- uppsrc/RichText/Para.h | 5 +++-- uppsrc/RichText/ParaData.cpp | 39 ++++++++++++++++++++++++++++++++ uppsrc/RichText/TextData.cpp | 26 +++++++++++----------- uppsrc/RichText/Txt.h | 3 ++- uppsrc/RichText/TxtOp.cpp | 16 ++++++++++++-- uppsrc/coff/uld/Copying | 43 ++++++++++++++---------------------- 7 files changed, 90 insertions(+), 46 deletions(-) diff --git a/uppsrc/RichText/Format.cpp b/uppsrc/RichText/Format.cpp index ce501aaa2..570808a75 100644 --- a/uppsrc/RichText/Format.cpp +++ b/uppsrc/RichText/Format.cpp @@ -199,8 +199,8 @@ void RichTxt::FormatInfo::ApplyTo(RichPara::Format& fmt) const fmt.reset_number = reset_number; memcpy(fmt.number, number, sizeof(number)); } - if(paravalid & TABS) - fmt.tab = tab; +// if(paravalid & TABS) +// fmt.tab = tab; if(paravalid & STYLE) fmt.styleid = styleid; if(paravalid & SPACING) diff --git a/uppsrc/RichText/Para.h b/uppsrc/RichText/Para.h index 0ace473bc..8bb587a9e 100644 --- a/uppsrc/RichText/Para.h +++ b/uppsrc/RichText/Para.h @@ -220,8 +220,9 @@ struct RichPara { int GetCount() const { return part.GetCount(); } bool IsEmpty() const; String Pack(const Format& style, Array& obj) const; - void Unpack(const String& s, const Array& obj, - const Format& style); + void Unpack(const String& s, const Array& obj, const Format& style); + + void ApplyStyle(const Format& newstyle); Part& operator[](int i) { return part[i]; } const Part& operator[](int i) const { return part[i]; } diff --git a/uppsrc/RichText/ParaData.cpp b/uppsrc/RichText/ParaData.cpp index e70256eb2..85fd90e36 100644 --- a/uppsrc/RichText/ParaData.cpp +++ b/uppsrc/RichText/ParaData.cpp @@ -652,6 +652,45 @@ void RichPara::Mid(int pos) } } +void ApplyCharStyle(RichPara::CharFormat& format, const RichPara::CharFormat& f0, + const RichPara::CharFormat& newstyle) { + if(format.IsBold() == f0.IsBold()) + format.Bold(newstyle.IsBold()); + if(format.IsUnderline() == f0.IsUnderline()) + format.Underline(newstyle.IsUnderline()); + if(format.IsItalic() == f0.IsItalic()) + format.Italic(newstyle.IsItalic()); + if(format.IsStrikeout() == f0.IsStrikeout()) + format.Strikeout(newstyle.IsStrikeout()); + if(format.IsNonAntiAliased() == f0.IsNonAntiAliased()) + format.NonAntiAliased(newstyle.IsNonAntiAliased()); + if(format.capitals == f0.capitals) + format.capitals = newstyle.capitals; + if(format.dashed == f0.dashed) + format.dashed = newstyle.dashed; + if(format.sscript == f0.sscript) + format.sscript = newstyle.sscript; + if(format.GetFace() == f0.GetFace()) + format.Face(newstyle.GetFace()); + if(format.GetHeight() == f0.GetHeight()) + format.Height(newstyle.GetHeight()); + if(format.ink == f0.ink) + format.ink = newstyle.ink; + if(format.paper == f0.paper) + format.paper = newstyle.paper; +} + +void RichPara::ApplyStyle(const Format& newstyle) +{ + CharFormat f0 = part.GetCount() ? part[0].format : format; + for(int i = 0; i < part.GetCount(); i++) + ApplyCharStyle(part[i].format, f0, newstyle); + CharFormat h = format; + ApplyCharStyle(h, f0, newstyle); + format = newstyle; + (CharFormat&)format = h; +} + #ifdef _DEBUG void RichPara::Dump() { diff --git a/uppsrc/RichText/TextData.cpp b/uppsrc/RichText/TextData.cpp index 41adf81bb..eb25bf140 100644 --- a/uppsrc/RichText/TextData.cpp +++ b/uppsrc/RichText/TextData.cpp @@ -234,17 +234,15 @@ void RichText::ApplyFormatInfo(int pos, const RichText::FormatInfo& fi, int coun if(pi == pi2) { RichPara pa, pa1, pa2; - if(fi.paravalid & RichText::STYLE) - pa = txt.Get(pi, fi.styleid, style); - else - pa = txt.Get(pi, style); + pa = txt.Get(pi, style); + ApplyStyle(fi, pa, style); pa1 <<= pa; pa2 <<= pa; pa.Trim(pos); pa2.Mid(pos2); pa1.Trim(pos2); pa1.Mid(pos); - Apply(fi, pa1); + Apply(fi, pa1, style); pa.Append(pa1); pa.Append(pa2); fi.ApplyTo(pa.format); @@ -252,27 +250,29 @@ void RichText::ApplyFormatInfo(int pos, const RichText::FormatInfo& fi, int coun } else { RichPara pa, pa1; - if(fi.paravalid & RichText::STYLE) - pa = txt.Get(pi, fi.styleid, style); - else +// if(fi.paravalid & RichText::STYLE) +// pa = txt.Get(pi, fi.styleid, style); +// else pa = txt.Get(pi, style); + ApplyStyle(fi, pa, style); pa1 <<= pa; pa.Trim(pos); pa1.Mid(pos); - Apply(fi, pa1); + Apply(fi, pa1, style); fi.ApplyTo(pa.format); pa.Append(pa1); txt.Put(pi, pa, style); pi++; txt.ApplyFormat(fi, pi, pi2, style); - if(fi.paravalid & RichText::STYLE) - pa = txt.Get(pi2, fi.styleid, style); - else +// if(fi.paravalid & RichText::STYLE) +// pa = txt.Get(pi2, fi.styleid, style); +// else pa = txt.Get(pi2, style); + ApplyStyle(fi, pa, style); pa1 <<= pa; pa.Trim(pos2); pa1.Mid(pos2); - Apply(fi, pa); + Apply(fi, pa, style); pa.Append(pa1); txt.Put(pi2, pa, style); } diff --git a/uppsrc/RichText/Txt.h b/uppsrc/RichText/Txt.h index 402be6beb..18ff293f7 100644 --- a/uppsrc/RichText/Txt.h +++ b/uppsrc/RichText/Txt.h @@ -151,7 +151,8 @@ protected: RichTxt& GetTableUpdateText(int table, const RichStyles& style, int& pi); void CombineFormat(FormatInfo& f, int pi, int pi2, bool& first, const RichStyles& style) const; - static void Apply(const FormatInfo& fi, RichPara& pa); + static void ApplyStyle(const FormatInfo& fi, RichPara& pa, const RichStyles& style); + static void Apply(const FormatInfo& fi, RichPara& pa, const RichStyles& style); void ApplyFormat(const FormatInfo& f, int pi, int pi2, const RichStyles& style); void SaveFormat(Formating& f, int p1, int p2, const RichStyles& style) const; void RestoreFormat(int pi, const Formating& info, int& ii, const RichStyles& style); diff --git a/uppsrc/RichText/TxtOp.cpp b/uppsrc/RichText/TxtOp.cpp index 4f8696b71..286e95865 100644 --- a/uppsrc/RichText/TxtOp.cpp +++ b/uppsrc/RichText/TxtOp.cpp @@ -147,8 +147,20 @@ void RichTxt::CombineFormat(FormatInfo& fi, int pi, int pi2, bool& first, const } } -void RichTxt::Apply(const RichText::FormatInfo& fi, RichPara& pa) +void RichTxt::ApplyStyle(const RichText::FormatInfo& fi, RichPara& pa, const RichStyles& style) { + if(fi.paravalid & STYLE) { + int q = style.Find(fi.styleid); + if(q >= 0) { + pa.ApplyStyle(style[q].format); + pa.format.styleid = fi.styleid; + } + } +} + +void RichTxt::Apply(const RichText::FormatInfo& fi, RichPara& pa, const RichStyles& style) +{ + ApplyStyle(fi, pa, style); for(int i = 0; i < pa.GetCount(); i++) fi.ApplyTo(pa[i].format); fi.ApplyTo(pa.format); @@ -173,7 +185,7 @@ void RichTxt::ApplyFormat(const FormatInfo& fi, int pi, int pi2, const RichStyle pa = RichTxt::Get(pi, fi.styleid, style); else pa = Get(pi, style); - Apply(fi, pa); + Apply(fi, pa, style); Put(pi, pa, style); } pi++; diff --git a/uppsrc/coff/uld/Copying b/uppsrc/coff/uld/Copying index 306c7974b..f135f3633 100644 --- a/uppsrc/coff/uld/Copying +++ b/uppsrc/coff/uld/Copying @@ -1,30 +1,21 @@ -Copyright (C) 2005 Mirek Fidler, Tomas Rylek and various contributors (see AUTHORS) +Copyright 1998-2008 The U++ Project. All rights reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to -deal in the Software without restriction, including without limitation the -rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -sell copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Redistribution and use in source and binary forms, with or without modification, are permitted +provided that the following conditions are met: -The above copyright notice and this permission notice shall be included in -all copies of the Software and its Copyright notices. In addition publicly -documented acknowledgment must be given that this software has been used if no -source code of this software is made available publicly. This includes -acknowledgments in either Copyright notices, Manuals, Publicity and Marketing -documents or any documentation provided with any product containing this -software. This License does not apply to any software that links to the -libraries provided by this software (statically or dynamically), but only to -the software provided. + 1. Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + 2. Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials + provided with the distribution. ------------ - -Please see the COPYING.PLAIN for a plain-english explanation of this notice -and it's intent. +THIS SOFTWARE IS PROVIDED BY THE U++ PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +OF THE POSSIBILITY OF SUCH DAMAGE.