From f88df0c7dc7aa1672d67809cf5e5f487015a8b5e Mon Sep 17 00:00:00 2001 From: cxl Date: Thu, 9 Jun 2011 19:02:49 +0000 Subject: [PATCH] .developing rainbow git-svn-id: svn://ultimatepp.org/upp/trunk@3501 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CtrlCore/BackDraw.cpp | 26 -- uppsrc/CtrlCore/CtrlCore.h | 77 ++++- uppsrc/CtrlCore/CtrlCore.upp | 34 +- uppsrc/CtrlCore/DrawOpWin32.cpp | 2 +- uppsrc/CtrlCore/DrawOpX11.cpp | 2 +- uppsrc/CtrlCore/DrawTextWin32.cpp | 2 +- uppsrc/CtrlCore/DrawTextX11.cpp | 502 +++++++++++++++--------------- uppsrc/CtrlCore/DrawWin32.cpp | 2 +- uppsrc/CtrlCore/DrawWin32.h | 274 ---------------- uppsrc/CtrlCore/DrawX11.cpp | 2 +- uppsrc/CtrlCore/DrawX11.h | 182 ----------- uppsrc/CtrlCore/ImageWin32.cpp | 2 +- uppsrc/CtrlCore/ImageX11.cpp | 2 +- uppsrc/CtrlCore/MKeys.h | 4 + uppsrc/CtrlCore/MetaFile.cpp | 3 +- uppsrc/CtrlCore/SystemDraw.cpp | 242 +++++++------- uppsrc/CtrlCore/SystemDraw.h | 121 ------- uppsrc/CtrlCore/TopWin32.cpp | 68 ++++ uppsrc/CtrlCore/TopWinX11.cpp | 59 ++++ uppsrc/CtrlCore/TopWindow.cpp | 21 +- uppsrc/CtrlCore/TopWindow.h | 7 + uppsrc/CtrlCore/Win32Ctrl.h | 65 ++++ uppsrc/CtrlCore/Win32Gui.h | 476 ++++++++++++++++------------ uppsrc/CtrlCore/Win32Keys.h | 109 +++++++ uppsrc/CtrlCore/Win32Top.h | 20 ++ uppsrc/CtrlCore/X11Gui.h | 196 +++++++++++- uppsrc/CtrlCore/init | 2 +- 27 files changed, 1293 insertions(+), 1209 deletions(-) delete mode 100644 uppsrc/CtrlCore/BackDraw.cpp delete mode 100644 uppsrc/CtrlCore/DrawWin32.h delete mode 100644 uppsrc/CtrlCore/DrawX11.h delete mode 100644 uppsrc/CtrlCore/SystemDraw.h create mode 100644 uppsrc/CtrlCore/Win32Ctrl.h create mode 100644 uppsrc/CtrlCore/Win32Keys.h create mode 100644 uppsrc/CtrlCore/Win32Top.h diff --git a/uppsrc/CtrlCore/BackDraw.cpp b/uppsrc/CtrlCore/BackDraw.cpp deleted file mode 100644 index 7a011bf1a..000000000 --- a/uppsrc/CtrlCore/BackDraw.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "SystemDraw.h" - -NAMESPACE_UPP - -SystemDraw& ScreenInfo(); - -bool BackDraw::IsPaintingOp(const Rect& r) const -{ - Rect rr = r + GetOffset(); - if(!rr.Intersects(size)) - return false; - return painting ? painting->IsPainting(rr + painting_offset) : true; -} - -BackDraw::BackDraw() -{ - painting = NULL; - painting_offset = Point(0, 0); -} - -BackDraw::~BackDraw() -{ - Destroy(); -} - -END_UPP_NAMESPACE diff --git a/uppsrc/CtrlCore/CtrlCore.h b/uppsrc/CtrlCore/CtrlCore.h index bb11d5ce1..db318a36a 100644 --- a/uppsrc/CtrlCore/CtrlCore.h +++ b/uppsrc/CtrlCore/CtrlCore.h @@ -3,8 +3,6 @@ #include -#include "SystemDraw.h" - #ifdef PLATFORM_WIN32 #include "Win32Gui.h" #endif @@ -15,6 +13,76 @@ NAMESPACE_UPP +#ifdef _MULTITHREADED +void EnterGuiMutex(); +void LeaveGuiMutex(); +#else +inline void EnterGuiMutex() {} +inline void LeaveGuiMutex() {} +#endif + +struct GuiLock { + GuiLock() { EnterGuiMutex(); } + ~GuiLock() { LeaveGuiMutex(); } +}; + +bool ScreenInPaletteMode(); +Size GetScreenSize(); + +class BackDraw : public SystemDraw { +public: + virtual bool IsPaintingOp(const Rect& r) const; + +protected: + GUIPLATFORM_BACKDRAW_DECLS + Size size; + Draw *painting; + Point painting_offset; + +public: + void Put(SystemDraw& w, int x, int y); + void Put(SystemDraw& w, Point p) { Put(w, p.x, p.y); } + + void Create(SystemDraw& w, int cx, int cy); + void Create(SystemDraw& w, Size sz) { Create(w, sz.cx, sz.cy); } + void Destroy(); + + void SetPaintingDraw(Draw& w, Point off) { painting = &w; painting_offset = off; } + + BackDraw(); + ~BackDraw(); +}; + +class ImageDraw : public SystemDraw { + Size size; + + GUIPLATFORM_IMAGEDRAW_DECLS + + bool has_alpha; + + void Init(); + Image Get(bool pm) const; + +public: + Draw& Alpha(); + + operator Image() const; + + Image GetStraight() const; + + ImageDraw(Size sz); + ImageDraw(int cx, int cy); + ~ImageDraw(); +}; + +typedef ImageDraw SystemImageDraw; + +void DrawDragRect(SystemDraw& w, const Rect& rect1, const Rect& rect2, const Rect& clip, int n, + Color color, uint64 pattern); + +void SetSurface(Draw& w, const Rect& dest, const RGBA *pixels, Size srcsz, Point poff); +void SetSurface(Draw& w, int x, int y, int cx, int cy, const RGBA *pixels); + enum { K_DELTA = 0x010000, @@ -622,7 +690,12 @@ private: typedef Ctrl CLASSNAME; + +#ifdef GUIPLATFORM_CTRL_DECLS_INCLUDE + #include GUIPLATFORM_CTRL_DECLS_INCLUDE +#else GUIPLATFORM_CTRL_DECLS +#endif private: void DoRemove(); diff --git a/uppsrc/CtrlCore/CtrlCore.upp b/uppsrc/CtrlCore/CtrlCore.upp index 4d61bfd46..b77ec915e 100644 --- a/uppsrc/CtrlCore/CtrlCore.upp +++ b/uppsrc/CtrlCore/CtrlCore.upp @@ -30,28 +30,11 @@ library(FREEBSD) xcb; library(POSIX !NOGTK) notify; file - SystemDraw readonly separator, - DrawWin32.h, - DrawWin32.cpp, - DrawOpWin32.cpp, - DrawTextWin32.cpp, - ImageWin32.cpp, - MetaFile.cpp, - DrawX11.h, - DrawX11.cpp, - DrawOpX11.cpp, - DrawTextX11.cpp, - ImageX11.cpp, - SystemDraw.h, - BackDraw.cpp, - SystemDraw.cpp, - DrawUtil.cpp, Core readonly separator, CtrlCore.h, - Win32Gui.h, - X11Gui.h, MKeys.h, stdids.h, + SystemDraw.cpp, Frame.cpp, CtrlMt.cpp, Ctrl.cpp, @@ -73,6 +56,16 @@ file lay.h, llay.h, Win32 readonly separator, + Win32Gui.h, + Win32Keys.h, + Win32Ctrl.h, + Win32Top.h, + DrawWin32.cpp, + DrawOpWin32.cpp, + DrawTextWin32.cpp, + ImageWin32.cpp, + MetaFile.cpp, + UtilWin32.cpp, MultiMon.dli, Win32Wnd.cpp, Win32Clip.cpp, @@ -82,6 +75,11 @@ file DHCtrl.cpp, Win32Msg.i, X11 readonly separator, + X11Gui.h, + DrawX11.cpp, + DrawOpX11.cpp, + DrawTextX11.cpp, + ImageX11.cpp, X11Wnd.cpp, X11Proc.cpp, TopWinX11.cpp, diff --git a/uppsrc/CtrlCore/DrawOpWin32.cpp b/uppsrc/CtrlCore/DrawOpWin32.cpp index 34a9fec0f..ca2a01633 100644 --- a/uppsrc/CtrlCore/DrawOpWin32.cpp +++ b/uppsrc/CtrlCore/DrawOpWin32.cpp @@ -1,4 +1,4 @@ -#include "SystemDraw.h" +#include "CtrlCore.h" NAMESPACE_UPP diff --git a/uppsrc/CtrlCore/DrawOpX11.cpp b/uppsrc/CtrlCore/DrawOpX11.cpp index 3eb76616c..d221c15cb 100644 --- a/uppsrc/CtrlCore/DrawOpX11.cpp +++ b/uppsrc/CtrlCore/DrawOpX11.cpp @@ -1,4 +1,4 @@ -#include "SystemDraw.h" +#include "CtrlCore.h" NAMESPACE_UPP diff --git a/uppsrc/CtrlCore/DrawTextWin32.cpp b/uppsrc/CtrlCore/DrawTextWin32.cpp index cba37dc36..f4dc696cb 100644 --- a/uppsrc/CtrlCore/DrawTextWin32.cpp +++ b/uppsrc/CtrlCore/DrawTextWin32.cpp @@ -1,4 +1,4 @@ -#include "SystemDraw.h" +#include "CtrlCore.h" NAMESPACE_UPP diff --git a/uppsrc/CtrlCore/DrawTextX11.cpp b/uppsrc/CtrlCore/DrawTextX11.cpp index 46e3dbad0..243b959cc 100644 --- a/uppsrc/CtrlCore/DrawTextX11.cpp +++ b/uppsrc/CtrlCore/DrawTextX11.cpp @@ -1,251 +1,251 @@ -#include "SystemDraw.h" - -NAMESPACE_UPP - -#ifdef PLATFORM_X11 - -#define LTIMING(x) -#define LLOG(x) - -int gtk_antialias = -1; -int gtk_hinting; -String gtk_hintstyle; -String gtk_rgba; - -XftFont *CreateXftFont(Font font, int angle) -{ - LTIMING("CreateXftFont"); - XftFont *xftfont; - double sina, cosa; - Std(font); - int hg = abs(font.GetHeight()); - if(hg == 0) hg = max(GetStdFontCy(), 10); - String face = font.GetFaceName(); - FcPattern *p = FcPatternCreate(); - FcPatternAddString(p, FC_FAMILY, (FcChar8*)~face); - FcPatternAddInteger(p, FC_SLANT, font.IsItalic() ? 110 : 0); - FcPatternAddInteger(p, FC_PIXEL_SIZE, hg); - FcPatternAddInteger(p, FC_WEIGHT, font.IsBold() ? 200 : 100); - FcPatternAddBool(p, FC_MINSPACE, 1); - if(angle) { - FcMatrix mx; - Draw::SinCos(angle, sina, cosa); - mx.xx = cosa; - mx.xy = -sina; - mx.yx = sina; - mx.yy = cosa; - FcPatternAddMatrix(p, FC_MATRIX, &mx); - } - FcResult result; - FcPattern *m = XftFontMatch(Xdisplay, Xscreenno, p, &result); - if(font.IsNonAntiAliased() || gtk_antialias >= 0) { - FcPatternDel(m, FC_ANTIALIAS); - FcPatternAddBool(m, FC_ANTIALIAS, - font.IsNonAntiAliased() ? FcFalse : gtk_antialias ? FcTrue : FcFalse); - } - if(gtk_hinting >= 0) { - FcPatternDel(m, FC_HINTING); - FcPatternAddBool(m, FC_HINTING, gtk_hinting); - } - const char *hs[] = { "hintnone", "hintslight", "hintmedium", "hintfull" }; - for(int i = 0; i < 4; i++) - if(gtk_hintstyle == hs[i]) { - FcPatternDel(m, FC_HINT_STYLE); - FcPatternAddInteger(m, FC_HINT_STYLE, i); - } - const char *rgba[] = { "_", "rgb", "bgr", "vrgb", "vbgr" }; - for(int i = 0; i < __countof(rgba); i++) - if(gtk_rgba == rgba[i]) { - FcPatternDel(m, FC_RGBA); - FcPatternAddInteger(m, FC_RGBA, i); - } - xftfont = XftFontOpenPattern(Xdisplay, m); - FcPatternDestroy(p); - return xftfont; -} - -#define FONTCACHE 37 - -struct XftEntry { - Font font; - int angle; - XftFont *xftfont; -}; - -XftFont *GetXftFont(Font fnt, int angle) -{ - static XftEntry cache[FONTCACHE]; - ONCELOCK { - for(int i = 0; i < FONTCACHE; i++) - cache[i].font.Height(-30000); - } - XftEntry be; - be = cache[0]; - for(int i = 0; i < FONTCACHE; i++) { - XftEntry e = cache[i]; - if(i) - cache[i] = be; - if(e.font == fnt && e.angle == angle) { - if(i) - cache[0] = e; - return e.xftfont; - } - be = e; - } - if(be.xftfont) { - XftFontClose(Xdisplay, be.xftfont); - } - be.font = fnt; - be.angle = angle; - be.xftfont = CreateXftFont(fnt, angle); - cache[0] = be; - return be.xftfont; -} - -CommonFontInfo XftGetFontInfoSys(Font font) -{ - CommonFontInfo fi; - String path; - XftFont *xftfont = GetXftFont(font, 0); - if(xftfont) { - fi.ascent = (int16)xftfont->ascent; - fi.descent = (int16)xftfont->descent; - fi.height = fi.ascent + fi.descent; - fi.lineheight = (int16)xftfont->height; - fi.external = 0; - fi.internal = 0; - fi.overhang = 0; - fi.maxwidth = (int16)xftfont->max_advance_width; - fi.avewidth = fi.maxwidth; - fi.default_char = '?'; - fi.fixedpitch = font.GetFaceInfo() & Font::FIXEDPITCH; - - char *fn = NULL; - XftPatternGetString(xftfont->pattern, XFT_FILE, 0, &fn); - if(fn && strlen(fn) < 250) - strcpy(fi.path, fn); - } - return fi; -} - -GlyphInfo XftGetGlyphInfoSys(Font font, int chr) -{ - wchar h = chr; - XGlyphInfo info; - XftTextExtents16(Xdisplay, GetXftFont(font, 0), &h, 1, &info); - GlyphInfo gi; - gi.width = info.xOff; - gi.lspc = -info.x; - gi.rspc = info.xOff - info.width + info.x; - return gi; -} - -INITBLOCK { -// extern FT_Face (*FTFaceXft)(Font fnt, String *rpath); - extern CommonFontInfo (*GetFontInfoSysXft)(Font font); - extern GlyphInfo (*GetGlyphInfoSysXft)(Font font, int chr); -// FTFaceXft = XftFTFace; - GetFontInfoSysXft = XftGetFontInfoSys; - GetGlyphInfoSysXft = XftGetGlyphInfoSys; -} - -void SystemDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, - Color ink, int n, const int *dx) { - GuiLock __; - LTIMING("DrawText"); - LLOG("DrawText " << ToUtf8(WString(text, n)) << " color:" << ink << " font:" << font); - //TODO - X11 seems to crash when displaying too long strings (?) - int ox = x + actual_offset.x; - int oy = y + actual_offset.y; - SetForeground(ink); - XftColor c; - c.color.red = ink.GetR() << 8; - c.color.green = ink.GetG() << 8; - c.color.blue = ink.GetB() << 8; - c.color.alpha = 0xffff; - c.pixel = GetXPixel(ink.GetR(), ink.GetG(), ink.GetB()); - XftFont *xftfont = GetXftFont(font, angle); - Size offset = Point(0, 0); - double sina, cosa; - int ascent = font.Info().GetAscent(); - if(angle) { - SinCos(angle, sina, cosa); - offset.cx = fround(ascent * sina); - offset.cy = fround(ascent * cosa); - } - int hg = abs(font.GetHeight()); - if(hg == 0) hg = 10; - int underline_thickness = max(hg / 20, 1); - int underline_position = max(hg / 15, int(font.Info().GetDescent() > 0)); - if(angle) { - int xpos = 0; - for(int i = 0; i < n; i++) { - wchar h = text[i]; - XftDrawString16(xftdraw, &c, xftfont, - int(ox + xpos * cosa + offset.cx), - int(oy - xpos * sina + offset.cy), - (FcChar16 *)&h, 1); - xpos += dx ? dx[i] : lastFont[text[i]]; - } - if(font.IsUnderline() || font.IsStrikeout()) { - x += offset.cx; - y += offset.cy; - if(font.IsUnderline()) - DrawLine( - int(x + underline_position * sina), - int(y + underline_position * cosa), - int(x + xpos * cosa + underline_position * sina), - int(y - xpos * sina + underline_position * cosa), - underline_thickness, - ink - ); - if(font.IsStrikeout()) { - int p = 2 * ascent / 3; - DrawLine( - int(x + p * sina), - int(y + p * cosa), - int(x + xpos * cosa + p * sina), - int(y - xpos * sina + p * cosa), - underline_thickness, - ink - ); - } - } - } - else { - if(dx) { - int xpos = ox; - Buffer ch(n); - for(int i = 0; i < n; i++) { - ch[i].ucs4 = text[i]; - ch[i].x = xpos; - ch[i].y = oy + ascent; - xpos += dx[i]; - } - XftDrawCharSpec(xftdraw, &c, xftfont, ch, n); - } - else - XftDrawString16(xftdraw, &c, xftfont, ox, oy + ascent, - (FcChar16 *)text, n); - LLOG("XftColor: r=" << c.color.red << ", g=" << c.color.green << ", b=" << c.color.blue - << ", alpha=" << c.color.alpha << ", pixel=" << FormatIntHex(c.pixel)); - if(font.IsUnderline() || font.IsStrikeout()) { - int cx; - if(dx && n > 0) { - cx = 0; - Sum(cx, dx, dx + n - 1); - cx += lastFont[text[n - 1]]; - } - else - cx = GetTextSize(text, font, n).cx; - if(font.IsUnderline()) - DrawRect(x, y + ascent + underline_position, cx, underline_thickness, ink); - if(font.IsStrikeout()) - DrawRect(x, y + 2 * ascent / 3, cx, underline_thickness, ink); - } - } -} - -#endif - -END_UPP_NAMESPACE +#include "CtrlCore.h" + +NAMESPACE_UPP + +#ifdef PLATFORM_X11 + +#define LTIMING(x) +#define LLOG(x) + +int gtk_antialias = -1; +int gtk_hinting; +String gtk_hintstyle; +String gtk_rgba; + +XftFont *CreateXftFont(Font font, int angle) +{ + LTIMING("CreateXftFont"); + XftFont *xftfont; + double sina, cosa; + Std(font); + int hg = abs(font.GetHeight()); + if(hg == 0) hg = max(GetStdFontCy(), 10); + String face = font.GetFaceName(); + FcPattern *p = FcPatternCreate(); + FcPatternAddString(p, FC_FAMILY, (FcChar8*)~face); + FcPatternAddInteger(p, FC_SLANT, font.IsItalic() ? 110 : 0); + FcPatternAddInteger(p, FC_PIXEL_SIZE, hg); + FcPatternAddInteger(p, FC_WEIGHT, font.IsBold() ? 200 : 100); + FcPatternAddBool(p, FC_MINSPACE, 1); + if(angle) { + FcMatrix mx; + Draw::SinCos(angle, sina, cosa); + mx.xx = cosa; + mx.xy = -sina; + mx.yx = sina; + mx.yy = cosa; + FcPatternAddMatrix(p, FC_MATRIX, &mx); + } + FcResult result; + FcPattern *m = XftFontMatch(Xdisplay, Xscreenno, p, &result); + if(font.IsNonAntiAliased() || gtk_antialias >= 0) { + FcPatternDel(m, FC_ANTIALIAS); + FcPatternAddBool(m, FC_ANTIALIAS, + font.IsNonAntiAliased() ? FcFalse : gtk_antialias ? FcTrue : FcFalse); + } + if(gtk_hinting >= 0) { + FcPatternDel(m, FC_HINTING); + FcPatternAddBool(m, FC_HINTING, gtk_hinting); + } + const char *hs[] = { "hintnone", "hintslight", "hintmedium", "hintfull" }; + for(int i = 0; i < 4; i++) + if(gtk_hintstyle == hs[i]) { + FcPatternDel(m, FC_HINT_STYLE); + FcPatternAddInteger(m, FC_HINT_STYLE, i); + } + const char *rgba[] = { "_", "rgb", "bgr", "vrgb", "vbgr" }; + for(int i = 0; i < __countof(rgba); i++) + if(gtk_rgba == rgba[i]) { + FcPatternDel(m, FC_RGBA); + FcPatternAddInteger(m, FC_RGBA, i); + } + xftfont = XftFontOpenPattern(Xdisplay, m); + FcPatternDestroy(p); + return xftfont; +} + +#define FONTCACHE 37 + +struct XftEntry { + Font font; + int angle; + XftFont *xftfont; +}; + +XftFont *GetXftFont(Font fnt, int angle) +{ + static XftEntry cache[FONTCACHE]; + ONCELOCK { + for(int i = 0; i < FONTCACHE; i++) + cache[i].font.Height(-30000); + } + XftEntry be; + be = cache[0]; + for(int i = 0; i < FONTCACHE; i++) { + XftEntry e = cache[i]; + if(i) + cache[i] = be; + if(e.font == fnt && e.angle == angle) { + if(i) + cache[0] = e; + return e.xftfont; + } + be = e; + } + if(be.xftfont) { + XftFontClose(Xdisplay, be.xftfont); + } + be.font = fnt; + be.angle = angle; + be.xftfont = CreateXftFont(fnt, angle); + cache[0] = be; + return be.xftfont; +} + +CommonFontInfo XftGetFontInfoSys(Font font) +{ + CommonFontInfo fi; + String path; + XftFont *xftfont = GetXftFont(font, 0); + if(xftfont) { + fi.ascent = (int16)xftfont->ascent; + fi.descent = (int16)xftfont->descent; + fi.height = fi.ascent + fi.descent; + fi.lineheight = (int16)xftfont->height; + fi.external = 0; + fi.internal = 0; + fi.overhang = 0; + fi.maxwidth = (int16)xftfont->max_advance_width; + fi.avewidth = fi.maxwidth; + fi.default_char = '?'; + fi.fixedpitch = font.GetFaceInfo() & Font::FIXEDPITCH; + + char *fn = NULL; + XftPatternGetString(xftfont->pattern, XFT_FILE, 0, &fn); + if(fn && strlen(fn) < 250) + strcpy(fi.path, fn); + } + return fi; +} + +GlyphInfo XftGetGlyphInfoSys(Font font, int chr) +{ + wchar h = chr; + XGlyphInfo info; + XftTextExtents16(Xdisplay, GetXftFont(font, 0), &h, 1, &info); + GlyphInfo gi; + gi.width = info.xOff; + gi.lspc = -info.x; + gi.rspc = info.xOff - info.width + info.x; + return gi; +} + +INITBLOCK { +// extern FT_Face (*FTFaceXft)(Font fnt, String *rpath); + extern CommonFontInfo (*GetFontInfoSysXft)(Font font); + extern GlyphInfo (*GetGlyphInfoSysXft)(Font font, int chr); +// FTFaceXft = XftFTFace; + GetFontInfoSysXft = XftGetFontInfoSys; + GetGlyphInfoSysXft = XftGetGlyphInfoSys; +} + +void SystemDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, + Color ink, int n, const int *dx) { + GuiLock __; + LTIMING("DrawText"); + LLOG("DrawText " << ToUtf8(WString(text, n)) << " color:" << ink << " font:" << font); + //TODO - X11 seems to crash when displaying too long strings (?) + int ox = x + actual_offset.x; + int oy = y + actual_offset.y; + SetForeground(ink); + XftColor c; + c.color.red = ink.GetR() << 8; + c.color.green = ink.GetG() << 8; + c.color.blue = ink.GetB() << 8; + c.color.alpha = 0xffff; + c.pixel = GetXPixel(ink.GetR(), ink.GetG(), ink.GetB()); + XftFont *xftfont = GetXftFont(font, angle); + Size offset = Point(0, 0); + double sina, cosa; + int ascent = font.Info().GetAscent(); + if(angle) { + SinCos(angle, sina, cosa); + offset.cx = fround(ascent * sina); + offset.cy = fround(ascent * cosa); + } + int hg = abs(font.GetHeight()); + if(hg == 0) hg = 10; + int underline_thickness = max(hg / 20, 1); + int underline_position = max(hg / 15, int(font.Info().GetDescent() > 0)); + if(angle) { + int xpos = 0; + for(int i = 0; i < n; i++) { + wchar h = text[i]; + XftDrawString16(xftdraw, &c, xftfont, + int(ox + xpos * cosa + offset.cx), + int(oy - xpos * sina + offset.cy), + (FcChar16 *)&h, 1); + xpos += dx ? dx[i] : lastFont[text[i]]; + } + if(font.IsUnderline() || font.IsStrikeout()) { + x += offset.cx; + y += offset.cy; + if(font.IsUnderline()) + DrawLine( + int(x + underline_position * sina), + int(y + underline_position * cosa), + int(x + xpos * cosa + underline_position * sina), + int(y - xpos * sina + underline_position * cosa), + underline_thickness, + ink + ); + if(font.IsStrikeout()) { + int p = 2 * ascent / 3; + DrawLine( + int(x + p * sina), + int(y + p * cosa), + int(x + xpos * cosa + p * sina), + int(y - xpos * sina + p * cosa), + underline_thickness, + ink + ); + } + } + } + else { + if(dx) { + int xpos = ox; + Buffer ch(n); + for(int i = 0; i < n; i++) { + ch[i].ucs4 = text[i]; + ch[i].x = xpos; + ch[i].y = oy + ascent; + xpos += dx[i]; + } + XftDrawCharSpec(xftdraw, &c, xftfont, ch, n); + } + else + XftDrawString16(xftdraw, &c, xftfont, ox, oy + ascent, + (FcChar16 *)text, n); + LLOG("XftColor: r=" << c.color.red << ", g=" << c.color.green << ", b=" << c.color.blue + << ", alpha=" << c.color.alpha << ", pixel=" << FormatIntHex(c.pixel)); + if(font.IsUnderline() || font.IsStrikeout()) { + int cx; + if(dx && n > 0) { + cx = 0; + Sum(cx, dx, dx + n - 1); + cx += lastFont[text[n - 1]]; + } + else + cx = GetTextSize(text, font, n).cx; + if(font.IsUnderline()) + DrawRect(x, y + ascent + underline_position, cx, underline_thickness, ink); + if(font.IsStrikeout()) + DrawRect(x, y + 2 * ascent / 3, cx, underline_thickness, ink); + } + } +} + +#endif + +END_UPP_NAMESPACE diff --git a/uppsrc/CtrlCore/DrawWin32.cpp b/uppsrc/CtrlCore/DrawWin32.cpp index 0894bf9f5..0526fa2b9 100644 --- a/uppsrc/CtrlCore/DrawWin32.cpp +++ b/uppsrc/CtrlCore/DrawWin32.cpp @@ -1,4 +1,4 @@ -#include "SystemDraw.h" +#include "CtrlCore.h" NAMESPACE_UPP diff --git a/uppsrc/CtrlCore/DrawWin32.h b/uppsrc/CtrlCore/DrawWin32.h deleted file mode 100644 index d69e77b6b..000000000 --- a/uppsrc/CtrlCore/DrawWin32.h +++ /dev/null @@ -1,274 +0,0 @@ -#ifdef PLATFORM_WIN32 - -NAMESPACE_UPP - -class SystemDraw : public Draw { -public: - virtual dword GetInfo() const; - virtual Size GetPageSize() const; - - virtual void BeginOp(); - virtual void EndOp(); - virtual void OffsetOp(Point p); - virtual bool ClipOp(const Rect& r); - virtual bool ClipoffOp(const Rect& r); - virtual bool ExcludeClipOp(const Rect& r); - virtual bool IntersectClipOp(const Rect& r); - virtual bool IsPaintingOp(const Rect& r) const; - virtual Rect GetPaintRect() const; - - virtual void DrawRectOp(int x, int y, int cx, int cy, Color color); - virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color); - virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color); - - virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count, - const int *counts, int count_count, - int width, Color color, Color doxor); - virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, - const int *subpolygon_counts, int scc, - const int *disjunct_polygon_counts, int dpcc, - Color color, int width, Color outline, - uint64 pattern, Color doxor); - virtual void DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color); - - virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor); - virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font, - Color ink, int n, const int *dx); - - virtual Size GetNativeDpi() const; - virtual void BeginNative(); - virtual void EndNative(); - - virtual int GetCloffLevel() const; - -private: - Size pageSize; - Size nativeSize; - Size nativeDpi; - bool palette:1; - bool color16:1; - bool is_mono:1; - int native; - - friend class ImageDraw; - friend class FontInfo; - friend class Font; - - friend void StaticExitDraw_(); - - Point actual_offset_bak; - - struct Cloff : Moveable { - Point org; - HRGN hrgn; - Rect drawingclip; - }; - - Array cloff; - Rect drawingclip; - - COLORREF lastTextColor; - Color lastColor; - HBRUSH orgBrush; - HBRUSH actBrush; - HPEN orgPen; - HPEN actPen; - int lastPen; - Color lastPenColor; - - void Unselect0(); - void Cinit(); - - void LoadCaps(); - void SetPrinterMode(); - void Reset(); - void SetOrg(); - friend HPALETTE GetQlibPalette(); - void DotsMode(); - - static void InitColors(); - - friend class BackDraw; - friend class ScreenDraw; - friend class PrintDraw; - -protected: - dword style; - HDC handle; - Point actual_offset; - - SystemDraw(); - void Init(); - void InitClip(const Rect& clip); - -public: - static Rect GetVirtualScreenArea(); - - static void SetAutoPalette(bool ap); - static bool AutoPalette(); - bool PaletteMode() { return palette; } - - static void Flush() { GdiFlush(); } - - COLORREF GetColor(Color color) const; - - Point GetOffset() const { return actual_offset; } - -#ifndef PLATFORM_WINCE - Point LPtoDP(Point p) const; - Point DPtoLP(Point p) const; - Rect LPtoDP(const Rect& r) const; - Rect DPtoLP(const Rect& r) const; -#endif - - void SetColor(Color color); - void SetDrawPen(int width, Color color); - - Size GetSizeCaps(int i, int j) const; - HDC BeginGdi(); - void EndGdi(); - HDC GetHandle() { return handle; } - operator HDC() const { return handle; } - void Unselect(); - void Attach(HDC ahandle) { handle = ahandle; Init(); } - HDC Detach() { Unselect(); HDC h = handle; handle = NULL; return h; } - - SystemDraw(HDC hdc); - virtual ~SystemDraw(); -}; - -#ifndef PLATFORM_WINCE -class WinMetaFile/* : NoCopy */{ - Size size; - /*mutable */HENHMETAFILE hemf; //TODO: Remove picks - - void ChkP() const { /*ASSERT(!IsPicked());*/ } - void Init(); -// void Pick(pick_ WinMetaFile& src); -// void Copy(const WinMetaFile& src); - -public: - void Attach(HENHMETAFILE emf); - HENHMETAFILE Detach(); - - void Set(const void *data, dword len); - void Set(const String& data) { Set(~data, data.GetCount()); } - - String Get() const; - -// bool IsPicked() const { return (uintptr_t) hemf == 0xffffffff; } - - operator bool() const { ChkP(); return hemf; } - void SetSize(const Size& sz) { size = sz; } - Size GetSize() const { ChkP(); return hemf ? size : Size(0, 0); } - - void Clear(); - - void Paint(Draw& w, const Rect& r) const; - void Paint(Draw& w, int x, int y, int cx, int cy) const; - - void Serialize(Stream& s); - - void ReadClipboard(); - void WriteClipboard() const; - void Load(const char *file) { Set(LoadFile(file)); } - - WinMetaFile() { Init(); } - WinMetaFile(HENHMETAFILE hemf); - WinMetaFile(HENHMETAFILE hemf, Size sz); - WinMetaFile(const char *file); - WinMetaFile(void *data, int len); - WinMetaFile(const String& data); - -// WinMetaFile(pick_ WinMetaFile& src) { Pick(src); } -// WinMetaFile(const WinMetaFile& src, int) { Copy(src); } -// void operator=(pick_ WinMetaFile& src) { Clear(); Pick(src); } -// void operator<<=(const WinMetaFile& src) { Clear(); Copy(src); } - - ~WinMetaFile() { Clear(); } - - HENHMETAFILE GetHEMF() const { ChkP(); return hemf; } -}; - -class WinMetaFileDraw : public SystemDraw { - Size size; - -public: - bool Create(HDC hdc, int cx, int cy, const char *app = NULL, const char *name = NULL, const char *file = NULL); - bool Create(int cx, int cy, const char *app = NULL, const char *name = NULL, const char *file = NULL); - WinMetaFile Close(); - - WinMetaFileDraw() {} - WinMetaFileDraw(HDC hdc, int cx, int cy, const char *app = NULL, const char *name = NULL, const char *file = NULL); - WinMetaFileDraw(int cx, int cy, const char *app = NULL, const char *name = NULL, const char *file = NULL); - ~WinMetaFileDraw(); -}; - -void DrawWMF(Draw& w, int x, int y, int cx, int cy, const String& wmf); -void DrawWMF(Draw& w, int x, int y, const String& wmf); -Drawing LoadWMF(const char *path, int cx, int cy); -Drawing LoadWMF(const char *path); - -String AsWMF(const Drawing& iw); - -#endif - -class ScreenDraw : public SystemDraw { -public: - ScreenDraw(bool ic = false); - ~ScreenDraw(); -}; - -#ifndef PLATFORM_WINCE -class PrintDraw : public SystemDraw { -public: - virtual void StartPage(); - virtual void EndPage(); - -private: - bool aborted; - - void InitPrinter(); -public: - PrintDraw(HDC hdc, const char *jobname); - ~PrintDraw(); -}; -#endif - -inline bool BitBlt(HDC ddc, Point d, HDC sdc, const Rect& s, dword rop = SRCCOPY) -{ return BitBlt(ddc, d.x, d.y, s.Width(), s.Height(), sdc, s.left, s.top, rop); } - -inline bool StretchBlt(HDC ddc, const Rect& r, HDC sdc, const Rect& s, dword rop = SRCCOPY) -{ return StretchBlt(ddc, r.left, r.top, r.Width(), r.Height(), sdc, s.left, s.top, s.Width(), s.Height(), rop); } - -inline bool PatBlt(HDC dc, const Rect& r, dword rop = PATCOPY) -{ return PatBlt(dc, r.left, r.top, r.Width(), r.Height(), rop); } - -inline void MoveTo(HDC hdc, Point pt) { MoveToEx(hdc, pt.x, pt.y, 0); } -inline void LineTo(HDC hdc, Point pt) { LineTo(hdc, pt.x, pt.y); } - -inline void DrawLine(HDC hdc, Point p, Point q) { MoveTo(hdc, p); LineTo(hdc, q); } -inline void DrawLine(HDC hdc, int px, int py, int qx, int qy) { MoveToEx(hdc, px, py, 0); LineTo(hdc, qx, qy); } - -#ifndef PLATFORM_WINCE -inline void DrawArc(HDC hdc, const Rect& rc, Point p, Point q){ Arc(hdc, rc.left, rc.top, rc.right, rc.bottom, p.x, p.y, q.x, q.y); } -#endif -inline void DrawCircle(HDC hdc, int x, int y, int radius) { Ellipse(hdc, x - radius, y - radius, x + radius + 1, y + radius + 1); } -inline void DrawCircle(HDC hdc, Point centre, int radius) { DrawCircle(hdc, centre.x, centre.y, radius); } -inline void DrawEllipse(HDC hdc, const Rect& rc) { Ellipse(hdc, rc.left, rc.top, rc.right, rc.bottom); } - -inline void DrawRect(HDC hdc, const Rect& rc) { Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom); } - -HDC ScreenHDC(); -HPALETTE GetQlibPalette(); - -Image Win32Icon(LPCSTR id, int iconsize = 0); -Image Win32Icon(int id, int iconsize = 0); -Image Win32Cursor(LPCSTR id); -Image Win32Cursor(int id); -HICON IconWin32(const Image& img, bool cursor = false); -Image Win32DllIcon(const char *dll, int ii, bool large); - -END_UPP_NAMESPACE - -#endif diff --git a/uppsrc/CtrlCore/DrawX11.cpp b/uppsrc/CtrlCore/DrawX11.cpp index ed0ce8068..e769f80b1 100644 --- a/uppsrc/CtrlCore/DrawX11.cpp +++ b/uppsrc/CtrlCore/DrawX11.cpp @@ -1,4 +1,4 @@ -#include "SystemDraw.h" +#include "CtrlCore.h" #ifdef PLATFORM_X11 diff --git a/uppsrc/CtrlCore/DrawX11.h b/uppsrc/CtrlCore/DrawX11.h deleted file mode 100644 index 6fb27c781..000000000 --- a/uppsrc/CtrlCore/DrawX11.h +++ /dev/null @@ -1,182 +0,0 @@ -#ifdef PLATFORM_X11 - -#define Time XTime -#define Font XFont -#define Display XDisplay -#define Picture XPicture - -#include -#include -#include - -#include -#include - -#undef Picture -#undef Time -#undef Font -#undef Display - -#undef True -#undef False - -#define XFalse 0 -#define XTrue 1 - -NAMESPACE_UPP - -extern XDisplay *Xdisplay; -extern Visual *Xvisual; -extern int Xscreenno; -extern Window Xroot; -extern Screen *Xscreen; -extern Colormap Xcolormap; -extern int Xheight; -extern int Xwidth; -extern int XheightMM; -extern int XwidthMM; -extern int Xdepth; -extern dword Xblack; -extern dword Xwhite; -extern int Xconnection; - -extern dword (*Xgetpixel)(int r, int g, int b); - -void InitX11Draw(const char *dispname = NULL); -void InitX11Draw(XDisplay *display); - -void XError(); -void XError(const char *s); - -inline dword GetXPixel(int r, int g, int b) { return (*Xgetpixel)(r, g, b); } -inline dword GetXPixel(Color color) { return (*Xgetpixel)(color.GetR(), color.GetG(), color.GetB()); } - -enum { - X11_ROP2_ZERO, - X11_ROP2_AND, - X11_ROP2_AND_NOT, - X11_ROP2_COPY, - X11_ROP2_NOT_AND, - X11_ROP2_NOP, - X11_ROP2_XOR, - X11_ROP2_OR, - X11_ROP2_NOT_AND_NOT, - X11_ROP2_NOT_XOR, - X11_ROP2_INVERT, - X11_ROP2_OR_NOT, - X11_ROP2_NOT_COPY, - X11_ROP2_NOT_OR, - X11_ROP2_NOT_OR_NOT, - X11_ROP2_ONE, -}; - -void SetClip(GC gc, XftDraw *xftdraw, const Vector& cl); - -class SystemDraw : public Draw { -public: - virtual dword GetInfo() const; - virtual Size GetPageSize() const; - - virtual void BeginOp(); - virtual void EndOp(); - virtual void OffsetOp(Point p); - virtual bool ClipOp(const Rect& r); - virtual bool ClipoffOp(const Rect& r); - virtual bool ExcludeClipOp(const Rect& r); - virtual bool IntersectClipOp(const Rect& r); - virtual bool IsPaintingOp(const Rect& r) const; - virtual Rect GetPaintRect() const; - - virtual void DrawRectOp(int x, int y, int cx, int cy, Color color); - virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color); - virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color); - - virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count, - const int *counts, int count_count, - int width, Color color, Color doxor); - virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, - const int *subpolygon_counts, int scc, - const int *disjunct_polygon_counts, int dpcc, - Color color, int width, Color outline, - uint64 pattern, Color doxor); - virtual void DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color); - - virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor); - virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font, - Color ink, int n, const int *dx); - - virtual Size GetNativeDpi() const; - virtual void BeginNative(); - virtual void EndNative(); - - virtual int GetCloffLevel() const; - -private: - Size pageSize; - - SystemDraw(); - - friend class ImageDraw; - friend class FontInfo; - friend class Font; - friend class ViewDraw; - - friend void StaticExitDraw_(); - friend Font StdFont(); - - FontInfo lastFont; - - Point actual_offset; - Point actual_offset_bak; - struct Cloff : Moveable { - Point org; - int clipi; - int offseti; - }; - - Array cloff; - Rect drawingclip; - Vector< Vector > clip; - Vector offset; - - Drawable dw; - GC gc; - XftDraw *xftdraw; - - int foreground; - int linewidth; - - void Init(); - void Init(const Vector& clip, Point offset = Point(0, 0)); - void CloneClip(); - - friend class BackDraw; - friend class ScreenDraw; - -public: - static void Flush() { XSync(Xdisplay, false); } - - Point GetOffset() const { return actual_offset; } - - static XftFont *CreateXftFont(Font f, int angle); - XftDraw *GetXftDraw() const { return xftdraw; } - - Rect GetClip() const; - - void SetForeground(Color color); - void SetLineStyle(int width); - void SetClip(); - - Drawable GetDrawable() const { return dw; } - GC GetGC() const { return gc; } - const Vector& GetClipList() const { return clip.Top(); } - - SystemDraw(Drawable dw, GC gc, XftDraw *xftdraw, const Vector& clip); -}; - -Image X11Cursor(int c); -void *CursorX11(const Image& img); - -END_UPP_NAMESPACE - -#endif diff --git a/uppsrc/CtrlCore/ImageWin32.cpp b/uppsrc/CtrlCore/ImageWin32.cpp index a3bf6477d..870def283 100644 --- a/uppsrc/CtrlCore/ImageWin32.cpp +++ b/uppsrc/CtrlCore/ImageWin32.cpp @@ -1,4 +1,4 @@ -#include "SystemDraw.h" +#include "CtrlCore.h" #ifdef PLATFORM_WIN32 #include diff --git a/uppsrc/CtrlCore/ImageX11.cpp b/uppsrc/CtrlCore/ImageX11.cpp index 3048c1c8c..cf4c0f4ac 100644 --- a/uppsrc/CtrlCore/ImageX11.cpp +++ b/uppsrc/CtrlCore/ImageX11.cpp @@ -1,4 +1,4 @@ -#include "SystemDraw.h" +#include "CtrlCore.h" NAMESPACE_UPP diff --git a/uppsrc/CtrlCore/MKeys.h b/uppsrc/CtrlCore/MKeys.h index f8e8f052d..82f967cf9 100644 --- a/uppsrc/CtrlCore/MKeys.h +++ b/uppsrc/CtrlCore/MKeys.h @@ -1,5 +1,9 @@ enum { +#ifdef GUIPLATFORM_KEYCODES_INCLUDE + #include GUIPLATFORM_KEYCODES_INCLUDE +#else GUIPLATFORM_KEYCODES +#endif K_CTRL_BACK = K_CTRL|K_BACKSPACE, K_CTRL_BACKSPACE = K_CTRL|K_BACKSPACE, diff --git a/uppsrc/CtrlCore/MetaFile.cpp b/uppsrc/CtrlCore/MetaFile.cpp index 6c10a468a..74f07765a 100644 --- a/uppsrc/CtrlCore/MetaFile.cpp +++ b/uppsrc/CtrlCore/MetaFile.cpp @@ -1,4 +1,4 @@ -#include "SystemDraw.h" +#include "CtrlCore.h" NAMESPACE_UPP @@ -10,7 +10,6 @@ void WinMetaFile::Init() { } void WinMetaFile::Paint(Draw& w, const Rect& r) const { - ChkP(); w.DrawRect(r, White()); if(!hemf) return; diff --git a/uppsrc/CtrlCore/SystemDraw.cpp b/uppsrc/CtrlCore/SystemDraw.cpp index d25d7420e..50b9131f8 100644 --- a/uppsrc/CtrlCore/SystemDraw.cpp +++ b/uppsrc/CtrlCore/SystemDraw.cpp @@ -1,112 +1,130 @@ -#include "SystemDraw.h" - -NAMESPACE_UPP - -#define LTIMING(x) - -void SystemDraw::DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color) -{ - GuiLock __; - LTIMING("DrawImageOp"); - bool tonative = !IsNative(); - if(tonative) { - BeginNative(); - Native(x, y); - Native(cx, cy); - } - Size sz = Size(cx, cy); - if((cx > 2000 || cy > 1500) && IsNull(color) && IsPrinter()) { - int yy = 0; - ImageRaster ir(img); - RescaleImage rm; - rm.Create(Size(cx, cy), ir, src); - while(yy < cy) { - int ccy = min(cy - yy, 16); - ImageBuffer ib(cx, ccy); - for(int q = 0; q < ccy; q++) - rm.Get(ib[q]); - DrawImageBandRLE(*this, x, y + yy, ib, 16); - yy += ccy; - } - } - else - if(src.GetSize() == sz) - img.PaintImage(*this, x, y, src, color); - else { - Image h = Rescale(img, Size(cx, cy), src); - h.PaintImage(*this, x, y, h.GetSize(), color); - } - if(tonative) - EndNative(); -} - - -Draw& ImageDraw::Alpha() -{ - if(!has_alpha) { - alpha.DrawRect(size, GrayColor(0)); - has_alpha = true; - } - return alpha; -} - -ImageBuffer::ImageBuffer(ImageDraw& iw) -{ - Image m = iw; - Set(m); -} - -void ImageAnyDrawSystem(Draw *(*f)(Size sz), Image (*e)(Draw *w)); - -static Draw *sCD(Size sz) -{ - return new ImageDraw(sz); -} - -static Image sED(Draw *w) -{ - ImageDraw *ip = dynamic_cast(w); - return ip ? (Image)(*ip) : Image(); -} - -void InstallSystemImage() -{ - Image::Data::InitSystemImage(&Image::Data::SysInitImp, &Image::Data::SysReleaseImp, - &Image::Data::GetResCountImp, &Image::Data::PaintImp); -} - -INITBLOCK { - ImageAnyDrawSystem(sCD, sED); - InstallSystemImage(); -} - -void SetSurface(SystemDraw& w, int x, int y, int cx, int cy, const RGBA *pixels); -void SetSurface(SystemDraw& w, const Rect& dest, const RGBA *pixels, Size psz, Point poff); - -void SetSurface(Draw& w, const Rect& dest, const RGBA *pixels, Size srcsz, Point poff) -{ - SystemDraw *sw = dynamic_cast(&w); -#ifdef PLATFORM_WIN32 - if(sw && sw->IsGui() && IsWinNT()) -#else - if(sw) -#endif - SetSurface(*sw, dest, pixels, srcsz, poff); - else { - ImageBuffer ib(dest.GetWidth(), dest.GetHeight()); - for(int i = 0; i < ib.GetHeight(); i++) { - int sl = poff.y + i; - if(i >= 0 && i < srcsz.cy) - Copy(ib[i], pixels + srcsz.cx * sl + poff.x, - minmax(srcsz.cx - poff.x, 0, min(dest.GetWidth(), srcsz.cx))); - } - w.DrawImage(dest.left, dest.top, ib); - } -} - -void SetSurface(Draw& w, int x, int y, int cx, int cy, const RGBA *pixels) -{ - SetSurface(w, RectC(x, y, cx, cy), pixels, Size(cx, cy), Point(0, 0)); -} - -END_UPP_NAMESPACE +#include "CtrlCore.h" + +NAMESPACE_UPP + +#define LTIMING(x) + +void SystemDraw::DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color) +{ + GuiLock __; + LTIMING("DrawImageOp"); + bool tonative = !IsNative(); + if(tonative) { + BeginNative(); + Native(x, y); + Native(cx, cy); + } + Size sz = Size(cx, cy); + if((cx > 2000 || cy > 1500) && IsNull(color) && IsPrinter()) { + int yy = 0; + ImageRaster ir(img); + RescaleImage rm; + rm.Create(Size(cx, cy), ir, src); + while(yy < cy) { + int ccy = min(cy - yy, 16); + ImageBuffer ib(cx, ccy); + for(int q = 0; q < ccy; q++) + rm.Get(ib[q]); + DrawImageBandRLE(*this, x, y + yy, ib, 16); + yy += ccy; + } + } + else + if(src.GetSize() == sz) + img.PaintImage(*this, x, y, src, color); + else { + Image h = Rescale(img, Size(cx, cy), src); + h.PaintImage(*this, x, y, h.GetSize(), color); + } + if(tonative) + EndNative(); +} + + +Draw& ImageDraw::Alpha() +{ + if(!has_alpha) { + alpha.DrawRect(size, GrayColor(0)); + has_alpha = true; + } + return alpha; +} + +ImageBuffer::ImageBuffer(ImageDraw& iw) +{ + Image m = iw; + Set(m); +} + +void ImageAnyDrawSystem(Draw *(*f)(Size sz), Image (*e)(Draw *w)); + +static Draw *sCD(Size sz) +{ + return new ImageDraw(sz); +} + +static Image sED(Draw *w) +{ + ImageDraw *ip = dynamic_cast(w); + return ip ? (Image)(*ip) : Image(); +} + +void InstallSystemImage() +{ + Image::Data::InitSystemImage(&Image::Data::SysInitImp, &Image::Data::SysReleaseImp, + &Image::Data::GetResCountImp, &Image::Data::PaintImp); +} + +INITBLOCK { + ImageAnyDrawSystem(sCD, sED); + InstallSystemImage(); +} + +void SetSurface(SystemDraw& w, int x, int y, int cx, int cy, const RGBA *pixels); +void SetSurface(SystemDraw& w, const Rect& dest, const RGBA *pixels, Size psz, Point poff); + +void SetSurface(Draw& w, const Rect& dest, const RGBA *pixels, Size srcsz, Point poff) +{ + SystemDraw *sw = dynamic_cast(&w); + if(sw && sw->CanSetSurface()) + SetSurface(*sw, dest, pixels, srcsz, poff); + else { + ImageBuffer ib(dest.GetWidth(), dest.GetHeight()); + for(int i = 0; i < ib.GetHeight(); i++) { + int sl = poff.y + i; + if(i >= 0 && i < srcsz.cy) + Copy(ib[i], pixels + srcsz.cx * sl + poff.x, + minmax(srcsz.cx - poff.x, 0, min(dest.GetWidth(), srcsz.cx))); + } + w.DrawImage(dest.left, dest.top, ib); + } +} + +void SetSurface(Draw& w, int x, int y, int cx, int cy, const RGBA *pixels) +{ + SetSurface(w, RectC(x, y, cx, cy), pixels, Size(cx, cy), Point(0, 0)); +} + + +SystemDraw& ScreenInfo(); + +bool BackDraw::IsPaintingOp(const Rect& r) const +{ + Rect rr = r + GetOffset(); + if(!rr.Intersects(size)) + return false; + return painting ? painting->IsPainting(rr + painting_offset) : true; +} + +BackDraw::BackDraw() +{ + painting = NULL; + painting_offset = Point(0, 0); +} + +BackDraw::~BackDraw() +{ + Destroy(); +} + +END_UPP_NAMESPACE diff --git a/uppsrc/CtrlCore/SystemDraw.h b/uppsrc/CtrlCore/SystemDraw.h deleted file mode 100644 index 1f5cd91a1..000000000 --- a/uppsrc/CtrlCore/SystemDraw.h +++ /dev/null @@ -1,121 +0,0 @@ -#ifndef SYSTEMDRAW_H -#define SYSTEMDRAW_H - -#include - -#ifdef PLATFORM_WIN32 -#include "DrawWin32.h" -#endif - -#ifdef PLATFORM_X11 -#include "DrawX11.h" -#endif - -NAMESPACE_UPP - -#ifdef _MULTITHREADED -void EnterGuiMutex(); -void LeaveGuiMutex(); -#else -inline void EnterGuiMutex() {} -inline void LeaveGuiMutex() {} -#endif - -struct GuiLock { - GuiLock() { EnterGuiMutex(); } - ~GuiLock() { LeaveGuiMutex(); } -}; - -bool ScreenInPaletteMode(); -Size GetScreenSize(); - -class BackDraw : public SystemDraw { -public: - virtual bool IsPaintingOp(const Rect& r) const; - -protected: -#ifdef PLATFORM_WIN32 - HBITMAP hbmpold; - HBITMAP hbmp; -#endif -#ifdef PLATFORM_X11 - Pixmap pixmap; -#endif - Size size; - Draw *painting; - Point painting_offset; - - -public: - void Put(SystemDraw& w, int x, int y); - void Put(SystemDraw& w, Point p) { Put(w, p.x, p.y); } - - void Create(SystemDraw& w, int cx, int cy); - void Create(SystemDraw& w, Size sz) { Create(w, sz.cx, sz.cy); } -// void Create(int cx, int cy); -// void Create(Size sz) { Create(sz.cx, sz.cy); } - void Destroy(); - - void SetPaintingDraw(Draw& w, Point off) { painting = &w; painting_offset = off; } - - BackDraw(); - ~BackDraw(); -/* -// Deprecated: - void Put(Draw& w, int x, int y) { Put(*(SystemDraw*)&w, x, y); } - void Put(Draw& w, Point p) { Put(*(SystemDraw*)&w, p.x, p.y); } - - void Create(Draw& w, int cx, int cy) { Create(*(SystemDraw*)&w, cx, cy); } - void Create(Draw& w, Size sz) { Create(*(SystemDraw*)&w, sz.cx, sz.cy); }*/ -}; - -class ImageDraw : public SystemDraw { - Size size; - -#ifdef PLATFORM_WIN32 - struct Section { - HDC dc; - HBITMAP hbmp, hbmpOld; - RGBA *pixels; - - void Init(int cx, int cy); - ~Section(); - }; - - Section rgb; - Section a; - SystemDraw alpha; -#endif - -#ifdef PLATFORM_X11 - SystemDraw alpha; -#endif - - bool has_alpha; - - void Init(); - Image Get(bool pm) const; - -public: - Draw& Alpha(); - - operator Image() const; - - Image GetStraight() const; - - ImageDraw(Size sz); - ImageDraw(int cx, int cy); - ~ImageDraw(); -}; - -typedef ImageDraw SystemImageDraw; - -void DrawDragRect(SystemDraw& w, const Rect& rect1, const Rect& rect2, const Rect& clip, int n, - Color color, uint64 pattern); - -void SetSurface(Draw& w, const Rect& dest, const RGBA *pixels, Size srcsz, Point poff); -void SetSurface(Draw& w, int x, int y, int cx, int cy, const RGBA *pixels); - -END_UPP_NAMESPACE - -#endif diff --git a/uppsrc/CtrlCore/TopWin32.cpp b/uppsrc/CtrlCore/TopWin32.cpp index 72a3feba2..945779f49 100644 --- a/uppsrc/CtrlCore/TopWin32.cpp +++ b/uppsrc/CtrlCore/TopWin32.cpp @@ -325,6 +325,74 @@ bool TopWindow::IsTopMost() const return GetExStyle() & WS_EX_TOPMOST; } +void TopWindow::GuiPlatformConstruct() +{ + style = 0; + exstyle = 0; + ico = lico = NULL; +} + +void TopWindow::GuiPlatformDestruct() +{ + DeleteIco(); +} + +void TopWindow::SerializePlacement(Stream& s, bool reminimize) +{ + GuiLock __; +#ifndef PLATFORM_WINCE + int version = 0; + s / version; + Rect rect = GetRect(); + s % overlapped % rect; + bool mn = state == MINIMIZED; + bool mx = state == MAXIMIZED; + s.Pack(mn, mx); + LLOG("TopWindow::SerializePlacement / " << (s.IsStoring() ? "write" : "read")); + LLOG("minimized = " << mn << ", maximized = " << mx); + LLOG("rect = " << rect << ", overlapped = " << overlapped); + if(s.IsLoading()) { + if(mn) rect = overlapped; + Rect limit = GetWorkArea(); + Rect outer = rect; + ::AdjustWindowRect(outer, WS_OVERLAPPEDWINDOW, FALSE); + limit.left += rect.left - outer.left; + limit.top += rect.top - outer.top; + limit.right += rect.right - outer.right; + limit.bottom += rect.bottom - outer.bottom; + Size sz = min(rect.Size(), limit.Size()); + rect = RectC( + minmax(rect.left, limit.left, limit.right - sz.cx), + minmax(rect.top, limit.top, limit.bottom - sz.cy), + sz.cx, sz.cy); + state = OVERLAPPED; + if(mn && reminimize) + state = MINIMIZED; + if(mx) + state = MAXIMIZED; + if(state == OVERLAPPED) + SetRect(rect); + if(IsOpen()) { + HWND hwnd = GetHWND(); + switch(state) { + case MINIMIZED: + if(!IsIconic(hwnd)) + ::ShowWindow(hwnd, SW_MINIMIZE); + break; + case MAXIMIZED: + if(!IsZoomed(hwnd)) + ::ShowWindow(hwnd, SW_MAXIMIZE); + break; + default: + if(IsIconic(hwnd) || IsZoomed(hwnd)) + ::ShowWindow(hwnd, SW_RESTORE); + break; + } + } + } +#endif +} + #endif END_UPP_NAMESPACE diff --git a/uppsrc/CtrlCore/TopWinX11.cpp b/uppsrc/CtrlCore/TopWinX11.cpp index ab61c97a8..0a0fcb08e 100644 --- a/uppsrc/CtrlCore/TopWinX11.cpp +++ b/uppsrc/CtrlCore/TopWinX11.cpp @@ -391,6 +391,65 @@ bool TopWindow::IsTopMost() const return topmost; } +void TopWindow::GuiPlatformConstruct() +{ + size_hints = XAllocSizeHints(); + wm_hints = XAllocWMHints(); + class_hint = XAllocClassHint(); + topmost = false; +} + +void TopWindow::GuiPlatformDestruct() +{ + XFree(size_hints); + XFree(wm_hints); + XFree(class_hint); +} + +void TopWindow::SerializePlacement(Stream& s, bool reminimize) +{ + GuiLock __; + int version = 0; + s / version; + Rect rect = GetRect(); + s % overlapped % rect; + bool mn = state == MINIMIZED; + bool mx = state == MAXIMIZED; + s.Pack(mn, mx); + LLOG("TopWindow::SerializePlacement / " << (s.IsStoring() ? "write" : "read")); + LLOG("minimized = " << mn << ", maximized = " << mx); + LLOG("rect = " << rect << ", overlapped = " << overlapped); + if(s.IsLoading()) { + if(mn) rect = overlapped; + Rect limit = GetWorkArea(); + Rect fm = windowFrameMargin; + if((fm.left|fm.right|fm.top|fm.bottom) == 0) + fm = Rect(8, 32, 8, 8); + limit.left += fm.left; + limit.right -= fm.right; + limit.top += fm.top; + limit.bottom -= fm.bottom; + Size sz = min(rect.Size(), limit.Size()); + rect = RectC( + minmax(rect.left, limit.left, limit.right - sz.cx), + minmax(rect.top, limit.top, limit.bottom - sz.cy), + sz.cx, sz.cy); + state = OVERLAPPED; + if(mn && reminimize) + state = MINIMIZED; + if(mx) + state = MAXIMIZED; + if(state == OVERLAPPED) + SetRect(rect); + if(IsOpen()) { + if(state == MINIMIZED) + Minimize(false); + if(state == MAXIMIZED) + Maximize(false); + } + } +} + #endif END_UPP_NAMESPACE diff --git a/uppsrc/CtrlCore/TopWindow.cpp b/uppsrc/CtrlCore/TopWindow.cpp index e7783d926..d7724e2b1 100644 --- a/uppsrc/CtrlCore/TopWindow.cpp +++ b/uppsrc/CtrlCore/TopWindow.cpp @@ -511,18 +511,7 @@ TopWindow::TopWindow() background = PaintRect(Single(), Null); center = 1; minsize = Size(80, 20); - -#ifdef PLATFORM_WIN32 - style = 0; - exstyle = 0; - ico = lico = NULL; -#endif -#ifdef PLATFORM_X11 - size_hints = XAllocSizeHints(); - wm_hints = XAllocWMHints(); - class_hint = XAllocClassHint(); - topmost = false; -#endif + GuiPlatfomInit(); maximizebox = minimizebox = sizeable = tool = noclosebox = false; state = OVERLAPPED; WhenClose = THISBACK(Close); @@ -538,14 +527,6 @@ TopWindow::~TopWindow() EndLoop(IDOK); if(!IsChild()) Close(); -#ifdef PLATFORM_WIN32 - DeleteIco(); -#endif -#ifdef PLATFORM_X11 - XFree(size_hints); - XFree(wm_hints); - XFree(class_hint); -#endif } void Maxisize(TopWindow& win, int screencxmax) diff --git a/uppsrc/CtrlCore/TopWindow.h b/uppsrc/CtrlCore/TopWindow.h index 354907bc7..33a211784 100644 --- a/uppsrc/CtrlCore/TopWindow.h +++ b/uppsrc/CtrlCore/TopWindow.h @@ -74,8 +74,15 @@ private: bool urgent:1; byte state; Image icon, largeicon; + + void GuiPlatformConstruct(); + void GuiPlatformDestruct(); +#ifdef GUIPLATFORM_TOPWINDOW_DECLS_INCLUDE + #include GUIPLATFORM_TOPWINDOW_DECLS_INCLUDE +#else GUIPLATFORM_TOPWINDOW_DECLS +#endif public: Callback WhenClose; diff --git a/uppsrc/CtrlCore/Win32Ctrl.h b/uppsrc/CtrlCore/Win32Ctrl.h new file mode 100644 index 000000000..a92168174 --- /dev/null +++ b/uppsrc/CtrlCore/Win32Ctrl.h @@ -0,0 +1,65 @@ +//$ class Ctrl { +private: + bool activex:1; + bool isdhctrl:1; + + static bool PeekMsg(MSG& msg); + + static LRESULT CALLBACK UtilityProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + static void RenderFormat(int format); + static void RenderAllFormats(); + static void DestroyClipboard(); + +public: + static Event ExitLoopEvent; + static bool& EndSession(); + static bool IsEndSession() { return EndSession(); } + static HINSTANCE hInstance; + +protected: + static HCURSOR hCursor; + + static VectorMap< HWND, Ptr >& Windows(); + static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + + static Event OverwatchEndSession; + static HWND OverwatchHWND; + static HANDLE OverwatchThread; + + static LRESULT CALLBACK OverwatchWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); + static DWORD WINAPI Win32OverwatchThread(LPVOID); + + static Rect GetScreenClient(HWND hwnd); + struct CreateBox; + void Create0(CreateBox *cr); + void Create(HWND parent, DWORD style, DWORD exstyle, bool savebits, int show, bool dropshadow); + Image DoMouse(int e, Point p, int zd = 0); + static void sProcessMSG(MSG& msg); + + static Vector hotkey; + + friend void sSetCursor(Ctrl *ctrl, const Image& m); + +public: + virtual void NcCreate(HWND hwnd); + virtual void NcDestroy(); + virtual void PreDestroy(); + virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); + + HWND GetHWND() const { return parent ? NULL : top ? top->hwnd : NULL; } + HWND GetOwnerHWND() const; + + static Ctrl *CtrlFromHWND(HWND hwnd); + + Ctrl& ActiveX(bool ax = true) { activex = ax; return *this; } + Ctrl& NoActiveX() { return ActiveX(false); } + bool IsActiveX() const { return activex; } + + void PopUpHWND(HWND hwnd, bool savebits = true, bool activate = true, bool dropshadow = false, + bool topmost = false); + + static void InitWin32(HINSTANCE hinst); + static void ExitWin32(); + static void GuiFlush() { ::GdiFlush(); } + +//$ }; diff --git a/uppsrc/CtrlCore/Win32Gui.h b/uppsrc/CtrlCore/Win32Gui.h index 8b8a7bcfb..acd6f6400 100644 --- a/uppsrc/CtrlCore/Win32Gui.h +++ b/uppsrc/CtrlCore/Win32Gui.h @@ -1,113 +1,287 @@ -#define GUIPLATFORM_KEYCODES \ -K_BACK = VK_BACK + K_DELTA,\ -K_BACKSPACE = VK_BACK + K_DELTA,\ + +NAMESPACE_UPP + +class SystemDraw : public Draw { +public: + virtual dword GetInfo() const; + virtual Size GetPageSize() const; + + virtual void BeginOp(); + virtual void EndOp(); + virtual void OffsetOp(Point p); + virtual bool ClipOp(const Rect& r); + virtual bool ClipoffOp(const Rect& r); + virtual bool ExcludeClipOp(const Rect& r); + virtual bool IntersectClipOp(const Rect& r); + virtual bool IsPaintingOp(const Rect& r) const; + virtual Rect GetPaintRect() const; + + virtual void DrawRectOp(int x, int y, int cx, int cy, Color color); + virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color); + virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color); + + virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count, + const int *counts, int count_count, + int width, Color color, Color doxor); + virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, + const int *subpolygon_counts, int scc, + const int *disjunct_polygon_counts, int dpcc, + Color color, int width, Color outline, + uint64 pattern, Color doxor); + virtual void DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color); + + virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor); + virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font, + Color ink, int n, const int *dx); + + virtual Size GetNativeDpi() const; + virtual void BeginNative(); + virtual void EndNative(); + + virtual int GetCloffLevel() const; + +private: + Size pageSize; + Size nativeSize; + Size nativeDpi; + bool palette:1; + bool color16:1; + bool is_mono:1; + int native; + + friend class ImageDraw; + friend class FontInfo; + friend class Font; + + friend void StaticExitDraw_(); + + Point actual_offset_bak; + + struct Cloff : Moveable { + Point org; + HRGN hrgn; + Rect drawingclip; + }; + + Array cloff; + Rect drawingclip; + + COLORREF lastTextColor; + Color lastColor; + HBRUSH orgBrush; + HBRUSH actBrush; + HPEN orgPen; + HPEN actPen; + int lastPen; + Color lastPenColor; + + void Unselect0(); + void Cinit(); + + void LoadCaps(); + void SetPrinterMode(); + void Reset(); + void SetOrg(); + friend HPALETTE GetQlibPalette(); + void DotsMode(); + + static void InitColors(); + + friend class BackDraw; + friend class ScreenDraw; + friend class PrintDraw; + +protected: + dword style; + HDC handle; + Point actual_offset; + + SystemDraw(); + void Init(); + void InitClip(const Rect& clip); + +public: + static Rect GetVirtualScreenArea(); + + static void SetAutoPalette(bool ap); + static bool AutoPalette(); + bool PaletteMode() { return palette; } + + static void Flush() { GdiFlush(); } + + COLORREF GetColor(Color color) const; + + Point GetOffset() const { return actual_offset; } + +#ifndef PLATFORM_WINCE + Point LPtoDP(Point p) const; + Point DPtoLP(Point p) const; + Rect LPtoDP(const Rect& r) const; + Rect DPtoLP(const Rect& r) const; +#endif + + void SetColor(Color color); + void SetDrawPen(int width, Color color); + + Size GetSizeCaps(int i, int j) const; + HDC BeginGdi(); + void EndGdi(); + HDC GetHandle() { return handle; } + operator HDC() const { return handle; } + void Unselect(); + void Attach(HDC ahandle) { handle = ahandle; Init(); } + HDC Detach() { Unselect(); HDC h = handle; handle = NULL; return h; } + + SystemDraw(HDC hdc); + virtual ~SystemDraw(); + + bool CanSetSurface() { return IsGui() && IsWinNT(); } +}; + +#ifndef PLATFORM_WINCE +class WinMetaFile { + Size size; + HENHMETAFILE hemf; + + void Init(); + +public: + void Attach(HENHMETAFILE emf); + HENHMETAFILE Detach(); + + void Set(const void *data, dword len); + void Set(const String& data) { Set(~data, data.GetCount()); } + + String Get() const; + + operator bool() const { return hemf; } + void SetSize(const Size& sz) { size = sz; } + Size GetSize() const { return hemf ? size : Size(0, 0); } + + void Clear(); + + void Paint(Draw& w, const Rect& r) const; + void Paint(Draw& w, int x, int y, int cx, int cy) const; + + void Serialize(Stream& s); + + void ReadClipboard(); + void WriteClipboard() const; + void Load(const char *file) { Set(LoadFile(file)); } + + WinMetaFile() { Init(); } + WinMetaFile(HENHMETAFILE hemf); + WinMetaFile(HENHMETAFILE hemf, Size sz); + WinMetaFile(const char *file); + WinMetaFile(void *data, int len); + WinMetaFile(const String& data); + + ~WinMetaFile() { Clear(); } + + HENHMETAFILE GetHEMF() const { return hemf; } +}; + +class WinMetaFileDraw : public SystemDraw { + Size size; + +public: + bool Create(HDC hdc, int cx, int cy, const char *app = NULL, const char *name = NULL, const char *file = NULL); + bool Create(int cx, int cy, const char *app = NULL, const char *name = NULL, const char *file = NULL); + WinMetaFile Close(); + + WinMetaFileDraw() {} + WinMetaFileDraw(HDC hdc, int cx, int cy, const char *app = NULL, const char *name = NULL, const char *file = NULL); + WinMetaFileDraw(int cx, int cy, const char *app = NULL, const char *name = NULL, const char *file = NULL); + ~WinMetaFileDraw(); +}; + +void DrawWMF(Draw& w, int x, int y, int cx, int cy, const String& wmf); +void DrawWMF(Draw& w, int x, int y, const String& wmf); +Drawing LoadWMF(const char *path, int cx, int cy); +Drawing LoadWMF(const char *path); + +String AsWMF(const Drawing& iw); + +#endif + +class ScreenDraw : public SystemDraw { +public: + ScreenDraw(bool ic = false); + ~ScreenDraw(); +}; + +#ifndef PLATFORM_WINCE +class PrintDraw : public SystemDraw { +public: + virtual void StartPage(); + virtual void EndPage(); + +private: + bool aborted; + + void InitPrinter(); +public: + PrintDraw(HDC hdc, const char *jobname); + ~PrintDraw(); +}; +#endif + +inline bool BitBlt(HDC ddc, Point d, HDC sdc, const Rect& s, dword rop = SRCCOPY) +{ return BitBlt(ddc, d.x, d.y, s.Width(), s.Height(), sdc, s.left, s.top, rop); } + +inline bool StretchBlt(HDC ddc, const Rect& r, HDC sdc, const Rect& s, dword rop = SRCCOPY) +{ return StretchBlt(ddc, r.left, r.top, r.Width(), r.Height(), sdc, s.left, s.top, s.Width(), s.Height(), rop); } + +inline bool PatBlt(HDC dc, const Rect& r, dword rop = PATCOPY) +{ return PatBlt(dc, r.left, r.top, r.Width(), r.Height(), rop); } + +inline void MoveTo(HDC hdc, Point pt) { MoveToEx(hdc, pt.x, pt.y, 0); } +inline void LineTo(HDC hdc, Point pt) { LineTo(hdc, pt.x, pt.y); } + +inline void DrawLine(HDC hdc, Point p, Point q) { MoveTo(hdc, p); LineTo(hdc, q); } +inline void DrawLine(HDC hdc, int px, int py, int qx, int qy) { MoveToEx(hdc, px, py, 0); LineTo(hdc, qx, qy); } + +#ifndef PLATFORM_WINCE +inline void DrawArc(HDC hdc, const Rect& rc, Point p, Point q){ Arc(hdc, rc.left, rc.top, rc.right, rc.bottom, p.x, p.y, q.x, q.y); } +#endif +inline void DrawCircle(HDC hdc, int x, int y, int radius) { Ellipse(hdc, x - radius, y - radius, x + radius + 1, y + radius + 1); } +inline void DrawCircle(HDC hdc, Point centre, int radius) { DrawCircle(hdc, centre.x, centre.y, radius); } +inline void DrawEllipse(HDC hdc, const Rect& rc) { Ellipse(hdc, rc.left, rc.top, rc.right, rc.bottom); } + +inline void DrawRect(HDC hdc, const Rect& rc) { Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom); } + +HDC ScreenHDC(); +HPALETTE GetQlibPalette(); + +Image Win32Icon(LPCSTR id, int iconsize = 0); +Image Win32Icon(int id, int iconsize = 0); +Image Win32Cursor(LPCSTR id); +Image Win32Cursor(int id); +HICON IconWin32(const Image& img, bool cursor = false); +Image Win32DllIcon(const char *dll, int ii, bool large); + +END_UPP_NAMESPACE + +#define GUIPLATFORM_KEYCODES_INCLUDE "Win32Keys.h" + +#define GUIPLATFORM_BACKDRAW_DECLS \ + HBITMAP hbmpold; \ + HBITMAP hbmp; \ + +#define GUIPLATFORM_IMAGEDRAW_DECLS \ + struct Section { \ + HDC dc; \ + HBITMAP hbmp, hbmpOld; \ + RGBA *pixels; \ \ -K_TAB = 9,\ + void Init(int cx, int cy); \ + ~Section(); \ + }; \ \ -K_SPACE = 32,\ -\ -K_RETURN = 13,\ -K_ENTER = K_RETURN,\ -\ -K_SHIFT_KEY = VK_SHIFT + K_DELTA,\ -K_CTRL_KEY = VK_CONTROL + K_DELTA,\ -K_ALT_KEY = VK_MENU + K_DELTA,\ -K_CAPSLOCK = VK_CAPITAL + K_DELTA,\ -K_ESCAPE = VK_ESCAPE + K_DELTA,\ -K_PRIOR = VK_PRIOR + K_DELTA,\ -K_PAGEUP = VK_PRIOR + K_DELTA,\ -K_NEXT = VK_NEXT + K_DELTA,\ -K_PAGEDOWN = VK_NEXT + K_DELTA,\ -K_END = VK_END + K_DELTA,\ -K_HOME = VK_HOME + K_DELTA,\ -K_LEFT = VK_LEFT + K_DELTA,\ -K_UP = VK_UP + K_DELTA,\ -K_RIGHT = VK_RIGHT + K_DELTA,\ -K_DOWN = VK_DOWN + K_DELTA,\ -K_INSERT = VK_INSERT + K_DELTA,\ -K_DELETE = VK_DELETE + K_DELTA,\ -\ -K_NUMPAD0 = VK_NUMPAD0 + K_DELTA,\ -K_NUMPAD1 = VK_NUMPAD1 + K_DELTA,\ -K_NUMPAD2 = VK_NUMPAD2 + K_DELTA,\ -K_NUMPAD3 = VK_NUMPAD3 + K_DELTA,\ -K_NUMPAD4 = VK_NUMPAD4 + K_DELTA,\ -K_NUMPAD5 = VK_NUMPAD5 + K_DELTA,\ -K_NUMPAD6 = VK_NUMPAD6 + K_DELTA,\ -K_NUMPAD7 = VK_NUMPAD7 + K_DELTA,\ -K_NUMPAD8 = VK_NUMPAD8 + K_DELTA,\ -K_NUMPAD9 = VK_NUMPAD9 + K_DELTA,\ -K_MULTIPLY = VK_MULTIPLY + K_DELTA,\ -K_ADD = VK_ADD + K_DELTA,\ -K_SEPARATOR = VK_SEPARATOR + K_DELTA,\ -K_SUBTRACT = VK_SUBTRACT + K_DELTA,\ -K_DECIMAL = VK_DECIMAL + K_DELTA,\ -K_DIVIDE = VK_DIVIDE + K_DELTA,\ -K_SCROLL = VK_SCROLL + K_DELTA,\ -\ -K_F1 = VK_F1 + K_DELTA,\ -K_F2 = VK_F2 + K_DELTA,\ -K_F3 = VK_F3 + K_DELTA,\ -K_F4 = VK_F4 + K_DELTA,\ -K_F5 = VK_F5 + K_DELTA,\ -K_F6 = VK_F6 + K_DELTA,\ -K_F7 = VK_F7 + K_DELTA,\ -K_F8 = VK_F8 + K_DELTA,\ -K_F9 = VK_F9 + K_DELTA,\ -K_F10 = VK_F10 + K_DELTA,\ -K_F11 = VK_F11 + K_DELTA,\ -K_F12 = VK_F12 + K_DELTA,\ -\ -K_A = 'A' + K_DELTA,\ -K_B = 'B' + K_DELTA,\ -K_C = 'C' + K_DELTA,\ -K_D = 'D' + K_DELTA,\ -K_E = 'E' + K_DELTA,\ -K_F = 'F' + K_DELTA,\ -K_G = 'G' + K_DELTA,\ -K_H = 'H' + K_DELTA,\ -K_I = 'I' + K_DELTA,\ -K_J = 'J' + K_DELTA,\ -K_K = 'K' + K_DELTA,\ -K_L = 'L' + K_DELTA,\ -K_M = 'M' + K_DELTA,\ -K_N = 'N' + K_DELTA,\ -K_O = 'O' + K_DELTA,\ -K_P = 'P' + K_DELTA,\ -K_Q = 'Q' + K_DELTA,\ -K_R = 'R' + K_DELTA,\ -K_S = 'S' + K_DELTA,\ -K_T = 'T' + K_DELTA,\ -K_U = 'U' + K_DELTA,\ -K_V = 'V' + K_DELTA,\ -K_W = 'W' + K_DELTA,\ -K_X = 'X' + K_DELTA,\ -K_Y = 'Y' + K_DELTA,\ -K_Z = 'Z' + K_DELTA,\ -K_0 = '0' + K_DELTA,\ -K_1 = '1' + K_DELTA,\ -K_2 = '2' + K_DELTA,\ -K_3 = '3' + K_DELTA,\ -K_4 = '4' + K_DELTA,\ -K_5 = '5' + K_DELTA,\ -K_6 = '6' + K_DELTA,\ -K_7 = '7' + K_DELTA,\ -K_8 = '8' + K_DELTA,\ -K_9 = '9' + K_DELTA,\ -\ -K_CTRL_LBRACKET = K_CTRL|219|K_DELTA,\ -K_CTRL_RBRACKET = K_CTRL|221|K_DELTA,\ -K_CTRL_MINUS = K_CTRL|0xbd|K_DELTA,\ -K_CTRL_GRAVE = K_CTRL|0xc0|K_DELTA,\ -K_CTRL_SLASH = K_CTRL|0xbf|K_DELTA,\ -K_CTRL_BACKSLASH = K_CTRL|0xdc|K_DELTA,\ -K_CTRL_COMMA = K_CTRL|0xbc|K_DELTA,\ -K_CTRL_PERIOD = K_CTRL|0xbe|K_DELTA,\ -K_CTRL_SEMICOLON = K_CTRL|0xbe|K_DELTA,\ -K_CTRL_EQUAL = K_CTRL|0xbb|K_DELTA,\ -K_CTRL_APOSTROPHE= K_CTRL|0xde|K_DELTA,\ -\ -K_BREAK = VK_CANCEL + K_DELTA,\ + Section rgb; \ + Section a; \ + SystemDraw alpha; \ + #define GUIPLATFORM_CTRL_TOP_DECLS \ @@ -115,95 +289,13 @@ K_BREAK = VK_CANCEL + K_DELTA,\ UDropTarget *dndtgt; \ -#define GUIPLATFORM_CTRL_DECLS \ -private: \ - bool activex:1; \ - bool isdhctrl:1; \ -\ - static bool PeekMsg(MSG& msg); \ -\ - static LRESULT CALLBACK UtilityProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); \ - static void RenderFormat(int format); \ - static void RenderAllFormats(); \ - static void DestroyClipboard(); \ - \ -public: \ - static Event ExitLoopEvent; \ - static bool& EndSession(); \ - static bool IsEndSession() { return EndSession(); } \ - static HINSTANCE hInstance; \ - \ -protected: \ - static HCURSOR hCursor; \ - \ - static VectorMap< HWND, Ptr >& Windows(); \ - static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); \ - \ - static Event OverwatchEndSession; \ - static HWND OverwatchHWND; \ - static HANDLE OverwatchThread; \ - \ - static LRESULT CALLBACK OverwatchWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); \ - static DWORD WINAPI Win32OverwatchThread(LPVOID); \ - \ - static Rect GetScreenClient(HWND hwnd); \ - struct CreateBox; \ - void Create0(CreateBox *cr); \ - void Create(HWND parent, DWORD style, DWORD exstyle, bool savebits, int show, bool dropshadow); \ - Image DoMouse(int e, Point p, int zd = 0); \ - static void sProcessMSG(MSG& msg); \ - \ - static Vector hotkey; \ - \ - friend void sSetCursor(Ctrl *ctrl, const Image& m); \ - \ -public: \ - virtual void NcCreate(HWND hwnd); \ - virtual void NcDestroy(); \ - virtual void PreDestroy(); \ - virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); \ - \ - HWND GetHWND() const { return parent ? NULL : top ? top->hwnd : NULL; } \ - HWND GetOwnerHWND() const; \ - \ - static Ctrl *CtrlFromHWND(HWND hwnd); \ - \ - Ctrl& ActiveX(bool ax = true) { activex = ax; return *this; } \ - Ctrl& NoActiveX() { return ActiveX(false); } \ - bool IsActiveX() const { return activex; } \ -\ - void PopUpHWND(HWND hwnd, bool savebits = true, bool activate = true, bool dropshadow = false, \ - bool topmost = false); \ -\ - static void InitWin32(HINSTANCE hinst); \ - static void ExitWin32(); \ - static void GuiFlush() { ::GdiFlush(); } \ +#define GUIPLATFORM_CTRL_DECLS_INCLUDE "Win32Ctrl.h" #define GUIPLATFORM_PASTECLIP_DECLS \ UDropTarget *dt; \ - -#define GUIPLATFORM_TOPWINDOW_DECLS \ -public: \ - virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); \ - \ -private: \ - dword style; \ - dword exstyle; \ - HICON ico, lico; \ - \ - void DeleteIco0(); \ - void DeleteIco(); \ - void CenterRect(HWND owner, int center); \ - \ -public: \ - void Open(HWND ownerhwnd); \ - TopWindow& Style(dword _style); \ - dword GetStyle() const { return style; } \ - TopWindow& ExStyle(dword _exstyle); \ - dword GetExStyle() const { return exstyle; } \ - +#define GUIPLATFORM_TOPWINDOW_DECLS_INCLUDE "Win32Top.h" #define GUIPLATFORM_VIEWDRAW_DECLS \ HWND hwnd; \ diff --git a/uppsrc/CtrlCore/Win32Keys.h b/uppsrc/CtrlCore/Win32Keys.h new file mode 100644 index 000000000..000cea433 --- /dev/null +++ b/uppsrc/CtrlCore/Win32Keys.h @@ -0,0 +1,109 @@ +K_BACK = VK_BACK + K_DELTA, +K_BACKSPACE = VK_BACK + K_DELTA, + +K_TAB = 9, + +K_SPACE = 32, + +K_RETURN = 13, +K_ENTER = K_RETURN, + +K_SHIFT_KEY = VK_SHIFT + K_DELTA, +K_CTRL_KEY = VK_CONTROL + K_DELTA, +K_ALT_KEY = VK_MENU + K_DELTA, +K_CAPSLOCK = VK_CAPITAL + K_DELTA, +K_ESCAPE = VK_ESCAPE + K_DELTA, +K_PRIOR = VK_PRIOR + K_DELTA, +K_PAGEUP = VK_PRIOR + K_DELTA, +K_NEXT = VK_NEXT + K_DELTA, +K_PAGEDOWN = VK_NEXT + K_DELTA, +K_END = VK_END + K_DELTA, +K_HOME = VK_HOME + K_DELTA, +K_LEFT = VK_LEFT + K_DELTA, +K_UP = VK_UP + K_DELTA, +K_RIGHT = VK_RIGHT + K_DELTA, +K_DOWN = VK_DOWN + K_DELTA, +K_INSERT = VK_INSERT + K_DELTA, +K_DELETE = VK_DELETE + K_DELTA, + +K_NUMPAD0 = VK_NUMPAD0 + K_DELTA, +K_NUMPAD1 = VK_NUMPAD1 + K_DELTA, +K_NUMPAD2 = VK_NUMPAD2 + K_DELTA, +K_NUMPAD3 = VK_NUMPAD3 + K_DELTA, +K_NUMPAD4 = VK_NUMPAD4 + K_DELTA, +K_NUMPAD5 = VK_NUMPAD5 + K_DELTA, +K_NUMPAD6 = VK_NUMPAD6 + K_DELTA, +K_NUMPAD7 = VK_NUMPAD7 + K_DELTA, +K_NUMPAD8 = VK_NUMPAD8 + K_DELTA, +K_NUMPAD9 = VK_NUMPAD9 + K_DELTA, +K_MULTIPLY = VK_MULTIPLY + K_DELTA, +K_ADD = VK_ADD + K_DELTA, +K_SEPARATOR = VK_SEPARATOR + K_DELTA, +K_SUBTRACT = VK_SUBTRACT + K_DELTA, +K_DECIMAL = VK_DECIMAL + K_DELTA, +K_DIVIDE = VK_DIVIDE + K_DELTA, +K_SCROLL = VK_SCROLL + K_DELTA, + +K_F1 = VK_F1 + K_DELTA, +K_F2 = VK_F2 + K_DELTA, +K_F3 = VK_F3 + K_DELTA, +K_F4 = VK_F4 + K_DELTA, +K_F5 = VK_F5 + K_DELTA, +K_F6 = VK_F6 + K_DELTA, +K_F7 = VK_F7 + K_DELTA, +K_F8 = VK_F8 + K_DELTA, +K_F9 = VK_F9 + K_DELTA, +K_F10 = VK_F10 + K_DELTA, +K_F11 = VK_F11 + K_DELTA, +K_F12 = VK_F12 + K_DELTA, + +K_A = 'A' + K_DELTA, +K_B = 'B' + K_DELTA, +K_C = 'C' + K_DELTA, +K_D = 'D' + K_DELTA, +K_E = 'E' + K_DELTA, +K_F = 'F' + K_DELTA, +K_G = 'G' + K_DELTA, +K_H = 'H' + K_DELTA, +K_I = 'I' + K_DELTA, +K_J = 'J' + K_DELTA, +K_K = 'K' + K_DELTA, +K_L = 'L' + K_DELTA, +K_M = 'M' + K_DELTA, +K_N = 'N' + K_DELTA, +K_O = 'O' + K_DELTA, +K_P = 'P' + K_DELTA, +K_Q = 'Q' + K_DELTA, +K_R = 'R' + K_DELTA, +K_S = 'S' + K_DELTA, +K_T = 'T' + K_DELTA, +K_U = 'U' + K_DELTA, +K_V = 'V' + K_DELTA, +K_W = 'W' + K_DELTA, +K_X = 'X' + K_DELTA, +K_Y = 'Y' + K_DELTA, +K_Z = 'Z' + K_DELTA, +K_0 = '0' + K_DELTA, +K_1 = '1' + K_DELTA, +K_2 = '2' + K_DELTA, +K_3 = '3' + K_DELTA, +K_4 = '4' + K_DELTA, +K_5 = '5' + K_DELTA, +K_6 = '6' + K_DELTA, +K_7 = '7' + K_DELTA, +K_8 = '8' + K_DELTA, +K_9 = '9' + K_DELTA, + +K_CTRL_LBRACKET = K_CTRL|219|K_DELTA, +K_CTRL_RBRACKET = K_CTRL|221|K_DELTA, +K_CTRL_MINUS = K_CTRL|0xbd|K_DELTA, +K_CTRL_GRAVE = K_CTRL|0xc0|K_DELTA, +K_CTRL_SLASH = K_CTRL|0xbf|K_DELTA, +K_CTRL_BACKSLASH = K_CTRL|0xdc|K_DELTA, +K_CTRL_COMMA = K_CTRL|0xbc|K_DELTA, +K_CTRL_PERIOD = K_CTRL|0xbe|K_DELTA, +K_CTRL_SEMICOLON = K_CTRL|0xbe|K_DELTA, +K_CTRL_EQUAL = K_CTRL|0xbb|K_DELTA, +K_CTRL_APOSTROPHE= K_CTRL|0xde|K_DELTA, + +K_BREAK = VK_CANCEL + K_DELTA, diff --git a/uppsrc/CtrlCore/Win32Top.h b/uppsrc/CtrlCore/Win32Top.h new file mode 100644 index 000000000..969ea547d --- /dev/null +++ b/uppsrc/CtrlCore/Win32Top.h @@ -0,0 +1,20 @@ +//$ class TopWindow { +public: + virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); + +private: + dword style; + dword exstyle; + HICON ico, lico; + + void DeleteIco0(); + void DeleteIco(); + void CenterRect(HWND owner, int center); + +public: + void Open(HWND ownerhwnd); + TopWindow& Style(dword _style); + dword GetStyle() const { return style; } + TopWindow& ExStyle(dword _exstyle); + dword GetExStyle() const { return exstyle; } +//$ }; \ No newline at end of file diff --git a/uppsrc/CtrlCore/X11Gui.h b/uppsrc/CtrlCore/X11Gui.h index d36eb7cf3..e4e8831dc 100644 --- a/uppsrc/CtrlCore/X11Gui.h +++ b/uppsrc/CtrlCore/X11Gui.h @@ -1,3 +1,189 @@ +#ifdef PLATFORM_X11 + +#define Time XTime +#define Font XFont +#define Display XDisplay +#define Picture XPicture + +#include +#include +#include + +#include +#include + +#undef Picture +#undef Time +#undef Font +#undef Display + +#undef True +#undef False + +#define XFalse 0 +#define XTrue 1 + +NAMESPACE_UPP + +extern XDisplay *Xdisplay; +extern Visual *Xvisual; +extern int Xscreenno; +extern Window Xroot; +extern Screen *Xscreen; +extern Colormap Xcolormap; +extern int Xheight; +extern int Xwidth; +extern int XheightMM; +extern int XwidthMM; +extern int Xdepth; +extern dword Xblack; +extern dword Xwhite; +extern int Xconnection; + +extern dword (*Xgetpixel)(int r, int g, int b); + +void InitX11Draw(const char *dispname = NULL); +void InitX11Draw(XDisplay *display); + +void XError(); +void XError(const char *s); + +inline dword GetXPixel(int r, int g, int b) { return (*Xgetpixel)(r, g, b); } +inline dword GetXPixel(Color color) { return (*Xgetpixel)(color.GetR(), color.GetG(), color.GetB()); } + +enum { + X11_ROP2_ZERO, + X11_ROP2_AND, + X11_ROP2_AND_NOT, + X11_ROP2_COPY, + X11_ROP2_NOT_AND, + X11_ROP2_NOP, + X11_ROP2_XOR, + X11_ROP2_OR, + X11_ROP2_NOT_AND_NOT, + X11_ROP2_NOT_XOR, + X11_ROP2_INVERT, + X11_ROP2_OR_NOT, + X11_ROP2_NOT_COPY, + X11_ROP2_NOT_OR, + X11_ROP2_NOT_OR_NOT, + X11_ROP2_ONE, +}; + +void SetClip(GC gc, XftDraw *xftdraw, const Vector& cl); + +class SystemDraw : public Draw { +public: + virtual dword GetInfo() const; + virtual Size GetPageSize() const; + + virtual void BeginOp(); + virtual void EndOp(); + virtual void OffsetOp(Point p); + virtual bool ClipOp(const Rect& r); + virtual bool ClipoffOp(const Rect& r); + virtual bool ExcludeClipOp(const Rect& r); + virtual bool IntersectClipOp(const Rect& r); + virtual bool IsPaintingOp(const Rect& r) const; + virtual Rect GetPaintRect() const; + + virtual void DrawRectOp(int x, int y, int cx, int cy, Color color); + virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color); + virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color); + + virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count, + const int *counts, int count_count, + int width, Color color, Color doxor); + virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, + const int *subpolygon_counts, int scc, + const int *disjunct_polygon_counts, int dpcc, + Color color, int width, Color outline, + uint64 pattern, Color doxor); + virtual void DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color); + + virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor); + virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font, + Color ink, int n, const int *dx); + + virtual Size GetNativeDpi() const; + virtual void BeginNative(); + virtual void EndNative(); + + virtual int GetCloffLevel() const; + +private: + Size pageSize; + + SystemDraw(); + + friend class ImageDraw; + friend class FontInfo; + friend class Font; + friend class ViewDraw; + + friend void StaticExitDraw_(); + friend Font StdFont(); + + FontInfo lastFont; + + Point actual_offset; + Point actual_offset_bak; + struct Cloff : Moveable { + Point org; + int clipi; + int offseti; + }; + + Array cloff; + Rect drawingclip; + Vector< Vector > clip; + Vector offset; + + Drawable dw; + GC gc; + XftDraw *xftdraw; + + int foreground; + int linewidth; + + void Init(); + void Init(const Vector& clip, Point offset = Point(0, 0)); + void CloneClip(); + + friend class BackDraw; + friend class ScreenDraw; + +public: + static void Flush() { XSync(Xdisplay, false); } + + Point GetOffset() const { return actual_offset; } + + static XftFont *CreateXftFont(Font f, int angle); + XftDraw *GetXftDraw() const { return xftdraw; } + + Rect GetClip() const; + + void SetForeground(Color color); + void SetLineStyle(int width); + void SetClip(); + + Drawable GetDrawable() const { return dw; } + GC GetGC() const { return gc; } + const Vector& GetClipList() const { return clip.Top(); } + + SystemDraw(Drawable dw, GC gc, XftDraw *xftdraw, const Vector& clip); + + bool CanSetSurface() { return true; } +}; + +Image X11Cursor(int c); +void *CursorX11(const Image& img); + +END_UPP_NAMESPACE + +#endif + + #ifdef PLATFORM_X11 #include "X11/keysym.h" #endif @@ -116,8 +302,16 @@ K_CTRL_APOSTROPHE= K_CTRL|0x27|K_DELTA,\ K_BREAK = XK_Pause|K_DELTA,\ +#define GUIPLATFORM_BACKDRAW_DECLS \ + Pixmap pixmap; \ + + +#define GUIPLATFORM_IMAGEDRAW_DECLS \ + SystemDraw alpha; \ + + #define GUIPLATFORM_CTRL_TOP_DECLS \ - Window window; + Window window; #define GUIPLATFORM_CTRL_DECLS \ diff --git a/uppsrc/CtrlCore/init b/uppsrc/CtrlCore/init index b10f7e781..1e1f862d7 100644 --- a/uppsrc/CtrlCore/init +++ b/uppsrc/CtrlCore/init @@ -3,7 +3,7 @@ #include "Draw/init" #include "plugin\bmp/init" #include "RichText/init" -#define BLITZ_INDEX__ F09A3D88FEC666ED2EE58B04C796FBDBD +#define BLITZ_INDEX__ F95C5E1981B7EFCA8A18F8BC5B179FC7D #include "CtrlCore.icpp" #undef BLITZ_INDEX__ #endif