# define WXFAR
#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 */
typedef void * WXHWND;
typedef void * WXHANDLE;
typedef WXHWND WXWidget;
#ifdef __WIN64__
-typedef unsigned __int64 WXWPARAM;
+typedef unsigned __int64 WXWPARAM;
typedef __int64 WXLPARAM;
typedef __int64 WXLRESULT;
#else
-typedef unsigned int WXWPARAM;
-typedef long WXLPARAM;
-typedef long WXLRESULT;
+typedef wxW64 unsigned int WXWPARAM;
+typedef wxW64 long WXLPARAM;
+typedef wxW64 long WXLRESULT;
#endif
#if defined(__GNUWIN32__) || defined(__WXMICROWIN__)
//
// notice that it also returns the id as an unsigned int, as required by
// Win32 API
- unsigned GetMSWId() const;
+ WXWPARAM GetMSWId() const;
// mark item as belonging to the given radio group
void SetAsRadioGroupStart();
// 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
-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
// wxFindWinFromHandle() above it will also work for "sub controls" of a
~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_
// overwrite them if there is a chance that they're not defined
#if !defined(_MSC_VER) || (_MSC_VER < 1300)
#define UINT_PTR unsigned int
+ #define INT_PTR int
#define LONG_PTR long
#define ULONG_PTR unsigned long
#define DWORD_PTR unsigned long
::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
// for it
RegisterWindowClasses();
- wxWinHandleHash = new wxWinHashTable(wxKEY_INTEGER, 100);
-
#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
wxSetKeyboardHook(true);
#endif
void wxApp::CleanUp()
{
- // all objects pending for deletion must be deleted first, otherwise we
- // would crash when they use wxWinHandleHash (and UnregisterWindowClasses()
- // call wouldn't succeed as long as any windows still exist), so call the
- // base class method first and only then do our clean up
+ // all objects pending for deletion must be deleted first, otherwise
+ // UnregisterWindowClasses() call wouldn't succeed (because windows
+ // using the classes being unregistered still exist), so call the base
+ // class method first and only then do our clean up
wxAppBase::CleanUp();
#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
// unregister the classes now
UnregisterWindowClasses();
- delete wxWinHandleHash;
- wxWinHandleHash = NULL;
-
#ifdef __WXWINCE__
free( wxCanvasClassName );
free( wxCanvasClassNameNR );
msStyle,
0, 0, 0, 0,
GetWinHwnd(parent),
- (HMENU)m_windowId.GetValue(),
+ (HMENU)wxUIntToPtr(m_windowId.GetValue()),
wxGetInstance(),
NULL
);
label.wx_str(), // the window name
style, // the window style
x, y, w, h, // the window position and size
- GetHwndOf(GetParent()), // parent
- (HMENU)GetId(), // child id
+ GetHwndOf(GetParent()), // parent
+ (HMENU)wxUIntToPtr(GetId()), // child id
wxGetInstance(), // app instance
NULL // creation parameters
);
#ifndef __WXMICROWIN__
int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm,
- DWORD dwStyle, LONG lParam);
+ DWORD dwStyle, LPARAM lParam);
#endif
// ============================================================================
#ifndef __WXMICROWIN__
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
HDC hdc = ::BeginPaint(GetHwnd(), &ps);
// 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 )
{
const wxIcon& icon = GetIcon();
HICON hIcon = icon.Ok() ? GetHiconOf(icon)
: (HICON)GetDefaultIcon();
- rc = (long)hIcon;
+ rc = (WXLRESULT)hIcon;
processed = rc != 0;
}
break;
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
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.
wxWindowCreationHook hook(this);
m_hWnd = (WXHWND)::SendMessage(GetWinHwnd(parent->GetClientWindow()),
- WM_MDICREATE, 0, (LONG)(LPSTR)&mcs);
+ WM_MDICREATE, 0, (LPARAM)&mcs);
if ( !m_hWnd )
{
{
success = true;
::InsertMenu(hmenu, i, MF_BYPOSITION | MF_POPUP | MF_STRING,
- (UINT)subMenu, _("&Window").wx_str());
+ (UINT_PTR)subMenu, _("&Window").wx_str());
break;
}
}
if ( !success )
{
- ::AppendMenu(hmenu, MF_POPUP, (UINT)subMenu, _("&Window").wx_str());
+ ::AppendMenu(hmenu, MF_POPUP,
+ (UINT_PTR)subMenu, _("&Window").wx_str());
}
}
// id is the numeric id for normal menu items and HMENU for submenus as
// required by ::AppendMenu() API
- UINT id;
+ UINT_PTR id;
wxMenu *submenu = pItem->GetSubMenu();
if ( submenu != NULL ) {
wxASSERT_MSG( submenu->GetHMenu(), wxT("invalid submenu") );
submenu->SetParent(this);
- id = (UINT)submenu->GetHMenu();
+ id = (UINT_PTR)submenu->GetHMenu();
flags |= MF_POPUP;
}
for ( i = 0, it = m_menus.begin(); i < count; i++, it++ )
{
if ( !::AppendMenu((HMENU)m_hMenu, MF_POPUP | MF_STRING,
- (UINT)(*it)->GetHMenu(),
+ (UINT_PTR)(*it)->GetHMenu(),
m_titles[i].wx_str()) )
{
wxLogLastError(wxT("AppendMenu"));
int mswpos = MSWPositionForWxMenu(GetMenu(pos),pos);
- UINT id;
+ UINT_PTR id;
UINT flagsOld = ::GetMenuState((HMENU)m_hMenu, mswpos, MF_BYPOSITION);
if ( flagsOld == 0xFFFFFFFF )
{
{
// HIBYTE contains the number of items in the submenu in this case
flagsOld &= 0xff;
- id = (UINT)::GetSubMenu((HMENU)m_hMenu, mswpos);
+ id = (UINT_PTR)::GetSubMenu((HMENU)m_hMenu, mswpos);
}
else
{
info.fType = MFT_STRING;
info.cch = label.length();
info.dwTypeData = wx_const_cast(wxChar *, label.wx_str());
- if ( !SetMenuItemInfo(GetHmenu(), id, TRUE, & info) )
+ if ( !SetMenuItemInfo(GetHmenu(), id, TRUE, &info) )
{
wxLogLastError(wxT("SetMenuItemInfo"));
}
if ( !::InsertMenu(GetHmenu(), (UINT)mswpos,
MF_BYPOSITION | MF_POPUP | MF_STRING,
- (UINT)GetHmenuOf(menu), title.wx_str()) )
+ (UINT_PTR)GetHmenuOf(menu), title.wx_str()) )
{
wxLogLastError(wxT("InsertMenu"));
}
#else
if ( !::InsertMenu(GetHmenu(), mswpos,
MF_BYPOSITION | MF_POPUP | MF_STRING,
- (UINT)GetHmenuOf(menu), title.wx_str()) )
+ (UINT_PTR)GetHmenuOf(menu), title.wx_str()) )
{
wxLogLastError(wxT("InsertMenu"));
}
}
#else
if ( !::AppendMenu(GetHmenu(), MF_POPUP | MF_STRING,
- (UINT)submenu, title.wx_str()) )
+ (UINT_PTR)submenu, title.wx_str()) )
{
wxLogLastError(wxT("AppendMenu"));
}
// ----
// 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
// pass ids > USHRT_MAX to them they get very confused (e.g. start
// generating WM_COMMAND messages with negative high word of wParam), so
// 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());
}
{
case wxSTIPPLE:
lb.lbStyle = BS_PATTERN;
- lb.lbHatch = (LONG)m_stipple.GetHBITMAP();
+ lb.lbHatch = wxPtrToUInt(m_stipple.GetHBITMAP());
break;
case wxBDIAGONAL_HATCH:
wxWindowsPrintNativeData::wxWindowsPrintNativeData()
{
- m_devMode = (void*) NULL;
- m_devNames = (void*) NULL;
+ m_devMode = NULL;
+ m_devNames = NULL;
m_customWindowsPaperId = 0;
}
wxWindowsPrintNativeData::~wxWindowsPrintNativeData()
{
- HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
- if ( hDevMode )
- GlobalFree(hDevMode);
- HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
- if ( hDevNames )
- GlobalFree(hDevNames);
+ if ( m_devMode )
+ ::GlobalFree(wx_static_cast(HGLOBAL, m_devMode));
+
+ if ( m_devNames )
+ ::GlobalFree(wx_static_cast(HGLOBAL, m_devNames));
}
bool wxWindowsPrintNativeData::IsOk() const
bool wxWindowsPrintNativeData::TransferTo( wxPrintData &data )
{
- HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
- HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
-
- if (!hDevMode)
- {
+ if ( !m_devMode )
return false;
- }
- else
- {
- LPDEVMODE devMode = (LPDEVMODE)GlobalLock(hDevMode);
- //// Orientation
- if (devMode->dmFields & DM_ORIENTATION)
- data.SetOrientation( devMode->dmOrientation );
+ GlobalPtrLock lockDevMode(m_devMode);
- //// Collation
- if (devMode->dmFields & DM_COLLATE)
- {
- if (devMode->dmCollate == DMCOLLATE_TRUE)
- data.SetCollate( true );
- else
- data.SetCollate( false );
- }
+ LPDEVMODE devMode = wx_static_cast(LPDEVMODE, lockDevMode.Get());
- //// 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) );
+ //// Orientation
+ if (devMode->dmFields & DM_ORIENTATION)
+ data.SetOrientation( devMode->dmOrientation );
- //// Colour
- if (devMode->dmFields & DM_COLOR)
- {
- if (devMode->dmColor == DMCOLOR_COLOR)
- data.SetColour( true );
- else
- data.SetColour( false );
- }
+ //// 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
+ data.SetColour( true );
- //// Paper size
+ //// 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.
+ // 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))
+ bool foundPaperSize = false;
+ if ((devMode->dmFields & DM_PAPERSIZE) && (devMode->dmPaperSize < DMPAPER_USER))
+ {
+ if (wxThePrintPaperDatabase)
{
- if (wxThePrintPaperDatabase)
+ wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize);
+ if (paper)
{
- wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize);
- if (paper)
- {
- 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) );
+ data.SetPaperId( paper->GetId() );
+ data.SetPaperSize( wxSize(paper->GetWidth() / 10,paper->GetHeight() / 10) );
m_customWindowsPaperId = 0;
-
- GlobalUnlock(hDevMode);
- return false;
+ 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;
- 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;
- }
+ return false;
}
+ }
- //// Duplex
-
- if (devMode->dmFields & DM_DUPLEX)
+ if (!foundPaperSize) {
+ if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH))
{
- 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;
- }
+ // 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
- data.SetDuplex( wxDUPLEX_SIMPLEX );
+ {
+ // 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;
+ }
+ }
- //// Quality
+ //// Duplex
- if (devMode->dmFields & DM_PRINTQUALITY)
+ if (devMode->dmFields & DM_DUPLEX)
+ {
+ switch (devMode->dmDuplex)
{
- switch (devMode->dmPrintQuality)
+ 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 );
+
+ //// 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:
{
- 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;
+ // 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);
}
+ else
+ data.SetQuality( wxPRINT_QUALITY_HIGH );
- if (hDevNames)
+ if (devMode->dmDriverExtra > 0)
+ data.SetPrivData( (char *)devMode+devMode->dmSize, devMode->dmDriverExtra );
+ else
+ data.SetPrivData( NULL, 0 );
+
+ if ( m_devNames )
{
- LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(hDevNames);
- if (lpDevNames)
- {
- // TODO: Unicode-ification
+ GlobalPtrLock lockDevNames(m_devNames);
+ LPDEVNAMES lpDevNames = wx_static_cast(LPDEVNAMES, lockDevNames.Get());
- // Get the port name
- // port is obsolete in WIN32
- // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
+ // TODO: Unicode-ification
- // Get the printer name
- wxString printerName = (LPTSTR)lpDevNames + lpDevNames->wDeviceOffset;
+ // Get the port name
+ // port is obsolete in WIN32
+ // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
- // 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!");
+ // Get the printer name
+ wxString printerName = (LPTSTR)lpDevNames + lpDevNames->wDeviceOffset;
- if (!printerName.empty())
- data.SetPrinterName( printerName );
+ // 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!");
- GlobalUnlock(hDevNames);
- }
+ if (!printerName.empty())
+ data.SetPrinterName( printerName );
}
return true;
bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData &data )
{
- HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
- HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
- if (!hDevMode)
+ HGLOBAL hDevMode = wx_static_cast(HGLOBAL, m_devMode);
+ if ( !m_devMode )
{
// Use PRINTDLG as a way of creating a DEVMODE object
PRINTDLG pd;
else
{
hDevMode = pd.hDevMode;
- m_devMode = (void*)(long) hDevMode;
+ m_devMode = hDevMode;
pd.hDevMode = NULL;
// We'll create a new DEVNAMEs structure below.
if ( hDevMode )
{
- LPDEVMODE devMode = (LPDEVMODE) GlobalLock(hDevMode);
+ GlobalPtrLock lockDevMode(hDevMode);
+ DEVMODE * const devMode = wx_static_cast(DEVMODE *, lockDevMode.Get());
//// Orientation
devMode->dmOrientation = (short)data.GetOrientation();
wxString name = data.GetPrinterName();
if (!name.empty())
{
- //int len = wxMin(31, m_printerName.Len());
- wxStrncpy((wxChar*)devMode->dmDeviceName,name.c_str(),31);
- devMode->dmDeviceName[31] = wxT('\0');
+ wxStrncpy(devMode->dmDeviceName, name.wx_str(),
+ WXSIZEOF(devMode->dmDeviceName) - 1);
+ devMode->dmDeviceName[WXSIZEOF(devMode->dmDeviceName) - 1] = wxT('\0');
}
//// Colour
devMode->dmMediaType = data.GetMedia();
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.
- m_devNames = (void*) (long) wxCreateDevNames(wxEmptyString, data.GetPrinterName(), wxEmptyString);
+ m_devNames = wxCreateDevNames(wxEmptyString, data.GetPrinterName(), wxEmptyString);
return true;
}
if (pd->hDevNames)
GlobalFree(pd->hDevNames);
- pd->hDevMode = (HGLOBAL)(DWORD) native_data->GetDevMode();
- native_data->SetDevMode( (void*) NULL);
+ pd->hDevMode = wx_static_cast(HGLOBAL, native_data->GetDevMode());
+ native_data->SetDevMode(NULL);
// 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!"));
- pd->hDevNames = (HGLOBAL)(DWORD) native_data->GetDevNames();
- native_data->SetDevNames( (void*) NULL);
+ pd->hDevNames = wx_static_cast(HGLOBAL, native_data->GetDevNames());
+ native_data->SetDevNames(NULL);
pd->hDC = (HDC) NULL;
{
if (native_data->GetDevMode())
{
- // Make sure we don't leak memory
- GlobalFree( (HGLOBAL)(DWORD) native_data->GetDevMode() );
+ ::GlobalFree(wx_static_cast(HGLOBAL, native_data->GetDevMode()));
}
- native_data->SetDevMode( (void*)(long) pd->hDevMode );
+ native_data->SetDevMode(pd->hDevMode);
pd->hDevMode = NULL;
}
{
if (native_data->GetDevNames())
{
- // Make sure we don't leak memory
- GlobalFree((HGLOBAL)(DWORD) native_data->GetDevNames());
+ ::GlobalFree(wx_static_cast(HGLOBAL, native_data->GetDevNames()));
}
- native_data->SetDevNames((void*)(long) pd->hDevNames);
+ native_data->SetDevNames(pd->hDevNames);
pd->hDevNames = NULL;
}
styleBtn,
0, 0, 0, 0, // will be set in SetSize()
GetHwndOf(parent),
- (HMENU)subid.GetValue(),
+ (HMENU)wxUIntToPtr(subid.GetValue()),
wxGetInstance(),
NULL);
wxEmptyString,
WS_GROUP | BS_AUTORADIOBUTTON | WS_CHILD,
0, 0, 0, 0, GetHwndOf(parent),
- (HMENU)m_dummyId.GetValue(), wxGetInstance(), NULL);
+ (HMENU)wxUIntToPtr(m_dummyId.GetValue()),
+ wxGetInstance(), NULL);
m_radioButtons->SetFont(GetFont());
WS_CHILD | WS_VISIBLE | SS_CENTER,
0, 0, 0, 0,
hwndParent,
- (HMENU)lblid.GetValue(),
+ (HMENU)wxUIntToPtr(lblid.GetValue()),
wxGetInstance(),
NULL
);
wstyle,
0, 0, 0, 0,
GetHwndOf(parent),
- (HMENU)m_windowId.GetValue(),
+ (HMENU)wxUIntToPtr(m_windowId.GetValue()),
wxGetInstance(),
NULL
);
TBREPLACEBITMAP replaceBitmap;
replaceBitmap.hInstOld = NULL;
replaceBitmap.hInstNew = NULL;
- replaceBitmap.nIDOld = (UINT) oldToolBarBitmap;
- replaceBitmap.nIDNew = (UINT) hBitmap;
+ replaceBitmap.nIDOld = (UINT_PTR)oldToolBarBitmap;
+ replaceBitmap.nIDNew = (UINT_PTR)hBitmap;
replaceBitmap.nButtons = nButtons;
if ( !::SendMessage(GetHwnd(), TB_REPLACEBITMAP,
0, (LPARAM) &replaceBitmap) )
{
TBADDBITMAP addBitmap;
addBitmap.hInst = 0;
- addBitmap.nID = (UINT) hBitmap;
+ addBitmap.nID = (UINT_PTR)hBitmap;
if ( ::SendMessage(GetHwnd(), TB_ADDBITMAP,
(WPARAM) nButtons, (LPARAM)&addBitmap) == -1 )
{
{
const wxString& label = tool->GetLabel();
if ( !label.empty() )
- button.iString = (int)label.wx_str();
+ button.iString = (INT_PTR)label.wx_str();
}
button.idCommand = tool->GetId();
uFlags |= TTF_TRANSPARENT;
}
- uId = (UINT)hwndOwner;
+ uId = (UINT_PTR)hwndOwner;
}
};
}
// 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,
- (void *)max);
+ wxUIntToPtr(max));
+ }
}
else
#endif // comctl32.dll >= 4.70
{
// restore focus to the child which was last focused unless we already
// have it
- wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd);
+ wxLogTrace(_T("focus"), _T("wxTLW %p activated."), m_hWnd);
wxWindow *winFocus = FindFocus();
if ( !winFocus || wxGetTopLevelParent(winFocus) != this )
}
wxLogTrace(_T("focus"),
- _T("wxTLW %08x deactivated, last focused: %08x."),
- (int) m_hWnd,
- (int) (m_winLastFocused ? GetHwndOf(m_winLastFocused)
- : NULL));
+ _T("wxTLW %p deactivated, last focused: %p."),
+ m_hWnd,
+ m_winLastFocused ? GetHwndOf(m_winLastFocused) : NULL);
event.Skip();
}
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
// ---------------------------------------------------------------------------
void wxRemoveHandleAssociation(wxWindowMSW *win);
extern void wxAssociateWinWithHandle(HWND hWnd, wxWindowMSW *win);
-wxWindow *wxFindWinFromHandle(WXHWND hWnd);
// get the text metrics for the current font
static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win);
/* static */ wxWindow *wxWindowBase::GetCapture()
{
HWND hwnd = ::GetCapture();
- return hwnd ? wxFindWinFromHandle((WXHWND)hwnd) : (wxWindow *)NULL;
+ return hwnd ? wxFindWinFromHandle(hwnd) : NULL;
}
bool wxWindowMSW::SetFont(const wxFont& font)
if ( (style & BS_OWNERDRAW) == BS_OWNERDRAW )
{
// emulate the button click
- btn = wxFindWinFromHandle((WXHWND)msg->hwnd);
+ btn = wxFindWinFromHandle(msg->hwnd);
}
bProcess = false;
// trace all messages - useful for the debugging
#ifdef __WXDEBUG__
wxLogTrace(wxTraceMessages,
- wxT("Processing %s(hWnd=%08lx, wParam=%8lx, lParam=%8lx)"),
- wxGetMessageName(message), (long)hWnd, (long)wParam, lParam);
+ wxT("Processing %s(hWnd=%p, wParam=%08lx, lParam=%08lx)"),
+ wxGetMessageName(message), hWnd, (long)wParam, lParam);
#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
// it with wxWindow stored in gs_winBeingCreated
break;
case WM_SETFOCUS:
- processed = HandleSetFocus((WXHWND)(HWND)wParam);
+ processed = HandleSetFocus((WXHWND)wParam);
break;
case WM_KILLFOCUS:
- processed = HandleKillFocus((WXHWND)(HWND)wParam);
+ processed = HandleKillFocus((WXHWND)wParam);
break;
case WM_PRINTCLIENT:
// for these messages we must return true if process the message
#ifdef WM_DRAWITEM
case WM_DRAWITEM:
- case WM_MEASUREITEM:
- {
- int idCtrl = (UINT)wParam;
- if ( message == WM_DRAWITEM )
- {
- processed = MSWOnDrawItem(idCtrl,
- (WXDRAWITEMSTRUCT *)lParam);
- }
- else
- {
- processed = MSWOnMeasureItem(idCtrl,
- (WXMEASUREITEMSTRUCT *)lParam);
- }
+ processed = MSWOnDrawItem(wParam, (WXDRAWITEMSTRUCT *)lParam);
+ if ( processed )
+ rc.result = TRUE;
+ break;
- if ( processed )
- rc.result = TRUE;
- }
+ case WM_MEASUREITEM:
+ processed = MSWOnMeasureItem(wParam, (WXMEASUREITEMSTRUCT *)lParam);
+ if ( processed )
+ rc.result = TRUE;
break;
#endif // defined(WM_DRAWITEM)
#endif
case WM_PALETTECHANGED:
- processed = HandlePaletteChanged((WXHWND) (HWND) wParam);
+ processed = HandlePaletteChanged((WXHWND)wParam);
break;
case WM_CAPTURECHANGED:
- processed = HandleCaptureChanged((WXHWND) (HWND) lParam);
+ processed = HandleCaptureChanged((WXHWND)lParam);
break;
case WM_SETTINGCHANGE:
break;
case WM_ERASEBKGND:
- processed = HandleEraseBkgnd((WXHDC)(HDC)wParam);
+ processed = HandleEraseBkgnd((WXHDC)wParam);
if ( processed )
{
// we processed the message, i.e. erased the background
#endif
case WM_INITDIALOG:
- processed = HandleInitDialog((WXHWND)(HWND)wParam);
+ processed = HandleInitDialog((WXHWND)wParam);
if ( processed )
{
#endif
case WM_SETCURSOR:
- processed = HandleSetCursor((WXHWND)(HWND)wParam,
+ processed = HandleSetCursor((WXHWND)wParam,
LOWORD(lParam), // hit test
HIWORD(lParam)); // mouse msg
// we could have got an event from our child, reflect it back
// to it if this is the case
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 )
// now alter the client size making room for drawing a themed border
NCCALCSIZE_PARAMS *csparam = NULL;
- RECT rect;
- if (wParam)
+ RECT *rect;
+ if ( wParam )
{
- csparam = (NCCALCSIZE_PARAMS*)lParam;
- rect = csparam->rgrc[0];
+ csparam = (NCCALCSIZE_PARAMS *)lParam;
+ rect = &csparam->rgrc[0];
}
else
{
- rect = *((RECT*)lParam);
+ rect = (RECT *)lParam;
}
+
wxUxThemeHandle hTheme((wxWindow *)this, L"EDIT");
RECT rcClient = { 0, 0, 0, 0 };
wxClientDC dc((wxWindow *)this);
wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl();
- if (theme->GetThemeBackgroundContentRect(
- hTheme, GetHdcOf(*impl), EP_EDITTEXT, ETS_NORMAL,
- &rect, &rcClient) == S_OK)
+ if ( theme->GetThemeBackgroundContentRect
+ (
+ hTheme,
+ GetHdcOf(*impl),
+ EP_EDITTEXT,
+ ETS_NORMAL,
+ rect,
+ &rcClient) == S_OK )
{
InflateRect(&rcClient, -1, -1);
- if (wParam)
- csparam->rgrc[0] = rcClient;
- else
- *((RECT*)lParam) = rcClient;
+ *rect = rcClient;
rc.result = WVR_REDRAW;
}
}
// wxWindow <-> HWND map
// ----------------------------------------------------------------------------
-wxWinHashTable *wxWinHandleHash = NULL;
-
-wxWindow *wxFindWinFromHandle(WXHWND hWnd)
+wxWindow *wxFindWinFromHandle(HWND 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
- wxCHECK_RET( hWnd != (HWND)NULL,
- wxT("attempt to add a NULL hWnd to window list ignored") );
+ wxCHECK_RET( hwnd != (HWND)NULL,
+ wxT("attempt to add a NULL hwnd to window list ignored") );
- wxWindow *oldWin = wxFindWinFromHandle((WXHWND) hWnd);
#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)"),
- (int) hWnd, win->GetClassInfo()->GetClassName());
+ if ( i->second != win )
+ {
+ 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__
- if (!oldWin)
- {
- wxWinHandleHash->Put((long)hWnd, (wxWindow *)win);
- }
+
+ gs_windowHandles[hwnd] = win;
}
void wxRemoveHandleAssociation(wxWindowMSW *win)
{
- wxWinHandleHash->Delete((long)win->GetHWND());
+ gs_windowHandles.erase(GetHwndOf(win));
}
// ----------------------------------------------------------------------------
style,
x, y, w, h,
(HWND)MSWGetParent(),
- (HMENU)controlId,
+ (HMENU)wxUIntToPtr(controlId),
wxGetInstance(),
NULL // no extra data
);
#ifndef __WXMICROWIN__
LPNMHDR hdr = (LPNMHDR)lParam;
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 ( win )
::IsWindowVisible(hwndUnderMouse) &&
::IsWindowEnabled(hwndUnderMouse) )
{
- wxWindow *winUnderMouse = wxFindWinFromHandle((WXHWND)hwndUnderMouse);
+ wxWindow *winUnderMouse = wxFindWinFromHandle(hwndUnderMouse);
if ( winUnderMouse )
{
// translate the mouse coords to the other window coords
HWND hWnd = GetActiveWindow();
if ( hWnd != 0 )
{
- return wxFindWinFromHandle((WXHWND) hWnd);
+ return wxFindWinFromHandle(hWnd);
}
return NULL;
}
wxWindow *win = (wxWindow *)NULL;
if ( hwnd )
{
- win = wxFindWinFromHandle((WXHWND)hwnd);
+ win = wxFindWinFromHandle(hwnd);
if ( !win )
{
#if wxUSE_RADIOBOX
#endif
hwnd = ::GetParent(hwnd);
- win = wxFindWinFromHandle((WXHWND)hwnd);
+ win = wxFindWinFromHandle(hwnd);
}
return win;