mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
context-related patches to RichText (continued); fixed hanging sockets in HTTP client; minor fixes in FormatDouble
git-svn-id: svn://ultimatepp.org/upp/trunk@1000 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
f197dc6ab5
commit
c608b82728
13 changed files with 94 additions and 75 deletions
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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[] = {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<UnknownRichObject>();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,16 +108,8 @@ class Bar;
|
|||
struct RichObjectType : Moveable<RichObjectType> {
|
||||
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<RichObjectType> {
|
|||
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<RichObject> {
|
||||
|
|
@ -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());
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -110,16 +110,20 @@ Array<HelpIndexFormattedEntry> 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
|
||||
|
|
|
|||
|
|
@ -90,6 +90,15 @@ void SetColumn(ArrayCtrl& table, Id column, const Value& value)
|
|||
SetColumn(table, table.GetPos(column), value);
|
||||
}
|
||||
|
||||
Index<int> GetSelIndex(const ArrayCtrl& table)
|
||||
{
|
||||
Index<int> 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 };
|
||||
|
|
|
|||
|
|
@ -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<int> GetSelIndex(const ArrayCtrl& table);
|
||||
|
||||
BorderFrame& TopJoinFrame();
|
||||
BorderFrame& BottomJoinFrame();
|
||||
|
|
|
|||
|
|
@ -124,9 +124,12 @@ String HttpClient::Execute(Gate2<int, int> 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<int, int> 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);
|
||||
|
|
|
|||
|
|
@ -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<const char *>(&ls), sizeof(ls)))
|
||||
SetSockError("setsockopt(SO_LINGER)");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue