more /Wp64 warning fixes: mostly use UINT_PTR instead of UINT and define our WX[WL]PARAM with __w64 if available to avoid hundreds of warnings when casting LPARAMs to pointers/handles

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52165 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-02-28 02:22:52 +00:00
parent 2d2b68baa3
commit dca0f65178
24 changed files with 341 additions and 347 deletions

View File

@@ -2778,6 +2778,17 @@ typedef void * WXRECTANGLEPTR;
# define WXFAR # define WXFAR
#endif #endif
// we can't rely on Windows _W64 being defined as windows.h may not be included
// so define our own equivalent: this should be used with types like WXLPARAM
// or WXWPARAM which are 64 bit under Win64 to avoid warnings each time we cast
// it to a pointer or a handle (which results in hundreds of warnings as Win32
// API often passes pointers in them)
#if wxCHECK_VISUALC_VERSION(7)
#define wxW64 __w64
#else
#define wxW64
#endif
/* Stand-ins for Windows types to avoid #including all of windows.h */ /* Stand-ins for Windows types to avoid #including all of windows.h */
typedef void * WXHWND; typedef void * WXHWND;
typedef void * WXHANDLE; typedef void * WXHANDLE;
@@ -2814,13 +2825,13 @@ typedef void * WXLPCREATESTRUCT;
typedef WXHWND WXWidget; typedef WXHWND WXWidget;
#ifdef __WIN64__ #ifdef __WIN64__
typedef unsigned __int64 WXWPARAM; typedef unsigned __int64 WXWPARAM;
typedef __int64 WXLPARAM; typedef __int64 WXLPARAM;
typedef __int64 WXLRESULT; typedef __int64 WXLRESULT;
#else #else
typedef unsigned int WXWPARAM; typedef wxW64 unsigned int WXWPARAM;
typedef long WXLPARAM; typedef wxW64 long WXLPARAM;
typedef long WXLRESULT; typedef wxW64 long WXLRESULT;
#endif #endif
#if defined(__GNUWIN32__) || defined(__WXMICROWIN__) #if defined(__GNUWIN32__) || defined(__WXMICROWIN__)

View File

@@ -57,7 +57,7 @@ public:
// //
// notice that it also returns the id as an unsigned int, as required by // notice that it also returns the id as an unsigned int, as required by
// Win32 API // Win32 API
unsigned GetMSWId() const; WXWPARAM GetMSWId() const;
// mark item as belonging to the given radio group // mark item as belonging to the given radio group
void SetAsRadioGroupStart(); void SetAsRadioGroupStart();

View File

@@ -901,9 +901,15 @@ inline bool wxStyleHasBorder(long style)
// functions mapping HWND to wxWindow // functions mapping HWND to wxWindow
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// this function simply checks whether the given hWnd corresponds to a wxWindow // this function simply checks whether the given hwnd corresponds to a wxWindow
// and returns either that window if it does or NULL otherwise // and returns either that window if it does or NULL otherwise
extern WXDLLEXPORT wxWindow* wxFindWinFromHandle(WXHWND hWnd); extern WXDLLEXPORT wxWindow* wxFindWinFromHandle(HWND hwnd);
// without STRICT WXHWND is the same as HWND anyhow
inline wxWindow* wxFindWinFromHandle(WXHWND hWnd)
{
return wxFindWinFromHandle(wx_static_cast(HWND, hWnd));
}
// find the window for HWND which is part of some wxWindow, i.e. unlike // find the window for HWND which is part of some wxWindow, i.e. unlike
// wxFindWinFromHandle() above it will also work for "sub controls" of a // wxFindWinFromHandle() above it will also work for "sub controls" of a

View File

@@ -597,17 +597,4 @@ public:
~wxWindowCreationHook(); ~wxWindowCreationHook();
}; };
// ----------------------------------------------------------------------------
// global objects
// ----------------------------------------------------------------------------
// notice that this hash must be defined after wxWindow declaration as it
// needs to "see" its dtor and not just forward declaration
#include "wx/hash.h"
// pseudo-template HWND <-> wxWindow hash table
WX_DECLARE_HASH(wxWindowMSW, wxWindowList, wxWinHashTable);
extern wxWinHashTable *wxWinHandleHash;
#endif // _WX_WINDOW_H_ #endif // _WX_WINDOW_H_

View File

@@ -79,6 +79,7 @@
// overwrite them if there is a chance that they're not defined // overwrite them if there is a chance that they're not defined
#if !defined(_MSC_VER) || (_MSC_VER < 1300) #if !defined(_MSC_VER) || (_MSC_VER < 1300)
#define UINT_PTR unsigned int #define UINT_PTR unsigned int
#define INT_PTR int
#define LONG_PTR long #define LONG_PTR long
#define ULONG_PTR unsigned long #define ULONG_PTR unsigned long
#define DWORD_PTR unsigned long #define DWORD_PTR unsigned long

View File

@@ -1033,7 +1033,7 @@ bool wxLaunchDefaultBrowser(const wxString& urlOrig, int flags)
::ShellExecuteEx(&sei); ::ShellExecuteEx(&sei);
const int nResult = (int) sei.hInstApp; const INT_PTR nResult = (INT_PTR)sei.hInstApp;
// Firefox returns file not found for some reason, so make an exception // Firefox returns file not found for some reason, so make an exception
// for it // for it

View File

@@ -355,8 +355,6 @@ bool wxApp::Initialize(int& argc, wxChar **argv)
RegisterWindowClasses(); RegisterWindowClasses();
wxWinHandleHash = new wxWinHashTable(wxKEY_INTEGER, 100);
#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
wxSetKeyboardHook(true); wxSetKeyboardHook(true);
#endif #endif
@@ -510,10 +508,10 @@ bool wxApp::UnregisterWindowClasses()
void wxApp::CleanUp() void wxApp::CleanUp()
{ {
// all objects pending for deletion must be deleted first, otherwise we // all objects pending for deletion must be deleted first, otherwise
// would crash when they use wxWinHandleHash (and UnregisterWindowClasses() // UnregisterWindowClasses() call wouldn't succeed (because windows
// call wouldn't succeed as long as any windows still exist), so call the // using the classes being unregistered still exist), so call the base
// base class method first and only then do our clean up // class method first and only then do our clean up
wxAppBase::CleanUp(); wxAppBase::CleanUp();
#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
@@ -528,9 +526,6 @@ void wxApp::CleanUp()
// unregister the classes now // unregister the classes now
UnregisterWindowClasses(); UnregisterWindowClasses();
delete wxWinHandleHash;
wxWinHandleHash = NULL;
#ifdef __WXWINCE__ #ifdef __WXWINCE__
free( wxCanvasClassName ); free( wxCanvasClassName );
free( wxCanvasClassNameNR ); free( wxCanvasClassNameNR );

View File

@@ -176,7 +176,7 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id,
msStyle, msStyle,
0, 0, 0, 0, 0, 0, 0, 0,
GetWinHwnd(parent), GetWinHwnd(parent),
(HMENU)m_windowId.GetValue(), (HMENU)wxUIntToPtr(m_windowId.GetValue()),
wxGetInstance(), wxGetInstance(),
NULL NULL
); );

View File

@@ -144,8 +144,8 @@ bool wxControl::MSWCreateControl(const wxChar *classname,
label.wx_str(), // the window name label.wx_str(), // the window name
style, // the window style style, // the window style
x, y, w, h, // the window position and size x, y, w, h, // the window position and size
GetHwndOf(GetParent()), // parent GetHwndOf(GetParent()), // parent
(HMENU)GetId(), // child id (HMENU)wxUIntToPtr(GetId()), // child id
wxGetInstance(), // app instance wxGetInstance(), // app instance
NULL // creation parameters NULL // creation parameters
); );

View File

@@ -99,7 +99,7 @@ private:
#ifndef __WXMICROWIN__ #ifndef __WXMICROWIN__
int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm, int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm,
DWORD dwStyle, LONG lParam); DWORD dwStyle, LPARAM lParam);
#endif #endif
// ============================================================================ // ============================================================================
@@ -269,7 +269,7 @@ bool wxFontEnumerator::EnumerateEncodings(const wxString& family)
#ifndef __WXMICROWIN__ #ifndef __WXMICROWIN__
int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm, int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm,
DWORD WXUNUSED(dwStyle), LONG lParam) DWORD WXUNUSED(dwStyle), LPARAM lParam)
{ {
// we used to process TrueType fonts only, but there doesn't seem to be any // we used to process TrueType fonts only, but there doesn't seem to be any

View File

@@ -853,7 +853,7 @@ bool wxFrame::HandlePaint()
HDC hdc = ::BeginPaint(GetHwnd(), &ps); HDC hdc = ::BeginPaint(GetHwnd(), &ps);
// Erase background before painting or we get white background // Erase background before painting or we get white background
MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L); MSWDefWindowProc(WM_ICONERASEBKGND, (WXWPARAM)ps.hdc, 0L);
if ( hIcon ) if ( hIcon )
{ {
@@ -1118,7 +1118,7 @@ WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lPara
const wxIcon& icon = GetIcon(); const wxIcon& icon = GetIcon();
HICON hIcon = icon.Ok() ? GetHiconOf(icon) HICON hIcon = icon.Ok() ? GetHiconOf(icon)
: (HICON)GetDefaultIcon(); : (HICON)GetDefaultIcon();
rc = (long)hIcon; rc = (WXLRESULT)hIcon;
processed = rc != 0; processed = rc != 0;
} }
break; break;

View File

@@ -98,13 +98,14 @@ bool wxWinHelpController::KeywordSearch(const wxString& k,
wxString str = GetValidFilename(m_helpFile); wxString str = GetValidFilename(m_helpFile);
return (WinHelp(GetSuitableHWND(this), str.wx_str(), HELP_PARTIALKEY, (DWORD)k.wx_str()) != 0); return WinHelp(GetSuitableHWND(this), str.wx_str(), HELP_PARTIALKEY,
(ULONG_PTR)k.wx_str()) != 0;
} }
// Can't close the help window explicitly in WinHelp // Can't close the help window explicitly in WinHelp
bool wxWinHelpController::Quit(void) bool wxWinHelpController::Quit(void)
{ {
return (WinHelp(GetSuitableHWND(this), 0, HELP_QUIT, 0L) != 0); return WinHelp(GetSuitableHWND(this), 0, HELP_QUIT, 0) != 0;
} }
// Append extension if necessary. // Append extension if necessary.

View File

@@ -756,7 +756,7 @@ bool wxMDIChildFrame::Create(wxMDIParentFrame *parent,
wxWindowCreationHook hook(this); wxWindowCreationHook hook(this);
m_hWnd = (WXHWND)::SendMessage(GetWinHwnd(parent->GetClientWindow()), m_hWnd = (WXHWND)::SendMessage(GetWinHwnd(parent->GetClientWindow()),
WM_MDICREATE, 0, (LONG)(LPSTR)&mcs); WM_MDICREATE, 0, (LPARAM)&mcs);
if ( !m_hWnd ) if ( !m_hWnd )
{ {
@@ -1430,14 +1430,15 @@ static void InsertWindowMenu(wxWindow *win, WXHMENU menu, HMENU subMenu)
{ {
success = true; success = true;
::InsertMenu(hmenu, i, MF_BYPOSITION | MF_POPUP | MF_STRING, ::InsertMenu(hmenu, i, MF_BYPOSITION | MF_POPUP | MF_STRING,
(UINT)subMenu, _("&Window").wx_str()); (UINT_PTR)subMenu, _("&Window").wx_str());
break; break;
} }
} }
if ( !success ) if ( !success )
{ {
::AppendMenu(hmenu, MF_POPUP, (UINT)subMenu, _("&Window").wx_str()); ::AppendMenu(hmenu, MF_POPUP,
(UINT_PTR)subMenu, _("&Window").wx_str());
} }
} }

View File

@@ -387,14 +387,14 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos)
// id is the numeric id for normal menu items and HMENU for submenus as // id is the numeric id for normal menu items and HMENU for submenus as
// required by ::AppendMenu() API // required by ::AppendMenu() API
UINT id; UINT_PTR id;
wxMenu *submenu = pItem->GetSubMenu(); wxMenu *submenu = pItem->GetSubMenu();
if ( submenu != NULL ) { if ( submenu != NULL ) {
wxASSERT_MSG( submenu->GetHMenu(), wxT("invalid submenu") ); wxASSERT_MSG( submenu->GetHMenu(), wxT("invalid submenu") );
submenu->SetParent(this); submenu->SetParent(this);
id = (UINT)submenu->GetHMenu(); id = (UINT_PTR)submenu->GetHMenu();
flags |= MF_POPUP; flags |= MF_POPUP;
} }
@@ -980,7 +980,7 @@ WXHMENU wxMenuBar::Create()
for ( i = 0, it = m_menus.begin(); i < count; i++, it++ ) for ( i = 0, it = m_menus.begin(); i < count; i++, it++ )
{ {
if ( !::AppendMenu((HMENU)m_hMenu, MF_POPUP | MF_STRING, if ( !::AppendMenu((HMENU)m_hMenu, MF_POPUP | MF_STRING,
(UINT)(*it)->GetHMenu(), (UINT_PTR)(*it)->GetHMenu(),
m_titles[i].wx_str()) ) m_titles[i].wx_str()) )
{ {
wxLogLastError(wxT("AppendMenu")); wxLogLastError(wxT("AppendMenu"));
@@ -1052,7 +1052,7 @@ void wxMenuBar::SetMenuLabel(size_t pos, const wxString& label)
int mswpos = MSWPositionForWxMenu(GetMenu(pos),pos); int mswpos = MSWPositionForWxMenu(GetMenu(pos),pos);
UINT id; UINT_PTR id;
UINT flagsOld = ::GetMenuState((HMENU)m_hMenu, mswpos, MF_BYPOSITION); UINT flagsOld = ::GetMenuState((HMENU)m_hMenu, mswpos, MF_BYPOSITION);
if ( flagsOld == 0xFFFFFFFF ) if ( flagsOld == 0xFFFFFFFF )
{ {
@@ -1065,7 +1065,7 @@ void wxMenuBar::SetMenuLabel(size_t pos, const wxString& label)
{ {
// HIBYTE contains the number of items in the submenu in this case // HIBYTE contains the number of items in the submenu in this case
flagsOld &= 0xff; flagsOld &= 0xff;
id = (UINT)::GetSubMenu((HMENU)m_hMenu, mswpos); id = (UINT_PTR)::GetSubMenu((HMENU)m_hMenu, mswpos);
} }
else else
{ {
@@ -1080,7 +1080,7 @@ void wxMenuBar::SetMenuLabel(size_t pos, const wxString& label)
info.fType = MFT_STRING; info.fType = MFT_STRING;
info.cch = label.length(); info.cch = label.length();
info.dwTypeData = wx_const_cast(wxChar *, label.wx_str()); info.dwTypeData = wx_const_cast(wxChar *, label.wx_str());
if ( !SetMenuItemInfo(GetHmenu(), id, TRUE, & info) ) if ( !SetMenuItemInfo(GetHmenu(), id, TRUE, &info) )
{ {
wxLogLastError(wxT("SetMenuItemInfo")); wxLogLastError(wxT("SetMenuItemInfo"));
} }
@@ -1132,7 +1132,7 @@ wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
if ( !::InsertMenu(GetHmenu(), (UINT)mswpos, if ( !::InsertMenu(GetHmenu(), (UINT)mswpos,
MF_BYPOSITION | MF_POPUP | MF_STRING, MF_BYPOSITION | MF_POPUP | MF_STRING,
(UINT)GetHmenuOf(menu), title.wx_str()) ) (UINT_PTR)GetHmenuOf(menu), title.wx_str()) )
{ {
wxLogLastError(wxT("InsertMenu")); wxLogLastError(wxT("InsertMenu"));
} }
@@ -1199,7 +1199,7 @@ bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
#else #else
if ( !::InsertMenu(GetHmenu(), mswpos, if ( !::InsertMenu(GetHmenu(), mswpos,
MF_BYPOSITION | MF_POPUP | MF_STRING, MF_BYPOSITION | MF_POPUP | MF_STRING,
(UINT)GetHmenuOf(menu), title.wx_str()) ) (UINT_PTR)GetHmenuOf(menu), title.wx_str()) )
{ {
wxLogLastError(wxT("InsertMenu")); wxLogLastError(wxT("InsertMenu"));
} }
@@ -1258,7 +1258,7 @@ bool wxMenuBar::Append(wxMenu *menu, const wxString& title)
} }
#else #else
if ( !::AppendMenu(GetHmenu(), MF_POPUP | MF_STRING, if ( !::AppendMenu(GetHmenu(), MF_POPUP | MF_STRING,
(UINT)submenu, title.wx_str()) ) (UINT_PTR)submenu, title.wx_str()) )
{ {
wxLogLastError(wxT("AppendMenu")); wxLogLastError(wxT("AppendMenu"));
} }

View File

@@ -186,13 +186,13 @@ wxMenuItem::~wxMenuItem()
// ---- // ----
// return the id for calling Win32 API functions // return the id for calling Win32 API functions
unsigned wxMenuItem::GetMSWId() const WXWPARAM wxMenuItem::GetMSWId() const
{ {
// we must use ids in unsigned short range with Windows functions, if we // we must use ids in unsigned short range with Windows functions, if we
// pass ids > USHRT_MAX to them they get very confused (e.g. start // pass ids > USHRT_MAX to them they get very confused (e.g. start
// generating WM_COMMAND messages with negative high word of wParam), so // generating WM_COMMAND messages with negative high word of wParam), so
// use the cast to ensure the id is in range // use the cast to ensure the id is in range
return m_subMenu ? wx_reinterpret_cast(unsigned, m_subMenu->GetHMenu()) return m_subMenu ? wxPtrToUInt(m_subMenu->GetHMenu())
: wx_static_cast(unsigned short, GetId()); : wx_static_cast(unsigned short, GetId());
} }

View File

@@ -338,7 +338,7 @@ bool wxPenRefData::Alloc()
{ {
case wxSTIPPLE: case wxSTIPPLE:
lb.lbStyle = BS_PATTERN; lb.lbStyle = BS_PATTERN;
lb.lbHatch = (LONG)m_stipple.GetHBITMAP(); lb.lbHatch = wxPtrToUInt(m_stipple.GetHBITMAP());
break; break;
case wxBDIAGONAL_HATCH: case wxBDIAGONAL_HATCH:

View File

@@ -122,19 +122,18 @@ IMPLEMENT_CLASS(wxWindowsPrintNativeData, wxPrintNativeDataBase)
wxWindowsPrintNativeData::wxWindowsPrintNativeData() wxWindowsPrintNativeData::wxWindowsPrintNativeData()
{ {
m_devMode = (void*) NULL; m_devMode = NULL;
m_devNames = (void*) NULL; m_devNames = NULL;
m_customWindowsPaperId = 0; m_customWindowsPaperId = 0;
} }
wxWindowsPrintNativeData::~wxWindowsPrintNativeData() wxWindowsPrintNativeData::~wxWindowsPrintNativeData()
{ {
HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode; if ( m_devMode )
if ( hDevMode ) ::GlobalFree(wx_static_cast(HGLOBAL, m_devMode));
GlobalFree(hDevMode);
HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames; if ( m_devNames )
if ( hDevNames ) ::GlobalFree(wx_static_cast(HGLOBAL, m_devNames));
GlobalFree(hDevNames);
} }
bool wxWindowsPrintNativeData::IsOk() const bool wxWindowsPrintNativeData::IsOk() const
@@ -144,205 +143,194 @@ bool wxWindowsPrintNativeData::IsOk() const
bool wxWindowsPrintNativeData::TransferTo( wxPrintData &data ) bool wxWindowsPrintNativeData::TransferTo( wxPrintData &data )
{ {
HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode; if ( !m_devMode )
HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
if (!hDevMode)
{
return false; return false;
GlobalPtrLock lockDevMode(m_devMode);
LPDEVMODE devMode = wx_static_cast(LPDEVMODE, lockDevMode.Get());
//// Orientation
if (devMode->dmFields & DM_ORIENTATION)
data.SetOrientation( devMode->dmOrientation );
//// Collation
if (devMode->dmFields & DM_COLLATE)
{
if (devMode->dmCollate == DMCOLLATE_TRUE)
data.SetCollate( true );
else
data.SetCollate( false );
}
//// Number of copies
if (devMode->dmFields & DM_COPIES)
data.SetNoCopies( devMode->dmCopies );
//// Bin
if (devMode->dmFields & DM_DEFAULTSOURCE) {
switch (devMode->dmDefaultSource) {
case DMBIN_ONLYONE : data.SetBin(wxPRINTBIN_ONLYONE ); break;
case DMBIN_LOWER : data.SetBin(wxPRINTBIN_LOWER ); break;
case DMBIN_MIDDLE : data.SetBin(wxPRINTBIN_MIDDLE ); break;
case DMBIN_MANUAL : data.SetBin(wxPRINTBIN_MANUAL ); break;
case DMBIN_ENVELOPE : data.SetBin(wxPRINTBIN_ENVELOPE ); break;
case DMBIN_ENVMANUAL : data.SetBin(wxPRINTBIN_ENVMANUAL ); break;
case DMBIN_AUTO : data.SetBin(wxPRINTBIN_AUTO ); break;
case DMBIN_TRACTOR : data.SetBin(wxPRINTBIN_TRACTOR ); break;
case DMBIN_SMALLFMT : data.SetBin(wxPRINTBIN_SMALLFMT ); break;
case DMBIN_LARGEFMT : data.SetBin(wxPRINTBIN_LARGEFMT ); break;
case DMBIN_LARGECAPACITY : data.SetBin(wxPRINTBIN_LARGECAPACITY ); break;
case DMBIN_CASSETTE : data.SetBin(wxPRINTBIN_CASSETTE ); break;
case DMBIN_FORMSOURCE : data.SetBin(wxPRINTBIN_FORMSOURCE ); break;
default:
if (devMode->dmDefaultSource>=DMBIN_USER) {
data.SetBin((wxPrintBin)((devMode->dmDefaultSource)-DMBIN_USER+(int)wxPRINTBIN_USER));
} else {
data.SetBin(wxPRINTBIN_DEFAULT);
}
break;
}
} else {
data.SetBin(wxPRINTBIN_DEFAULT);
}
if (devMode->dmFields & DM_MEDIATYPE)
{
wxASSERT( (int)devMode->dmMediaType != wxPRINTMEDIA_DEFAULT );
data.SetMedia(devMode->dmMediaType);
}
//// Printer name
if (devMode->dmDeviceName[0] != 0)
// This syntax fixes a crash when using VS 7.1
data.SetPrinterName( wxString(devMode->dmDeviceName, CCHDEVICENAME) );
//// Colour
if (devMode->dmFields & DM_COLOR)
{
if (devMode->dmColor == DMCOLOR_COLOR)
data.SetColour( true );
else
data.SetColour( false );
} }
else else
data.SetColour( true );
//// Paper size
// We don't know size of user defined paper and some buggy drivers
// set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
// dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
// code wouldn't set m_paperSize correctly.
bool foundPaperSize = false;
if ((devMode->dmFields & DM_PAPERSIZE) && (devMode->dmPaperSize < DMPAPER_USER))
{ {
LPDEVMODE devMode = (LPDEVMODE)GlobalLock(hDevMode); if (wxThePrintPaperDatabase)
//// Orientation
if (devMode->dmFields & DM_ORIENTATION)
data.SetOrientation( devMode->dmOrientation );
//// Collation
if (devMode->dmFields & DM_COLLATE)
{ {
if (devMode->dmCollate == DMCOLLATE_TRUE) wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize);
data.SetCollate( true ); if (paper)
else
data.SetCollate( false );
}
//// Number of copies
if (devMode->dmFields & DM_COPIES)
data.SetNoCopies( devMode->dmCopies );
//// Bin
if (devMode->dmFields & DM_DEFAULTSOURCE) {
switch (devMode->dmDefaultSource) {
case DMBIN_ONLYONE : data.SetBin(wxPRINTBIN_ONLYONE ); break;
case DMBIN_LOWER : data.SetBin(wxPRINTBIN_LOWER ); break;
case DMBIN_MIDDLE : data.SetBin(wxPRINTBIN_MIDDLE ); break;
case DMBIN_MANUAL : data.SetBin(wxPRINTBIN_MANUAL ); break;
case DMBIN_ENVELOPE : data.SetBin(wxPRINTBIN_ENVELOPE ); break;
case DMBIN_ENVMANUAL : data.SetBin(wxPRINTBIN_ENVMANUAL ); break;
case DMBIN_AUTO : data.SetBin(wxPRINTBIN_AUTO ); break;
case DMBIN_TRACTOR : data.SetBin(wxPRINTBIN_TRACTOR ); break;
case DMBIN_SMALLFMT : data.SetBin(wxPRINTBIN_SMALLFMT ); break;
case DMBIN_LARGEFMT : data.SetBin(wxPRINTBIN_LARGEFMT ); break;
case DMBIN_LARGECAPACITY : data.SetBin(wxPRINTBIN_LARGECAPACITY ); break;
case DMBIN_CASSETTE : data.SetBin(wxPRINTBIN_CASSETTE ); break;
case DMBIN_FORMSOURCE : data.SetBin(wxPRINTBIN_FORMSOURCE ); break;
default:
if (devMode->dmDefaultSource>=DMBIN_USER) {
data.SetBin((wxPrintBin)((devMode->dmDefaultSource)-DMBIN_USER+(int)wxPRINTBIN_USER));
} else {
data.SetBin(wxPRINTBIN_DEFAULT);
}
break;
}
} else {
data.SetBin(wxPRINTBIN_DEFAULT);
}
if (devMode->dmFields & DM_MEDIATYPE)
{
wxASSERT( (int)devMode->dmMediaType != wxPRINTMEDIA_DEFAULT );
data.SetMedia(devMode->dmMediaType);
}
//// Printer name
if (devMode->dmDeviceName[0] != 0)
// This syntax fixes a crash when using VS 7.1
data.SetPrinterName( wxString(devMode->dmDeviceName, CCHDEVICENAME) );
//// Colour
if (devMode->dmFields & DM_COLOR)
{
if (devMode->dmColor == DMCOLOR_COLOR)
data.SetColour( true );
else
data.SetColour( false );
}
else
data.SetColour( true );
//// Paper size
// We don't know size of user defined paper and some buggy drivers
// set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
// dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
// code wouldn't set m_paperSize correctly.
bool foundPaperSize = false;
if ((devMode->dmFields & DM_PAPERSIZE) && (devMode->dmPaperSize < DMPAPER_USER))
{
if (wxThePrintPaperDatabase)
{ {
wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize); data.SetPaperId( paper->GetId() );
if (paper) data.SetPaperSize( wxSize(paper->GetWidth() / 10,paper->GetHeight() / 10) );
{
data.SetPaperId( paper->GetId() );
data.SetPaperSize( wxSize(paper->GetWidth() / 10,paper->GetHeight() / 10) );
m_customWindowsPaperId = 0;
foundPaperSize = true;
}
}
else
{
// Shouldn't really get here
wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
data.SetPaperId( wxPAPER_NONE );
data.SetPaperSize( wxSize(0,0) );
m_customWindowsPaperId = 0; m_customWindowsPaperId = 0;
foundPaperSize = true;
GlobalUnlock(hDevMode);
return false;
} }
} }
else
if (!foundPaperSize) {
if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH))
{
// DEVMODE is in tenths of a millimeter
data.SetPaperSize( wxSize(devMode->dmPaperWidth / 10, devMode->dmPaperLength / 10) );
data.SetPaperId( wxPAPER_NONE );
m_customWindowsPaperId = devMode->dmPaperSize;
}
else
{
// Often will reach this for non-standard paper sizes (sizes which
// wouldn't be in wxWidget's paper database). Setting
// m_customWindowsPaperId to devMode->dmPaperSize should be enough
// to get this paper size working.
data.SetPaperSize( wxSize(0,0) );
data.SetPaperId( wxPAPER_NONE );
m_customWindowsPaperId = devMode->dmPaperSize;
}
}
//// Duplex
if (devMode->dmFields & DM_DUPLEX)
{ {
switch (devMode->dmDuplex) // Shouldn't really get here
{ wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
case DMDUP_HORIZONTAL: data.SetDuplex( wxDUPLEX_HORIZONTAL ); break; data.SetPaperId( wxPAPER_NONE );
case DMDUP_VERTICAL: data.SetDuplex( wxDUPLEX_VERTICAL ); break; data.SetPaperSize( wxSize(0,0) );
default: m_customWindowsPaperId = 0;
case DMDUP_SIMPLEX: data.SetDuplex( wxDUPLEX_SIMPLEX ); break;
} return false;
} }
else
data.SetDuplex( wxDUPLEX_SIMPLEX );
//// Quality
if (devMode->dmFields & DM_PRINTQUALITY)
{
switch (devMode->dmPrintQuality)
{
case DMRES_MEDIUM: data.SetQuality( wxPRINT_QUALITY_MEDIUM ); break;
case DMRES_LOW: data.SetQuality( wxPRINT_QUALITY_LOW ); break;
case DMRES_DRAFT: data.SetQuality( wxPRINT_QUALITY_DRAFT ); break;
case DMRES_HIGH: data.SetQuality( wxPRINT_QUALITY_HIGH ); break;
default:
{
// TODO: if the printer fills in the resolution in DPI, how
// will the application know if it's high, low, draft etc.??
// wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
data.SetQuality( devMode->dmPrintQuality );
break;
}
}
}
else
data.SetQuality( wxPRINT_QUALITY_HIGH );
if (devMode->dmDriverExtra > 0)
data.SetPrivData( (char *)devMode+devMode->dmSize, devMode->dmDriverExtra );
else
data.SetPrivData( NULL, 0 );
GlobalUnlock(hDevMode);
} }
if (hDevNames) if (!foundPaperSize) {
{ if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH))
LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(hDevNames);
if (lpDevNames)
{ {
// TODO: Unicode-ification // DEVMODE is in tenths of a millimeter
data.SetPaperSize( wxSize(devMode->dmPaperWidth / 10, devMode->dmPaperLength / 10) );
data.SetPaperId( wxPAPER_NONE );
m_customWindowsPaperId = devMode->dmPaperSize;
}
else
{
// Often will reach this for non-standard paper sizes (sizes which
// wouldn't be in wxWidget's paper database). Setting
// m_customWindowsPaperId to devMode->dmPaperSize should be enough
// to get this paper size working.
data.SetPaperSize( wxSize(0,0) );
data.SetPaperId( wxPAPER_NONE );
m_customWindowsPaperId = devMode->dmPaperSize;
}
}
// Get the port name //// Duplex
// port is obsolete in WIN32
// m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
// Get the printer name if (devMode->dmFields & DM_DUPLEX)
wxString printerName = (LPTSTR)lpDevNames + lpDevNames->wDeviceOffset; {
switch (devMode->dmDuplex)
{
case DMDUP_HORIZONTAL: data.SetDuplex( wxDUPLEX_HORIZONTAL ); break;
case DMDUP_VERTICAL: data.SetDuplex( wxDUPLEX_VERTICAL ); break;
default:
case DMDUP_SIMPLEX: data.SetDuplex( wxDUPLEX_SIMPLEX ); break;
}
}
else
data.SetDuplex( wxDUPLEX_SIMPLEX );
// Not sure if we should check for this mismatch //// Quality
if (devMode->dmFields & DM_PRINTQUALITY)
{
switch (devMode->dmPrintQuality)
{
case DMRES_MEDIUM: data.SetQuality( wxPRINT_QUALITY_MEDIUM ); break;
case DMRES_LOW: data.SetQuality( wxPRINT_QUALITY_LOW ); break;
case DMRES_DRAFT: data.SetQuality( wxPRINT_QUALITY_DRAFT ); break;
case DMRES_HIGH: data.SetQuality( wxPRINT_QUALITY_HIGH ); break;
default:
{
// TODO: if the printer fills in the resolution in DPI, how
// will the application know if it's high, low, draft etc.??
// wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
data.SetQuality( devMode->dmPrintQuality );
break;
}
}
}
else
data.SetQuality( wxPRINT_QUALITY_HIGH );
if (devMode->dmDriverExtra > 0)
data.SetPrivData( (char *)devMode+devMode->dmSize, devMode->dmDriverExtra );
else
data.SetPrivData( NULL, 0 );
if ( m_devNames )
{
GlobalPtrLock lockDevNames(m_devNames);
LPDEVNAMES lpDevNames = wx_static_cast(LPDEVNAMES, lockDevNames.Get());
// TODO: Unicode-ification
// Get the port name
// port is obsolete in WIN32
// m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
// Get the printer name
wxString printerName = (LPTSTR)lpDevNames + lpDevNames->wDeviceOffset;
// Not sure if we should check for this mismatch
// wxASSERT_MSG( (m_printerName.empty() || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!"); // wxASSERT_MSG( (m_printerName.empty() || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
if (!printerName.empty()) if (!printerName.empty())
data.SetPrinterName( printerName ); data.SetPrinterName( printerName );
GlobalUnlock(hDevNames);
}
} }
return true; return true;
@@ -350,9 +338,8 @@ bool wxWindowsPrintNativeData::TransferTo( wxPrintData &data )
bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData &data ) bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData &data )
{ {
HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode; HGLOBAL hDevMode = wx_static_cast(HGLOBAL, m_devMode);
HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames; if ( !m_devMode )
if (!hDevMode)
{ {
// Use PRINTDLG as a way of creating a DEVMODE object // Use PRINTDLG as a way of creating a DEVMODE object
PRINTDLG pd; PRINTDLG pd;
@@ -398,7 +385,7 @@ bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData &data )
else else
{ {
hDevMode = pd.hDevMode; hDevMode = pd.hDevMode;
m_devMode = (void*)(long) hDevMode; m_devMode = hDevMode;
pd.hDevMode = NULL; pd.hDevMode = NULL;
// We'll create a new DEVNAMEs structure below. // We'll create a new DEVNAMEs structure below.
@@ -415,7 +402,8 @@ bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData &data )
if ( hDevMode ) if ( hDevMode )
{ {
LPDEVMODE devMode = (LPDEVMODE) GlobalLock(hDevMode); GlobalPtrLock lockDevMode(hDevMode);
DEVMODE * const devMode = wx_static_cast(DEVMODE *, lockDevMode.Get());
//// Orientation //// Orientation
devMode->dmOrientation = (short)data.GetOrientation(); devMode->dmOrientation = (short)data.GetOrientation();
@@ -432,9 +420,9 @@ bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData &data )
wxString name = data.GetPrinterName(); wxString name = data.GetPrinterName();
if (!name.empty()) if (!name.empty())
{ {
//int len = wxMin(31, m_printerName.Len()); wxStrncpy(devMode->dmDeviceName, name.wx_str(),
wxStrncpy((wxChar*)devMode->dmDeviceName,name.c_str(),31); WXSIZEOF(devMode->dmDeviceName) - 1);
devMode->dmDeviceName[31] = wxT('\0'); devMode->dmDeviceName[WXSIZEOF(devMode->dmDeviceName) - 1] = wxT('\0');
} }
//// Colour //// Colour
@@ -559,16 +547,15 @@ bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData &data )
devMode->dmMediaType = data.GetMedia(); devMode->dmMediaType = data.GetMedia();
devMode->dmFields |= DM_MEDIATYPE; devMode->dmFields |= DM_MEDIATYPE;
} }
GlobalUnlock(hDevMode);
} }
if ( hDevNames ) if ( m_devNames )
{ {
GlobalFree(hDevNames); ::GlobalFree(wx_static_cast(HGLOBAL, m_devNames));
} }
// TODO: I hope it's OK to pass some empty strings to DEVNAMES. // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
m_devNames = (void*) (long) wxCreateDevNames(wxEmptyString, data.GetPrinterName(), wxEmptyString); m_devNames = wxCreateDevNames(wxEmptyString, data.GetPrinterName(), wxEmptyString);
return true; return true;
} }
@@ -700,14 +687,14 @@ bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData &data )
if (pd->hDevNames) if (pd->hDevNames)
GlobalFree(pd->hDevNames); GlobalFree(pd->hDevNames);
pd->hDevMode = (HGLOBAL)(DWORD) native_data->GetDevMode(); pd->hDevMode = wx_static_cast(HGLOBAL, native_data->GetDevMode());
native_data->SetDevMode( (void*) NULL); native_data->SetDevMode(NULL);
// Shouldn't assert; we should be able to test Ok-ness at a higher level // Shouldn't assert; we should be able to test Ok-ness at a higher level
//wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!")); //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
pd->hDevNames = (HGLOBAL)(DWORD) native_data->GetDevNames(); pd->hDevNames = wx_static_cast(HGLOBAL, native_data->GetDevNames());
native_data->SetDevNames( (void*) NULL); native_data->SetDevNames(NULL);
pd->hDC = (HDC) NULL; pd->hDC = (HDC) NULL;
@@ -772,10 +759,9 @@ bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData &data )
{ {
if (native_data->GetDevMode()) if (native_data->GetDevMode())
{ {
// Make sure we don't leak memory ::GlobalFree(wx_static_cast(HGLOBAL, native_data->GetDevMode()));
GlobalFree( (HGLOBAL)(DWORD) native_data->GetDevMode() );
} }
native_data->SetDevMode( (void*)(long) pd->hDevMode ); native_data->SetDevMode(pd->hDevMode);
pd->hDevMode = NULL; pd->hDevMode = NULL;
} }
@@ -784,10 +770,9 @@ bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData &data )
{ {
if (native_data->GetDevNames()) if (native_data->GetDevNames())
{ {
// Make sure we don't leak memory ::GlobalFree(wx_static_cast(HGLOBAL, native_data->GetDevNames()));
GlobalFree((HGLOBAL)(DWORD) native_data->GetDevNames());
} }
native_data->SetDevNames((void*)(long) pd->hDevNames); native_data->SetDevNames(pd->hDevNames);
pd->hDevNames = NULL; pd->hDevNames = NULL;
} }

View File

@@ -183,7 +183,7 @@ bool wxRadioBox::Create(wxWindow *parent,
styleBtn, styleBtn,
0, 0, 0, 0, // will be set in SetSize() 0, 0, 0, 0, // will be set in SetSize()
GetHwndOf(parent), GetHwndOf(parent),
(HMENU)subid.GetValue(), (HMENU)wxUIntToPtr(subid.GetValue()),
wxGetInstance(), wxGetInstance(),
NULL); NULL);
@@ -210,7 +210,8 @@ bool wxRadioBox::Create(wxWindow *parent,
wxEmptyString, wxEmptyString,
WS_GROUP | BS_AUTORADIOBUTTON | WS_CHILD, WS_GROUP | BS_AUTORADIOBUTTON | WS_CHILD,
0, 0, 0, 0, GetHwndOf(parent), 0, 0, 0, 0, GetHwndOf(parent),
(HMENU)m_dummyId.GetValue(), wxGetInstance(), NULL); (HMENU)wxUIntToPtr(m_dummyId.GetValue()),
wxGetInstance(), NULL);
m_radioButtons->SetFont(GetFont()); m_radioButtons->SetFont(GetFont());

View File

@@ -217,7 +217,7 @@ wxSlider::Create(wxWindow *parent,
WS_CHILD | WS_VISIBLE | SS_CENTER, WS_CHILD | WS_VISIBLE | SS_CENTER,
0, 0, 0, 0, 0, 0, 0, 0,
hwndParent, hwndParent,
(HMENU)lblid.GetValue(), (HMENU)wxUIntToPtr(lblid.GetValue()),
wxGetInstance(), wxGetInstance(),
NULL NULL
); );

View File

@@ -106,7 +106,7 @@ bool wxStatusBar95::Create(wxWindow *parent,
wstyle, wstyle,
0, 0, 0, 0, 0, 0, 0, 0,
GetHwndOf(parent), GetHwndOf(parent),
(HMENU)m_windowId.GetValue(), (HMENU)wxUIntToPtr(m_windowId.GetValue()),
wxGetInstance(), wxGetInstance(),
NULL NULL
); );

View File

@@ -805,8 +805,8 @@ bool wxToolBar::Realize()
TBREPLACEBITMAP replaceBitmap; TBREPLACEBITMAP replaceBitmap;
replaceBitmap.hInstOld = NULL; replaceBitmap.hInstOld = NULL;
replaceBitmap.hInstNew = NULL; replaceBitmap.hInstNew = NULL;
replaceBitmap.nIDOld = (UINT) oldToolBarBitmap; replaceBitmap.nIDOld = (UINT_PTR)oldToolBarBitmap;
replaceBitmap.nIDNew = (UINT) hBitmap; replaceBitmap.nIDNew = (UINT_PTR)hBitmap;
replaceBitmap.nButtons = nButtons; replaceBitmap.nButtons = nButtons;
if ( !::SendMessage(GetHwnd(), TB_REPLACEBITMAP, if ( !::SendMessage(GetHwnd(), TB_REPLACEBITMAP,
0, (LPARAM) &replaceBitmap) ) 0, (LPARAM) &replaceBitmap) )
@@ -835,7 +835,7 @@ bool wxToolBar::Realize()
{ {
TBADDBITMAP addBitmap; TBADDBITMAP addBitmap;
addBitmap.hInst = 0; addBitmap.hInst = 0;
addBitmap.nID = (UINT) hBitmap; addBitmap.nID = (UINT_PTR)hBitmap;
if ( ::SendMessage(GetHwnd(), TB_ADDBITMAP, if ( ::SendMessage(GetHwnd(), TB_ADDBITMAP,
(WPARAM) nButtons, (LPARAM)&addBitmap) == -1 ) (WPARAM) nButtons, (LPARAM)&addBitmap) == -1 )
{ {
@@ -915,7 +915,7 @@ bool wxToolBar::Realize()
{ {
const wxString& label = tool->GetLabel(); const wxString& label = tool->GetLabel();
if ( !label.empty() ) if ( !label.empty() )
button.iString = (int)label.wx_str(); button.iString = (INT_PTR)label.wx_str();
} }
button.idCommand = tool->GetId(); button.idCommand = tool->GetId();

View File

@@ -105,7 +105,7 @@ public:
uFlags |= TTF_TRANSPARENT; uFlags |= TTF_TRANSPARENT;
} }
uId = (UINT)hwndOwner; uId = (UINT_PTR)hwndOwner;
} }
}; };
@@ -374,9 +374,12 @@ void wxToolTip::Add(WXHWND hWnd)
} }
// only set a new width if it is bigger than the current setting // only set a new width if it is bigger than the current setting
if (max > SendTooltipMessage(GetToolTipCtrl(), TTM_GETMAXTIPWIDTH, 0)) if ( max > SendTooltipMessage(GetToolTipCtrl(),
TTM_GETMAXTIPWIDTH, 0) )
{
SendTooltipMessage(GetToolTipCtrl(), TTM_SETMAXTIPWIDTH, SendTooltipMessage(GetToolTipCtrl(), TTM_SETMAXTIPWIDTH,
(void *)max); wxUIntToPtr(max));
}
} }
else else
#endif // comctl32.dll >= 4.70 #endif // comctl32.dll >= 4.70

View File

@@ -1233,7 +1233,7 @@ void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event)
{ {
// restore focus to the child which was last focused unless we already // restore focus to the child which was last focused unless we already
// have it // have it
wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd); wxLogTrace(_T("focus"), _T("wxTLW %p activated."), m_hWnd);
wxWindow *winFocus = FindFocus(); wxWindow *winFocus = FindFocus();
if ( !winFocus || wxGetTopLevelParent(winFocus) != this ) if ( !winFocus || wxGetTopLevelParent(winFocus) != this )
@@ -1266,10 +1266,9 @@ void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event)
} }
wxLogTrace(_T("focus"), wxLogTrace(_T("focus"),
_T("wxTLW %08x deactivated, last focused: %08x."), _T("wxTLW %p deactivated, last focused: %p."),
(int) m_hWnd, m_hWnd,
(int) (m_winLastFocused ? GetHwndOf(m_winLastFocused) m_winLastFocused ? GetHwndOf(m_winLastFocused) : NULL);
: NULL));
event.Skip(); event.Skip();
} }

View File

@@ -212,6 +212,13 @@ WX_DECLARE_HASH_MAP(int, wxWindow::MSWMessageHandler,
static MSWMessageHandlers gs_messageHandlers; static MSWMessageHandlers gs_messageHandlers;
// hash containing all our windows, it uses HWND keys and wxWindow* values
WX_DECLARE_HASH_MAP(HWND, wxWindow *,
wxPointerHash, wxPointerEqual,
WindowHandles);
static WindowHandles gs_windowHandles;
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// private functions // private functions
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@@ -227,7 +234,6 @@ LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message,
void wxRemoveHandleAssociation(wxWindowMSW *win); void wxRemoveHandleAssociation(wxWindowMSW *win);
extern void wxAssociateWinWithHandle(HWND hWnd, wxWindowMSW *win); extern void wxAssociateWinWithHandle(HWND hWnd, wxWindowMSW *win);
wxWindow *wxFindWinFromHandle(WXHWND hWnd);
// get the text metrics for the current font // get the text metrics for the current font
static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win); static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win);
@@ -848,7 +854,7 @@ void wxWindowMSW::DoReleaseMouse()
/* static */ wxWindow *wxWindowBase::GetCapture() /* static */ wxWindow *wxWindowBase::GetCapture()
{ {
HWND hwnd = ::GetCapture(); HWND hwnd = ::GetCapture();
return hwnd ? wxFindWinFromHandle((WXHWND)hwnd) : (wxWindow *)NULL; return hwnd ? wxFindWinFromHandle(hwnd) : NULL;
} }
bool wxWindowMSW::SetFont(const wxFont& font) bool wxWindowMSW::SetFont(const wxFont& font)
@@ -2350,7 +2356,7 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
if ( (style & BS_OWNERDRAW) == BS_OWNERDRAW ) if ( (style & BS_OWNERDRAW) == BS_OWNERDRAW )
{ {
// emulate the button click // emulate the button click
btn = wxFindWinFromHandle((WXHWND)msg->hwnd); btn = wxFindWinFromHandle(msg->hwnd);
} }
bProcess = false; bProcess = false;
@@ -2641,11 +2647,11 @@ LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM w
// trace all messages - useful for the debugging // trace all messages - useful for the debugging
#ifdef __WXDEBUG__ #ifdef __WXDEBUG__
wxLogTrace(wxTraceMessages, wxLogTrace(wxTraceMessages,
wxT("Processing %s(hWnd=%08lx, wParam=%8lx, lParam=%8lx)"), wxT("Processing %s(hWnd=%p, wParam=%08lx, lParam=%08lx)"),
wxGetMessageName(message), (long)hWnd, (long)wParam, lParam); wxGetMessageName(message), hWnd, (long)wParam, lParam);
#endif // __WXDEBUG__ #endif // __WXDEBUG__
wxWindowMSW *wnd = wxFindWinFromHandle((WXHWND) hWnd); wxWindowMSW *wnd = wxFindWinFromHandle(hWnd);
// when we get the first message for the HWND we just created, we associate // when we get the first message for the HWND we just created, we associate
// it with wxWindow stored in gs_winBeingCreated // it with wxWindow stored in gs_winBeingCreated
@@ -2781,11 +2787,11 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
break; break;
case WM_SETFOCUS: case WM_SETFOCUS:
processed = HandleSetFocus((WXHWND)(HWND)wParam); processed = HandleSetFocus((WXHWND)wParam);
break; break;
case WM_KILLFOCUS: case WM_KILLFOCUS:
processed = HandleKillFocus((WXHWND)(HWND)wParam); processed = HandleKillFocus((WXHWND)wParam);
break; break;
case WM_PRINTCLIENT: case WM_PRINTCLIENT:
@@ -3007,23 +3013,15 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
// for these messages we must return true if process the message // for these messages we must return true if process the message
#ifdef WM_DRAWITEM #ifdef WM_DRAWITEM
case WM_DRAWITEM: case WM_DRAWITEM:
case WM_MEASUREITEM: processed = MSWOnDrawItem(wParam, (WXDRAWITEMSTRUCT *)lParam);
{ if ( processed )
int idCtrl = (UINT)wParam; rc.result = TRUE;
if ( message == WM_DRAWITEM ) break;
{
processed = MSWOnDrawItem(idCtrl,
(WXDRAWITEMSTRUCT *)lParam);
}
else
{
processed = MSWOnMeasureItem(idCtrl,
(WXMEASUREITEMSTRUCT *)lParam);
}
if ( processed ) case WM_MEASUREITEM:
rc.result = TRUE; processed = MSWOnMeasureItem(wParam, (WXMEASUREITEMSTRUCT *)lParam);
} if ( processed )
rc.result = TRUE;
break; break;
#endif // defined(WM_DRAWITEM) #endif // defined(WM_DRAWITEM)
@@ -3215,11 +3213,11 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
#endif #endif
case WM_PALETTECHANGED: case WM_PALETTECHANGED:
processed = HandlePaletteChanged((WXHWND) (HWND) wParam); processed = HandlePaletteChanged((WXHWND)wParam);
break; break;
case WM_CAPTURECHANGED: case WM_CAPTURECHANGED:
processed = HandleCaptureChanged((WXHWND) (HWND) lParam); processed = HandleCaptureChanged((WXHWND)lParam);
break; break;
case WM_SETTINGCHANGE: case WM_SETTINGCHANGE:
@@ -3231,7 +3229,7 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
break; break;
case WM_ERASEBKGND: case WM_ERASEBKGND:
processed = HandleEraseBkgnd((WXHDC)(HDC)wParam); processed = HandleEraseBkgnd((WXHDC)wParam);
if ( processed ) if ( processed )
{ {
// we processed the message, i.e. erased the background // we processed the message, i.e. erased the background
@@ -3246,7 +3244,7 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
#endif #endif
case WM_INITDIALOG: case WM_INITDIALOG:
processed = HandleInitDialog((WXHWND)(HWND)wParam); processed = HandleInitDialog((WXHWND)wParam);
if ( processed ) if ( processed )
{ {
@@ -3270,7 +3268,7 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
#endif #endif
case WM_SETCURSOR: case WM_SETCURSOR:
processed = HandleSetCursor((WXHWND)(HWND)wParam, processed = HandleSetCursor((WXHWND)wParam,
LOWORD(lParam), // hit test LOWORD(lParam), // hit test
HIWORD(lParam)); // mouse msg HIWORD(lParam)); // mouse msg
@@ -3355,9 +3353,10 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
// we could have got an event from our child, reflect it back // we could have got an event from our child, reflect it back
// to it if this is the case // to it if this is the case
wxWindowMSW *win = NULL; wxWindowMSW *win = NULL;
if ( (WXHWND)wParam != m_hWnd ) WXHWND hWnd = (WXHWND)wParam;
if ( hWnd != m_hWnd )
{ {
win = FindItemByHWND((WXHWND)wParam); win = FindItemByHWND(hWnd);
} }
if ( !win ) if ( !win )
@@ -3409,30 +3408,33 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
// now alter the client size making room for drawing a themed border // now alter the client size making room for drawing a themed border
NCCALCSIZE_PARAMS *csparam = NULL; NCCALCSIZE_PARAMS *csparam = NULL;
RECT rect; RECT *rect;
if (wParam) if ( wParam )
{ {
csparam = (NCCALCSIZE_PARAMS*)lParam; csparam = (NCCALCSIZE_PARAMS *)lParam;
rect = csparam->rgrc[0]; rect = &csparam->rgrc[0];
} }
else else
{ {
rect = *((RECT*)lParam); rect = (RECT *)lParam;
} }
wxUxThemeHandle hTheme((wxWindow *)this, L"EDIT"); wxUxThemeHandle hTheme((wxWindow *)this, L"EDIT");
RECT rcClient = { 0, 0, 0, 0 }; RECT rcClient = { 0, 0, 0, 0 };
wxClientDC dc((wxWindow *)this); wxClientDC dc((wxWindow *)this);
wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl(); wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl();
if (theme->GetThemeBackgroundContentRect( if ( theme->GetThemeBackgroundContentRect
hTheme, GetHdcOf(*impl), EP_EDITTEXT, ETS_NORMAL, (
&rect, &rcClient) == S_OK) hTheme,
GetHdcOf(*impl),
EP_EDITTEXT,
ETS_NORMAL,
rect,
&rcClient) == S_OK )
{ {
InflateRect(&rcClient, -1, -1); InflateRect(&rcClient, -1, -1);
if (wParam) *rect = rcClient;
csparam->rgrc[0] = rcClient;
else
*((RECT*)lParam) = rcClient;
rc.result = WVR_REDRAW; rc.result = WVR_REDRAW;
} }
} }
@@ -3513,38 +3515,40 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
// wxWindow <-> HWND map // wxWindow <-> HWND map
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
wxWinHashTable *wxWinHandleHash = NULL; wxWindow *wxFindWinFromHandle(HWND hwnd)
wxWindow *wxFindWinFromHandle(WXHWND hWnd)
{ {
return (wxWindow*)wxWinHandleHash->Get((long)hWnd); WindowHandles::const_iterator i = gs_windowHandles.find(hwnd);
return i == gs_windowHandles.end() ? NULL : i->second;
} }
void wxAssociateWinWithHandle(HWND hWnd, wxWindowMSW *win) void wxAssociateWinWithHandle(HWND hwnd, wxWindowMSW *win)
{ {
// adding NULL hWnd is (first) surely a result of an error and // adding NULL hwnd is (first) surely a result of an error and
// (secondly) breaks menu command processing // (secondly) breaks menu command processing
wxCHECK_RET( hWnd != (HWND)NULL, wxCHECK_RET( hwnd != (HWND)NULL,
wxT("attempt to add a NULL hWnd to window list ignored") ); wxT("attempt to add a NULL hwnd to window list ignored") );
wxWindow *oldWin = wxFindWinFromHandle((WXHWND) hWnd);
#ifdef __WXDEBUG__ #ifdef __WXDEBUG__
if ( oldWin && (oldWin != win) ) WindowHandles::const_iterator i = gs_windowHandles.find(hwnd);
if ( i != gs_windowHandles.end() )
{ {
wxLogDebug(wxT("HWND %X already associated with another window (%s)"), if ( i->second != win )
(int) hWnd, win->GetClassInfo()->GetClassName()); {
wxLogDebug(wxT("HWND %p already associated with another window (%s)"),
hwnd, win->GetClassInfo()->GetClassName());
}
//else: this actually happens currently because we associate the window
// with its HWND during creation (if we create it) and also when
// SubclassWin() is called later, this is ok
} }
else
#endif // __WXDEBUG__ #endif // __WXDEBUG__
if (!oldWin)
{ gs_windowHandles[hwnd] = win;
wxWinHandleHash->Put((long)hWnd, (wxWindow *)win);
}
} }
void wxRemoveHandleAssociation(wxWindowMSW *win) void wxRemoveHandleAssociation(wxWindowMSW *win)
{ {
wxWinHandleHash->Delete((long)win->GetHWND()); gs_windowHandles.erase(GetHwndOf(win));
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -3686,7 +3690,7 @@ bool wxWindowMSW::MSWCreate(const wxChar *wclass,
style, style,
x, y, w, h, x, y, w, h,
(HWND)MSWGetParent(), (HWND)MSWGetParent(),
(HMENU)controlId, (HMENU)wxUIntToPtr(controlId),
wxGetInstance(), wxGetInstance(),
NULL // no extra data NULL // no extra data
); );
@@ -3716,7 +3720,7 @@ bool wxWindowMSW::HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
#ifndef __WXMICROWIN__ #ifndef __WXMICROWIN__
LPNMHDR hdr = (LPNMHDR)lParam; LPNMHDR hdr = (LPNMHDR)lParam;
HWND hWnd = hdr->hwndFrom; HWND hWnd = hdr->hwndFrom;
wxWindow *win = wxFindWinFromHandle((WXHWND)hWnd); wxWindow *win = wxFindWinFromHandle(hWnd);
// if the control is one of our windows, let it handle the message itself // if the control is one of our windows, let it handle the message itself
if ( win ) if ( win )
@@ -5183,7 +5187,7 @@ static wxWindowMSW *FindWindowForMouseEvent(wxWindowMSW *win, int *x, int *y)
::IsWindowVisible(hwndUnderMouse) && ::IsWindowVisible(hwndUnderMouse) &&
::IsWindowEnabled(hwndUnderMouse) ) ::IsWindowEnabled(hwndUnderMouse) )
{ {
wxWindow *winUnderMouse = wxFindWinFromHandle((WXHWND)hwndUnderMouse); wxWindow *winUnderMouse = wxFindWinFromHandle(hwndUnderMouse);
if ( winUnderMouse ) if ( winUnderMouse )
{ {
// translate the mouse coords to the other window coords // translate the mouse coords to the other window coords
@@ -6185,7 +6189,7 @@ wxWindow *wxGetActiveWindow()
HWND hWnd = GetActiveWindow(); HWND hWnd = GetActiveWindow();
if ( hWnd != 0 ) if ( hWnd != 0 )
{ {
return wxFindWinFromHandle((WXHWND) hWnd); return wxFindWinFromHandle(hWnd);
} }
return NULL; return NULL;
} }
@@ -6200,7 +6204,7 @@ extern wxWindow *wxGetWindowFromHWND(WXHWND hWnd)
wxWindow *win = (wxWindow *)NULL; wxWindow *win = (wxWindow *)NULL;
if ( hwnd ) if ( hwnd )
{ {
win = wxFindWinFromHandle((WXHWND)hwnd); win = wxFindWinFromHandle(hwnd);
if ( !win ) if ( !win )
{ {
#if wxUSE_RADIOBOX #if wxUSE_RADIOBOX
@@ -6244,7 +6248,7 @@ extern wxWindow *wxGetWindowFromHWND(WXHWND hWnd)
#endif #endif
hwnd = ::GetParent(hwnd); hwnd = ::GetParent(hwnd);
win = wxFindWinFromHandle((WXHWND)hwnd); win = wxFindWinFromHandle(hwnd);
} }
return win; return win;