📄 w32wince.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft shared
// source or premium shared source license agreement under which you licensed
// this source code. If you did not accept the terms of the license agreement,
// you are not authorized to use this source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the SOURCE.RTF on your install media or the root of your tools installation.
// THE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
// Windows CE implementations of W32 Interfaces.
// The following function is needed only because a Windows CE dll must have at least one export
__declspec(dllexport) void Useless( void )
{
return;
}
LRESULT CW32System::WndProc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
CTxtWinHost *phost = (CTxtWinHost *) GetWindowLong(hwnd, ibPed);
#ifdef DEBUG
Tracef(TRCSEVINFO, "hwnd %lx, msg %lx, wparam %lx, lparam %lx", hwnd, msg, wparam, lparam);
#endif // DEBUG
switch(msg)
{
case WM_CREATE:
// On Win CE we must simulate a WM_NCCREATE
(void) CTxtWinHost::OnNCCreate(hwnd, (CREATESTRUCT *) lparam);
phost = (CTxtWinHost *) GetWindowLong(hwnd, ibPed);
break;
case WM_DESTROY:
if( phost )
{
CTxtWinHost::OnNCDestroy(phost);
}
return 0;
}
return phost ? phost->TxWindowProc(hwnd, msg, wparam, lparam)
: DefWindowProc(hwnd, msg, wparam, lparam);
}
LONG ValidateTextRange(TEXTRANGE *pstrg);
ATOM WINAPI CW32System::RegisterREClass(
const WNDCLASSW *lpWndClass,
const char *szAnsiClassName,
WNDPROC AnsiWndProc
)
{
// On Windows CE we don't do anything with ANSI window class
return ::RegisterClass(lpWndClass);
}
LRESULT CW32System::ANSIWndProc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
// Should never be used in WinCE
Assert(0);
RETAILMSG(1, (__TEXT("CW32System::ANSIWndProc called!!!!!!!!!\r\n")));
return 0;
}
HGLOBAL WINAPI CW32System::GlobalAlloc( UINT uFlags, DWORD dwBytes )
{
#ifdef TARGET_NT
return ::GlobalAlloc( uFlags, dwBytes);
#else
return LocalAlloc( uFlags & GMEM_ZEROINIT, dwBytes );
#endif
}
HGLOBAL WINAPI CW32System::GlobalFree( HGLOBAL hMem )
{
#ifdef TARGET_NT
return ::GlobalFree( hMem );
#else
return LocalFree( hMem );
#endif
}
UINT WINAPI CW32System::GlobalFlags( HGLOBAL hMem )
{
#ifdef TARGET_NT
return ::GlobalFlags( hMem );
#else
return LocalFlags( hMem );
#endif
}
HGLOBAL WINAPI CW32System::GlobalReAlloc( HGLOBAL hMem, DWORD dwBytes, UINT uFlags )
{
#ifdef TARGET_NT
return ::GlobalReAlloc(hMem, dwBytes, uFlags);
#else
return LocalReAlloc( hMem, dwBytes, uFlags );
#endif
}
DWORD WINAPI CW32System::GlobalSize( HGLOBAL hMem )
{
#ifdef TARGET_NT
return ::GlobalSize( hMem );
#else
return LocalSize( hMem );
#endif
}
LPVOID WINAPI CW32System::GlobalLock( HGLOBAL hMem )
{
#ifdef TARGET_NT
return ::GlobalLock( hMem );
#else
return LocalLock( hMem );
#endif
}
HGLOBAL WINAPI CW32System::GlobalHandle( LPCVOID pMem )
{
#ifdef TARGET_NT
return ::GlobalHandle( pMem );
#else
return LocalHandle( pMem );
#endif
}
BOOL WINAPI CW32System::GlobalUnlock( HGLOBAL hMem )
{
#ifdef TARGET_NT
return ::GlobalUnlock( hMem );
#else
return LocalUnlock( hMem );
#endif
}
BOOL WINAPI CW32System::REGetCharWidth(
HDC hdc,
UINT iChar,
LPINT pAns,
UINT // For Windows CE the code page is not used
// as the A version is not called.
)
{
int i;
SIZE size;
TCHAR buff[2];
buff[0] = iChar;
buff[1] = 0;
if (GetTextExtentExPoint(hdc, buff, 1, 32000, &i, (LPINT)pAns, &size))
{
return TRUE;
}
return FALSE;
}
BOOL WINAPI CW32System::REExtTextOut(
CONVERTMODE cm,
UINT uiCodePage,
HDC hdc,
int x,
int y,
UINT fuOptions,
CONST RECT *lprc,
const WCHAR *lpString,
UINT cbCount,
CONST INT *lpDx,
BOOL FEFontOnNonFEWin95
)
{
return ExtTextOut(hdc, x, y, fuOptions, lprc, lpString, cbCount, lpDx);
}
CONVERTMODE WINAPI CW32System::DetermineConvertMode( BYTE tmCharSet )
{
return CM_NONE;
}
// Workaround for SA1100 compiler bug
#if ARM
#pragma optimize("",off)
#endif
void WINAPI CW32System::CalcUnderlineInfo( CCcs *pcccs, TEXTMETRIC *ptm )
{
// Default calculation of size of underline
// Implements a heuristic in the absence of better font information.
SHORT dyDescent = pcccs->_yDescent;
if (0 == dyDescent)
{
dyDescent = pcccs->_yHeight >> 3;
}
pcccs->_dyULWidth = max(1, dyDescent / 4);
pcccs->_dyULOffset = (dyDescent - 3 * pcccs->_dyULWidth + 1) / 2;
if ((0 == pcccs->_dyULOffset) && (dyDescent > 1))
{
pcccs->_dyULOffset = 1;
}
pcccs->_dySOOffset = -ptm->tmAscent / 3;
pcccs->_dySOWidth = pcccs->_dyULWidth;
return;
}
// Workaround for SA1100 compiler bug
#if ARM
#pragma optimize("",on)
#endif
BOOL WINAPI CW32System::ShowScrollBar( HWND hWnd, int wBar, BOOL bShow, LONG nMax )
{
SCROLLINFO si;
Assert(wBar == SB_VERT || wBar == SB_HORZ);
W32->ZeroMemory(&si, sizeof(SCROLLINFO));
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_RANGE | SIF_DISABLENOSCROLL;
if (bShow)
{
si.nMax = nMax;
}
::SetScrollInfo(hWnd, wBar, &si, TRUE);
return TRUE;
}
BOOL WINAPI CW32System::EnableScrollBar( HWND hWnd, UINT wSBflags, UINT wArrows )
{
BOOL fEnable = TRUE;
BOOL fApi;
SCROLLINFO si;
Assert (wSBflags == SB_VERT || wSBflags == SB_HORZ);
if (wArrows == ESB_DISABLE_BOTH)
{
fEnable = FALSE;
}
// Get the current scroll range
W32->ZeroMemory(&si, sizeof(SCROLLINFO));
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_RANGE;
fApi = ::GetScrollInfo(hWnd, wSBflags, &si);
if (fApi && !fEnable)
{
si.fMask = SIF_RANGE | SIF_DISABLENOSCROLL;
si.nMin = 0;
si.nMax = 0;
}
if (fApi) ::SetScrollInfo(hWnd, wSBflags, &si, TRUE);
return fApi ? TRUE : FALSE;
}
BOOL WINAPI CW32System::IsEnhancedMetafileDC( HDC )
{
// No enhanced metafile
return FALSE;
}
UINT WINAPI CW32System::GetTextAlign(HDC hdc)
{
// Review :: SHould we set last error?
return GDI_ERROR;
}
UINT WINAPI CW32System::SetTextAlign(HDC hdc, UINT uAlign)
{
// Review :: SHould we set last error?
return GDI_ERROR;
}
UINT WINAPI CW32System::InvertRect(HDC hdc, CONST RECT *prc)
{
HBITMAP hbm, hbmOld;
HDC hdcMem;
int nHeight, nWidth;
UINT RetVal = FALSE;
nWidth = prc->right-prc->left;
nHeight = prc->bottom-prc->top;
hdcMem = CreateCompatibleDC(hdc);
if(!hdcMem)
{
goto leave;
}
hbm = CreateCompatibleBitmap(hdc, nWidth, nHeight);
if(!hbm)
{
DeleteObject(hdcMem);
goto leave;
}
hbmOld = (HBITMAP) SelectObject(hdcMem, hbm);
BitBlt(hdcMem, 0, 0, nWidth, nHeight, hdc, prc->left, prc->top,
SRCCOPY);
FillRect(hdc, prc, (HBRUSH)GetStockObject(WHITE_BRUSH));
BitBlt(hdc, prc->left, prc->top, nWidth,
nHeight, hdcMem, 0, 0, SRCINVERT);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
DeleteObject(hbm);
RetVal = TRUE;
leave:
return RetVal;
}
HPALETTE WINAPI CW32System::ManagePalette(
HDC,
CONST LOGPALETTE *,
HPALETTE &,
HPALETTE &
)
{
// No op for Windows CE
return NULL;
}
int WINAPI CW32System::GetMapMode(HDC)
{
// Only MM Text supported on Win CE
return MM_TEXT;
}
BOOL WINAPI CW32System::WinLPtoDP(HDC, LPPOINT, int)
{
// This is not available on Win CE
return 0;
}
BOOL WINAPI CW32System::WinDPtoLP(HDC, LPPOINT, int)
{
// This is not available on Win CE
return 0;
}
long WINAPI CW32System::WvsprintfA( LONG cbBuf, LPSTR pszBuf, LPCSTR pszFmt, va_list arglist )
{
WCHAR wszBuf[64];
WCHAR wszFmt[64];
WCHAR *pwszBuf = wszBuf;
WCHAR *pwszFmt = wszFmt;
UINT cch = 0;
Assert(cbBuf < 64);
while (*pszFmt && (cch<62))
{
*pwszFmt++ = *pszFmt++;
cch++;
if (*(pwszFmt - 1) == '%')
{
Assert(*pszFmt == 's' || *pszFmt == 'd' || *pszFmt == '0' || *pszFmt == 'c');
if (*pszFmt == 's')
{
*pwszFmt++ = 'h';
cch++;
}
}
}
*pwszFmt = 0;
LONG cw = wvsprintf( wszBuf, wszFmt, arglist );
while (*pszBuf++ = *pwszBuf++);
Assert(cw < cbBuf);
return cw;
}
int WINAPI CW32System::MulDiv(int nNumber, int nNumerator, int nDenominator)
{
// Special handling for Win CE
// Must be careful to not cause divide by zero
// Note that overflow on the multiplication is not handled
// Hopefully that is not a problem for RichEdit use
// Added Guy's fix up for rounding.
// Conservative check to see if multiplication will overflow.
if (IN_RANGE(_I16_MIN, nNumber, _I16_MAX) &&
IN_RANGE(_I16_MIN, nNumerator, _I16_MAX))
{
return nDenominator ? ((nNumber * nNumerator) + (nDenominator / 2)) / nDenominator : -1;
}
__int64 NNumber = nNumber;
__int64 NNumerator = nNumerator;
__int64 NDenominator = nDenominator;
return NDenominator ? ((NNumber * NNumerator) + (NDenominator / 2)) / NDenominator : -1;
}
void CW32System::CheckChangeKeyboardLayout ( CTxtSelection *psel, BOOL fChangedFont )
{
return;
}
void CW32System::CheckChangeFont (
CTxtSelection *psel,
CTxtEdit * const ped,
BOOL fEnableReassign, // @parm Do we enable CTRL key?
const WORD lcID, // @parm LCID from WM_ message
UINT cpg // @parm code page to use (could be ANSI for far east with IME off)
)
{
return;
}
BOOL CW32System::FormatMatchesKeyboard( const CCharFormat *pFormat )
{
return FALSE;
}
/*
HKL CW32System::GetKeyboardLayout ( DWORD )
{
return NULL;
}
int CW32System::GetKeyboardLayoutList ( int, HKL FAR * )
{
return 0;
}
*/
HRESULT CW32System::LoadRegTypeLib ( REFGUID, WORD, WORD, LCID, ITypeLib ** )
{
return E_NOTIMPL;
}
HRESULT CW32System::LoadTypeLib ( const OLECHAR *, ITypeLib ** )
{
return E_NOTIMPL;
}
BSTR CW32System::SysAllocString ( const OLECHAR * )
{
return NULL;
}
BSTR CW32System::SysAllocStringLen ( const OLECHAR *, UINT )
{
return NULL;
}
void CW32System::SysFreeString ( BSTR )
{
return;
}
UINT CW32System::SysStringLen ( BSTR )
{
return 0;
}
void CW32System::VariantInit ( VARIANTARG * )
{
return;
}
HRESULT CW32System::OleCreateFromData ( LPDATAOBJECT, REFIID, DWORD, LPFORMATETC, LPOLECLIENTSITE, LPSTORAGE, void ** )
{
return 0;
}
void CW32System::CoTaskMemFree ( LPVOID )
{
return;
}
HRESULT CW32System::CreateBindCtx ( DWORD, LPBC * )
{
return 0;
}
HANDLE CW32System::OleDuplicateData ( HANDLE, CLIPFORMAT, UINT )
{
return NULL;
}
HRESULT CW32System::CoTreatAsClass ( REFCLSID, REFCLSID )
{
return 0;
}
HRESULT CW32System::ProgIDFromCLSID ( REFCLSID, LPOLESTR * )
{
return E_NOTIMPL;
}
HRESULT CW32System::OleConvertIStorageToOLESTREAM ( LPSTORAGE, LPOLESTREAM )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -