]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/private.h
A couple more 'int' to UWORD conversions I had not merged into my previous checkin.
[wxWidgets.git] / include / wx / msw / private.h
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: private.h
a23fd0e1
VZ
3// Purpose: Private declarations: as this header is only included by
4// wxWindows itself, it may contain identifiers which don't start
5// with "wx".
2bda0e17
KB
6// Author: Julian Smart
7// Modified by:
8// Created: 01/02/97
9// RCS-ID: $Id$
bbcdf8bc 10// Copyright: (c) Julian Smart
c085e333 11// Licence: wxWindows licence
2bda0e17
KB
12/////////////////////////////////////////////////////////////////////////////
13
bbcdf8bc
JS
14#ifndef _WX_PRIVATE_H_
15#define _WX_PRIVATE_H_
2bda0e17 16
2bda0e17
KB
17#include <windows.h>
18
42e69d6b
VZ
19// undefine conflicting symbols which were defined in windows.h
20#include "wx/msw/winundef.h"
21
a23fd0e1 22class WXDLLEXPORT wxFont;
d427503c 23class WXDLLEXPORT wxWindow;
2bda0e17 24
42e69d6b
VZ
25// ---------------------------------------------------------------------------
26// private constants
27// ---------------------------------------------------------------------------
28
29// Conversion
30static const double METRIC_CONVERSION_CONSTANT = 0.0393700787;
31
32// Scaling factors for various unit conversions
33static const double mm2inches = (METRIC_CONVERSION_CONSTANT);
34static const double inches2mm = (1/METRIC_CONVERSION_CONSTANT);
35
36static const double mm2twips = (METRIC_CONVERSION_CONSTANT*1440);
37static const double twips2mm = (1/(METRIC_CONVERSION_CONSTANT*1440));
38
39static const double mm2pt = (METRIC_CONVERSION_CONSTANT*72);
40static const double pt2mm = (1/(METRIC_CONVERSION_CONSTANT*72));
41
a23fd0e1
VZ
42// ---------------------------------------------------------------------------
43// standard icons from the resources
44// ---------------------------------------------------------------------------
2bda0e17 45
b568d04f
VZ
46#if wxUSE_GUI
47
2bda0e17
KB
48WXDLLEXPORT_DATA(extern HICON) wxSTD_FRAME_ICON;
49WXDLLEXPORT_DATA(extern HICON) wxSTD_MDIPARENTFRAME_ICON;
50WXDLLEXPORT_DATA(extern HICON) wxSTD_MDICHILDFRAME_ICON;
51WXDLLEXPORT_DATA(extern HICON) wxDEFAULT_FRAME_ICON;
52WXDLLEXPORT_DATA(extern HICON) wxDEFAULT_MDIPARENTFRAME_ICON;
53WXDLLEXPORT_DATA(extern HICON) wxDEFAULT_MDICHILDFRAME_ICON;
54WXDLLEXPORT_DATA(extern HFONT) wxSTATUS_LINE_FONT;
55
b568d04f
VZ
56#endif // wxUSE_GUI
57
a23fd0e1 58// ---------------------------------------------------------------------------
11c7d5b6 59// define things missing from some compilers' headers
a23fd0e1 60// ---------------------------------------------------------------------------
c455ab93 61
b64f0a5f 62#if defined(__GNUWIN32__) && !wxUSE_NORLANDER_HEADERS
01dba85a 63#ifndef ZeroMemory
11c7d5b6 64 inline void ZeroMemory(void *buf, size_t len) { memset(buf, 0, len); }
01dba85a 65#endif
11c7d5b6
VZ
66#endif // old mingw32
67
68// this defines a CASTWNDPROC macro which casts a pointer to the type of a
69// window proc
62448488 70
f6bcfd97
BP
71#ifdef __GNUWIN32_OLD__
72 #define CASTWNDPROC (long unsigned)
c3b177ae 73#else
f6bcfd97
BP
74 #if defined(STRICT) || defined(__GNUC__)
75 typedef WNDPROC WndProcCast;
76 #else
77 typedef FARPROC WndProcCast;
78 #endif
79 #define CASTWNDPROC (WndProcCast)
80#endif // __GNUWIN32_OLD__
2bda0e17 81
a23fd0e1
VZ
82// ---------------------------------------------------------------------------
83// some stuff for old Windows versions (FIXME: what does it do here??)
84// ---------------------------------------------------------------------------
85
c085e333 86#if !defined(APIENTRY) // NT defines APIENTRY, 3.x not
a23fd0e1 87 #define APIENTRY FAR PASCAL
2bda0e17 88#endif
c085e333 89
2bda0e17 90#ifdef __WIN32__
a23fd0e1 91 #define _EXPORT
2bda0e17 92#else
a23fd0e1
VZ
93 #define _EXPORT _export
94#endif
95
96#ifndef __WIN32__
97 typedef signed short int SHORT;
2bda0e17 98#endif
c085e333
VZ
99
100#if !defined(__WIN32__) // 3.x uses FARPROC for dialogs
27a9bd48 101#ifndef STRICT
a23fd0e1 102 #define DLGPROC FARPROC
2bda0e17 103#endif
27a9bd48 104#endif
2bda0e17 105
47d67540 106#if wxUSE_PENWIN
cc2b7472
VZ
107 WXDLLEXPORT void wxRegisterPenWin();
108 WXDLLEXPORT void wxCleanUpPenWin();
109 WXDLLEXPORT void wxEnablePenAppHooks (bool hook);
110#endif // wxUSE_PENWIN
2bda0e17 111
47d67540 112#if wxUSE_ITSY_BITSY
a23fd0e1
VZ
113 #define IBS_HORZCAPTION 0x4000L
114 #define IBS_VERTCAPTION 0x8000L
2bda0e17 115
a23fd0e1
VZ
116 UINT WINAPI ibGetCaptionSize( HWND hWnd ) ;
117 UINT WINAPI ibSetCaptionSize( HWND hWnd, UINT nSize ) ;
118 LRESULT WINAPI ibDefWindowProc( HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam ) ;
119 VOID WINAPI ibAdjustWindowRect( HWND hWnd, LPRECT lprc ) ;
120#endif // wxUSE_ITSY_BITSY
2bda0e17 121
1f112209 122#if wxUSE_CTL3D
a23fd0e1
VZ
123 #include "wx/msw/ctl3d/ctl3d.h"
124#endif // wxUSE_CTL3D
2bda0e17
KB
125
126/*
127 * Decide what window classes we're going to use
128 * for this combination of CTl3D/FAFA settings
129 */
c085e333 130
223d09f6 131#define STATIC_CLASS wxT("STATIC")
2bda0e17 132#define STATIC_FLAGS (SS_LEFT|WS_CHILD|WS_VISIBLE)
223d09f6 133#define CHECK_CLASS wxT("BUTTON")
2bda0e17
KB
134#define CHECK_FLAGS (BS_AUTOCHECKBOX|WS_TABSTOP|WS_CHILD)
135#define CHECK_IS_FAFA FALSE
223d09f6 136#define RADIO_CLASS wxT("BUTTON")
2bda0e17
KB
137#define RADIO_FLAGS (BS_AUTORADIOBUTTON|WS_CHILD|WS_VISIBLE)
138#define RADIO_SIZE 20
139#define RADIO_IS_FAFA FALSE
140#define PURE_WINDOWS
223d09f6 141#define GROUP_CLASS wxT("BUTTON")
2bda0e17
KB
142#define GROUP_FLAGS (BS_GROUPBOX|WS_CHILD|WS_VISIBLE)
143
144/*
145#define BITCHECK_FLAGS (FB_BITMAP|FC_BUTTONDRAW|FC_DEFAULT|WS_VISIBLE)
146#define BITRADIO_FLAGS (FC_BUTTONDRAW|FB_BITMAP|FC_RADIO|WS_CHILD|WS_VISIBLE)
147*/
148
a23fd0e1
VZ
149// ---------------------------------------------------------------------------
150// misc macros
151// ---------------------------------------------------------------------------
152
2bda0e17 153#define MEANING_CHARACTER '0'
5d368213 154#define DEFAULT_ITEM_WIDTH 100
2bda0e17 155#define DEFAULT_ITEM_HEIGHT 80
1c4a764c
VZ
156
157// Scale font to get edit control height
f6bcfd97
BP
158//#define EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) (3*(cy)/2)
159#define EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) (cy+8)
2bda0e17
KB
160
161// Generic subclass proc, for panel item moving/sizing and intercept
162// EDIT control VK_RETURN messages
163extern LONG APIENTRY _EXPORT
164 wxSubclassedGenericControlProc(WXHWND hWnd, WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
165
a23fd0e1
VZ
166// ---------------------------------------------------------------------------
167// constants which might miss from some compilers' headers
168// ---------------------------------------------------------------------------
169
170#if !defined(__WIN32__) && !defined(WS_EX_CLIENTEDGE)
171 #define WS_EX_CLIENTEDGE 0
172#endif
173
174#if defined(__WIN32__) && !defined(WS_EX_CLIENTEDGE)
175 #define WS_EX_CLIENTEDGE 0x00000200L
176#endif
177
178#ifndef ENDSESSION_LOGOFF
179 #define ENDSESSION_LOGOFF 0x80000000
180#endif
181
11c7d5b6
VZ
182// ---------------------------------------------------------------------------
183// useful macros and functions
184// ---------------------------------------------------------------------------
185
186// a wrapper macro for ZeroMemory()
0e528b99 187#ifdef __WIN32__
11c7d5b6 188#define wxZeroMemory(obj) ::ZeroMemory(&obj, sizeof(obj))
0e528b99
JS
189#else
190#define wxZeroMemory(obj) memset((void*) & obj, 0, sizeof(obj))
191#endif
11c7d5b6 192
f6bcfd97
BP
193#if wxUSE_GUI
194
01dba85a
JS
195#include <wx/gdicmn.h>
196
11c7d5b6
VZ
197// make conversion from wxColour and COLORREF a bit less painful
198inline COLORREF wxColourToRGB(const wxColour& c)
199{
200 return RGB(c.Red(), c.Green(), c.Blue());
201}
202
203inline void wxRGBToColour(wxColour& c, COLORREF rgb)
204{
205 c.Set(GetRValue(rgb), GetGValue(rgb), GetBValue(rgb));
206}
207
ed791986
VZ
208// copy Windows RECT to our wxRect
209inline void wxCopyRECTToRect(const RECT& r, wxRect& rect)
210{
211 rect.y = r.top;
212 rect.x = r.left;
213 rect.width = r.right - r.left;
214 rect.height = r.bottom - r.top;
215}
216
d9317fd4
VZ
217// translations between HIMETRIC units (which OLE likes) and pixels (which are
218// liked by all the others) - implemented in msw/utilsexc.cpp
219extern void HIMETRICToPixel(LONG *x, LONG *y);
220extern void PixelToHIMETRIC(LONG *x, LONG *y);
221
4b7f2165
VZ
222// Windows convention of the mask is opposed to the wxWindows one, so we need
223// to invert the mask each time we pass one/get one to/from Windows
224extern HBITMAP wxInvertMask(HBITMAP hbmpMask, int w = 0, int h = 0);
225
8614c467
VZ
226// get (x, y) from DWORD - notice that HI/LOWORD can *not* be used because they
227// will fail on system with multiple monitors where the coords may be negative
228//
229// these macros are standard now (Win98) but some older headers don't have them
230#ifndef GET_X_LPARAM
231 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
232 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
233#endif // GET_X_LPARAM
234
a95e38c0 235// get the current state of SHIFT/CTRL keys
1f80a703 236inline bool wxIsShiftDown()
a95e38c0
VZ
237{
238 return (::GetKeyState(VK_SHIFT) & 0x100) != 0;
239}
240
1f80a703 241inline bool wxIsCtrlDown()
a95e38c0
VZ
242{
243 return (::GetKeyState(VK_CONTROL) & 0x100) != 0;
244}
245
6d167489
VZ
246// ---------------------------------------------------------------------------
247// small helper classes
248// ---------------------------------------------------------------------------
249
250// create an instance of this class and use it as the HDC for screen, will
251// automatically release the DC going out of scope
252class ScreenHDC
253{
254public:
255 ScreenHDC() { m_hdc = GetDC(NULL); }
256 ~ScreenHDC() { ReleaseDC(NULL, m_hdc); }
257 operator HDC() const { return m_hdc; }
258
259private:
260 HDC m_hdc;
261};
262
a23fd0e1 263// ---------------------------------------------------------------------------
42e69d6b 264// macros to make casting between WXFOO and FOO a bit easier: the GetFoo()
c50f1fb9
VZ
265// returns Foo cast to the Windows type for oruselves, while GetFooOf() takes
266// an argument which should be a pointer or reference to the object of the
267// corresponding class (this depends on the macro)
a23fd0e1
VZ
268// ---------------------------------------------------------------------------
269
270#define GetHwnd() ((HWND)GetHWND())
c50f1fb9
VZ
271#define GetHwndOf(win) ((HWND)((win)->GetHWND()))
272// old name
273#define GetWinHwnd GetHwndOf
a23fd0e1
VZ
274
275#define GetHdc() ((HDC)GetHDC())
c50f1fb9 276#define GetHdcOf(dc) ((HDC)(dc).GetHDC())
a23fd0e1 277
11c7d5b6
VZ
278#define GetHbitmap() ((HBITMAP)GetHBITMAP())
279#define GetHbitmapOf(bmp) ((HBITMAP)(bmp).GetHBITMAP())
280
42e69d6b 281#define GetHicon() ((HICON)GetHICON())
c50f1fb9 282#define GetHiconOf(icon) ((HICON)(icon).GetHICON())
42e69d6b 283
a23fd0e1 284#define GetHaccel() ((HACCEL)GetHACCEL())
c50f1fb9
VZ
285#define GetHaccelOf(table) ((HACCEL)((table).GetHACCEL()))
286
287#define GetHmenu() ((HMENU)GetHMenu())
288#define GetHmenuOf(menu) ((HMENU)menu->GetHMenu())
a23fd0e1 289
bfbd6dc1
VZ
290#define GetHcursor() ((HCURSOR)GetHCURSOR())
291#define GetHcursorOf(cursor) ((HCURSOR)(cursor).GetHCURSOR())
292
f6bcfd97
BP
293#define GetHfont() ((HFONT)GetHFONT())
294#define GetHfontOf(font) ((HFONT)(font).GetHFONT())
295
296#endif // wxUSE_GUI
297
a23fd0e1
VZ
298// ---------------------------------------------------------------------------
299// global data
300// ---------------------------------------------------------------------------
2bda0e17 301
621ae68a 302WXDLLEXPORT_DATA(extern wxChar*) wxBuffer;
b568d04f 303
2bda0e17
KB
304WXDLLEXPORT_DATA(extern HINSTANCE) wxhInstance;
305
a23fd0e1
VZ
306// ---------------------------------------------------------------------------
307// global functions
308// ---------------------------------------------------------------------------
309
18600546
GRG
310extern "C"
311{
b568d04f 312 WXDLLEXPORT HINSTANCE wxGetInstance();
18600546
GRG
313}
314
a23fd0e1
VZ
315WXDLLEXPORT void wxSetInstance(HINSTANCE hInst);
316
b568d04f
VZ
317#if wxUSE_GUI
318
bfbd6dc1
VZ
319// cursor stuff
320extern HCURSOR wxGetCurrentBusyCursor(); // from msw/utils.cpp
321extern const wxCursor *wxGetGlobalCursor(); // from msw/cursor.cpp
322
a23fd0e1
VZ
323WXDLLEXPORT wxWindow* wxFindWinFromHandle(WXHWND hWnd);
324
f68586e5 325WXDLLEXPORT void wxGetCharSize(WXHWND wnd, int *x, int *y, const wxFont *the_font);
11c7d5b6
VZ
326WXDLLEXPORT void wxFillLogFont(LOGFONT *logFont, const wxFont *font);
327WXDLLEXPORT wxFont wxCreateFontFromLogFont(const LOGFONT *logFont);
f6bcfd97 328WXDLLEXPORT wxFontEncoding wxGetFontEncFromCharSet(int charset);
a23fd0e1
VZ
329
330WXDLLEXPORT void wxSliderEvent(WXHWND control, WXWORD wParam, WXWORD pos);
331WXDLLEXPORT void wxScrollBarEvent(WXHWND hbar, WXWORD wParam, WXWORD pos);
332
333// Find maximum size of window/rectangle
334WXDLLEXPORT extern void wxFindMaxSize(WXHWND hwnd, RECT *rect);
335
184b5d99
JS
336WXDLLEXPORT wxWindow* wxFindControlFromHandle(WXHWND hWnd);
337WXDLLEXPORT void wxAddControlHandle(WXHWND hWnd, wxWindow *item);
2bda0e17 338
1c4a764c 339// Safely get the window text (i.e. without using fixed size buffer)
184b5d99 340WXDLLEXPORT extern wxString wxGetWindowText(WXHWND hWnd);
1c4a764c 341
cc2b7472
VZ
342// get the window class name
343WXDLLEXPORT extern wxString wxGetWindowClass(WXHWND hWnd);
344
42e69d6b
VZ
345// get the window id (should be unsigned, hence this is not wxWindowID which
346// is, for mainly historical reasons, signed)
347WXDLLEXPORT extern WXWORD wxGetWindowId(WXHWND hWnd);
cc2b7472 348
c085e333 349// Does this window style specify any border?
184b5d99 350inline bool wxStyleHasBorder(long style)
c085e333
VZ
351{
352 return (style & (wxSIMPLE_BORDER | wxRAISED_BORDER |
353 wxSUNKEN_BORDER | wxDOUBLE_BORDER)) != 0;
354}
355
8614c467
VZ
356// find the window for HWND which is part of some wxWindow, returns just the
357// corresponding wxWindow for HWND which just is one
358//
359// may return NULL
360extern wxWindow *wxGetWindowFromHWND(WXHWND hwnd);
361
b568d04f
VZ
362#endif // wxUSE_GUI
363
2bda0e17 364#endif
bbcdf8bc 365 // _WX_PRIVATE_H_