diff --git a/uppsrc/Core/Inet.h b/uppsrc/Core/Inet.h index 5916b80fe..ec075c5c5 100644 --- a/uppsrc/Core/Inet.h +++ b/uppsrc/Core/Inet.h @@ -84,6 +84,9 @@ class TcpSocket { int global_timeout; int start_time; +#ifdef PLATFORM_WIN32 + int connection_start; +#endif int errorcode; String errordesc; @@ -139,7 +142,7 @@ class TcpSocket { void SetSockError(const char *context); static int GetErrorCode(); - static bool WouldBlock(); + bool WouldBlock(); static void Init(); diff --git a/uppsrc/Core/Socket.cpp b/uppsrc/Core/Socket.cpp index 9efe2ca3a..761ba6986 100644 --- a/uppsrc/Core/Socket.cpp +++ b/uppsrc/Core/Socket.cpp @@ -274,6 +274,9 @@ TcpSocket::TcpSocket() waitstep = 10; asn1 = false; global_timeout = Null; +#ifdef PLATFORM_WIN32 + connection_start = Null; +#endif } bool TcpSocket::Open(int family, int type, int protocol) @@ -285,6 +288,7 @@ bool TcpSocket::Open(int family, int type, int protocol) return false; LLOG("TcpSocket::Data::Open() -> " << (int)socket); #ifdef PLATFORM_WIN32 + connection_start = msecs(); u_long arg = 1; if(ioctlsocket(socket, FIONBIO, &arg)) SetSockError("ioctlsocket(FIO[N]BIO)"); @@ -489,7 +493,9 @@ bool TcpSocket::WouldBlock() return c == SOCKERR(EWOULDBLOCK) || c == SOCKERR(EAGAIN); #endif #ifdef PLATFORM_WIN32 - return c == SOCKERR(EWOULDBLOCK) || c == SOCKERR(ENOTCONN); + if(c == SOCKERR(ENOTCONN) && !IsNull(connection_start) && msecs(connection_start) < 20000) + return true; + return c == SOCKERR(EWOULDBLOCK); #endif } @@ -571,8 +577,12 @@ bool TcpSocket::RawWait(dword flags, int end_time) SetSockError("wait"); return false; } - if(avail > 0) + if(avail > 0) { + #ifdef PLATFORM_WIN32 + connection_start = Null; + #endif return true; + } if(IsGlobalTimeout()) return false; if(to <= 0 && timeout) @@ -597,8 +607,14 @@ bool TcpSocket::Wait(dword flags, int end_time) int TcpSocket::GetEndTime() const { - return min(IsNull(global_timeout) ? INT_MAX : start_time + global_timeout, - IsNull(timeout) ? INT_MAX : msecs() + timeout); + int o = min(IsNull(global_timeout) ? INT_MAX : start_time + global_timeout, + IsNull(timeout) ? INT_MAX : msecs() + timeout); +#ifdef PLATFORM_WIN32 + if(GetErrorCode() == SOCKERR(ENOTCONN) && !IsNull(connection_start)) + if(msecs(connection_start) < 20000) + o = connection_start + 20000; +#endif + return o; } bool TcpSocket::Wait(dword flags) diff --git a/uppsrc/IconDes/IconDes.h b/uppsrc/IconDes/IconDes.h index 916094ca0..b20038003 100644 --- a/uppsrc/IconDes/IconDes.h +++ b/uppsrc/IconDes/IconDes.h @@ -317,6 +317,8 @@ public: void SetEditPos(const EditPos& o); void SerializeSettings(Stream& s); + + void HideList() { list.Hide(); } typedef IconDes CLASSNAME; diff --git a/uppsrc/ide/Img/Img.h b/uppsrc/ide/Img/Img.h index ce6dbaf1d..ed1413268 100644 --- a/uppsrc/ide/Img/Img.h +++ b/uppsrc/ide/Img/Img.h @@ -1,22 +1,28 @@ -#ifndef _ide_IconDes_IconDes_h_ -#define _ide_IconDes_IconDes_h_ - -#include -#include - -struct IdeImgView : IdeDesigner, Ctrl { - Size img_sz; - Image img; - String filename; - - virtual void Paint(Draw& w); - - virtual String GetFileName() const { return filename; } - virtual void EditMenu(Bar& menu); - virtual void Save() {} - virtual Ctrl& DesignerCtrl() { return *this; } - - typedef IdeImgView CLASSNAME; -}; - +#ifndef _ide_ImgDes_ImgDes_h_ +#define _ide_ImgDes_ImgDes_h_ + +#include +#include + +struct IdeImgView : IdeDesigner, Ctrl { + Size img_sz; + Image img; + String filename; + + virtual void Paint(Draw& w); + + virtual String GetFileName() const { return filename; } + virtual void EditMenu(Bar& menu); + virtual void Save() {} + virtual Ctrl& DesignerCtrl() { return *this; } + + typedef IdeImgView CLASSNAME; +}; + +struct IdePngDes : IdeIconDes { + virtual void Save(); + + void Load(const char *filename); +}; + #endif \ No newline at end of file diff --git a/uppsrc/ide/Img/Img.icpp b/uppsrc/ide/Img/Img.icpp index 83b2da589..f6df76d82 100644 --- a/uppsrc/ide/Img/Img.icpp +++ b/uppsrc/ide/Img/Img.icpp @@ -1,64 +1,71 @@ -#include "Img.h" - -void IdeImgView::Paint(Draw& w) -{ - Size sz = GetSize(); - String t = (img_sz != img.GetSize() ? "Resized from: " : "Image size: "); - t << Format("%d x %d", img_sz.cx, img_sz.cy); - int tcy = Draw::GetStdFontCy(); - w.DrawRect(0, 0, sz.cx, tcy, SColorFace()); - w.DrawText(5, 0, t, StdFont(), SColorText()); - int ii = 0; - for(int x = 0; x < sz.cx; x += 16) { - int jj = ii; - for(int y = tcy; y < sz.cy; y += 16) - w.DrawRect(x, y, 16, 16, jj++ & 1 ? LtGray() : WhiteGray()); - ii++; - } - w.DrawImage(5, 5 + tcy, img); -} - -void IdeImgView::EditMenu(Bar& menu) -{ - -} - -bool IsImgFile(const String& path) -{ - String s = ToLower(GetFileExt(path)); - return s == ".png" || s == ".jpg" || s == ".gif" || s == ".bmp"; -} - -struct ImageViewModule : public IdeModule { - virtual void CleanUsc() {} - virtual bool ParseUsc(CParser& p) { return false; } - virtual Image FileIcon(const char *path) { - return IsImgFile(path) ? IconDesImg::FileIcon() : Null; - } - virtual IdeDesigner *CreateDesigner(const char *path, byte) { - if(IsImgFile(path)) { - FileIn in(path); - One o = StreamRaster::OpenAny(in); - if(o) { - Size sz = o->GetSize(); - IdeImgView *d = new IdeImgView; - d->img_sz = sz; - d->filename = path; - if(sz.cx < 1024 && sz.cy < 768) - d->img = o->GetImage(); - else { - ImageEncoder m; - Rescale(m, GetFitSize(sz, Size(1024, 768)), *o, sz); - d->img = m; - } - return d; - } - } - return NULL; - } -}; - -INITBLOCK -{ - RegisterIdeModule(Single()); -} +#include "Img.h" + +void IdeImgView::Paint(Draw& w) +{ + Size sz = GetSize(); + String t = (img_sz != img.GetSize() ? "Resized from: " : "Image size: "); + t << Format("%d x %d", img_sz.cx, img_sz.cy); + int tcy = Draw::GetStdFontCy(); + w.DrawRect(0, 0, sz.cx, tcy, SColorFace()); + w.DrawText(5, 0, t, StdFont(), SColorText()); + int ii = 0; + for(int x = 0; x < sz.cx; x += 16) { + int jj = ii; + for(int y = tcy; y < sz.cy; y += 16) + w.DrawRect(x, y, 16, 16, jj++ & 1 ? LtGray() : WhiteGray()); + ii++; + } + w.DrawImage(5, 5 + tcy, img); +} + +void IdeImgView::EditMenu(Bar& menu) +{ + +} + +bool IsImgFile(const String& path) +{ + String s = ToLower(GetFileExt(path)); + return s == ".png" || s == ".jpg" || s == ".gif" || s == ".bmp"; +} + +struct ImageViewModule : public IdeModule { + virtual void CleanUsc() {} + virtual bool ParseUsc(CParser& p) { return false; } + virtual Image FileIcon(const char *path) { + return IsImgFile(path) ? IconDesImg::FileIcon() : Null; + } + virtual IdeDesigner *CreateDesigner(const char *path, byte) { + if(IsImgFile(path)) { + FileIn in(path); + One o = StreamRaster::OpenAny(in); + if(o) { + Size sz = o->GetSize(); + if(ToLower(GetFileExt(path)) == ".png" && sz.cx <= 768 && sz.cy <= 512) { + IdePngDes *d = new IdePngDes; + d->Load(path); + return d; + } + else { + IdeImgView *d = new IdeImgView; + d->img_sz = sz; + d->filename = path; + if(sz.cx <= 1024 && sz.cy <= 768) + d->img = o->GetImage(); + else { + ImageEncoder m; + Rescale(m, GetFitSize(sz, Size(1024, 768)), *o, sz); + d->img = m; + } + return d; + } + } + } + return NULL; + } +}; + +INITBLOCK +{ + RegisterIdeModule(Single()); +} diff --git a/uppsrc/ide/Img/Img.upp b/uppsrc/ide/Img/Img.upp index 7dc1bc27f..b2d2e0d5c 100644 --- a/uppsrc/ide/Img/Img.upp +++ b/uppsrc/ide/Img/Img.upp @@ -2,6 +2,6 @@ description "\377B"; file Img.h, - ImgEdit.cpp, + Png.cpp, Img.icpp; diff --git a/uppsrc/ide/Img/ImgEdit.cpp b/uppsrc/ide/Img/ImgEdit.cpp deleted file mode 100644 index 2ce77a101..000000000 --- a/uppsrc/ide/Img/ImgEdit.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "Img.h" - -// \ No newline at end of file diff --git a/uppsrc/ide/Img/Png.cpp b/uppsrc/ide/Img/Png.cpp new file mode 100644 index 000000000..f8386ae3a --- /dev/null +++ b/uppsrc/ide/Img/Png.cpp @@ -0,0 +1,15 @@ +#include "Img.h" + +void IdePngDes::Save() +{ +} + +void IdePngDes::Load(const char *_filename) +{ + Clear(); + filename = _filename; + filetime = FileGetTime(filename); + Image m = StreamRaster::LoadFileAny(filename); + AddImage(filename, m, false); + HideList(); +}