aboutsummaryrefslogtreecommitdiffstats
path: root/fake-w32-gdi.h
blob: bcc2fa9e391a25b2197c44cf3f98c4e4ad0c26e0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/* See LICENSE file for copyright and license details. */
#ifndef LIBGAMMA_FAKE_W32_GDI_H
#define LIBGAMMA_FAKE_W32_GDI_H

#ifndef FAKE_LIBGAMMA_METHOD_W32_GDI
# error Including fake-w32-gdi.h without FAKE_LIBGAMMA_METHOD_W32_GDI
#endif


#ifndef __GNUC__
# define __attribute__(x)
#endif

#include <stdint.h>


/**
 * One of the Windows `typedef`:s for unsigned 16-bit integer
 * This is the one used in these functions
 * 
 * @see  http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx#WORD
 */
typedef uint16_t WORD;

/**
 * One of the Windows `typedef`:s for unsigned 32-bit integer
 * This is the one used in these functions
 * 
 * @see  http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx#DWORD
 */
typedef uint32_t DWORD;

/**
 * One of the Windows `typedef` for booleanic values, the `int` variant
 * 
 * @see  http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx#BOOL
 */
typedef int BOOL;

/**
 * Windows `typedef` for a device context (the 'h' stands for 'handle')
 * 
 * @see  http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx#HDC
 */
typedef void *HDC;

/**
 * Windows `typedef` for a window (the 'h' stands for 'handle')
 * 
 * @see  http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx#HWND
 */
typedef void *HWND;

/**
 * One of the Windows `typedef`:s for `void *`, a generic pointer
 * 
 * @see  http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx#LPVOID
 */
typedef void *LPVOID;

/**
 * A silly Windows `typedef` for a `const char *`, a constant string
 * 
 * It is also defined as NUL-terminated, but so are all C-strings
 * and it makes no difference. However if `UNICODE` were to be defined
 * it would be `const wchar_t *`.
 * 
 * @see  http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx#LPCTSTR
 */
typedef const char *LPCTSTR;

/**
 * Even more silly. A Windows `typedef` for either `wchar_t` or
 * `char`, depending on whether `UNICODE` is defined (we will
 * assume `UNICODE` is not definied because that is just silly)
 * 
 * @see  http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx#TCHAR
 */
typedef char TCHAR;

/**
 * Apperently we need `TRUE` to be defined to understand code,
 * at least in Windows...
 * 
 * @see  http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx#BOOL
 */
#define TRUE 1

/**
 * Apperently we need `FALSE` to be defined to understand code,
 * at least in Windows...
 * 
 * @see  http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx#BOOL
 */
#define FALSE 0



/**
 * Get the device context for a window or the entire screen
 * 
 * @param   hWnd  The window, `NULL` for the entire screen
 * @return        The device context
 * @see           http://msdn.microsoft.com/en-us/library/windows/desktop/dd144871(v=vs.85).aspx
 */
HDC GetDC(HWND);

/**
 * Free a device context
 * 
 * @param   hWnd  The window whose device context is `hDC`, `NULL` for the entire screen
 * @param   hDC   The device context to free
 * @return        Whether the call was successful
 * @see           http://msdn.microsoft.com/en-us/library/windows/desktop/dd162920(v=vs.85).aspx
 */
int ReleaseDC(HWND, HDC);


/**
 * Get information (capabilities) for a device context
 * 
 * @param   hDC     The device context
 * @param   nIndex  The information to retrieve, may be `COLORMGMTCAPS`
 * @return          The details of the queried information, can return `CM_GAMMA_RAMP`
 *                  if `nIndex` is `COLORMGMTCAPS`
 * @see             http://msdn.microsoft.com/en-us/library/windows/desktop/dd144877(v=vs.85).aspx
 */
int GetDeviceCaps(HDC, int) __attribute__((const));

/**
 * Colour management capabilities
 * 
 * @see  http://msdn.microsoft.com/en-us/library/windows/desktop/dd144877(v=vs.85).aspx
 */
#define COLORMGMTCAPS 1

/**
 * Colour management capabilities: has gamma ramps
 * 
 * @see  http://msdn.microsoft.com/en-us/library/windows/desktop/dd144877(v=vs.85).aspx
 */
#define CM_GAMMA_RAMP 1


/**
 * Set the gamma ramps for a device
 * 
 * @param   hDC     The device context
 * @param   lpRamp  The gamma ramps joined in the order: red, green, blue;
 *                  this is a `WORD *` casted to `void *`
 * @return          Whether the call was successful
 * @see             http://msdn.microsoft.com/en-us/library/windows/desktop/dd372194(v=vs.85).aspx
 */
BOOL SetDeviceGammaRamp(HDC, LPVOID restrict);

/**
 * Get the current gamma ramps for a device
 * 
 * @param   hDC     The device context
 * @param   lpRamp  The output for the gamma ramps joined in the order: red, green, blue
 *                  This is a `WORD *` casted to `void *`
 * @return          Whether the call was successful
 * @see             http://msdn.microsoft.com/en-us/library/windows/desktop/dd316946(v=vs.85).aspx
 */
BOOL GetDeviceGammaRamp(HDC, LPVOID restrict);


/**
 * Get the context for a device
 * 
 * @param   lpszDriver  The driver or a display device, use "DISPLAY" if you want a display
 * @param   lpszDevice  The name of the device. If you want a display use can use the member
 *                      name `DeviceName` in the third parameter, an output parameter, of
 *                      `EnumDisplayDevices`.
 * @param   lpszOutput  We will always use `NULL` here
 * @param   lpInitData  We will always use `NULL` here; this should actually by a `const DEVMODE *`
 * @return              The context for the device
 * @see                 http://msdn.microsoft.com/en-us/library/windows/desktop/dd183490(v=vs.85).aspx
 */
HDC CreateDC(LPCTSTR restrict, LPCTSTR restrict, LPCTSTR restrict, const void *restrict);

/**
 * This macro does not seem to have an official documentation that is correct
 * 
 * @see  http://msdn.microsoft.com/en-us/library/windows/desktop/dd183490(v=vs.85).aspx
 * @see  http://msdn.microsoft.com/en-us/library/windows/desktop/dd374074(v=vs.85).aspx
 */
#define TEXT(X) ((LPCTSTR)(X))


/**
 * Information about a display device
 * 
 * @see  http://msdn.microsoft.com/en-us/library/windows/desktop/dd183569(v=vs.85).aspx
 */
typedef struct {
	/**
	 * Set this to `sizeof(DISPLAY_DEVICE)`
	 */
	DWORD cb;

	/**
	 * The name of the device
	 */
	TCHAR DeviceName[32];

	/**
	 * The status of the device, can include `DISPLAY_DEVICE_ACTIVE`
	 */
	DWORD StateFlags;

} DISPLAY_DEVICE;

/**
 * Appearently we are incapable of putting asterisks at the
 * end of types names, so istead we preprend them with 'P'
 * 
 * @see  http://msdn.microsoft.com/en-us/library/windows/desktop/dd183569(v=vs.85).aspx
 */
typedef DISPLAY_DEVICE *PDISPLAY_DEVICE;

/**
 * The monitor is "on"
 * 
 * @see  http://msdn.microsoft.com/en-us/library/windows/desktop/dd183569(v=vs.85).aspx
 */
#define DISPLAY_DEVICE_ACTIVE 1

/**
 * Get a display device by its name or index
 * 
 * @param   lpDevice         The name of the device, use `NULL` to base the call on `iDevNum` instead
 * @param   iDevNum          The index of the device
 * @param   lpDisplayDevice  Output for the found device
 * @param   dwFlags          Flags, we will always use zero
 * @return                   Whether the call was successful; zero is also returned if `iDevNum`
 *                           is greater than the largest device index on the system
 * @see                      http://msdn.microsoft.com/en-us/library/windows/desktop/dd162609(v=vs.85).aspx
 */
BOOL EnumDisplayDevices(LPCTSTR restrict, DWORD, PDISPLAY_DEVICE restrict, DWORD)



#ifndef __GNUC__
# undef __attribute__
#endif

#endif