13#if defined(BI_MULTI_THREAD_RTL)
40 TObjInfo() : Handle(nullptr), Type(
TGdiObject::None), RefCount(0)
42 TObjInfo(HANDLE handle) : Handle(handle)
45 : Handle(handle), Type(type), RefCount(ref)
49 bool operator ==(
const TObjInfo& other)
const {
50 return other.Handle == Handle;
52 bool operator <(
const TObjInfo& other)
const {
53 return other.Handle < Handle;
60#if defined(BI_MULTI_THREAD_RTL)
64#if defined(BI_MULTI_THREAD_RTL)
65#define LOCKOBJECTBAG(s) TMRSWSection::TLock __lock(*__ObjInfoBagLock,s)
67#define LOCKOBJECTBAG(s)
73static const LPCTSTR ObjTypeStr[] = {
74 _T(
"?"),
_T(
"Pen"),
_T(
"Brush"),
_T(
"Font"),
_T(
"Palette"),
75 _T(
"Bitmap"),
_T(
"TextBrush"), 0
80static void createObjInfoBag()
82 static LONG createObjInfo = -1;
86 if(::InterlockedIncrement(&createObjInfo)==0){
87 ::InterlockedIncrement(&createObjInfo);
89#if defined(BI_MULTI_THREAD_RTL)
96static void destroyObjInfoBag()
98 static LONG destroyObjInfo = -1;
99 if(__ObjInfoBag==
nullptr || __ObjInfoBag->Size()>0)
102 if(::InterlockedIncrement(&destroyObjInfo)==0){
103 ::InterlockedIncrement(&destroyObjInfo);
105#if defined(BI_MULTI_THREAD_RTL)
106 delete __ObjInfoBagLock;
108 __ObjInfoBag =
nullptr;
121 if (handle && __ObjInfoBag)
124 const auto pos = __ObjInfoBag->Find(TObjInfo(handle));
125 if (pos != __ObjInfoBag->NPOS)
126 return &((*__ObjInfoBag)[pos]);
140#if !defined(NO_GDI_SHARE_HANDLES)
142 TObjInfo* member =
RefFind(handle);
147 __ObjInfoBag->Add(TObjInfo(handle, type, 1));
151 if (handle && !
RefFind(handle)){
153 __ObjInfoBag->Add(TObjInfo(handle, type, 1));
169 __ObjInfoBag->DestroyItem(TObjInfo(handle));
181 TObjInfo* member =
RefFind(handle);
205 TObjInfo* member =
RefFind(handle);
207 bool needDelete = --(member->RefCount) == 0;
209 if (needDelete != wantDelete) {
211 TRACEX(OwlGDIOrphan, 1,
"Orphan" << ObjTypeStr[member->Type] <<
212 static_cast<void*
>(member->Handle) <<
"Deleted");
215 TRACEX(OwlGDIOrphan, 1, ObjTypeStr[member->Type] <<
216 static_cast<void*
>(member->Handle) <<
"Orphan");
222 if (!::DeleteObject(member->Handle))
230 __ObjInfoBag->DestroyItem(*member);
244 TObjInfo* member =
RefFind(handle);
246 return member->RefCount;
257#if defined(__TRACE) || defined(__WARN)
260 os <<
"@" << (
void*)&gdiObject <<
" ";
262 os <<
typeid(gdiObject).name() <<
',';
276 TRACEX(OwlGDI, 2,
"TGdiObject constructed " << *
this);
292 TRACEX(OwlGDI, 2,
"TGdiObject constructed " << *
this);
305 TRACEX(OwlGDI, 2,
"TGdiObject destructed " << *
this);
#define TRACEX(group, level, message)
TGdiBase()
This default constructor sets Handle to 0 and ShouldDelete to true.
GdiObject is the root, pseudo-abstract base class for ObjectWindows' GDI (Graphics Device Interface) ...
static void RefInc(HANDLE handle)
Increments by 1 the reference count of the object associated with the given handle.
static TObjInfo * RefFind(HANDLE object)
Searches for the given object handle.
~TGdiObject()
Decrement the reference count on this object.
static void RefDec(HANDLE handle, bool wantDelete)
Decrements this object's reference count by 1 and deletes the object when the reference count reaches...
TType
This enumeration is used to store the object type in the struct TObjInfo.
static void RefRemove(HANDLE handle)
Removes the reference entry to the object with the given handle.
static int RefCount(HANDLE handle)
Returns this object's current reference count or -1 if the object is not found.
bool ShouldDelete
Should object delete GDI handle in dtor?
static void RefAdd(HANDLE handle, TType type)
RefAdd adds a reference entry for the object with the given handle and type.
TGdiObject()
This default constructor sets Handle to 0 and ShouldDelete to true.
HANDLE Handle
GDI handle of this object.
Multiple Read, Single Write section.
static void Raise(uint resId=IDS_GDIFAILURE, HANDLE handle=0)
Throws the exception.
Definition of abstract GDI object class and derived classes.
TAutoDelete
Flag for Handle ctors to control Handle deletion in dtor.
Object Windows Library (OWLNext Core).
owl::opstream & operator<<(owl::opstream &os, const TColor &c)
Insert the color value into a persistent output stream.
TSortedObjectArray< TObjInfo > TObjInfoBag
void InUse(const T &arg)
Handy utility to avoid compiler warnings about unused parameters.
DIAG_DEFINE_GROUP_INIT(OWL_INI, OwlApp, 1, 0)
Definition of container classes used and made available by OWL.