OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
cursor.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1992, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of TCursor, a GDI Cursor object class
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9
10#include <owl/module.h>
11
12#include <owl/gdiobjec.h>
13
14namespace owl {
15
17DIAG_DECLARE_GROUP(OwlGDI); // General GDI diagnostic group
18
19//
20/// Creates a TCursor object and sets the Handle data member to the given borrowed
21/// handle. The ShouldDelete data member defaults to false, ensuring that the
22/// borrowed handle will not be deleted when the C++ object is destroyed.
23//
25:
27{
28 TRACEX(OwlGDI, OWL_CDLEVEL, "TCursor constructed @" << (void*)this <<
29 " from handle " << static_cast<void*>(handle));
30}
31
32//
33/// Creates a copy of the given cursor object. The 32bit version (for compiling a
34/// Win32 application) uses CopyIcon() and does a cast to get to HICON.
35//
37{
38 Handle = reinterpret_cast<HCURSOR>(::CopyIcon(reinterpret_cast<HICON>(static_cast<HCURSOR>(cursor))));
39 CheckValid();
40 TRACEX(OwlGDI, OWL_CDLEVEL, "TCursor @" << (void*)this <<
41 " copied from TCursor " << (void*)&cursor);
42}
43
44//
45/// Constructs a cursor object from the specified resource ID.
46//
48{
50 Handle = ::LoadCursor(instance, resId);
51 if(!Handle && instance != GetGlobalModule().GetHandle()){ // default load from OWL DLL
54 }
55 ShouldDelete = (instance != nullptr);
56 CheckValid();
57 TRACEX(OwlGDI, OWL_CDLEVEL, "TCursor @" << (void*)this <<
58 " loaded from resource " << resId);
59}
60
61//
62/// Constructs a TCursor object of the specified size at the specified point.
63//
65 void * andBits, void * xorBits)
66{
68 Handle = ::CreateCursor(instance, hotSpot.x, hotSpot.y, size.cx, size.cy,
70 CheckValid();
71 TRACEX(OwlGDI, OWL_CDLEVEL, "TCursor @" << (void*)this << " created from bits ");
72}
73
74//
75/// Constructs a TCursor object from the specified resource.
76//
78{
80 Handle = ::CreateIconFromResource(reinterpret_cast<PBYTE>(const_cast<void*>(resBits)), resSize, false, 0x00030000);
81 CheckValid();
82 TRACEX(OwlGDI, OWL_CDLEVEL, "TCursor @" << (void*)this <<
83 " created from bits (32)");
84}
85
86//
87/// Creates a TCursor object from the specified ICONINFO structure information.
88//
90{
91 WARN(iconInfo.fIcon, "TCursor constructor called with ICONINFO::fIcon == true"); // Turn this into a precondition?
92 ICONINFO i = iconInfo; // Make a clone, since CreateIconIndirect is not const-correct.
94 CheckValid();
95 TRACEX(OwlGDI, OWL_CDLEVEL, "TCursor constructed indirectly @" << static_cast<void*>(this));
96}
97
98#if defined(OWL5_COMPAT)
99
100//
101/// Creates a TCursor object from the specified ICONINFO structure information.
102/// This overload is deprecated. Use the overload that takes a reference instead.
103//
105{
107 //iconInfo->fIcon = false;
109 CheckValid();
110 TRACEX(OwlGDI, OWL_CDLEVEL, "TCursor constructed indirectly @" << (void*)this);
111}
112
113#endif
114
115//
116/// Destroys a TCursor object.
117//
119{
120 if (ShouldDelete && Handle)
121 ::DestroyCursor(static_cast<HCURSOR>(Handle));
122 TRACEX(OwlGDI, OWL_CDLEVEL, "TCursor destructed @" << (void*)this);
123}
124
125//
126/// Retrieves information about this cursor.
127/// Throws TXGdi on failure.
128//
129auto TCursor::GetInfo() const -> TInfo
130{
131 auto i = GetIconInfoEx();
132 CHECK(i.fIcon == FALSE);
133 i.szModName[MAX_PATH - 1] = _T('\0'); // Ensure termination.
134 i.szResName[MAX_PATH - 1] = _T('\0'); // Ensure termination.
135 return TInfo
136 {
137 TPoint{static_cast<int>(i.xHotspot), static_cast<int>(i.yHotspot)},
138 TBitmap{i.hbmMask, AutoDelete}, // Takes ownership.
139 TBitmap{i.hbmColor, AutoDelete}, // Takes ownership.
140 i.wResID,
141 tstring{&i.szModName[0]},
142 tstring{&i.szResName[0]}
143 };
144}
145
146//
147/// Retrieves information about this cursor.
148/// Wrapper for the Windows API function of the same name. Throws TXGdi on failure.
149///
150/// \note GetIconInfo creates bitmaps for the hbmMask and hbmColor members of ICONINFO. The calling
151/// application must manage these bitmaps and delete them when they are no longer necessary (using
152/// the Windows API function ::DeleteObject explicitly, or by passing ownership of the handles to
153/// TBitmap with the parameter `autoDelete` set to TAutoDelete::AutoDelete).
154///
155/// \sa http://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-geticoninfo
156//
158{
159 auto i = ICONINFO{};
160 const auto r = ::GetIconInfo(GetHandle(), &i);
161 if (!r || i.fIcon != FALSE) throw TXGdi(IDS_GDIFAILURE, GetHandle());
162 return i;
163}
164
165//
166/// Retrieves information about this cursor.
167/// Wrapper for the Windows API function of the same name. Throws TXGdi on failure.
168///
169/// \note GetIconInfoEx creates bitmaps for the hbmMask and hbmColor members of ICONINFOEX. The calling
170/// application must manage these bitmaps and delete them when they are no longer necessary (using
171/// the Windows API function ::DeleteObject explicitly, or by passing ownership of the handles to
172/// TBitmap with the parameter `autoDelete` set to TAutoDelete::AutoDelete).
173///
174/// \sa http://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-geticoninfoexa
175//
177{
178 auto i = ICONINFOEX{sizeof(ICONINFOEX)};
179 const auto r = ::GetIconInfoEx(GetHandle(), &i);
180 if (!r || i.fIcon != FALSE) throw TXGdi(IDS_GDIFAILURE, GetHandle());
181 return i;
182}
183
184} // OWL namespace
185/* ========================================================================== */
#define CHECK(condition)
Definition checks.h:239
#define WARN(condition, message)
Definition checks.h:273
#define PRECONDITION(condition)
Definition checks.h:227
#define DIAG_DECLARE_GROUP(group)
Definition checks.h:404
#define TRACEX(group, level, message)
Definition checks.h:263
TBitmap is the GDI bitmap class derived from TGdiObject.
Definition gdiobjec.h:510
TCursor, derived from TGdiBase, represents the GDI cursor object class.
Definition gdiobjec.h:730
auto GetInfo() const -> TInfo
Retrieves information about this cursor.
Definition cursor.cpp:129
TCursor(HCURSOR handle, TAutoDelete autoDelete=NoAutoDelete)
Creates a TCursor object and sets the Handle data member to the given borrowed handle.
Definition cursor.cpp:24
HCURSOR GetHandle() const
Returns the handle of the cursor with type HCURSOR.
Definition gdiobjec.h:1623
auto GetIconInfoEx() const -> ICONINFOEX
Retrieves information about this cursor.
Definition cursor.cpp:176
auto GetIconInfo() const -> ICONINFO
Retrieves information about this cursor.
Definition cursor.cpp:157
~TCursor()
Destroys a TCursor object.
Definition cursor.cpp:118
Root and abstract class for Windows object wrappers.
Definition gdibase.h:79
void CheckValid(uint resId=IDS_GDIFAILURE)
Definition gdibase.cpp:49
bool ShouldDelete
Should object delete GDI handle in dtor?
Definition gdibase.h:82
HANDLE Handle
GDI handle of this object.
Definition gdibase.h:81
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
The tagSIZE struct is defined as.
Definition geometry.h:234
Describes an exception resulting from GDI failures such as creating too many TWindow device contexts ...
Definition gdibase.h:52
#define MAX_PATH
Definition cygwin.h:98
#define _T(x)
Definition cygwin.h:51
Definition of abstract GDI object class and derived classes.
TAutoDelete
Flag for Handle ctors to control Handle deletion in dtor.
Definition gdibase.h:70
@ AutoDelete
Definition gdibase.h:70
THandle GetHandle() const
Return the instance handle of the library module represented by the TModule obect.
Definition module.h:1233
HCURSOR LoadCursor(TResId id) const
Wrapper for the Windows API.
Definition module.cpp:892
Definition of class TModule.
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
unsigned long uint32
Definition number.h:34
OWL_DIAGINFO
Definition animctrl.cpp:14
std::string tstring
Definition defs.h:79
TModule & GetGlobalModule()
Definition global.cpp:48
#define OWL_CDLEVEL
Definition defs.h:171