1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Private declarations: as this header is only included by
4 // wxWindows itself, it may contain identifiers which don't start
6 // Author: Julian Smart
10 // Copyright: (c) Julian Smart
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
14 #ifndef _WX_PRIVATE_H_
15 #define _WX_PRIVATE_H_
17 #include "wx/msw/wrapwin.h"
19 #if defined (__WXWINCE__)
20 #include <wingdi.h> // RGB, COLORREF
22 #include <winuser.h> // Global Namespaces ::GetKeyState, ::GetWindowRect
23 #include "wx/msw/winundef.h"
28 // Extra prototypes and symbols not defined by MicroWindows
29 #include "wx/msw/microwin.h"
32 // Include fixes for MSLU:
33 #include "wx/msw/mslu.h"
37 class WXDLLEXPORT wxFont
;
38 class WXDLLEXPORT wxWindow
;
40 // ---------------------------------------------------------------------------
42 // ---------------------------------------------------------------------------
45 static const double METRIC_CONVERSION_CONSTANT
= 0.0393700787;
47 // Scaling factors for various unit conversions
48 static const double mm2inches
= (METRIC_CONVERSION_CONSTANT
);
49 static const double inches2mm
= (1/METRIC_CONVERSION_CONSTANT
);
51 static const double mm2twips
= (METRIC_CONVERSION_CONSTANT
*1440);
52 static const double twips2mm
= (1/(METRIC_CONVERSION_CONSTANT
*1440));
54 static const double mm2pt
= (METRIC_CONVERSION_CONSTANT
*72);
55 static const double pt2mm
= (1/(METRIC_CONVERSION_CONSTANT
*72));
57 // ---------------------------------------------------------------------------
58 // standard icons from the resources
59 // ---------------------------------------------------------------------------
63 WXDLLEXPORT_DATA(extern HICON
) wxSTD_FRAME_ICON
;
64 WXDLLEXPORT_DATA(extern HICON
) wxSTD_MDIPARENTFRAME_ICON
;
65 WXDLLEXPORT_DATA(extern HICON
) wxSTD_MDICHILDFRAME_ICON
;
66 WXDLLEXPORT_DATA(extern HICON
) wxDEFAULT_FRAME_ICON
;
67 WXDLLEXPORT_DATA(extern HICON
) wxDEFAULT_MDIPARENTFRAME_ICON
;
68 WXDLLEXPORT_DATA(extern HICON
) wxDEFAULT_MDICHILDFRAME_ICON
;
69 WXDLLEXPORT_DATA(extern HFONT
) wxSTATUS_LINE_FONT
;
73 // ---------------------------------------------------------------------------
74 // define things missing from some compilers' headers
75 // ---------------------------------------------------------------------------
77 #if defined(__WXWINCE__) || (defined(__GNUWIN32__) && !wxUSE_NORLANDER_HEADERS)
79 inline void ZeroMemory(void *buf
, size_t len
) { memset(buf
, 0, len
); }
83 // this defines a CASTWNDPROC macro which casts a pointer to the type of a
85 #if defined(STRICT) || defined(__GNUC__)
86 typedef WNDPROC WndProcCast
;
88 typedef FARPROC WndProcCast
;
92 #define CASTWNDPROC (WndProcCast)
94 // ---------------------------------------------------------------------------
95 // some stuff for old Windows versions (FIXME: what does it do here??)
96 // ---------------------------------------------------------------------------
98 #if !defined(APIENTRY) // NT defines APIENTRY, 3.x not
99 #define APIENTRY FAR PASCAL
105 #define _EXPORT _export
109 typedef signed short int SHORT
;
112 #if !defined(__WIN32__) // 3.x uses FARPROC for dialogs
114 #define DLGPROC FARPROC
119 WXDLLEXPORT
void wxRegisterPenWin();
120 WXDLLEXPORT
void wxCleanUpPenWin();
121 WXDLLEXPORT
void wxEnablePenAppHooks (bool hook
);
122 #endif // wxUSE_PENWIN
125 #define IBS_HORZCAPTION 0x4000L
126 #define IBS_VERTCAPTION 0x8000L
128 UINT WINAPI
ibGetCaptionSize( HWND hWnd
) ;
129 UINT WINAPI
ibSetCaptionSize( HWND hWnd
, UINT nSize
) ;
130 LRESULT WINAPI
ibDefWindowProc( HWND hWnd
, UINT uiMsg
, WPARAM wParam
, LPARAM lParam
) ;
131 VOID WINAPI
ibAdjustWindowRect( HWND hWnd
, LPRECT lprc
) ;
132 #endif // wxUSE_ITSY_BITSY
135 #include "wx/msw/ctl3d/ctl3d.h"
136 #endif // wxUSE_CTL3D
139 * Decide what window classes we're going to use
140 * for this combination of CTl3D/FAFA settings
143 #define STATIC_CLASS wxT("STATIC")
144 #define STATIC_FLAGS (SS_LEFT|WS_CHILD|WS_VISIBLE)
145 #define CHECK_CLASS wxT("BUTTON")
146 #define CHECK_FLAGS (BS_AUTOCHECKBOX|WS_TABSTOP|WS_CHILD)
147 #define CHECK_IS_FAFA FALSE
148 #define RADIO_CLASS wxT("BUTTON")
149 #define RADIO_FLAGS (BS_AUTORADIOBUTTON|WS_CHILD|WS_VISIBLE)
150 #define RADIO_SIZE 20
151 #define RADIO_IS_FAFA FALSE
153 #define GROUP_CLASS wxT("BUTTON")
154 #define GROUP_FLAGS (BS_GROUPBOX|WS_CHILD|WS_VISIBLE)
157 #define BITCHECK_FLAGS (FB_BITMAP|FC_BUTTONDRAW|FC_DEFAULT|WS_VISIBLE)
158 #define BITRADIO_FLAGS (FC_BUTTONDRAW|FB_BITMAP|FC_RADIO|WS_CHILD|WS_VISIBLE)
161 // ---------------------------------------------------------------------------
163 // ---------------------------------------------------------------------------
165 #define MEANING_CHARACTER '0'
166 #define DEFAULT_ITEM_WIDTH 100
167 #define DEFAULT_ITEM_HEIGHT 80
169 // Scale font to get edit control height
170 //#define EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) (3*(cy)/2)
171 #define EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) (cy+8)
173 // Generic subclass proc, for panel item moving/sizing and intercept
174 // EDIT control VK_RETURN messages
175 extern LONG APIENTRY _EXPORT
176 wxSubclassedGenericControlProc(WXHWND hWnd
, WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
);
178 // ---------------------------------------------------------------------------
179 // useful macros and functions
180 // ---------------------------------------------------------------------------
182 // a wrapper macro for ZeroMemory()
183 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
184 #define wxZeroMemory(obj) ::ZeroMemory(&obj, sizeof(obj))
186 #define wxZeroMemory(obj) memset((void*) & obj, 0, sizeof(obj))
191 #include <wx/gdicmn.h>
192 #include <wx/colour.h>
194 // make conversion from wxColour and COLORREF a bit less painful
195 inline COLORREF
wxColourToRGB(const wxColour
& c
)
197 return RGB(c
.Red(), c
.Green(), c
.Blue());
200 inline COLORREF
wxColourToPalRGB(const wxColour
& c
)
202 return PALETTERGB(c
.Red(), c
.Green(), c
.Blue());
205 inline wxColour
wxRGBToColour(COLORREF rgb
)
207 return wxColour(GetRValue(rgb
), GetGValue(rgb
), GetBValue(rgb
));
210 inline void wxRGBToColour(wxColour
& c
, COLORREF rgb
)
212 c
.Set(GetRValue(rgb
), GetGValue(rgb
), GetBValue(rgb
));
215 // get the standard colour map for some standard colours - see comment in this
216 // function to understand why is it needed and when should it be used
218 // it returns a wxCOLORMAP (can't use COLORMAP itself here as comctl32.dll
219 // might be not included/available) array of size wxSTD_COLOUR_MAX
221 // NB: if you change these colours, update wxBITMAP_STD_COLOURS in the
222 // resources as well: it must have the same number of pixels!
228 wxSTD_COL_BTNHIGHLIGHT
,
232 struct WXDLLEXPORT wxCOLORMAP
237 // this function is implemented in src/msw/window.cpp
238 extern wxCOLORMAP
*wxGetStdColourMap();
240 // copy Windows RECT to our wxRect
241 inline void wxCopyRECTToRect(const RECT
& r
, wxRect
& rect
)
245 rect
.width
= r
.right
- r
.left
;
246 rect
.height
= r
.bottom
- r
.top
;
249 // translations between HIMETRIC units (which OLE likes) and pixels (which are
250 // liked by all the others) - implemented in msw/utilsexc.cpp
251 extern void HIMETRICToPixel(LONG
*x
, LONG
*y
);
252 extern void PixelToHIMETRIC(LONG
*x
, LONG
*y
);
254 // Windows convention of the mask is opposed to the wxWindows one, so we need
255 // to invert the mask each time we pass one/get one to/from Windows
256 extern HBITMAP
wxInvertMask(HBITMAP hbmpMask
, int w
= 0, int h
= 0);
258 // Creates an icon or cursor depending from a bitmap
260 // The bitmap must be valid and it should have a mask. If it doesn't, a default
261 // mask is created using light grey as the transparent colour.
262 extern HICON
wxBitmapToHICON(const wxBitmap
& bmp
);
264 // Same requirments as above apply and the bitmap must also have the correct
267 HCURSOR
wxBitmapToHCURSOR(const wxBitmap
& bmp
, int hotSpotX
, int hotSpotY
);
269 // get (x, y) from DWORD - notice that HI/LOWORD can *not* be used because they
270 // will fail on system with multiple monitors where the coords may be negative
272 // these macros are standard now (Win98) but some older headers don't have them
274 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
275 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
276 #endif // GET_X_LPARAM
278 // get the current state of SHIFT/CTRL keys
279 inline bool wxIsShiftDown()
281 // return (::GetKeyState(VK_SHIFT) & 0x100) != 0;
282 // Returns different negative values on WinME and WinNT,
283 // so simply test for negative value.
284 return ::GetKeyState(VK_SHIFT
) < 0;
287 inline bool wxIsCtrlDown()
289 // return (::GetKeyState(VK_CONTROL) & 0x100) != 0;
290 // Returns different negative values on WinME and WinNT,
291 // so simply test for negative value.
292 return ::GetKeyState(VK_CONTROL
) < 0;
295 // wrapper around GetWindowRect() and GetClientRect() APIs doing error checking
297 inline RECT
wxGetWindowRect(HWND hwnd
)
301 ::GetWindowRect(hwnd
, &rect
);
303 if ( !::GetWindowRect(hwnd
, &rect
) )
305 wxLogLastError(_T("GetWindowRect"));
312 inline RECT
wxGetClientRect(HWND hwnd
)
316 ::GetClientRect(hwnd
, &rect
);
318 if ( !::GetClientRect(hwnd
, &rect
) )
320 wxLogLastError(_T("GetClientRect"));
327 // ---------------------------------------------------------------------------
328 // small helper classes
329 // ---------------------------------------------------------------------------
331 // a template to make initializing Windows styructs less painful: it zeroes all
332 // the struct fields and also sets cbSize member to the correct value (and so
333 // can be only used with structures which have this member...)
335 struct WinStruct
: public T
339 ::ZeroMemory(this, sizeof(T
));
345 // create an instance of this class and use it as the HDC for screen, will
346 // automatically release the DC going out of scope
350 ScreenHDC() { m_hdc
= ::GetDC(NULL
); }
351 ~ScreenHDC() { ::ReleaseDC(NULL
, m_hdc
); }
353 operator HDC() const { return m_hdc
; }
358 DECLARE_NO_COPY_CLASS(ScreenHDC
)
361 // the same as ScreenHDC but for memory DCs: creates the HDC compatible with
362 // the given one (screen by default) in ctor and destroys it in dtor
366 MemoryHDC(HDC hdc
= 0) { m_hdc
= ::CreateCompatibleDC(hdc
); }
367 ~MemoryHDC() { ::DeleteDC(m_hdc
); }
369 operator HDC() const { return m_hdc
; }
374 DECLARE_NO_COPY_CLASS(MemoryHDC
)
377 // a class which selects a GDI object into a DC in its ctor and deselects in
382 SelectInHDC(HDC hdc
, HGDIOBJ hgdiobj
) : m_hdc(hdc
)
383 { m_hgdiobj
= ::SelectObject(hdc
, hgdiobj
); }
385 ~SelectInHDC() { ::SelectObject(m_hdc
, m_hgdiobj
); }
387 // return true if the object was successfully selected
388 operator bool() const { return m_hgdiobj
!= 0; }
394 DECLARE_NO_COPY_CLASS(SelectInHDC
)
398 // when working with global pointers (which is unfortunately still necessary
399 // sometimes, e.g. for clipboard) it is important to unlock them exactly as
400 // many times as we lock them which just asks for using a "smart lock" class
404 GlobalPtr(HGLOBAL hGlobal
) : m_hGlobal(hGlobal
)
406 m_ptr
= ::GlobalLock(hGlobal
);
409 wxLogLastError(_T("GlobalLock"));
415 if ( !::GlobalUnlock(m_hGlobal
) )
418 // this might happen simply because the block became unlocked
419 DWORD dwLastError
= ::GetLastError();
420 if ( dwLastError
!= NO_ERROR
)
422 wxLogApiError(_T("GlobalUnlock"), dwLastError
);
424 #endif // __WXDEBUG__
428 operator void *() const { return m_ptr
; }
434 DECLARE_NO_COPY_CLASS(GlobalPtr
)
438 // ---------------------------------------------------------------------------
439 // macros to make casting between WXFOO and FOO a bit easier: the GetFoo()
440 // returns Foo cast to the Windows type for oruselves, while GetFooOf() takes
441 // an argument which should be a pointer or reference to the object of the
442 // corresponding class (this depends on the macro)
443 // ---------------------------------------------------------------------------
445 #define GetHwnd() ((HWND)GetHWND())
446 #define GetHwndOf(win) ((HWND)((win)->GetHWND()))
448 #define GetWinHwnd GetHwndOf
450 #define GetHdc() ((HDC)GetHDC())
451 #define GetHdcOf(dc) ((HDC)(dc).GetHDC())
453 #define GetHbitmap() ((HBITMAP)GetHBITMAP())
454 #define GetHbitmapOf(bmp) ((HBITMAP)(bmp).GetHBITMAP())
456 #define GetHicon() ((HICON)GetHICON())
457 #define GetHiconOf(icon) ((HICON)(icon).GetHICON())
459 #define GetHaccel() ((HACCEL)GetHACCEL())
460 #define GetHaccelOf(table) ((HACCEL)((table).GetHACCEL()))
462 #define GetHmenu() ((HMENU)GetHMenu())
463 #define GetHmenuOf(menu) ((HMENU)menu->GetHMenu())
465 #define GetHcursor() ((HCURSOR)GetHCURSOR())
466 #define GetHcursorOf(cursor) ((HCURSOR)(cursor).GetHCURSOR())
468 #define GetHfont() ((HFONT)GetHFONT())
469 #define GetHfontOf(font) ((HFONT)(font).GetHFONT())
471 #define GetHpalette() ((HPALETTE)GetHPALETTE())
472 #define GetHpaletteOf(pal) ((HPALETTE)(pal).GetHPALETTE())
474 #define GetHrgn() ((HRGN)GetHRGN())
475 #define GetHrgnOf(rgn) ((HRGN)(rgn).GetHRGN())
479 // ---------------------------------------------------------------------------
481 // ---------------------------------------------------------------------------
483 WXDLLIMPEXP_DATA_BASE(extern HINSTANCE
) wxhInstance
;
485 // ---------------------------------------------------------------------------
487 // ---------------------------------------------------------------------------
491 WXDLLIMPEXP_BASE HINSTANCE
wxGetInstance();
494 WXDLLIMPEXP_BASE
void wxSetInstance(HINSTANCE hInst
);
499 extern HCURSOR
wxGetCurrentBusyCursor(); // from msw/utils.cpp
500 extern const wxCursor
*wxGetGlobalCursor(); // from msw/cursor.cpp
502 WXDLLEXPORT
void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
*the_font
);
503 WXDLLEXPORT
void wxFillLogFont(LOGFONT
*logFont
, const wxFont
*font
);
504 WXDLLEXPORT wxFont
wxCreateFontFromLogFont(const LOGFONT
*logFont
);
505 WXDLLEXPORT wxFontEncoding
wxGetFontEncFromCharSet(int charset
);
507 WXDLLEXPORT
void wxSliderEvent(WXHWND control
, WXWORD wParam
, WXWORD pos
);
508 WXDLLEXPORT
void wxScrollBarEvent(WXHWND hbar
, WXWORD wParam
, WXWORD pos
);
510 // Find maximum size of window/rectangle
511 WXDLLEXPORT
extern void wxFindMaxSize(WXHWND hwnd
, RECT
*rect
);
513 // Safely get the window text (i.e. without using fixed size buffer)
514 WXDLLEXPORT
extern wxString
wxGetWindowText(WXHWND hWnd
);
516 // get the window class name
517 WXDLLEXPORT
extern wxString
wxGetWindowClass(WXHWND hWnd
);
519 // get the window id (should be unsigned, hence this is not wxWindowID which
520 // is, for mainly historical reasons, signed)
521 WXDLLEXPORT
extern WXWORD
wxGetWindowId(WXHWND hWnd
);
523 // check if hWnd's WNDPROC is wndProc. Return true if yes, false if they are
525 WXDLLEXPORT
extern bool wxCheckWindowWndProc(WXHWND hWnd
, WXFARPROC wndProc
);
527 // Does this window style specify any border?
528 inline bool wxStyleHasBorder(long style
)
530 return (style
& (wxSIMPLE_BORDER
| wxRAISED_BORDER
|
531 wxSUNKEN_BORDER
| wxDOUBLE_BORDER
)) != 0;
534 // ----------------------------------------------------------------------------
535 // functions mapping HWND to wxWindow
536 // ----------------------------------------------------------------------------
538 // this function simply checks whether the given hWnd corresponds to a wxWindow
539 // and returns either that window if it does or NULL otherwise
540 WXDLLEXPORT
extern wxWindow
* wxFindWinFromHandle(WXHWND hWnd
);
542 // find the window for HWND which is part of some wxWindow, i.e. unlike
543 // wxFindWinFromHandle() above it will also work for "sub controls" of a
546 // returns the wxWindow corresponding to the given HWND or NULL.
547 WXDLLEXPORT
extern wxWindow
*wxGetWindowFromHWND(WXHWND hwnd
);
549 // Get the size of an icon
550 WXDLLEXPORT
extern wxSize
wxGetHiconSize(HICON hicon
);
552 // Lines are drawn differently for WinCE and regular WIN32
553 WXDLLEXPORT
void wxDrawLine(HDC hdc
, int x1
, int y1
, int x2
, int y2
);
555 // LocalAlloc should be used on WinCE
559 #if _WIN32_WCE <= 211
560 #define GlobalAlloc LocalAlloc
561 #define GlobalFree LocalFree
562 #define GlobalLock(mem) mem
563 #define GlobalUnlock(mem)
564 #define GlobalSize LocalSize
567 #define GMEM_MOVEABLE 0
587 #define LMEM_FIXED 0x0000
588 #define LMEM_MOVEABLE 0x0002
589 #define LMEM_NOCOMPACT 0x0010 /**** Used for Moveable Memory ***/
590 #define LMEM_NODISCARD 0x0020 /**** Ignored *****/
591 #define LMEM_ZEROINIT 0x0040
592 #define LMEM_MODIFY 0x0080 /*** Used only in LocalReAlloc() **/
593 #define LMEM_DISCARDABLE 0x0F00 /**** Ignored ****/
594 #define LMEM_VALID_FLAGS 0x0F72
595 #define LMEM_INVALID_HANDLE 0x8000
597 #define LHND (LMEM_MOVEABLE | LMEM_ZEROINIT)
598 #define LPTR (LMEM_FIXED | LMEM_ZEROINIT)