home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / OWLSRC.PAK / PEN.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.2 KB  |  120 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.5  $
  6. //
  7. // Implementation of TPen, an encapsulation of the GDI Pen object
  8. //----------------------------------------------------------------------------
  9. #include <owl/pch.h>
  10. #if !defined(OWL_GDIOBJEC_H)
  11. # include <owl/gdiobjec.h>
  12. #endif
  13.  
  14. OWL_DIAGINFO;
  15. DIAG_DECLARE_GROUP(OwlGDI);        // General GDI diagnostic group
  16. DIAG_DECLARE_GROUP(OwlGDIOrphan);  // Orphan control tracing group
  17.  
  18. //
  19. // Constructors
  20. //
  21.  
  22. //
  23. // Alias an existing pen handle. Assume ownership if autoDelete says so
  24. //
  25. TPen::TPen(HPEN handle, TAutoDelete autoDelete)
  26. :
  27.   TGdiObject(handle, autoDelete)
  28. {
  29.     if (ShouldDelete)
  30.       RefAdd(Handle, Pen);
  31. }
  32.  
  33. //
  34. // Basic pen constructor.
  35. // Detect constructions of stock pens & get stock objects instead
  36. //
  37. TPen::TPen(const TColor& color, int width, int style)
  38. {
  39.   if (width == 1 && style == PS_SOLID &&
  40.      (color == TColor::Black || color == TColor::White)) {
  41.     if (color == TColor::Black)
  42.       Handle = ::GetStockObject(BLACK_PEN);
  43.     else
  44.       Handle = ::GetStockObject(WHITE_PEN);
  45.     ShouldDelete = false;
  46.     return;
  47.   }
  48.   Handle = ::CreatePen(style, width, color);
  49.   WARNX(OwlGDI, !Handle, 0, "Cannot create TPen (" << color << " " << width <<
  50.         " " << style << ")");
  51.   CheckValid();
  52.   RefAdd(Handle, Pen);
  53. }
  54.  
  55. //
  56. // Construct a TPen given a logical pen object
  57. //
  58. TPen::TPen(const LOGPEN far* logPen)
  59. {
  60.   PRECONDITION(logPen);
  61.   Handle = ::CreatePenIndirect((LPLOGPEN)logPen);
  62.   WARNX(OwlGDI, !Handle, 0, "Cannot create TPen from logPen @" <<
  63.         hex << uint32(LPVOID(logPen)));
  64.   CheckValid();
  65.   RefAdd(Handle, Pen);
  66. }
  67.  
  68. //
  69. // Construct a copy of an existing pen. Contructed pen will share the handle
  70. // unless NO_GDI_SHARE_HANDLES is defined, in which case a new handle is
  71. // created
  72. //
  73. TPen::TPen(const TPen& src)
  74. {
  75. #if !defined(NO_GDI_SHARE_HANDLES)
  76.   Handle = src.Handle;
  77.   RefAdd(Handle, Pen);
  78. #else
  79.   LOGPEN logPen;
  80.  
  81.   src.GetObject(logPen);
  82.   Handle = ::CreatePenIndirect(&logPen);
  83.   WARNX(OwlGDI, !Handle, 0, "Cannot create TPen from TPen @" <<
  84.         hex << uint32(LPVOID(&src)));
  85.   CheckValid();
  86.   RefAdd(Handle, Pen);
  87. #endif
  88. }
  89.  
  90. #if defined(BI_PLAT_WIN32)
  91. //
  92. // Construct a Win32 type pen
  93. //
  94. TPen::TPen(uint32 penStyle, uint32 width, const TBrush& brush,
  95.            uint32 styleCount, uint32* style)
  96. {
  97.   LOGBRUSH logBrush;
  98.   brush.GetObject(logBrush);
  99.   Handle = ::ExtCreatePen(penStyle, width, &logBrush, styleCount, style);
  100.   WARNX(OwlGDI, !Handle, 0, "Cannot create TPen from brush " << hex <<
  101.         uint(HBRUSH(brush)));
  102.   CheckValid();
  103.   RefAdd(Handle, Pen);
  104. }
  105.  
  106. //
  107. // Construct a Win32 type pen
  108. //
  109. TPen::TPen(uint32 penStyle, uint32 width, const LOGBRUSH& logBrush,
  110.            uint32 styleCount, uint32* style)
  111. {
  112.   Handle = ::ExtCreatePen(penStyle, width, (LPLOGBRUSH)&logBrush, styleCount,
  113.                           style);
  114.   WARNX(OwlGDI, !Handle, 0, "Cannot create TPen from logBrush @" <<
  115.         hex << uint32(LPVOID(&logBrush)));
  116.   CheckValid();
  117.   RefAdd(Handle, Pen);
  118. }
  119. #endif
  120.