From 28de468f3a0d48fb46be9482dbeddfefd4adba75 Mon Sep 17 00:00:00 2001 From: cxl Date: Thu, 7 May 2009 17:11:56 +0000 Subject: [PATCH] Developing Draw git-svn-id: svn://ultimatepp.org/upp/trunk@1130 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppdev/Draw/BackDraw.h | 14 ++-- uppdev/Draw/Draw.cpp | 35 +++++---- uppdev/Draw/Draw.h | 49 ++++++------ uppdev/Draw/DrawOpWin32.cpp | 42 +++++------ uppdev/Draw/DrawWin32.cpp | 143 ++++++++++++++---------------------- uppdev/Draw/DrawWin32.h | 20 +++-- 6 files changed, 143 insertions(+), 160 deletions(-) diff --git a/uppdev/Draw/BackDraw.h b/uppdev/Draw/BackDraw.h index 775bfc95c..cc47cf483 100644 --- a/uppdev/Draw/BackDraw.h +++ b/uppdev/Draw/BackDraw.h @@ -1,4 +1,4 @@ -class BackDraw : public Draw { +class BackDraw : public SystemDraw { public: virtual bool IsPaintingOp(const Rect& r) const; @@ -16,16 +16,16 @@ protected: public: - void Put(Draw& w, int x, int y); - void Put(Draw& w, Point p) { Put(w, p.x, p.y); } + void Put(SystemDraw& w, int x, int y); + void Put(SystemDraw& w, Point p) { Put(w, p.x, p.y); } - void Create(Draw& draw, int cx, int cy); - void Create(Draw& draw, Size sz) { Create(draw, sz.cx, sz.cy); } + void Create(SystemDraw& draw, int cx, int cy); + void Create(SystemDraw& draw, Size sz) { Create(draw, sz.cx, sz.cy); } void Create(int cx, int cy); - void Create(Size sz) { Create(sz.cx, sz.cy); } + void Create(Size sz) { Create(sz.cx, sz.cy); } void Destroy(); - void SetPaintingDraw(Draw& w, Point off) { painting = &w; painting_offset = off; } + void SetPaintingDraw(Draw& w, Point off) { painting = &w; painting_offset = off; } BackDraw(); ~BackDraw(); diff --git a/uppdev/Draw/Draw.cpp b/uppdev/Draw/Draw.cpp index 279fe7db4..5a216a0d5 100644 --- a/uppdev/Draw/Draw.cpp +++ b/uppdev/Draw/Draw.cpp @@ -29,6 +29,11 @@ void Draw::SinCos(int angle, double& sina, double& cosa) } } +Size Draw::GetPixelsPerInch() const +{ + return IsDots() ? Size(600, 600) : Size(96, 96); +} + int Draw::GetNativeX(int x) const { Size inchPixels = GetPixelsPerInch(); @@ -395,26 +400,26 @@ void Draw::DrawPainting(int x, int y, int cx, int cy, const Painting& ig) // --------------------------- +dword NilDraw::GetInfo() const { return DOTS; } +Size NilDraw::GetPagePixels() const { return Size(0, 0); } void NilDraw::BeginOp() {} +void NilDraw::EndOp() {} +void NilDraw::OffsetOp(Point p) {} bool NilDraw::ClipOp(const Rect& r) { return false; } bool NilDraw::ClipoffOp(const Rect& r) { return false; } -void NilDraw::DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color) {} -void NilDraw::DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id) {} -void NilDraw::DrawDrawingOp(const Rect& target, const Drawing& w) {} -void NilDraw::DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor) {} -void NilDraw::DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color) {} -void NilDraw::DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color) {} -void NilDraw::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) {} -void NilDraw::DrawPolyPolylineOp(const Point *vertices, int vertex_count, const int *counts, int count_count, int width, Color color, Color doxor) {} -void NilDraw::DrawRectOp(int x, int y, int cx, int cy, Color color) {} -void NilDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Color ink, int n, const int *dx) {} -void NilDraw::EndOp() {} -void NilDraw::EndPage() {} bool NilDraw::ExcludeClipOp(const Rect& r) { return false; } -Rect NilDraw::GetClipOp() const { return Null; } bool NilDraw::IntersectClipOp(const Rect& r) { return false; } bool NilDraw::IsPaintingOp(const Rect& r) const { return false; } -void NilDraw::OffsetOp(Point p) {} -void NilDraw::StartPage() {} +void NilDraw::DrawRectOp(int x, int y, int cx, int cy, Color color) {} +void NilDraw::DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color) {} +void NilDraw::DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id) {} +void NilDraw::DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color) {} +void NilDraw::DrawPolyPolylineOp(const Point *vertices, int vertex_count, const int *counts, int count_count, int width, Color color, Color doxor) {} +void NilDraw::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) {} +void NilDraw::DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color) {} +void NilDraw::DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor) {} +void NilDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Color ink, int n, const int *dx) {} +void NilDraw::DrawDrawingOp(const Rect& target, const Drawing& w) {} +void NilDraw::DrawPaintingOp(const Rect& target, const Painting& w) {} END_UPP_NAMESPACE diff --git a/uppdev/Draw/Draw.h b/uppdev/Draw/Draw.h index 8135a78c3..8b31c468a 100644 --- a/uppdev/Draw/Draw.h +++ b/uppdev/Draw/Draw.h @@ -321,8 +321,6 @@ class FontInfo : Moveable { static void FreeFonts(); typedef Link FontLink; - - friend class Font; #ifdef PLATFORM_WIN32 static int CALLBACK AddFace(const LOGFONT *logfont, const TEXTMETRIC *, dword type, LPARAM param); @@ -332,6 +330,10 @@ class FontInfo : Moveable { static FontInfo AcquireFontInfo(Font font, int angle); #endif + friend class Font; + friend class SystemDraw; + friend void StaticExitDraw_(); + public: int GetAscent() const { return ptr->ascent; } int GetDescent() const { return ptr->descent; } @@ -551,7 +553,7 @@ private: public: enum { DOTS = 0x001, - SYSTEM = 0x002, + GUI = 0x002, PRINTER = 0x004, BACK = 0x008, PALETTE = 0x020, @@ -607,7 +609,7 @@ public: bool Dots() const { return GetInfo() & DOTS; } bool Pixels() const { return !Dots(); } - bool IsSystem() const { return GetInfo() & SYSTEM; } + bool IsGui() const { return GetInfo() & GUI; } bool IsPrinter() const { return GetInfo() & PRINTER; } bool IsNative() const { return GetInfo() & NATIVE; } bool IsBack() const { return GetInfo() & BACK; } @@ -845,30 +847,35 @@ public: class NilDraw : public Draw { public: + virtual dword GetInfo() const; + virtual Size GetPagePixels() 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 void DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color); - virtual void DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id); - virtual void DrawDrawingOp(const Rect& target, const Drawing& w); - virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor); - 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 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 DrawPolyPolylineOp(const Point *vertices, int vertex_count, const int *counts, int count_count, int width, Color color, Color doxor); - virtual void DrawRectOp(int x, int y, int cx, int cy, Color color); - virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Color ink, int n, const int *dx); - virtual void EndOp(); - virtual void EndPage(); virtual bool ExcludeClipOp(const Rect& r); - virtual Rect GetClipOp() const; virtual bool IntersectClipOp(const Rect& r); virtual bool IsPaintingOp(const Rect& r) const; - virtual void OffsetOp(Point p); - virtual void StartPage(); - NilDraw(); - ~NilDraw(); + 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 DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id); + 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 void DrawDrawingOp(const Rect& target, const Drawing& w); + virtual void DrawPaintingOp(const Rect& target, const Painting& w); }; void AddNotEmpty(Vector& result, int left, int right, int top, int bottom); diff --git a/uppdev/Draw/DrawOpWin32.cpp b/uppdev/Draw/DrawOpWin32.cpp index f76c50943..3e723713d 100644 --- a/uppdev/Draw/DrawOpWin32.cpp +++ b/uppdev/Draw/DrawOpWin32.cpp @@ -7,7 +7,7 @@ NAMESPACE_UPP #define LLOG(x) // LOG(x) #define LTIMING(x) // RTIMING(x) -void Draw::BeginOp() +void SystemDraw::BeginOp() { LTIMING("Begin"); DrawLock __; @@ -23,7 +23,7 @@ void Draw::BeginOp() } } -void Draw::OffsetOp(Point p) +void SystemDraw::OffsetOp(Point p) { DrawLock __; Begin(); @@ -32,7 +32,7 @@ void Draw::OffsetOp(Point p) SetOrg(); } -bool Draw::ClipOp(const Rect& r) +bool SystemDraw::ClipOp(const Rect& r) { DrawLock __; Begin(); @@ -40,7 +40,7 @@ bool Draw::ClipOp(const Rect& r) return IntersectClip(r); } -bool Draw::ClipoffOp(const Rect& r) +bool SystemDraw::ClipoffOp(const Rect& r) { DrawLock __; Begin(); @@ -53,7 +53,7 @@ bool Draw::ClipoffOp(const Rect& r) return q; } -void Draw::EndOp() +void SystemDraw::EndOp() { DrawLock __; LTIMING("End"); @@ -67,7 +67,7 @@ void Draw::EndOp() cloff.Drop(); } -bool Draw::ExcludeClipOp(const Rect& r) +bool SystemDraw::ExcludeClipOp(const Rect& r) { DrawLock __; #ifdef PLATFORM_WINCE @@ -83,7 +83,7 @@ bool Draw::ExcludeClipOp(const Rect& r) return q == SIMPLEREGION || q == COMPLEXREGION; } -bool Draw::IntersectClipOp(const Rect& r) +bool SystemDraw::IntersectClipOp(const Rect& r) { DrawLock __; #ifdef PLATFORM_WINCE @@ -99,23 +99,15 @@ bool Draw::IntersectClipOp(const Rect& r) return q == SIMPLEREGION || q == COMPLEXREGION; } -Rect Draw::GetClipOp() const -{ - DrawLock __; - Rect r; - ::GetClipBox(handle, r); - return r; -} - -bool Draw::IsPaintingOp(const Rect& r) const +bool SystemDraw::IsPaintingOp(const Rect& r) const { DrawLock __; LTIMING("IsPainting"); - LLOG("Draw::IsPaintingOp r: " << r); + LLOG("SystemDraw::IsPaintingOp r: " << r); return ::RectVisible(handle, r); } -void Draw::DrawRectOp(int x, int y, int cx, int cy, Color color) +void SystemDraw::DrawRectOp(int x, int y, int cx, int cy, Color color) { DrawLock __; LTIMING("DrawRect"); @@ -130,7 +122,7 @@ void Draw::DrawRectOp(int x, int y, int cx, int cy, Color color) } } -void Draw::DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color) +void SystemDraw::DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color) { DrawLock __; if(IsNull(width) || IsNull(color)) return; @@ -141,7 +133,7 @@ void Draw::DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color) #ifndef PLATFORM_WINCE -void Draw::DrawPolyPolylineOp(const Point *vertices, int vertex_count, +void SystemDraw::DrawPolyPolylineOp(const Point *vertices, int vertex_count, const int *counts, int count_count, int width, Color color, Color doxor) { @@ -165,7 +157,7 @@ void Draw::DrawPolyPolylineOp(const Point *vertices, int vertex_count, } static void DrawPolyPolyPolygonRaw( - Draw& draw, const Point *vertices, int vertex_count, + SystemDraw& draw, const Point *vertices, int vertex_count, const int *subpolygon_counts, int subpolygon_count_count, const int *disjunct_polygon_counts, int disjunct_polygon_count_count) { @@ -195,7 +187,7 @@ static void DrawPolyPolyPolygonRaw( } } -void Draw::DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, +void SystemDraw::DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, const int *subpolygon_counts, int subpolygon_count_count, const int *disjunct_polygon_counts, int disjunct_polygon_count_count, Color color, int width, Color outline, uint64 pattern, Color doxor) @@ -268,7 +260,7 @@ void Draw::DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, } } -void Draw::DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color) +void SystemDraw::DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color) { DrawLock __; SetDrawPen(width, color); @@ -277,7 +269,7 @@ void Draw::DrawArcOp(const Rect& rc, Point start, Point end, int width, Color co #endif -void Draw::DrawEllipseOp(const Rect& r, Color color, int width, Color pencolor) +void SystemDraw::DrawEllipseOp(const Rect& r, Color color, int width, Color pencolor) { DrawLock __; SetColor(color); @@ -285,7 +277,7 @@ void Draw::DrawEllipseOp(const Rect& r, Color color, int width, Color pencolor) ::Ellipse(GetHandle(), r.left, r.top, r.right, r.bottom); } -void Draw::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Color ink, +void SystemDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Color ink, int n, const int *dx) { while(n > 30000) { DrawTextOp(x, y, angle, text, font, ink, 30000, dx); diff --git a/uppdev/Draw/DrawWin32.cpp b/uppdev/Draw/DrawWin32.cpp index ff3186cfe..0a4ed6772 100644 --- a/uppdev/Draw/DrawWin32.cpp +++ b/uppdev/Draw/DrawWin32.cpp @@ -9,14 +9,14 @@ NAMESPACE_UPP static COLORREF sLightGray; -Size Draw::GetNativeDpi() const +Size SystemDraw::GetNativeDpi() const { return nativeDpi; } void StaticExitDraw_() { - Draw::FreeFonts(); + FontInfo::FreeFonts(); } EXITBLOCK @@ -37,7 +37,7 @@ HPALETTE GetQlibPalette() { static HPALETTE hQlibPalette; if(hQlibPalette) return hQlibPalette; - Draw::InitColors(); + SystemDraw::InitColors(); LOGPALETTE *pal = (LOGPALETTE *) new byte[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)]; pal->palNumEntries = 0; pal->palVersion = 0x300; @@ -54,7 +54,7 @@ HPALETTE GetQlibPalette() } #endif -Draw& GLOBAL_VP(ScreenDraw, ScreenInfo, (true)) +SystemDraw& GLOBAL_VP(ScreenDraw, ScreenInfo, (true)) HDC ScreenHDC() { @@ -62,10 +62,10 @@ HDC ScreenHDC() } static bool _AutoPalette = true; -bool Draw::AutoPalette() { return _AutoPalette; } -void Draw::SetAutoPalette(bool ap) { _AutoPalette = ap; } +bool SystemDraw::AutoPalette() { return _AutoPalette; } +void SystemDraw::SetAutoPalette(bool ap) { _AutoPalette = ap; } -COLORREF Draw::GetColor(Color c) const { +COLORREF SystemDraw::GetColor(Color c) const { COLORREF color = c; #ifdef PLATFORM_WINCE return color; @@ -100,11 +100,11 @@ COLORREF Draw::GetColor(Color c) const { #endif } -void Draw::InitColors() +void SystemDraw::InitColors() { } -void Draw::SetColor(Color color) +void SystemDraw::SetColor(Color color) { DrawLock __; LLOG("SetColor " << color); @@ -128,7 +128,7 @@ void Draw::SetColor(Color color) } } -void Draw::SetDrawPen(int width, Color color) { +void SystemDraw::SetDrawPen(int width, Color color) { DrawLock __; if(IsNull(width)) width = PEN_NULL; @@ -151,38 +151,38 @@ void Draw::SetDrawPen(int width, Color color) { } -void Draw::SetOrg() { +void SystemDraw::SetOrg() { DrawLock __; #ifdef PLATFORM_WINCE ::SetViewportOrgEx(handle, actual_offset.x, actual_offset.y, 0); #else - LLOG("Draw::SetOrg: clip = " << GetClip() << ", offset = " << actual_offset); + LLOG("SystemDraw::SetOrg: clip = " << GetClip() << ", offset = " << actual_offset); ::SetWindowOrgEx(handle, -actual_offset.x, -actual_offset.y, 0); - LLOG("//Draw::SetOrg: clip = " << GetClip()); + LLOG("//SystemDraw::SetOrg: clip = " << GetClip()); #endif } #ifndef PLATFORM_WINCE -Point Draw::LPtoDP(Point p) const { +Point SystemDraw::LPtoDP(Point p) const { DrawLock __; ::LPtoDP(handle, p, 1); return p; } -Point Draw::DPtoLP(Point p) const { +Point SystemDraw::DPtoLP(Point p) const { DrawLock __; ::DPtoLP(handle, p, 1); return p; } -Rect Draw::LPtoDP(const Rect& r) const { +Rect SystemDraw::LPtoDP(const Rect& r) const { DrawLock __; Rect w = r; ::LPtoDP(handle, reinterpret_cast(&w), 2); return w; } -Rect Draw::DPtoLP(const Rect& r) const { +Rect SystemDraw::DPtoLP(const Rect& r) const { DrawLock __; Rect w = r; ::LPtoDP(handle, reinterpret_cast(&w), 2); @@ -190,12 +190,12 @@ Rect Draw::DPtoLP(const Rect& r) const { } #endif -Size Draw::GetSizeCaps(int i, int j) const { +Size SystemDraw::GetSizeCaps(int i, int j) const { DrawLock __; return Size(GetDeviceCaps(handle, i), GetDeviceCaps(handle, j)); } -void Draw::DotsMode() +void SystemDraw::DotsMode() { ::SetMapMode(handle, MM_ANISOTROPIC); ::SetViewportExtEx(handle, nativeDpi.cx, nativeDpi.cy, NULL); @@ -204,9 +204,9 @@ void Draw::DotsMode() ::SetWindowOrgEx(handle, 0, 0, NULL); } -void Draw::BeginNative() +void SystemDraw::BeginNative() { - if(inchPixels != nativeDpi && ++native == 1) { + if(GetPixelsPerInch() != nativeDpi && ++native == 1) { ::SetMapMode(handle, MM_TEXT); actual_offset_bak = actual_offset; Native(actual_offset); @@ -214,37 +214,27 @@ void Draw::BeginNative() } } -void Draw::EndNative() +void SystemDraw::EndNative() { - if(inchPixels != nativeDpi && --native == 0) { + if(GetPixelsPerInch() != nativeDpi && --native == 0) { DotsMode(); actual_offset = actual_offset_bak; SetOrg(); } } -void Draw::LoadCaps() { +void SystemDraw::LoadCaps() { DrawLock __; color16 = false; palette = (GetDeviceCaps(handle, RASTERCAPS) & RC_PALETTE); if(palette) color16 = GetDeviceCaps(handle, SIZEPALETTE) != 256; - pageDots = pagePixels = GetSizeCaps(HORZRES, VERTRES); - pageMMs = GetSizeCaps(HORZSIZE, VERTSIZE); - nativeDpi = inchPixels = GetSizeCaps(LOGPIXELSX, LOGPIXELSY); - sheetPixels = GetSizeCaps(PHYSICALWIDTH, PHYSICALHEIGHT); - pageOffset = GetSizeCaps(PHYSICALOFFSETX, PHYSICALOFFSETY); + pagePixels = GetSizeCaps(HORZRES, VERTRES); _DBG_ + nativeDpi = GetSizeCaps(LOGPIXELSX, LOGPIXELSY); is_mono = GetDeviceCaps(handle, BITSPIXEL) == 1 && GetDeviceCaps(handle, PLANES) == 1; } -void Draw::SetDevice(const char *s) { - DrawLock __; - static Index map; - device = map.FindAdd(s) + 1; - LoadCaps(); -} - -void Draw::Cinit() { +void SystemDraw::Cinit() { DrawLock __; lastColor = Color::FromCR(COLORREF(-5)); lastPenColor = Color::FromCR(COLORREF(-5)); @@ -256,7 +246,7 @@ void Draw::Cinit() { lastFont.Clear(); } -void Draw::Init() { +void SystemDraw::Init() { DrawLock __; Cinit(); SetBkMode(handle, TRANSPARENT); @@ -269,33 +259,31 @@ void Draw::Init() { LoadCaps(); } -void Draw::Reset() { +void SystemDraw::Reset() { DrawLock __; - device = 0; - pixels = true; - printer = aborted = backdraw = is_mono = false; + style = GUI; } -Draw::Draw() { +SystemDraw::SystemDraw() { DrawLock __; native = 0; InitColors(); - InitFonts(); + FontInfo::InitFonts(); actual_offset = Point(0, 0); Reset(); handle = NULL; } -Draw::Draw(HDC hdc) { +SystemDraw::SystemDraw(HDC hdc) { DrawLock __; native = 0; InitColors(); - InitFonts(); + FontInfo::InitFonts(); Reset(); Attach(hdc); } -void Draw::Unselect0() { +void SystemDraw::Unselect0() { DrawLock __; if(orgPen) SelectObject(handle, orgPen); if(orgBrush) SelectObject(handle, orgBrush); @@ -305,44 +293,32 @@ void Draw::Unselect0() { Cinit(); } -void Draw::Unselect() { +void SystemDraw::Unselect() { DrawLock __; while(cloff.GetCount()) End(); Unselect0(); } -Draw::~Draw() { +SystemDraw::~SystemDraw() { DrawLock __; if(handle) Unselect(); } -HDC Draw::BeginGdi() { +HDC SystemDraw::BeginGdi() { DrawLock __; Begin(); return handle; } -void Draw::EndGdi() { +void SystemDraw::EndGdi() { DrawLock __; Unselect0(); End(); } -NilDraw::NilDraw() { - DrawLock __; - Attach(ScreenInfo().GetHandle()); - pixels = false; - cloff.Clear(); -} - -NilDraw::~NilDraw() { - DrawLock __; - Detach(); -} - -void BackDraw::Create(Draw& w, int cx, int cy) { +void BackDraw::Create(SystemDraw& w, int cx, int cy) { ASSERT(w.GetHandle()); DrawLock __; Destroy(); @@ -353,17 +329,17 @@ void BackDraw::Create(Draw& w, int cx, int cy) { ASSERT(hbmp); ASSERT(handle); #ifndef PLATFORM_WINCE - if(w.PaletteMode() && AutoPalette()) { + if(AutoPalette()) { ::SelectPalette(handle, GetQlibPalette(), FALSE); ::RealizePalette(handle); } #endif hbmpold = (HBITMAP) ::SelectObject(handle, hbmp); Init(); - backdraw = true; + style = GUI|BACK; } -void BackDraw::Put(Draw& w, int x, int y) { +void BackDraw::Put(SystemDraw& w, int x, int y) { DrawLock __; ASSERT(handle); LTIMING("BackDraw::Put"); @@ -392,7 +368,7 @@ ScreenDraw::ScreenDraw(bool ic) { Attach(CreateDC(NULL, NULL, NULL, NULL)); #else Attach((ic ? CreateIC : CreateDC)("DISPLAY", NULL, NULL, NULL)); - if(PaletteMode() && AutoPalette()) { + if(AutoPalette()) { SelectPalette(handle, GetQlibPalette(), TRUE); RealizePalette(handle); } @@ -411,25 +387,20 @@ void PrintDraw::InitPrinter() { DrawLock __; Init(); - printer = true; - pixels = false; - nativeDpi = inchPixels; + style = PRINTER|DOTS; DotsMode(); native = 0; actual_offset = Point(0, 0); - pageDots.cx = 600 * pagePixels.cx / inchPixels.cx; - pageDots.cy = 600 * pagePixels.cy / inchPixels.cy; - inchPixels.cx = 600; - inchPixels.cy = 600; + aborted = false; } void PrintDraw::StartPage() { DrawLock __; - if(IsAborted()) return; + if(aborted) return; Unselect(); if(::StartPage(handle) <= 0) - Abort(); + aborted = true; else InitPrinter(); } @@ -437,15 +408,14 @@ void PrintDraw::StartPage() void PrintDraw::EndPage() { DrawLock __; - if(IsAborted()) return; + if(aborted) return; Unselect(); - ASSERT(printer); if(::EndPage(handle) <= 0) - Abort(); + aborted = true; } PrintDraw::PrintDraw(HDC hdc, const char *docname) - : Draw(hdc) + : SystemDraw(hdc) { DrawLock __; DOCINFO di; @@ -453,16 +423,15 @@ PrintDraw::PrintDraw(HDC hdc, const char *docname) di.cbSize = sizeof(di); String sys_docname = ToSystemCharset(docname); di.lpszDocName = ~sys_docname; - if(::StartDoc(hdc, &di) <= 0) { - Abort(); - return; - } - InitPrinter(); + if(::StartDoc(hdc, &di) <= 0) + aborted = true; + else + InitPrinter(); } PrintDraw::~PrintDraw() { DrawLock __; - if(IsAborted()) + if(aborted) ::AbortDoc(handle); else ::EndDoc(handle); diff --git a/uppdev/Draw/DrawWin32.h b/uppdev/Draw/DrawWin32.h index 96ce81469..eeac2c993 100644 --- a/uppdev/Draw/DrawWin32.h +++ b/uppdev/Draw/DrawWin32.h @@ -48,6 +48,10 @@ private: dword style; Size pagePixels; Size nativeDpi; + bool palette:1; + bool color16:1; + bool is_mono:1; + int native; SystemDraw(); @@ -87,20 +91,24 @@ private: void Init(); void LoadCaps(); - void SetDevice(const char *devicename); void SetPrinterMode(); void Reset(); void SetOrg(); friend HPALETTE GetQlibPalette(); void DotsMode(); + static void InitColors(); + + friend class BackDraw; + friend class ScreenDraw; + friend class PrintDraw; + public: + static void SetAutoPalette(bool ap); static bool AutoPalette(); static void Flush() { GdiFlush(); } - bool IsMetaFile() const { return device == -1; } - COLORREF GetColor(Color color) const; #ifndef PLATFORM_WINCE @@ -187,19 +195,21 @@ public: }; #endif -class ScreenDraw : public Draw { +class ScreenDraw : public SystemDraw { public: ScreenDraw(bool ic = false); ~ScreenDraw(); }; #ifndef PLATFORM_WINCE -class PrintDraw : public Draw { +class PrintDraw : public SystemDraw { public: virtual void StartPage(); virtual void EndPage(); private: + bool aborted; + void InitPrinter(); public: PrintDraw(HDC hdc, const char *jobname);