diff --git a/uppsrc/Core/Format.cpp b/uppsrc/Core/Format.cpp index 53965a6ee..2c547e856 100644 --- a/uppsrc/Core/Format.cpp +++ b/uppsrc/Core/Format.cpp @@ -306,38 +306,31 @@ String FormatDoubleFix(double d, int digits, int flags) String out; if(flags & FD_SIGN || d < 0 && !IsNull(exp)) out.Cat(d >= 0 ? '+' : '-'); - if(IsNull(exp) || exp < -digits) - { + if(IsNull(exp) || exp < -digits) { out.Cat('0'); - if(flags & FD_ZERO) - { + if((flags & FD_ZERO) && digits) { out.Cat('.'); out.Cat('0', digits); } } - else if(exp < 0) - { + else if(exp < 0) { out.Cat("0."); out.Cat('0', -1 - exp); int fill = digits + exp + 1; if(!(flags & FD_ZERO) || dig.GetLength() >= fill) out.Cat(dig, min(fill, dig.GetLength())); - else - { + else { out.Cat(dig); out.Cat('0', fill - dig.GetLength()); } } - else if(exp < dig.GetLength()) - { + else if(exp < dig.GetLength()) { out.Cat(dig, ++exp); - if(digits > 0 && ((flags & FD_ZERO) || dig.GetLength() > exp)) - { + if(digits > 0 && ((flags & FD_ZERO) || dig.GetLength() > exp)) { out.Cat('.'); if(!(flags & FD_ZERO) || dig.GetLength() - exp >= digits) out.Cat(dig.Begin() + exp, min(dig.GetLength() - exp, digits)); - else - { + else { out.Cat(dig.Begin() + exp, dig.GetLength() - exp); out.Cat('0', digits - (dig.GetLength() - exp)); } diff --git a/uppsrc/RichEdit/Clip.cpp b/uppsrc/RichEdit/Clip.cpp index 278da6f19..79ef742a0 100644 --- a/uppsrc/RichEdit/Clip.cpp +++ b/uppsrc/RichEdit/Clip.cpp @@ -43,7 +43,7 @@ bool RichEdit::Accept(PasteClip& d, RichText& clip) } } if(d.Accept("text/QTF")) - clip = ParseQTF(~d); + clip = ParseQTF(~d, 0, context); else if(d.Accept(RTFS)) clip = ParseRTF(~d); diff --git a/uppsrc/RichEdit/Editor.cpp b/uppsrc/RichEdit/Editor.cpp index 5ed0c8753..01cf63c12 100644 --- a/uppsrc/RichEdit/Editor.cpp +++ b/uppsrc/RichEdit/Editor.cpp @@ -418,7 +418,7 @@ Value RichEdit::GetData() const void RichEdit::SetData(const Value& v) { - Pick(ParseQTF((String)v)); + Pick(ParseQTF((String)v, 0, context)); } void RichEdit::Serialize(Stream& s) @@ -430,7 +430,7 @@ void RichEdit::Serialize(Stream& s) h = AsQTF(text); s % h; if(s.IsLoading()) - Pick(ParseQTF(h)); + Pick(ParseQTF(h, 0, context)); } int RichEdit::fh[] = { diff --git a/uppsrc/RichEdit/RichEdit.h b/uppsrc/RichEdit/RichEdit.h index 40a40068b..f07ee7a00 100644 --- a/uppsrc/RichEdit/RichEdit.h +++ b/uppsrc/RichEdit/RichEdit.h @@ -645,7 +645,7 @@ public: void Clear(); void Pick(pick_ RichText& t); - void SetQTF(const char *qtf) { Pick(ParseQTF(qtf)); } + void SetQTF(const char *qtf) { Pick(ParseQTF(qtf, 0, context)); } const RichText& Get() const { return text; } String GetQTF(byte cs = CHARSET_UTF8) const { return AsQTF(text, cs); } void ApplyStylesheet(const RichText& r); diff --git a/uppsrc/RichText/Object.cpp b/uppsrc/RichText/Object.cpp index 8355f0b8a..1e5b4532c 100644 --- a/uppsrc/RichText/Object.cpp +++ b/uppsrc/RichText/Object.cpp @@ -122,7 +122,7 @@ String RichObjectType::GetLink(const Value& data, Point pt, Size sz, void *conte return Null; } -void RichObject::InitSize(int cx, int cy) +void RichObject::InitSize(int cx, int cy, void *context) { Size sz; Size phsz = GetPixelSize(); @@ -192,26 +192,26 @@ const RichObjectType& RichObject::GetType() const return Single(); } -void RichObject::Set(RichObjectType *_type, const Value& _data, Size maxsize) +void RichObject::Set(RichObjectType *_type, const Value& _data, Size maxsize, void *context) { Clear(); type = _type; if(type) { data = _data; - physical_size = type->GetPhysicalSize(data); - pixel_size = type->GetPixelSize(data); - size = type->GetDefaultSize(data, maxsize); + physical_size = type->GetPhysicalSize(data, context); + pixel_size = type->GetPixelSize(data, context); + size = type->GetDefaultSize(data, maxsize, context); } NewSerial(); } -bool RichObject::Set(const String& _type_name, const Value& _data, Size maxsize) +bool RichObject::Set(const String& _type_name, const Value& _data, Size maxsize, void *context) { NewSerial(); type_name = _type_name; RichObjectType *t = Map().Get(type_name, NULL); if(t) { - Set(t, _data); + Set(t, _data, maxsize, context); return true; } else { @@ -222,7 +222,7 @@ bool RichObject::Set(const String& _type_name, const Value& _data, Size maxsiz return false; } -bool RichObject::Read(const String& _type_name, const String& _data, Size sz) +bool RichObject::Read(const String& _type_name, const String& _data, Size sz, void *context) { NewSerial(); type_name = _type_name; @@ -231,8 +231,8 @@ bool RichObject::Read(const String& _type_name, const String& _data, Size sz) Clear(); type = t; data = type->Read(_data); - physical_size = type->GetPhysicalSize(data); - pixel_size = type->GetPixelSize(data); + physical_size = type->GetPhysicalSize(data, context); + pixel_size = type->GetPixelSize(data, context); size = sz; return true; } diff --git a/uppsrc/RichText/ParseQtf.cpp b/uppsrc/RichText/ParseQtf.cpp index 6338a2e80..03dae40a0 100644 --- a/uppsrc/RichText/ParseQtf.cpp +++ b/uppsrc/RichText/ParseQtf.cpp @@ -30,6 +30,7 @@ int QTFFontHeight[] = { }; class RichQtfParser { + void *context; const char *term; WString text; RichPara paragraph; @@ -96,17 +97,19 @@ public: void Parse(const char *qtf, int accesskey); - RichQtfParser(); + RichQtfParser(void *context); }; void init_s_nodeqtf(); -RichQtfParser::RichQtfParser() +RichQtfParser::RichQtfParser(void *context_) +: context(context_) { format.Face(Font::ARIAL); format.Height(100); format.charset = GetDefaultCharset(); format.language = 0; + context = NULL; breakpage = false; istable = false; oldtab = false; @@ -286,7 +289,7 @@ void RichQtfParser::ReadObject() seven >>= 1; } } - obj.Read(type, data, sz); + obj.Read(type, data, sz, context); obj.KeepRatio(keepratio); obj.SetYDelta(yd); } @@ -925,9 +928,9 @@ void RichQtfParser::Parse(const char *qtf, int _accesskey) FlushStyles(); } -RichText ParseQTF(const char *qtf, int accesskey) +RichText ParseQTF(const char *qtf, int accesskey, void *context) { - RichQtfParser p; + RichQtfParser p(context); try { p.Parse(qtf, accesskey); } diff --git a/uppsrc/RichText/RichText.h b/uppsrc/RichText/RichText.h index 67d6baf5b..244d4537d 100644 --- a/uppsrc/RichText/RichText.h +++ b/uppsrc/RichText/RichText.h @@ -108,16 +108,8 @@ class Bar; struct RichObjectType : Moveable { virtual String GetTypeName(const Value& v) const = 0; virtual String GetCreateName() const; - virtual Size GetDefaultSize(const Value& data, Size maxsize) const; - virtual Size GetPhysicalSize(const Value& data) const; - virtual Size GetPixelSize(const Value& data) const; - virtual void Paint(const Value& data, Draw& w, Size sz) const; - virtual Image ToImage(const Value& data, Size sz) const; virtual Value Read(const String& s) const; virtual String Write(const Value& v) const; - virtual void Menu(Bar& bar, RichObject& ex) const; - virtual void DefaultAction(RichObject& ex) const; - virtual String GetLink(const Value& data, Point pt, Size sz) const; virtual bool Accept(PasteClip& clip); virtual Value Read(PasteClip& clip); @@ -133,10 +125,20 @@ struct RichObjectType : Moveable { virtual void DefaultAction(RichObject& ex, void *context) const; virtual String GetLink(const Value& data, Point pt, Size sz, void *context) const; - Size StdDefaultSize(const Value& data, Size maxsize, void * context) const; + Size StdDefaultSize(const Value& data, Size maxsize, void *context) const; RichObjectType(); virtual ~RichObjectType(); + +protected: + virtual Size GetDefaultSize(const Value& data, Size maxsize) const; + virtual Size GetPhysicalSize(const Value& data) const; + virtual Size GetPixelSize(const Value& data) const; + virtual void Paint(const Value& data, Draw& w, Size sz) const; + virtual Image ToImage(const Value& data, Size sz) const; + virtual void Menu(Bar& bar, RichObject& ex) const; + virtual void DefaultAction(RichObject& ex) const; + virtual String GetLink(const Value& data, Point pt, Size sz) const; }; class RichObject : Moveable { @@ -168,18 +170,18 @@ public: Image ToImage(Size sz, void *context = NULL) const; Size GetPhysicalSize() const { return physical_size; } Size GetPixelSize() const { return pixel_size; } - Size GetDefaultSize(Size maxsize) const { return type ? type->GetDefaultSize(data, maxsize) : physical_size; } + Size GetDefaultSize(Size maxsize, void *context = NULL) const { return type ? type->GetDefaultSize(data, maxsize, context) : physical_size; } - void Set(RichObjectType *type, const Value& data, Size maxsize = Size(3967, 3967)); - bool Set(const String& type_name, const Value& data, Size maxsize = Size(3967, 3967)); + void Set(RichObjectType *type, const Value& data, Size maxsize = Size(3967, 3967), void *context = NULL); + bool Set(const String& type_name, const Value& data, Size maxsize = Size(3967, 3967), void *context = NULL); String GetTypeName() const; Value GetData() const { return data; } - String GetLink(Point pt, Size sz) const { return type ? type->GetLink(data, pt, sz) : String(); } + String GetLink(Point pt, Size sz, void *context = NULL) const { return type ? type->GetLink(data, pt, sz, context) : String(); } const RichObjectType& GetType() const; - bool Read(const String& type, const String& data, Size sz); + bool Read(const String& type, const String& data, Size sz, void *context = NULL); String Write() const { return type ? type->Write(data) : (String)data; } void KeepRatio(bool b) { keepratio = b; } @@ -197,7 +199,7 @@ public: int64 GetSerialId() const { return serial; } - void InitSize(int cx, int cy); + void InitSize(int cx, int cy, void *context = NULL); RichObject(); RichObject(RichObjectType *type, const Value& data, Size maxsize = Size(3967, 3967)); @@ -382,7 +384,7 @@ public: String AsQTF(const RichObject& obj); -RichText ParseQTF(const char *qtf, int accesskey = 0); +RichText ParseQTF(const char *qtf, int accesskey = 0, void *context = NULL); RichText AsRichText(const wchar *s, const RichPara::Format& f = RichPara::Format()); diff --git a/uppsrc/TCtrlLib/Help/helputil.cpp b/uppsrc/TCtrlLib/Help/helputil.cpp index c9f7fa1bf..aa0036b47 100644 --- a/uppsrc/TCtrlLib/Help/helputil.cpp +++ b/uppsrc/TCtrlLib/Help/helputil.cpp @@ -1121,14 +1121,14 @@ void RichObjectDisplay::Paint(Draw& draw, const Rect& rc, const Value& v, Color return; draw.DrawRect(rc, paper); if(type) { - Size rawsize = type->GetPhysicalSize(v); + Size rawsize = type->GetPhysicalSize(v, context); if(MulVector(rawsize, outsize) >= 0) outsize.cy = iscale(outsize.cx, rawsize.cy, rawsize.cx); else outsize.cx = iscale(outsize.cy, rawsize.cx, rawsize.cy); Rect rrc(Point((rc.TopLeft() + rc.BottomRight() - outsize) >> 1), outsize); draw.Clipoff(rrc); - type->Paint(v, draw, outsize); + type->Paint(v, draw, outsize, context); draw.End(); } else { @@ -1139,7 +1139,7 @@ void RichObjectDisplay::Paint(Draw& draw, const Rect& rc, const Value& v, Color Size RichObjectDisplay::GetStdSize(const Value& v) const { - return type ? type->GetPhysicalSize(v) : CtrlImg::question().GetSize(); + return type ? type->GetPhysicalSize(v, context) : CtrlImg::question().GetSize(); } /* diff --git a/uppsrc/TCtrlLib/Help/helputil.h b/uppsrc/TCtrlLib/Help/helputil.h index 6ce03a21a..289b59dc5 100644 --- a/uppsrc/TCtrlLib/Help/helputil.h +++ b/uppsrc/TCtrlLib/Help/helputil.h @@ -110,16 +110,20 @@ Array HelpTopicFormatIndex(); class RichObjectDisplay : public Display { public: - RichObjectDisplay(const RichObjectType *type = NULL) : type(type) {} + RichObjectDisplay(const RichObjectType *type = NULL, void *context = NULL) : type(type), context(context) {} void SetType(const RichObjectType *t) { type = t; } const RichObjectType *GetType() const { return type; } + void SetContext(void *t) { context = t; } + void *GetContext() const { return context; } + virtual void Paint(Draw& draw, const Rect& rc, const Value& v, Color ink, Color paper, dword style) const; virtual Size GetStdSize(const Value& v) const; private: const RichObjectType *type; + void *context; }; END_UPP_NAMESPACE diff --git a/uppsrc/TCtrlLib/util.cpp b/uppsrc/TCtrlLib/util.cpp index 5783a3ac7..5e6160ac4 100644 --- a/uppsrc/TCtrlLib/util.cpp +++ b/uppsrc/TCtrlLib/util.cpp @@ -90,6 +90,15 @@ void SetColumn(ArrayCtrl& table, Id column, const Value& value) SetColumn(table, table.GetPos(column), value); } +Index GetSelIndex(const ArrayCtrl& table) +{ + Index out; + for(int i = 0; i < table.GetCount(); i++) + if(table.IsSelected(i)) + out.Add(i); + return out; +} + BorderFrame& TopJoinFrame() { static const ColorF b[] = { (ColorF)1, &SLtGray, &SLtGray, &SLtGray, &SGray }; diff --git a/uppsrc/TCtrlLib/util.h b/uppsrc/TCtrlLib/util.h index 4bcd3157e..b5784d752 100644 --- a/uppsrc/TCtrlLib/util.h +++ b/uppsrc/TCtrlLib/util.h @@ -207,6 +207,7 @@ bool IsUnique(const ArrayCtrl& table, Id column); int SwapRows(ArrayCtrl& table, int row1, int row2); void SetColumn(ArrayCtrl& table, int index, const Value& value); void SetColumn(ArrayCtrl& table, Id column, const Value& value); +Index GetSelIndex(const ArrayCtrl& table); BorderFrame& TopJoinFrame(); BorderFrame& BottomJoinFrame(); diff --git a/uppsrc/Web/httpcli.cpp b/uppsrc/Web/httpcli.cpp index fa56c0dbd..f45ec1d10 100644 --- a/uppsrc/Web/httpcli.cpp +++ b/uppsrc/Web/httpcli.cpp @@ -124,9 +124,12 @@ String HttpClient::Execute(Gate2 progress) int sock_port = (use_proxy ? proxy_port : port); LLOG("socket host = " << sock_host << ":" << sock_port); - if(!socket.IsOpen() && !ClientSocket(socket, sock_host, sock_port, true, NULL, 0, false)) { - error = Socket::GetErrorText(); - return String::GetVoid(); + if(!socket.IsOpen()) { + if(!ClientSocket(socket, sock_host, sock_port, true, NULL, 0, false)) { + error = Socket::GetErrorText(); + return String::GetVoid(); + } + socket.Linger(0); } while(!socket.PeekWrite(1000)) { int time = msecs(); @@ -312,28 +315,32 @@ String HttpClient::Execute(Gate2 progress) ; body.Remove(0, nextline); if(part_length <= 0) { - p = body.Begin(); - while(p < e - 2) - if(*p == '\n' && (p[1] == '\n' || p[1] == '\r' && p[2] == '\n')) - goto EXIT; - else + for(;;) { + const char *b = body.Begin(); + p = b; + while(*p && *p != '\n') p++; - while(socket.IsOpen() && !socket.IsError() && !socket.IsEof()) { - if(msecs(end_time) >= 0) { - error = NFormat("Timeout reading footer block (%d B).", body.GetLength()); - goto EXIT; + if(!*p && socket.IsOpen() && !socket.IsError() && !socket.IsEof()) { + if(msecs(end_time) >= 0) { + error = NFormat("Timeout reading footer block (%d B).", body.GetLength()); + break; + } + if(body.GetLength() > 3) + body.Remove(0, body.GetLength() - 3); + String part = socket.Read(1000); + body.Cat(part); + continue; } - if(body.GetLength() > 3) - body.Remove(0, body.GetLength() - 3); - String part = socket.Read(1000); - body.Cat(part); - const char *p = body; - while(*p && !(*p == '\n' && (p[1] == '\n' || p[1] == '\r' && p[2] == '\n'))) + const char *l = p; + if(*p == '\n') p++; - if(*p) - goto EXIT; + if(l > b && l[-1] == '\r') + l--; + if(l == b) + break; + server_headers.Cat(b, p - b); } - break; + goto EXIT; } if(body.GetLength() >= part_length) { chunked.Cat(body, part_length); diff --git a/uppsrc/Web/socket.cpp b/uppsrc/Web/socket.cpp index d1141ad7f..12b74221e 100644 --- a/uppsrc/Web/socket.cpp +++ b/uppsrc/Web/socket.cpp @@ -395,7 +395,7 @@ void Socket::Data::Linger(int msecs) ASSERT(IsOpen()); linger ls; ls.l_onoff = !IsNull(msecs) ? 1 : 0; - ls.l_linger = !IsNull(msecs) ? (msecs / 1000) + 1 : 0; + ls.l_linger = !IsNull(msecs) ? (msecs + 999) / 1000 : 0; if(setsockopt(socket, SOL_SOCKET, SO_LINGER, reinterpret_cast(&ls), sizeof(ls))) SetSockError("setsockopt(SO_LINGER)");