home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / owlsrc.pak / PEN.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-24  |  2.6 KB  |  93 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // (C) Copyright 1992, 1994 by Borland International, All Rights Reserved
  4. //
  5. //   Implementation for GDI Pen object
  6. //----------------------------------------------------------------------------
  7. #include <owl/owlpch.h>
  8. #include <owl/gdiobjec.h>
  9.  
  10. DIAG_DECLARE_GROUP(OwlGDI);        // General GDI diagnostic group
  11. DIAG_DECLARE_GROUP(OwlGDIOrphan);  // Orphan control tracing group
  12.  
  13. //
  14. // Constructors
  15. //
  16. TPen::TPen(HPEN handle, TAutoDelete autoDelete)
  17. :
  18.   TGdiObject(handle, autoDelete)
  19. {
  20.   #if !defined(NO_GDI_ORPHAN_CONTROL)
  21.     if (ShouldDelete)
  22.       OBJ_REF_ADD(Handle, Pen);
  23.   #endif
  24. }
  25.  
  26. //
  27. // detect constructions of stock pens & get stock objects instead
  28. //
  29. TPen::TPen(TColor color, int width, int style)
  30. {
  31.   if (width == 1 && style == PS_SOLID &&
  32.      (color == TColor::Black || color == TColor::White)) {
  33.     if (color == TColor::Black)
  34.       Handle = ::GetStockObject(BLACK_PEN);
  35.     else
  36.       Handle = ::GetStockObject(WHITE_PEN);
  37.     ShouldDelete = false;
  38.     return;
  39.   }
  40.   Handle = ::CreatePen(style, width, color);
  41.   WARNX(OwlGDI, !Handle, 0, "Cannot create TPen (" << color << " " << width <<
  42.         " " << style << ")");
  43.   CheckValid();
  44.   OBJ_REF_ADD(Handle, Pen);
  45. }
  46.  
  47. TPen::TPen(const LOGPEN far* logPen)
  48. {
  49.   PRECONDITION(logPen);
  50.   Handle = ::CreatePenIndirect((LPLOGPEN)logPen);
  51.   WARNX(OwlGDI, !Handle, 0, "Cannot create TPen from logPen @" <<
  52.         hex << uint32(LPVOID(logPen)));
  53.   CheckValid();
  54.   OBJ_REF_ADD(Handle, Pen);
  55. }
  56.  
  57. TPen::TPen(const TPen& src)
  58. {
  59.   LOGPEN logPen;
  60.  
  61.   src.GetObject(logPen);
  62.   Handle = ::CreatePenIndirect(&logPen);
  63.   WARNX(OwlGDI, !Handle, 0, "Cannot create TPen from TPen @" <<
  64.         hex << uint32(LPVOID(&src)));
  65.   CheckValid();
  66.   OBJ_REF_ADD(Handle, Pen);
  67. }
  68.  
  69. #if defined(BI_PLAT_WIN32)
  70. TPen::TPen(uint32 penStyle, uint32 width, const TBrush& brush,
  71.            uint32 styleCount, uint32* style)
  72. {
  73.   LOGBRUSH logBrush;
  74.   brush.GetObject(logBrush);
  75.   Handle = ::ExtCreatePen(penStyle, width, &logBrush, styleCount, style);
  76.   WARNX(OwlGDI, !Handle, 0, "Cannot create TPen from brush " << hex << 
  77.         uint(HBRUSH(brush)));
  78.   CheckValid();
  79.   OBJ_REF_ADD(Handle, Pen);
  80. }
  81.  
  82. TPen::TPen(uint32 penStyle, uint32 width, const LOGBRUSH& logBrush,
  83.            uint32 styleCount, uint32* style)
  84. {
  85.   Handle = ::ExtCreatePen(penStyle, width, (LPLOGBRUSH)&logBrush, styleCount,
  86.                           style);
  87.   WARNX(OwlGDI, !Handle, 0, "Cannot create TPen from logBrush @" <<
  88.         hex << uint32(LPVOID(&logBrush)));
  89.   CheckValid();
  90.   OBJ_REF_ADD(Handle, Pen);
  91. }
  92. #endif
  93.