diff options
| author | Petr Mrázek <peterix@gmail.com> | 2013-12-10 07:22:22 +0100 |
|---|---|---|
| committer | Petr Mrázek <peterix@gmail.com> | 2013-12-10 07:22:22 +0100 |
| commit | aa61bbe9e414648399aff2802df5b587dee1a084 (patch) | |
| tree | ff7809bea445bb76c9fd27a3245e1b2cb7c72596 /mmc_updater/depends/win32cpp/gdi.h | |
| parent | 3f5c46a1c4b27e82976e0067e4ec2d6abfffd9ba (diff) | |
| parent | 712b87c643bbd7bc4ed2cfd459d0b9fdb69e5f0d (diff) | |
| download | PrismLauncher-aa61bbe9e414648399aff2802df5b587dee1a084.tar.gz PrismLauncher-aa61bbe9e414648399aff2802df5b587dee1a084.tar.bz2 PrismLauncher-aa61bbe9e414648399aff2802df5b587dee1a084.zip | |
Merge branch 'develop' of github.com:MultiMC/MultiMC5 into develop
Conflicts:
CMakeLists.txt
gui/MainWindow.cpp
Diffstat (limited to 'mmc_updater/depends/win32cpp/gdi.h')
| -rw-r--r-- | mmc_updater/depends/win32cpp/gdi.h | 3944 |
1 files changed, 3944 insertions, 0 deletions
diff --git a/mmc_updater/depends/win32cpp/gdi.h b/mmc_updater/depends/win32cpp/gdi.h new file mode 100644 index 00000000..45141f7b --- /dev/null +++ b/mmc_updater/depends/win32cpp/gdi.h @@ -0,0 +1,3944 @@ +// Win32++ Version 7.2 +// Released: 5th AUgust 2011 +// +// David Nash +// email: dnash@bigpond.net.au +// url: https://sourceforge.net/projects/win32-framework +// +// +// Copyright (c) 2005-2011 David Nash +// +// Permission is hereby granted, free of charge, to +// any person obtaining a copy of this software and +// associated documentation files (the "Software"), +// to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, +// merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom +// the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice +// shall be included in all copies or substantial portions +// of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE +// OR OTHER DEALINGS IN THE SOFTWARE. +// +//////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////// +// gdi.h +// Declaration of the CDC class, and CBitmapInfoPtr class + +// The CDC class provides a device context, along with the various associated +// objects such as Bitmaps, Brushes, Bitmaps, Fonts and Pens. This class +// handles the creation, selection, de-selection and deletion of these objects +// automatically. It also automatically deletes or releases the device context +// itself as appropriate. Any failure to create the new GDI object throws an +// exception. +// +// The CDC class is sufficient for most GDI programming needs. Sometimes +// however we need to have the GDI object seperated from the device context. +// Wrapper classes for GDI objects are provided for this purpose. The classes +// are CBitmap, CBrush, CFont, CPalette, CPen and CRgn. These classes +// automatically delete the GDI resouce assigned to them when their destructor +// is called. These wrapper class objects can be attached to the CDC as +// shown below. +// +// Coding Exampe without CDC ... +// void DrawLine() +// { +// HDC hdcClient = ::GetDC(m_hWnd); +// HDC hdcMem = ::CreateCompatibleDC(hdcClient); +// HBITMAP hBitmap = ::CreateCompatibleBitmap(hdcClient, cx, cy); +// HBITMAP hOldBitmap = (HBITMAP)::SelectObject(hdcMem, hBitmap); +// HPEN hPen = ::CreatePen(PS_SOLID, 1, RGB(255,0,0); +// HPEN hOldPen = (HPEN)::SelectObject(hdcMem, hPen); +// ::MoveToEx(hdcMem, 0, 0, NULL); +// ::LineTo(hdcMem, 50, 50); +// ::BitBlt(hdcClient, 0, 0, cx, cy, hdcMem, 0, 0); +// ::SelectObject(hdcMem, hOldPen); +// ::DeleteObject(hPen); +// ::SelectObject(hdcMem, hOldBitmap); +// ::DeleteObject(hBitmap); +// ::DeleteDC(hdcMem); +// ::ReleaseDC(m_hWnd, hdcClient); +// } +// +// Coding Example with CDC classes ... +// void DrawLine() +// { +// CClientDC dcClient(this) +// CMemDC dcMem(&dcClient); +// CBitmap* pOldBitmap = dcMem.CreateCompatibleBitmap(&dcClient, cx, cy); +// CPen* pOldPen = CMemDC.CreatePen(PS_SOLID, 1, RGB(255,0,0); +// CMemDC.MoveTo(0, 0); +// CMemDC.LineTo(50, 50); +// dcClient.BitBlt(0, 0, cx, cy, &CMemDC, 0, 0); +// } +// +// Coding Example with CDC classes and CPen ... +// void DrawLine() +// { +// CClientDC dcClient(this) +// CMemDC CMemDC(&dcClient); +// CBitmap* pOldBitmap = dcMem.CreateCompatibleBitmap(&dcClient, cx, cy); +// CPen MyPen(PS_SOLID, 1, RGB(255,0,0)); +// CPen* pOldPen = CMemDC.SelectObject(&MyPen); +// CMemDC.MoveTo(0, 0); +// CMemDC.LineTo(50, 50); +// dcClient.BitBlt(0, 0, cx, cy, &CMemDC, 0, 0); +// } + +// Notes: +// * When the CDC object drops out of scope, it's destructor is called, releasing +// or deleting the device context as appropriate. +// * When the destructor for CBitmap, CBrush, CPalette, CPen and CRgn are called, +// the destructor is called deleting their GDI object. +// * When the CDC object' destructor is called, any GDI objects created by one of +// the CDC member functions (CDC::CreatePen for example) will be deleted. +// * Bitmaps can only be selected into one device context at a time. +// * Palettes use SelectPalatte to select them into device the context. +// * Regions use SelectClipRgn to select them into the device context. +// * The FromHandle function can be used to convert a GDI handle (HDC, HPEN, +// HBITMAP etc) to a pointer of the appropriate GDI class (CDC, CPen CBitmap etc). +// The FromHandle function creates a temporary object unless the HANDLE is already +// assigned to a GDI class. Temporary objects don't delete their GDI object when +// their destructor is called. +// * All the GDI classes are reference counted. This allows functions to safely +// pass these objects by value, as well as by pointer or by reference. + +// The CBitmapInfoPtr class is a convienient wrapper for the BITMAPINFO structure. +// The size of the BITMAPINFO structure is dependant on the type of HBITMAP, and its +// space needs to be allocated dynamically. CBitmapInfoPtr automatically allocates +// and deallocates the memory for the structure. A CBitmapInfoPtr object can be +// used anywhere in place of a LPBITMAPINFO. LPBITMAPINFO is used in functions like +// GetDIBits and SetDIBits. +// +// Coding example ... +// CDC MemDC = CreateCompatibleDC(NULL); +// CBitmapInfoPtr pbmi(hBitmap); +// MemDC.GetDIBits(hBitmap, 0, pbmi->bmiHeader.biHeight, NULL, pbmi, DIB_RGB_COLORS); + +#ifndef _WIN32XX_GDI_H_ +#define _WIN32XX_GDI_H_ + +#include "wincore.h" + +// Disable macros from Windowsx.h +#undef CopyRgn + +namespace Win32xx +{ + + ///////////////////////////////////////////////////////////////// + // Declarations for some global functions in the Win32xx namespace + // +#ifndef _WIN32_WCE + void GrayScaleBitmap(CBitmap* pbmSource); + void TintBitmap(CBitmap* pbmSource, int cRed, int cGreen, int cBlue); + HIMAGELIST CreateDisabledImageList(HIMAGELIST himlNormal); +#endif + + /////////////////////////////////////////////// + // Declarations for the CGDIObject class + // + class CGDIObject + { + friend CBitmap* FromHandle(HBITMAP hBitmap); + friend CBrush* FromHandle(HBRUSH hBrush); + friend CDC* FromHandle(HDC hDC); + friend CFont* FromHandle(HFONT hFont); + friend CPalette* FromHandle(HPALETTE hPalette); + friend CPen* FromHandle(HPEN hPen); + friend CRgn* FromHandle(HRGN hRgn); + + public: + struct DataMembers // A structure that contains the data members for CGDIObject + { + HGDIOBJ hGDIObject; + long Count; + BOOL bRemoveObject; + }; + CGDIObject(); + CGDIObject(const CGDIObject& rhs); + virtual ~CGDIObject(); + CGDIObject& operator = ( const CGDIObject& rhs ); + void operator = (HGDIOBJ hObject); + + void Attach(HGDIOBJ hObject); + HGDIOBJ Detach(); + HGDIOBJ GetHandle() const; + int GetObject(int nCount, LPVOID pObject) const; + + protected: + DataMembers* m_pData; + + private: + void AddToMap(); + BOOL RemoveFromMap(); + void Release(); + }; + + + /////////////////////////////////////////////// + // Declarations for the CBitmap class + // + class CBitmap : public CGDIObject + { + public: + CBitmap(); + CBitmap(HBITMAP hBitmap); + CBitmap(LPCTSTR lpstr); + CBitmap(int nID); + operator HBITMAP() const; + ~CBitmap(); + + // Create and load methods + BOOL LoadBitmap(LPCTSTR lpszName); + BOOL LoadBitmap(int nID); + BOOL LoadImage(LPCTSTR lpszName, int cxDesired, int cyDesired, UINT fuLoad); + BOOL LoadImage(UINT nID, int cxDesired, int cyDesired, UINT fuLoad); + BOOL LoadOEMBitmap(UINT nIDBitmap); + HBITMAP CreateBitmap(int nWidth, int nHeight, UINT nPlanes, UINT nBitsPerPixel, LPCVOID lpBits); + HBITMAP CreateCompatibleBitmap(CDC* pDC, int nWidth, int nHeight); + HBITMAP CreateDIBSection(CDC* pDC, CONST BITMAPINFO* lpbmi, UINT uColorUse, LPVOID* ppvBits, HANDLE hSection, DWORD dwOffset); + +#ifndef _WIN32_WCE + HBITMAP CreateDIBitmap(CDC* pDC, CONST BITMAPINFOHEADER* lpbmih, DWORD dwInit, LPCVOID lpbInit, CONST BITMAPINFO* lpbmi, UINT uColorUse); + HBITMAP CreateMappedBitmap(UINT nIDBitmap, UINT nFlags = 0, LPCOLORMAP lpColorMap = NULL, int nMapSize = 0); + HBITMAP CreateBitmapIndirect(LPBITMAP lpBitmap); + int GetDIBits(CDC* pDC, UINT uStartScan, UINT cScanLines, LPVOID lpvBits, LPBITMAPINFO lpbmi, UINT uColorUse) const; + int SetDIBits(CDC* pDC, UINT uStartScan, UINT cScanLines, CONST VOID* lpvBits, CONST BITMAPINFO* lpbmi, UINT uColorUse); + CSize GetBitmapDimensionEx() const; + CSize SetBitmapDimensionEx(int nWidth, int nHeight); +#endif // !_WIN32_WCE + + // Attributes + BITMAP GetBitmapData() const; + }; + + + /////////////////////////////////////////////// + // Declarations for the CBrush class + // + class CBrush : public CGDIObject + { + public: + CBrush(); + CBrush(HBRUSH hBrush); + CBrush(COLORREF crColor); + operator HBRUSH() const; + ~CBrush(); + + HBRUSH CreateSolidBrush(COLORREF crColor); + HBRUSH CreatePatternBrush(CBitmap* pBitmap); + LOGBRUSH GetLogBrush() const; + +#ifndef _WIN32_WCE + HBRUSH CreateHatchBrush(int nIndex, COLORREF crColor); + HBRUSH CreateBrushIndirect(LPLOGBRUSH lpLogBrush); + HBRUSH CreateDIBPatternBrush(HGLOBAL hglbDIBPacked, UINT fuColorSpec); + HBRUSH CreateDIBPatternBrushPt(LPCVOID lpPackedDIB, UINT nUsage); +#endif // !defined(_WIN32_WCE) + + }; + + + /////////////////////////////////////////////// + // Declarations for the CFont class + // + class CFont : public CGDIObject + { + public: + CFont(); + CFont(HFONT hFont); + CFont(const LOGFONT* lpLogFont); + operator HFONT() const; + ~CFont(); + + // Create methods + HFONT CreateFontIndirect(const LOGFONT* lpLogFont); + HFONT CreatePointFont(int nPointSize, LPCTSTR lpszFaceName, CDC* pDC = NULL, BOOL bBold = FALSE, BOOL bItalic = FALSE); + HFONT CreatePointFontIndirect(const LOGFONT* lpLogFont, CDC* pDC = NULL); + +#ifndef _WIN32_WCE + HFONT CreateFont(int nHeight, int nWidth, int nEscapement, + int nOrientation, int nWeight, DWORD dwItalic, DWORD dwUnderline, + DWORD dwStrikeOut, DWORD dwCharSet, DWORD dwOutPrecision, + DWORD dwClipPrecision, DWORD dwQuality, DWORD dwPitchAndFamily, + LPCTSTR lpszFacename); +#endif // #ifndef _WIN32_WCE + + // Attributes + LOGFONT GetLogFont() const; + }; + + + /////////////////////////////////////////////// + // Declarations for the CPalette class + // + class CPalette : public CGDIObject + { + public: + CPalette(); + CPalette(HPALETTE hPalette); + operator HPALETTE() const; + ~CPalette(); + + // Create methods + HPALETTE CreatePalette(LPLOGPALETTE lpLogPalette); + +#ifndef _WIN32_WCE + HPALETTE CreateHalftonePalette(CDC* pDC); +#endif // !_WIN32_WCE + + // Attributes + int GetEntryCount() const; + UINT GetPaletteEntries(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors) const; + UINT SetPaletteEntries(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors); + + // Operations +#ifndef _WIN32_WCE + BOOL ResizePalette(UINT nNumEntries); + void AnimatePalette(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors); +#endif // !_WIN32_WCE + + UINT GetNearestPaletteIndex (COLORREF crColor) const; + + }; + + + /////////////////////////////////////////////// + // Declarations for the CPen class + // + class CPen : public CGDIObject + { + public: + CPen(); + CPen(HPEN hPen); + CPen(int nPenStyle, int nWidth, COLORREF crColor); +#ifndef _WIN32_WCE + CPen(int nPenStyle, int nWidth, const LOGBRUSH* pLogBrush, int nStyleCount = 0, const DWORD* lpStyle = NULL); +#endif // !_WIN32_WCE + operator HPEN() const; + ~CPen(); + + HPEN CreatePen(int nPenStyle, int nWidth, COLORREF crColor); + HPEN CreatePenIndirect(LPLOGPEN lpLogPen); + LOGPEN GetLogPen() const; + +#ifndef _WIN32_WCE + HPEN ExtCreatePen(int nPenStyle, int nWidth, const LOGBRUSH* pLogBrush, int nStyleCount = 0, const DWORD* lpStyle = NULL); + EXTLOGPEN GetExtLogPen() const; +#endif // !_WIN32_WCE + + }; + + + /////////////////////////////////////////////// + // Declarations for the CRgn class + // + class CRgn : public CGDIObject + { + public: + CRgn(); + CRgn(HRGN hRgn); + operator HRGN() const; + ~CRgn (); + + // Create methods + HRGN CreateRectRgn(int x1, int y1, int x2, int y2); + HRGN CreateRectRgnIndirect(const RECT& rc); + HRGN CreateFromData(const XFORM* lpXForm, int nCount, const RGNDATA* pRgnData); + +#ifndef _WIN32_WCE + HRGN CreateEllipticRgn(int x1, int y1, int x2, int y2); + HRGN CreateEllipticRgnIndirect(const RECT& rc); + HRGN CreatePolygonRgn(LPPOINT lpPoints, int nCount, int nMode); + HRGN CreatePolyPolygonRgn(LPPOINT lpPoints, LPINT lpPolyCounts, int nCount, int nPolyFillMode); + HRGN CreateRoundRectRgn(int x1, int y1, int x2, int y2, int x3, int y3); + HRGN CreateFromPath(HDC hDC); +#endif // !_WIN32_WCE + + // Operations + void SetRectRgn(int x1, int y1, int x2, int y2); + void SetRectRgn(const RECT& rc); + int CombineRgn(CRgn* pRgnSrc1, CRgn* pRgnSrc2, int nCombineMode); + int CombineRgn(CRgn* pRgnSrc, int nCombineMode); + int CopyRgn(CRgn* pRgnSrc); + BOOL EqualRgn(CRgn* pRgn) const; + int OffsetRgn(int x, int y); + int OffsetRgn(POINT& pt); + int GetRgnBox(RECT& rc) const; + BOOL PtInRegion(int x, int y) const; + BOOL PtInRegion(POINT& pt) const; + BOOL RectInRegion(const RECT& rc) const; + int GetRegionData(LPRGNDATA lpRgnData, int nDataSize) const; + }; + + + /////////////////////////////////////////////// + // Declarations for the CDC class + // + class CDC + { + friend class CWinApp; + friend class CWnd; + friend CDC* FromHandle(HDC hDC); + + public: + struct DataMembers // A structure that contains the data members for CDC + { + std::vector<GDIPtr> m_vGDIObjects; // Smart pointers to internally created Bitmaps, Brushes, Fonts, Bitmaps and Regions + HDC hDC; // The HDC belonging to this CDC + long Count; // Reference count + BOOL bRemoveHDC; // Delete/Release the HDC on destruction + HWND hWnd; // The HWND of a Window or Client window DC + int nSavedDCState; // The save state of the HDC. + }; + + CDC(); // Constructs a new CDC without assigning a HDC + CDC(HDC hDC, HWND hWnd = 0); // Assigns a HDC to a new CDC + CDC(const CDC& rhs); // Constructs a new copy of the CDC + virtual ~CDC(); + operator HDC() const { return m_pData->hDC; } // Converts a CDC to a HDC + CDC& operator = (const CDC& rhs); // Assigns a CDC to an existing CDC + + void Attach(HDC hDC, HWND hWnd = 0); + void Destroy(); + HDC Detach(); + HDC GetHDC() const { return m_pData->hDC; } + CPalette* SelectPalette(const CPalette* pPalette, BOOL bForceBkgnd); + CBitmap* SelectObject(const CBitmap* pBitmap); + CBrush* SelectObject(const CBrush* pBrush); + CFont* SelectObject(const CFont* pFont); + CPalette* SelectObject(const CPalette* pPalette); + CPen* SelectObject(const CPen* pPen); + +#ifndef _WIN32_WCE + void operator = (const HDC hDC); +#endif + + // Initialization + BOOL CreateCompatibleDC(CDC* pDC); + BOOL CreateDC(LPCTSTR lpszDriver, LPCTSTR lpszDevice, LPCTSTR lpszOutput, const DEVMODE* pInitData); + int GetDeviceCaps(int nIndex) const; +#ifndef _WIN32_WCE + BOOL CreateIC(LPCTSTR lpszDriver, LPCTSTR lpszDevice, LPCTSTR lpszOutput, const DEVMODE* pInitData); +#endif + + // Create and Select Bitmaps + CBitmap* CreateBitmap(int cx, int cy, UINT Planes, UINT BitsPerPixel, LPCVOID pvColors); + CBitmap* CreateCompatibleBitmap(CDC* pDC, int cx, int cy); + CBitmap* CreateDIBSection(CDC* pDC, const BITMAPINFO& bmi, UINT iUsage, LPVOID *ppvBits, + HANDLE hSection, DWORD dwOffset); + BITMAP GetBitmapData() const; + CBitmap* LoadBitmap(UINT nID); + CBitmap* LoadBitmap(LPCTSTR lpszName); + CBitmap* LoadImage(UINT nID, int cxDesired, int cyDesired, UINT fuLoad); + CBitmap* LoadImage(LPCTSTR lpszName, int cxDesired, int cyDesired, UINT fuLoad); + CBitmap* LoadOEMBitmap(UINT nIDBitmap); // for OBM_/OCR_/OIC + +#ifndef _WIN32_WCE + CBitmap* CreateBitmapIndirect(LPBITMAP pBitmap); + CBitmap* CreateDIBitmap(CDC* pDC, const BITMAPINFOHEADER& bmih, DWORD fdwInit, LPCVOID lpbInit, + BITMAPINFO& bmi, UINT fuUsage); + CBitmap* CreateMappedBitmap(UINT nIDBitmap, UINT nFlags /*= 0*/, LPCOLORMAP lpColorMap /*= NULL*/, int nMapSize /*= 0*/); +#endif + + // Create and Select Brushes + CBrush* CreatePatternBrush(CBitmap* pBitmap); + CBrush* CreateSolidBrush(COLORREF rbg); + LOGBRUSH GetLogBrush() const; + +#ifndef _WIN32_WCE + CBrush* CreateBrushIndirect(LPLOGBRUSH pLogBrush); + CBrush* CreateHatchBrush(int fnStyle, COLORREF rgb); + CBrush* CreateDIBPatternBrush(HGLOBAL hglbDIBPacked, UINT fuColorSpec); + CBrush* CreateDIBPatternBrushPt(LPCVOID lpPackedDIB, UINT iUsage); +#endif + + // Create and Select Fonts + CFont* CreateFontIndirect(LPLOGFONT plf); + LOGFONT GetLogFont() const; + +#ifndef _WIN32_WCE + CFont* CreateFont(int nHeight, int nWidth, int nEscapement, int nOrientation, int fnWeight, + DWORD fdwItalic, DWORD fdwUnderline, DWORD fdwStrikeOut, DWORD fdwCharSet, + DWORD fdwOutputPrecision, DWORD fdwClipPrecision, DWORD fdwQuality, + DWORD fdwPitchAndFamily, LPCTSTR lpszFace); +#endif + + // Create and Select Pens + CPen* CreatePen(int nStyle, int nWidth, COLORREF rgb); + CPen* CreatePenIndirect(LPLOGPEN pLogPen); + LOGPEN GetLogPen() const; + + // Create Select Regions + int CreateRectRgn(int left, int top, int right, int bottom); + int CreateRectRgnIndirect(const RECT& rc); + int CreateFromData(const XFORM* Xform, DWORD nCount, const RGNDATA *pRgnData); +#ifndef _WIN32_WCE + int CreateEllipticRgn(int left, int top, int right, int bottom); + int CreateEllipticRgnIndirect(const RECT& rc); + int CreatePolygonRgn(LPPOINT ppt, int cPoints, int fnPolyFillMode); + int CreatePolyPolygonRgn(LPPOINT ppt, LPINT pPolyCounts, int nCount, int fnPolyFillMode); +#endif + + // Wrappers for WinAPI functions + + // Point and Line Drawing Functions + CPoint GetCurrentPosition() const; + CPoint MoveTo(int x, int y) const; + CPoint MoveTo(POINT pt) const; + BOOL LineTo(int x, int y) const; + BOOL LineTo(POINT pt) const; + COLORREF GetPixel(int x, int y) const; + COLORREF GetPixel(POINT pt) const; + COLORREF SetPixel(int x, int y, COLORREF crColor) const; + COLORREF SetPixel(POINT pt, COLORREF crColor) const; +#ifndef _WIN32_WCE + BOOL Arc(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) const; + BOOL Arc(RECT& rc, POINT ptStart, POINT ptEnd) const; + BOOL ArcTo(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) const; + BOOL ArcTo(RECT& rc, POINT ptStart, POINT ptEnd) const; + BOOL AngleArc(int x, int y, int nRadius, float fStartAngle, float fSweepAngle) const; + int GetArcDirection() const; + int SetArcDirection(int nArcDirection) const; + BOOL PolyDraw(const POINT* lpPoints, const BYTE* lpTypes, int nCount) const; + BOOL Polyline(LPPOINT lpPoints, int nCount) const; + BOOL PolyPolyline(const POINT* lpPoints, const DWORD* lpPolyPoints, int nCount) const; + BOOL PolylineTo(const POINT* lpPoints, int nCount) const; + BOOL PolyBezier(const POINT* lpPoints, int nCount) const; + BOOL PolyBezierTo(const POINT* lpPoints, int nCount) const; + BOOL SetPixelV(int x, int y, COLORREF crColor) const; + BOOL SetPixelV(POINT pt, COLORREF crColor) const; +#endif + + // Shape Drawing Functions + void DrawFocusRect(const RECT& rc) const; + BOOL Ellipse(int x1, int y1, int x2, int y2) const; + BOOL Ellipse(const RECT& rc) const; + BOOL Polygon(LPPOINT lpPoints, int nCount) const; + BOOL Rectangle(int x1, int y1, int x2, int y2) const; + BOOL Rectangle(const RECT& rc) const; + BOOL RoundRect(int x1, int y1, int x2, int y2, int nWidth, int nHeight) const; + BOOL RoundRect(const RECT& rc, int nWidth, int nHeight) const; + +#ifndef _WIN32_WCE + BOOL Chord(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) const; + BOOL Chord(const RECT& rc, POINT ptStart, POINT ptEnd) const; + BOOL Pie(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) const; + BOOL Pie(const RECT& rc, POINT ptStart, POINT ptEnd) const; + BOOL PolyPolygon(LPPOINT lpPoints, LPINT lpPolyCounts, int nCount) const; +#endif + + // Fill and Image Drawing functions + BOOL FillRect(const RECT& rc, CBrush* pBrushr) const; + BOOL InvertRect(const RECT& rc) const; + BOOL DrawIconEx(int xLeft, int yTop, HICON hIcon, int cxWidth, int cyWidth, UINT istepIfAniCur, CBrush* pFlickerFreeDraw, UINT diFlags) const; + BOOL DrawEdge(const RECT& rc, UINT nEdge, UINT nFlags) const; + BOOL DrawFrameControl(const RECT& rc, UINT nType, UINT nState) const; + BOOL FillRgn(CRgn* pRgn, CBrush* pBrush) const; + void GradientFill(COLORREF Color1, COLORREF Color2, const RECT& rc, BOOL bVertical); + void SolidFill(COLORREF Color, const RECT& rc); + +#ifndef _WIN32_WCE + BOOL DrawIcon(int x, int y, HICON hIcon) const; + BOOL DrawIcon(POINT point, HICON hIcon) const; + BOOL FrameRect(const RECT& rc, CBrush* pBrush) const; + BOOL PaintRgn(CRgn* pRgn) const; +#endif + + // Bitmap Functions + void DrawBitmap(int x, int y, int cx, int cy, CBitmap& Bitmap, COLORREF clrMask); + int StretchDIBits(int XDest, int YDest, int nDestWidth, int nDestHeight, int XSrc, int YSrc, int nSrcWidth, + int nSrcHeight, CONST VOID *lpBits, BITMAPINFO& bi, UINT iUsage, DWORD dwRop) const; + BOOL PatBlt(int x, int y, int nWidth, int nHeight, DWORD dwRop) const; + BOOL BitBlt(int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, DWORD dwRop) const; + BOOL StretchBlt(int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, int nSrcWidth, int nSrcHeight, DWORD dwRop) const; + +#ifndef _WIN32_WCE + int GetDIBits(CBitmap* pBitmap, UINT uStartScan, UINT cScanLines, LPVOID lpvBits, LPBITMAPINFO lpbi, UINT uUsage) const; + int SetDIBits(CBitmap* pBitmap, UINT uStartScan, UINT cScanLines, CONST VOID *lpvBits, LPBITMAPINFO lpbi, UINT fuColorUse) const; + int GetStretchBltMode() const; + int SetStretchBltMode(int iStretchMode) const; + BOOL FloodFill(int x, int y, COLORREF crColor) const; + BOOL ExtFloodFill(int x, int y, COLORREF crColor, UINT nFillType) const; +#endif + + // Brush Functions +#ifdef GetDCBrushColor + COLORREF GetDCBrushColor() const; + COLORREF SetDCBrushColor(COLORREF crColor) const; +#endif + + // Clipping Functions + int ExcludeClipRect(int Left, int Top, int Right, int BottomRect); + int ExcludeClipRect(const RECT& rc); + int GetClipBox(RECT& rc); + int GetClipRgn(HRGN hrgn); + int IntersectClipRect(int Left, int Top, int Right, int Bottom); + int IntersectClipRect(const RECT& rc); + BOOL RectVisible(const RECT& rc); + int SelectClipRgn(CRgn* pRgn); + +#ifndef _WIN32_WCE + int ExtSelectClipRgn(CRgn* pRgn, int fnMode); + int OffsetClipRgn(int nXOffset, int nYOffset); + BOOL PtVisible(int X, int Y); +#endif + + // Co-ordinate Functions +#ifndef _WIN32_WCE + BOOL DPtoLP(LPPOINT lpPoints, int nCount) const; + BOOL DPtoLP(RECT& rc) const; + BOOL LPtoDP(LPPOINT lpPoints, int nCount) const; + BOOL LPtoDP(RECT& rc) const; +#endif + + // Layout Functions + DWORD GetLayout() const; + DWORD SetLayout(DWORD dwLayout) const; + + // Mapping functions +#ifndef _WIN32_WCE + int GetMapMode() const; + int SetMapMode(int nMapMode) const; + BOOL GetViewportOrgEx(LPPOINT lpPoint) const; + BOOL SetViewportOrgEx(int x, int y, LPPOINT lpPoint = NULL) const; + BOOL SetViewportOrgEx(POINT point, LPPOINT lpPointRet = NULL) const; + BOOL OffsetViewportOrgEx(int nWidth, int nHeight, LPPOINT lpPoint = NULL) const; + BOOL GetViewportExtEx(LPSIZE lpSize) const; + BOOL SetViewportExtEx(int x, int y, LPSIZE lpSize) const; + BOOL SetViewportExtEx(SIZE size, LPSIZE lpSizeRet) const; + BOOL ScaleViewportExtEx(int xNum, int xDenom, int yNum, int yDenom, LPSIZE lpSize) const; + BOOL OffsetWindowOrg(int nWidth, int nHeight, LPPOINT lpPoint) const; + BOOL GetWindowExtEx(LPSIZE lpSize) const; + BOOL SetWindowExtEx(int x, int y, LPSIZE lpSize) const; + BOOL SetWindowExtEx(SIZE size, LPSIZE lpSizeRet) const; + BOOL ScaleWindowExtEx(int xNum, int xDenom, int yNum, int yDenom, LPSIZE lpSize) const; + BOOL GetWindowOrgEx(LPPOINT lpPoint) const; + BOOL SetWindowOrgEx(int x, int y, LPPOINT lpPoint) const; + BOOL SetWindowOrgEx(POINT point, LPPOINT lpPointRet) const; + BOOL OffsetWindowOrgEx(int nWidth, int nHeight, LPPOINT lpPoint) const; +#endif + + // Printer Functions + int StartDoc(LPDOCINFO lpDocInfo) const; + int EndDoc() const; + int StartPage() const; + int EndPage() const; + int AbortDoc() const; + int SetAbortProc(BOOL (CALLBACK* lpfn)(HDC, int)) const; + + // Text Functions + int DrawText(LPCTSTR lpszString, int nCount, LPRECT lprc, UINT nFormat) const; + BOOL ExtTextOut(int x, int y, UINT nOptions, LPCRECT lprc, LPCTSTR lpszString, int nCount = -1, LPINT lpDxWidths = NULL) const; + COLORREF GetBkColor() const; + int GetBkMode() const; + UINT GetTextAlign() const; + int GetTextFace(int nCount, LPTSTR lpszFacename) const; + COLORREF GetTextColor() const; + BOOL GetTextMetrics(TEXTMETRIC& Metrics) const; + COLORREF SetBkColor(COLORREF crColor) const; + int SetBkMode(int iBkMode) const; + UINT SetTextAlign(UINT nFlags) const; + COLORREF SetTextColor(COLORREF crColor) const; + +#ifndef _WIN32_WCE + int DrawTextEx(LPTSTR lpszString, int nCount, LPRECT lprc, UINT nFormat, LPDRAWTEXTPARAMS lpDTParams) const; + CSize GetTabbedTextExtent(LPCTSTR lpszString, int nCount, int nTabPositions, LPINT lpnTabStopPositions) const; + int GetTextCharacterExtra() const; + CSize GetTextExtentPoint32(LPCTSTR lpszString, int nCount) const; + BOOL GrayString(CBrush* pBrush, GRAYSTRINGPROC lpOutputFunc, LPARAM lpData, int nCount, int x, int y, int nWidth, int nHeight) const; + int SetTextCharacterExtra(int nCharExtra) const; + int SetTextJustification(int nBreakExtra, int nBreakCount) const; + CSize TabbedTextOut(int x, int y, LPCTSTR lpszString, int nCount, int nTabPositions, LPINT lpnTabStopPositions, int nTabOrigin) const; + BOOL TextOut(int x, int y, LPCTSTR lpszString, int nCount = -1) const; +#endif + + private: + void AddToMap(); + static CDC* AddTempHDC(HDC hDC, HWND hWnd); + void Release(); + BOOL RemoveFromMap(); + + DataMembers* m_pData; // pointer to the class's data members + }; + + class CClientDC : public CDC + { + public: + CClientDC(const CWnd* pWnd) + { + if (pWnd) assert(pWnd->IsWindow()); + HWND hWnd = pWnd? pWnd->GetHwnd() : GetDesktopWindow(); + Attach(::GetDC(hWnd), hWnd); + } + virtual ~CClientDC() {} + }; + + class CMemDC : public CDC + { + public: + CMemDC(const CDC* pDC) + { + if (pDC) assert(pDC->GetHDC()); + HDC hDC = pDC? pDC->GetHDC() : NULL; + Attach(::CreateCompatibleDC(hDC)); + } + virtual ~CMemDC() {} + }; + + class CPaintDC : public CDC + { + public: + CPaintDC(const CWnd* pWnd) + { + assert(pWnd->IsWindow()); + m_hWnd = pWnd->GetHwnd(); + Attach(::BeginPaint(pWnd->GetHwnd(), &m_ps), m_hWnd); + } + + virtual ~CPaintDC() { ::EndPaint(m_hWnd, &m_ps); } + + private: + HWND m_hWnd; + PAINTSTRUCT m_ps; + }; + + class CWindowDC : public CDC + { + public: + CWindowDC(const CWnd* pWnd) + { + if (pWnd) assert(pWnd->IsWindow()); + HWND hWnd = pWnd? pWnd->GetHwnd() : GetDesktopWindow(); + Attach(::GetWindowDC(hWnd), hWnd); + } + virtual ~CWindowDC() {} + }; + +#ifndef _WIN32_WCE + class CMetaFileDC : public CDC + { + public: + CMetaFileDC() : m_hMF(0), m_hEMF(0) {} + virtual ~CMetaFileDC() + { + if (m_hMF) + { + ::CloseMetaFile(GetHDC()); + ::DeleteMetaFile(m_hMF); + } + if (m_hEMF) + { + ::CloseEnhMetaFile(GetHDC()); + ::DeleteEnhMetaFile(m_hEMF); + } + } + void Create(LPCTSTR lpszFilename = NULL) { Attach(::CreateMetaFile(lpszFilename)); } + void CreateEnhanced(CDC* pDCRef, LPCTSTR lpszFileName, LPCRECT lpBounds, LPCTSTR lpszDescription) + { + HDC hDC = pDCRef? pDCRef->GetHDC() : NULL; + ::CreateEnhMetaFile(hDC, lpszFileName, lpBounds, lpszDescription); + assert(GetHDC()); + } + HMETAFILE Close() { return ::CloseMetaFile(GetHDC()); } + HENHMETAFILE CloseEnhanced() { return ::CloseEnhMetaFile(GetHDC()); } + + private: + HMETAFILE m_hMF; + HENHMETAFILE m_hEMF; + }; +#endif + + + /////////////////////////////////////////////// + // Declarations for the CBitmapInfoPtr class + // The CBitmapInfoPtr class is a convienient wrapper for the BITMAPINFO structure. + class CBitmapInfoPtr + { + public: + CBitmapInfoPtr(CBitmap* pBitmap) + { + BITMAP bmSource = pBitmap->GetBitmapData(); + + // Convert the color format to a count of bits. + WORD cClrBits = (WORD)(bmSource.bmPlanes * bmSource.bmBitsPixel); + if (cClrBits == 1) cClrBits = 1; + else if (cClrBits <= 4) cClrBits = 4; + else if (cClrBits <= 8) cClrBits = 8; + else if (cClrBits <= 16) cClrBits = 16; + else if (cClrBits <= 24) cClrBits = 24; + else cClrBits = 32; + + // Allocate memory for the BITMAPINFO structure. + UINT uQuadSize = (cClrBits == 24)? 0 : sizeof(RGBQUAD) * (int)(1 << cClrBits); + m_bmi.assign(sizeof(BITMAPINFOHEADER) + uQuadSize, 0); + m_pbmiArray = (LPBITMAPINFO) &m_bmi[0]; + + m_pbmiArray->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + m_pbmiArray->bmiHeader.biHeight = bmSource.bmHeight; + m_pbmiArray->bmiHeader.biWidth = bmSource.bmWidth; + m_pbmiArray->bmiHeader.biPlanes = bmSource.bmPlanes; + m_pbmiArray->bmiHeader.biBitCount = bmSource.bmBitsPixel; + m_pbmiArray->bmiHeader.biCompression = BI_RGB; + if (cClrBits < 24) + m_pbmiArray->bmiHeader.biClrUsed = (1<<cClrBits); + } + LPBITMAPINFO get() const { return m_pbmiArray; } + operator LPBITMAPINFO() const { return m_pbmiArray; } + LPBITMAPINFO operator->() const { return m_pbmiArray; } + + private: + CBitmapInfoPtr(const CBitmapInfoPtr&); // Disable copy construction + CBitmapInfoPtr& operator = (const CBitmapInfoPtr&); // Disable assignment operator + LPBITMAPINFO m_pbmiArray; + std::vector<byte> m_bmi; + }; + + + CBitmap* FromHandle(HBITMAP hBitmap); + CBrush* FromHandle(HBRUSH hBrush); + CFont* FromHandle(HFONT hFont); + CPalette* FromHandle(HPALETTE hPalette); + CPen* FromHandle(HPEN hPen); + CRgn* FromHandle(HRGN hRgn); + +} + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +namespace Win32xx +{ + + /////////////////////////////////////////////// + // Declarations for the CGDIObject class + // + + inline CGDIObject::CGDIObject() + // Constructs the CGDIObject + { + m_pData = new DataMembers; + m_pData->hGDIObject = 0; + m_pData->Count = 1L; + m_pData->bRemoveObject = TRUE; + } + + inline CGDIObject::CGDIObject(const CGDIObject& rhs) + // Note: A copy of a CGDIObject is a clone of the original. + // Both objects manipulate the one HGDIOBJ. + { + m_pData = rhs.m_pData; + InterlockedIncrement(&m_pData->Count); + } + + inline CGDIObject::~CGDIObject() + // Deconstructs the CGDIObject + { + Release(); + } + + inline CGDIObject& CGDIObject::operator = ( const CGDIObject& rhs ) + // Note: A copy of a CGDIObject is a clone of the original. + // Both objects manipulate the one HGDIOBJ. + { + if (this != &rhs) + { + InterlockedIncrement(&rhs.m_pData->Count); + Release(); + m_pData = rhs.m_pData; + } + + return *this; + } + + inline void CGDIObject::operator = (HGDIOBJ hObject) + { + assert(m_pData); + assert (m_pData->hGDIObject == NULL); + m_pData->hGDIObject = hObject; + } + + inline void CGDIObject::AddToMap() + // Store the HDC and CDC pointer in the HDC map + { + assert( GetApp() ); + GetApp()->m_csMapLock.Lock(); + + assert(m_pData->hGDIObject); + assert(!GetApp()->GetCGDIObjectFromMap(m_pData->hGDIObject)); + + GetApp()->m_mapGDI.insert(std::make_pair(m_pData->hGDIObject, this)); + GetApp()->m_csMapLock.Release(); + } + + inline void CGDIObject::Attach(HGDIOBJ hObject) + // Attaches a GDI HANDLE to the CGDIObject. + // The HGDIOBJ will be automatically deleted when the destructor is called unless it is detached. + { + assert(m_pData); + + if (m_pData->hGDIObject != NULL && m_pData->hGDIObject != hObject) + { + ::DeleteObject(Detach()); + } + + CGDIObject* pObject = GetApp()->GetCGDIObjectFromMap(hObject); + if (pObject) + { + delete m_pData; + m_pData = pObject->m_pData; + InterlockedIncrement(&m_pData->Count); + } + else + { + m_pData->hGDIObject = hObject; + AddToMap(); + } + } + + inline HGDIOBJ CGDIObject::Detach() + // Detaches the HGDIOBJ from this object. + { + assert(m_pData); + assert(m_pData->hGDIObject); + + GetApp()->m_csMapLock.Lock(); + RemoveFromMap(); + HGDIOBJ hObject = m_pData->hGDIObject; + m_pData->hGDIObject = 0; + + if (m_pData->Count) + { + if (InterlockedDecrement(&m_pData->Count) == 0) + { + delete m_pData; + } + } + + GetApp()->m_csMapLock.Release(); + + // Assign values to our data members + m_pData = new DataMembers; + m_pData->hGDIObject = 0; + m_pData->Count = 1L; + m_pData->bRemoveObject = TRUE; + + return hObject; + } + + inline HGDIOBJ CGDIObject::GetHandle() const + { + assert(m_pData); + return m_pData->hGDIObject; + } + + inline int CGDIObject::GetObject(int nCount, LPVOID pObject) const + { + assert(m_pData); + return ::GetObject(m_pData->hGDIObject, nCount, pObject); + } + + inline void CGDIObject::Release() + { + assert(m_pData); + BOOL bSucceeded = TRUE; + + if (InterlockedDecrement(&m_pData->Count) == 0) + { + if (m_pData->hGDIObject != NULL) + { + if (m_pData->bRemoveObject) + bSucceeded = ::DeleteObject(m_pData->hGDIObject); + else + bSucceeded = TRUE; + } + + RemoveFromMap(); + delete m_pData; + m_pData = 0; + } + + assert(bSucceeded); + } + + inline BOOL CGDIObject::RemoveFromMap() + { + BOOL Success = FALSE; + + if( GetApp() ) + { + // Allocate an iterator for our HDC map + std::map<HGDIOBJ, CGDIObject*, CompareGDI>::iterator m; + + CWinApp* pApp = GetApp(); + if (pApp) + { + // Erase the CGDIObject pointer entry from the map + pApp->m_csMapLock.Lock(); + m = pApp->m_mapGDI.find(m_pData->hGDIObject); + if (m != pApp->m_mapGDI.end()) + { + pApp->m_mapGDI. |
