1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Private declarations: as this header is only included by
4 // wxWidgets 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"
20 // Extra prototypes and symbols not defined by MicroWindows
21 #include "wx/msw/microwin.h"
24 // Include fixes for MSLU:
25 #include "wx/msw/mslu.h"
29 class WXDLLEXPORT wxFont
;
30 class WXDLLEXPORT wxWindow
;
32 // ---------------------------------------------------------------------------
34 // ---------------------------------------------------------------------------
36 // 260 was taken from windef.h
41 // ---------------------------------------------------------------------------
42 // standard icons from the resources
43 // ---------------------------------------------------------------------------
47 WXDLLEXPORT_DATA(extern HICON
) wxSTD_FRAME_ICON
;
48 WXDLLEXPORT_DATA(extern HICON
) wxSTD_MDIPARENTFRAME_ICON
;
49 WXDLLEXPORT_DATA(extern HICON
) wxSTD_MDICHILDFRAME_ICON
;
50 WXDLLEXPORT_DATA(extern HICON
) wxDEFAULT_FRAME_ICON
;
51 WXDLLEXPORT_DATA(extern HICON
) wxDEFAULT_MDIPARENTFRAME_ICON
;
52 WXDLLEXPORT_DATA(extern HICON
) wxDEFAULT_MDICHILDFRAME_ICON
;
53 WXDLLEXPORT_DATA(extern HFONT
) wxSTATUS_LINE_FONT
;
57 // ---------------------------------------------------------------------------
58 // define things missing from some compilers' headers
59 // ---------------------------------------------------------------------------
61 #if defined(__WXWINCE__) || (defined(__GNUWIN32__) && !wxUSE_NORLANDER_HEADERS)
63 inline void ZeroMemory(void *buf
, size_t len
) { memset(buf
, 0, len
); }
67 // this defines a CASTWNDPROC macro which casts a pointer to the type of a
69 #if defined(STRICT) || defined(__GNUC__)
70 typedef WNDPROC WndProcCast
;
72 typedef FARPROC WndProcCast
;
76 #define CASTWNDPROC (WndProcCast)
80 // ---------------------------------------------------------------------------
81 // some stuff for old Windows versions (FIXME: what does it do here??)
82 // ---------------------------------------------------------------------------
84 #if !defined(APIENTRY) // NT defines APIENTRY, 3.x not
85 #define APIENTRY FAR PASCAL
91 #define _EXPORT _export
95 typedef signed short int SHORT
;
98 #if !defined(__WIN32__) // 3.x uses FARPROC for dialogs
100 #define DLGPROC FARPROC
105 WXDLLEXPORT
void wxRegisterPenWin();
106 WXDLLEXPORT
void wxCleanUpPenWin();
107 WXDLLEXPORT
void wxEnablePenAppHooks (bool hook
);
108 #endif // wxUSE_PENWIN
111 #define IBS_HORZCAPTION 0x4000L
112 #define IBS_VERTCAPTION 0x8000L
114 UINT WINAPI
ibGetCaptionSize( HWND hWnd
) ;
115 UINT WINAPI
ibSetCaptionSize( HWND hWnd
, UINT nSize
) ;
116 LRESULT WINAPI
ibDefWindowProc( HWND hWnd
, UINT uiMsg
, WPARAM wParam
, LPARAM lParam
) ;
117 VOID WINAPI
ibAdjustWindowRect( HWND hWnd
, LPRECT lprc
) ;
118 #endif // wxUSE_ITSY_BITSY
121 #include "wx/msw/ctl3d/ctl3d.h"
122 #endif // wxUSE_CTL3D
125 * Decide what window classes we're going to use
126 * for this combination of CTl3D/FAFA settings
129 #define STATIC_CLASS wxT("STATIC")
130 #define STATIC_FLAGS (SS_LEFT|WS_CHILD|WS_VISIBLE)
131 #define CHECK_CLASS wxT("BUTTON")
132 #define CHECK_FLAGS (BS_AUTOCHECKBOX|WS_TABSTOP|WS_CHILD)
133 #define CHECK_IS_FAFA FALSE
134 #define RADIO_CLASS wxT("BUTTON")
135 #define RADIO_FLAGS (BS_AUTORADIOBUTTON|WS_CHILD|WS_VISIBLE)
136 #define RADIO_SIZE 20
137 #define RADIO_IS_FAFA FALSE
139 #define GROUP_CLASS wxT("BUTTON")
140 #define GROUP_FLAGS (BS_GROUPBOX|WS_CHILD|WS_VISIBLE)
143 #define BITCHECK_FLAGS (FB_BITMAP|FC_BUTTONDRAW|FC_DEFAULT|WS_VISIBLE)
144 #define BITRADIO_FLAGS (FC_BUTTONDRAW|FB_BITMAP|FC_RADIO|WS_CHILD|WS_VISIBLE)
147 // ---------------------------------------------------------------------------
149 // ---------------------------------------------------------------------------
151 #define MEANING_CHARACTER '0'
152 #define DEFAULT_ITEM_WIDTH 100
153 #define DEFAULT_ITEM_HEIGHT 80
155 // Scale font to get edit control height
156 //#define EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) (3*(cy)/2)
157 #define EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) (cy+8)
159 // Generic subclass proc, for panel item moving/sizing and intercept
160 // EDIT control VK_RETURN messages
161 extern LONG APIENTRY _EXPORT
162 wxSubclassedGenericControlProc(WXHWND hWnd
, WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
);
164 // ---------------------------------------------------------------------------
165 // useful macros and functions
166 // ---------------------------------------------------------------------------
168 // a wrapper macro for ZeroMemory()
169 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
170 #define wxZeroMemory(obj) ::ZeroMemory(&obj, sizeof(obj))
172 #define wxZeroMemory(obj) memset((void*) & obj, 0, sizeof(obj))
177 #include <wx/gdicmn.h>
178 #include <wx/colour.h>
180 // make conversion from wxColour and COLORREF a bit less painful
181 inline COLORREF
wxColourToRGB(const wxColour
& c
)
183 return RGB(c
.Red(), c
.Green(), c
.Blue());
186 inline COLORREF
wxColourToPalRGB(const wxColour
& c
)
188 return PALETTERGB(c
.Red(), c
.Green(), c
.Blue());
191 inline wxColour
wxRGBToColour(COLORREF rgb
)
193 return wxColour(GetRValue(rgb
), GetGValue(rgb
), GetBValue(rgb
));
196 inline void wxRGBToColour(wxColour
& c
, COLORREF rgb
)
198 c
.Set(GetRValue(rgb
), GetGValue(rgb
), GetBValue(rgb
));
201 // get the standard colour map for some standard colours - see comment in this
202 // function to understand why is it needed and when should it be used
204 // it returns a wxCOLORMAP (can't use COLORMAP itself here as comctl32.dll
205 // might be not included/available) array of size wxSTD_COLOUR_MAX
207 // NB: if you change these colours, update wxBITMAP_STD_COLOURS in the
208 // resources as well: it must have the same number of pixels!
214 wxSTD_COL_BTNHIGHLIGHT
,
218 struct WXDLLEXPORT wxCOLORMAP
223 // this function is implemented in src/msw/window.cpp
224 extern wxCOLORMAP
*wxGetStdColourMap();
226 // create a wxRect from Windows RECT
227 inline wxRect
wxRectFromRECT(const RECT
& r
)
229 return wxRect(r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
);
232 // copy Windows RECT to our wxRect
233 inline void wxCopyRECTToRect(const RECT
& r
, wxRect
& rect
)
235 rect
= wxRectFromRECT(r
);
238 // translations between HIMETRIC units (which OLE likes) and pixels (which are
239 // liked by all the others) - implemented in msw/utilsexc.cpp
240 extern void HIMETRICToPixel(LONG
*x
, LONG
*y
);
241 extern void PixelToHIMETRIC(LONG
*x
, LONG
*y
);
243 // Windows convention of the mask is opposed to the wxWidgets one, so we need
244 // to invert the mask each time we pass one/get one to/from Windows
245 extern HBITMAP
wxInvertMask(HBITMAP hbmpMask
, int w
= 0, int h
= 0);
247 // Creates an icon or cursor depending from a bitmap
249 // The bitmap must be valid and it should have a mask. If it doesn't, a default
250 // mask is created using light grey as the transparent colour.
251 extern HICON
wxBitmapToHICON(const wxBitmap
& bmp
);
253 // Same requirments as above apply and the bitmap must also have the correct
256 HCURSOR
wxBitmapToHCURSOR(const wxBitmap
& bmp
, int hotSpotX
, int hotSpotY
);
258 // get (x, y) from DWORD - notice that HI/LOWORD can *not* be used because they
259 // will fail on system with multiple monitors where the coords may be negative
261 // these macros are standard now (Win98) but some older headers don't have them
263 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
264 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
265 #endif // GET_X_LPARAM
267 // get the current state of SHIFT/CTRL keys
268 inline bool wxIsShiftDown()
270 // return (::GetKeyState(VK_SHIFT) & 0x100) != 0;
271 // Returns different negative values on WinME and WinNT,
272 // so simply test for negative value.
273 return ::GetKeyState(VK_SHIFT
) < 0;
276 inline bool wxIsCtrlDown()
278 // return (::GetKeyState(VK_CONTROL) & 0x100) != 0;
279 // Returns different negative values on WinME and WinNT,
280 // so simply test for negative value.
281 return ::GetKeyState(VK_CONTROL
) < 0;
284 // wrapper around GetWindowRect() and GetClientRect() APIs doing error checking
286 inline RECT
wxGetWindowRect(HWND hwnd
)
290 if ( !::GetWindowRect(hwnd
, &rect
) )
292 wxLogLastError(_T("GetWindowRect"));
298 inline RECT
wxGetClientRect(HWND hwnd
)
302 if ( !::GetClientRect(hwnd
, &rect
) )
304 wxLogLastError(_T("GetClientRect"));
310 // ---------------------------------------------------------------------------
311 // small helper classes
312 // ---------------------------------------------------------------------------
314 // a template to make initializing Windows styructs less painful: it zeroes all
315 // the struct fields and also sets cbSize member to the correct value (and so
316 // can be only used with structures which have this member...)
318 struct WinStruct
: public T
322 ::ZeroMemory(this, sizeof(T
));
324 // explicit qualification is required here for this to be valid C++
325 this->cbSize
= sizeof(T
);
330 // create an instance of this class and use it as the HDC for screen, will
331 // automatically release the DC going out of scope
335 ScreenHDC() { m_hdc
= ::GetDC(NULL
); }
336 ~ScreenHDC() { ::ReleaseDC(NULL
, m_hdc
); }
338 operator HDC() const { return m_hdc
; }
343 DECLARE_NO_COPY_CLASS(ScreenHDC
)
346 // the same as ScreenHDC but for window DCs
350 WindowHDC(HWND hwnd
) { m_hdc
= ::GetDC(m_hwnd
= hwnd
); }
351 ~WindowHDC() { ::ReleaseDC(m_hwnd
, m_hdc
); }
353 operator HDC() const { return m_hdc
; }
359 DECLARE_NO_COPY_CLASS(WindowHDC
)
362 // the same as ScreenHDC but for memory DCs: creates the HDC compatible with
363 // the given one (screen by default) in ctor and destroys it in dtor
367 MemoryHDC(HDC hdc
= 0) { m_hdc
= ::CreateCompatibleDC(hdc
); }
368 ~MemoryHDC() { ::DeleteDC(m_hdc
); }
370 operator HDC() const { return m_hdc
; }
375 DECLARE_NO_COPY_CLASS(MemoryHDC
)
378 // a class which selects a GDI object into a DC in its ctor and deselects in
383 SelectInHDC(HDC hdc
, HGDIOBJ hgdiobj
) : m_hdc(hdc
)
384 { m_hgdiobj
= ::SelectObject(hdc
, hgdiobj
); }
386 ~SelectInHDC() { ::SelectObject(m_hdc
, m_hgdiobj
); }
388 // return true if the object was successfully selected
389 operator bool() const { return m_hgdiobj
!= 0; }
395 DECLARE_NO_COPY_CLASS(SelectInHDC
)
398 // a class for temporary bitmaps
399 class CompatibleBitmap
402 CompatibleBitmap(HDC hdc
, int w
, int h
)
404 m_hbmp
= ::CreateCompatibleBitmap(hdc
, w
, h
);
410 ::DeleteObject(m_hbmp
);
413 operator HBITMAP() const { return m_hbmp
; }
419 // when working with global pointers (which is unfortunately still necessary
420 // sometimes, e.g. for clipboard) it is important to unlock them exactly as
421 // many times as we lock them which just asks for using a "smart lock" class
425 GlobalPtr(HGLOBAL hGlobal
) : m_hGlobal(hGlobal
)
427 m_ptr
= GlobalLock(hGlobal
);
430 wxLogLastError(_T("GlobalLock"));
436 if ( !GlobalUnlock(m_hGlobal
) )
439 // this might happen simply because the block became unlocked
440 DWORD dwLastError
= ::GetLastError();
441 if ( dwLastError
!= NO_ERROR
)
443 wxLogApiError(_T("GlobalUnlock"), dwLastError
);
445 #endif // __WXDEBUG__
449 operator void *() const { return m_ptr
; }
455 DECLARE_NO_COPY_CLASS(GlobalPtr
)
458 // ---------------------------------------------------------------------------
459 // macros to make casting between WXFOO and FOO a bit easier: the GetFoo()
460 // returns Foo cast to the Windows type for oruselves, while GetFooOf() takes
461 // an argument which should be a pointer or reference to the object of the
462 // corresponding class (this depends on the macro)
463 // ---------------------------------------------------------------------------
465 #define GetHwnd() ((HWND)GetHWND())
466 #define GetHwndOf(win) ((HWND)((win)->GetHWND()))
468 #define GetWinHwnd GetHwndOf
470 #define GetHdc() ((HDC)GetHDC())
471 #define GetHdcOf(dc) ((HDC)(dc).GetHDC())
473 #define GetHbitmap() ((HBITMAP)GetHBITMAP())
474 #define GetHbitmapOf(bmp) ((HBITMAP)(bmp).GetHBITMAP())
476 #define GetHicon() ((HICON)GetHICON())
477 #define GetHiconOf(icon) ((HICON)(icon).GetHICON())
479 #define GetHaccel() ((HACCEL)GetHACCEL())
480 #define GetHaccelOf(table) ((HACCEL)((table).GetHACCEL()))
482 #define GetHbrush() ((HPEN)GetResourceHandle())
483 #define GetHbrushOf(brush) ((HPEN)(brush).GetResourceHandle())
485 #define GetHmenu() ((HMENU)GetHMenu())
486 #define GetHmenuOf(menu) ((HMENU)menu->GetHMenu())
488 #define GetHcursor() ((HCURSOR)GetHCURSOR())
489 #define GetHcursorOf(cursor) ((HCURSOR)(cursor).GetHCURSOR())
491 #define GetHfont() ((HFONT)GetHFONT())
492 #define GetHfontOf(font) ((HFONT)(font).GetHFONT())
494 #define GetHpalette() ((HPALETTE)GetHPALETTE())
495 #define GetHpaletteOf(pal) ((HPALETTE)(pal).GetHPALETTE())
497 #define GetHpen() ((HPEN)GetResourceHandle())
498 #define GetHpenOf(pen) ((HPEN)(pen).GetResourceHandle())
500 #define GetHrgn() ((HRGN)GetHRGN())
501 #define GetHrgnOf(rgn) ((HRGN)(rgn).GetHRGN())
505 // ---------------------------------------------------------------------------
507 // ---------------------------------------------------------------------------
509 WXDLLIMPEXP_DATA_BASE(extern HINSTANCE
) wxhInstance
;
511 // ---------------------------------------------------------------------------
513 // ---------------------------------------------------------------------------
517 WXDLLIMPEXP_BASE HINSTANCE
wxGetInstance();
520 WXDLLIMPEXP_BASE
void wxSetInstance(HINSTANCE hInst
);
522 // return the full name of the program file
523 inline wxString
wxGetFullModuleName()
526 if ( !::GetModuleFileName
528 (HMODULE
)wxGetInstance(),
529 wxStringBuffer(fullname
, MAX_PATH
),
533 wxLogLastError(_T("GetModuleFileName"));
542 extern HCURSOR
wxGetCurrentBusyCursor(); // from msw/utils.cpp
543 extern const wxCursor
*wxGetGlobalCursor(); // from msw/cursor.cpp
545 WXDLLEXPORT
void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
& the_font
);
546 WXDLLEXPORT
void wxFillLogFont(LOGFONT
*logFont
, const wxFont
*font
);
547 WXDLLEXPORT wxFont
wxCreateFontFromLogFont(const LOGFONT
*logFont
);
548 WXDLLEXPORT wxFontEncoding
wxGetFontEncFromCharSet(int charset
);
550 WXDLLEXPORT
void wxSliderEvent(WXHWND control
, WXWORD wParam
, WXWORD pos
);
551 WXDLLEXPORT
void wxScrollBarEvent(WXHWND hbar
, WXWORD wParam
, WXWORD pos
);
553 // Find maximum size of window/rectangle
554 WXDLLEXPORT
extern void wxFindMaxSize(WXHWND hwnd
, RECT
*rect
);
556 // Safely get the window text (i.e. without using fixed size buffer)
557 WXDLLEXPORT
extern wxString
wxGetWindowText(WXHWND hWnd
);
559 // get the window class name
560 WXDLLEXPORT
extern wxString
wxGetWindowClass(WXHWND hWnd
);
562 // get the window id (should be unsigned, hence this is not wxWindowID which
563 // is, for mainly historical reasons, signed)
564 WXDLLEXPORT
extern WXWORD
wxGetWindowId(WXHWND hWnd
);
566 // check if hWnd's WNDPROC is wndProc. Return true if yes, false if they are
568 WXDLLEXPORT
extern bool wxCheckWindowWndProc(WXHWND hWnd
, WXFARPROC wndProc
);
570 // Does this window style specify any border?
571 inline bool wxStyleHasBorder(long style
)
573 return (style
& (wxSIMPLE_BORDER
| wxRAISED_BORDER
|
574 wxSUNKEN_BORDER
| wxDOUBLE_BORDER
)) != 0;
577 // ----------------------------------------------------------------------------
578 // functions mapping HWND to wxWindow
579 // ----------------------------------------------------------------------------
581 // this function simply checks whether the given hWnd corresponds to a wxWindow
582 // and returns either that window if it does or NULL otherwise
583 WXDLLEXPORT
extern wxWindow
* wxFindWinFromHandle(WXHWND hWnd
);
585 // find the window for HWND which is part of some wxWindow, i.e. unlike
586 // wxFindWinFromHandle() above it will also work for "sub controls" of a
589 // returns the wxWindow corresponding to the given HWND or NULL.
590 WXDLLEXPORT
extern wxWindow
*wxGetWindowFromHWND(WXHWND hwnd
);
592 // Get the size of an icon
593 WXDLLEXPORT
extern wxSize
wxGetHiconSize(HICON hicon
);
595 // Lines are drawn differently for WinCE and regular WIN32
596 WXDLLEXPORT
void wxDrawLine(HDC hdc
, int x1
, int y1
, int x2
, int y2
);
598 // ----------------------------------------------------------------------------
600 // ----------------------------------------------------------------------------
604 inline void *wxGetWindowProc(HWND hwnd
)
606 return (void *)::GetWindowLongPtr(hwnd
, GWLP_WNDPROC
);
609 inline void *wxGetWindowUserData(HWND hwnd
)
611 return (void *)::GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
614 inline WNDPROC
wxSetWindowProc(HWND hwnd
, WNDPROC func
)
616 return (WNDPROC
)::SetWindowLongPtr(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)func
);
619 inline void *wxSetWindowUserData(HWND hwnd
, void *data
)
621 return (void *)::SetWindowLongPtr(hwnd
, GWLP_USERDATA
, (LONG_PTR
)data
);
627 // strangely enough, VC++ 7.1 gives warnings about 32 -> 64 bit conversions
628 // in the functions below, even in spite of the explicit casts
629 #pragma warning(disable:4311)
630 #pragma warning(disable:4312)
633 inline void *wxGetWindowProc(HWND hwnd
)
635 return (void *)::GetWindowLong(hwnd
, GWL_WNDPROC
);
638 inline void *wxGetWindowUserData(HWND hwnd
)
640 return (void *)::GetWindowLong(hwnd
, GWL_USERDATA
);
643 inline WNDPROC
wxSetWindowProc(HWND hwnd
, WNDPROC func
)
645 return (WNDPROC
)::SetWindowLong(hwnd
, GWL_WNDPROC
, (LONG
)func
);
648 inline void *wxSetWindowUserData(HWND hwnd
, void *data
)
650 return (void *)::SetWindowLong(hwnd
, GWL_USERDATA
, (LONG
)data
);
654 #pragma warning(default:4311)
655 #pragma warning(default:4312)
658 #endif // __WIN64__/__WIN32__