The TGdiObject base class is designed as a reference-counted encapsulation around a GDI handle (e.g. HPEN, HBRUSH, HFONT, HPALETTE and HBITMAP). In effect, it works like a smart pointer. Many objects can be made, all encapsulating the same handle, i.e. the same underlying object. Copying a TGdiObject instance does not copy the underlying object pointed to by the handle. It merely copies the handle and keeps track of reference counts.
However, the derived classes (TPen, TBrush, TFont, TPalette and TBitmap) are not consistent in their copy semantics. In particular, TPalette and TBitmap implement deep copy in their copy constructors, as if these classes encapsulated the object, not just the handle. In short, they do not behave like smart pointers, as intended by the TGdiObject base class design.
I propose changing this in OWLNext, even though it is a major breaking change. The deep copying should be moved to a named member functions (e.g. DeepCopy), and the copy constructors should behave consistently like smart pointers. I also propose implementing move constructors, to eliminate superfluous and inefficient reference count updates.
However, I will implement this only in Owlet, then wait for feedback and any interest, before thinking about merging it into OWLNext 7. Let me know what you think.
Discussion: Selecting and restoring objects in TDC
Feature Requests: #178
This issue was fixed as proposed in Owlet in [r5430].
This revision also adds move constructors.
Related
Commit: [r5430]