void ConvertKeyToCurrentKeyboard(char* sNewKey, char* sOldKey, int nNewKeyMaxSize) { if (_mbstrlen(sOldKey) == 1) { HKL nDefaultKeyboard = GetKeyboardLayout(0); SHORT nCharCode = sOldKey[0]; if ((nCharCode > 0) && (nCharCode <= 255)) { SHORT nScanCode = g_pEnglishCharToScanCodeTable[nCharCode]; if (nScanCode != -1) { SHORT nKeyCode2 = MapVirtualKeyEx(nScanCode & 0xff, 1, nDefaultKeyboard); if (nKeyCode2 != -1) { UINT nNewChar = MapVirtualKeyEx( nKeyCode2 & 0xff, 2, nDefaultKeyboard); if (nNewChar != 0) { sNewKey[0] = (char)nNewChar; sNewKey[1] = '\0'; return; } } } } } _mbsncpy((unsigned char*)sNewKey, (const unsigned char*)sOldKey, nNewKeyMaxSize); sNewKey[nNewKeyMaxSize-1] = '\0'; }
// Plays a sound HSOUNDDE CMainMenus::PlaySound(char *lpszSound, DBOOL bStream, DBOOL bLoop, DBOOL bGetHandle) { PlaySoundInfo playSoundInfo; PLAYSOUNDINFO_INIT(playSoundInfo); playSoundInfo.m_dwFlags = PLAYSOUND_LOCAL; if (bStream) { playSoundInfo.m_dwFlags |= PLAYSOUND_FILESTREAM; } if (bLoop) { playSoundInfo.m_dwFlags |= PLAYSOUND_LOOP; } if (bGetHandle) { playSoundInfo.m_dwFlags |= PLAYSOUND_GETHANDLE; } _mbsncpy((unsigned char*)playSoundInfo.m_szSoundName, (const unsigned char*)lpszSound, sizeof( playSoundInfo.m_szSoundName ) - 1 ); playSoundInfo.m_nPriority = SOUNDPRIORITY_MISC_MEDIUM; // Play the sound if( m_pClientDE->PlaySound (&playSoundInfo) != LT_OK ) return NULL; return playSoundInfo.m_hSound; }
void CNewStatusBar::UpdateObjectives(char *title, char *string) { if(!m_pClientDE || !m_hObjectives) return; // If we send in a null title or string, reset the objectives if(!title || !string) { InitObjectivesTab(); m_nObjIcon = OBJICON_INVISIBLE; return; } // If we're not in the right game type for objectives, just return if (g_pBloodClientShell->GetGameType() != GAMETYPE_SINGLE && g_pBloodClientShell->GetGameType() != GAMETYPE_CUSTOM) { return; } // Reset the background picture of the objectives DDWORD width, height; m_pClientDE->DrawBitmapToSurface(m_hObjectives, "interface/objectives/objectives.pcx", DNULL, 0, 0); m_pClientDE->GetSurfaceDims(m_hObjectives, &width, &height); // Setup the font and print it out on the surface m_pStatCursor->SetFont(m_pObjectivesFont1); m_pStatCursor->SetDest(m_hObjectives); m_pStatCursor->SetJustify(CF_JUSTIFY_CENTER); m_pStatCursor->SetLoc(OBJTAB_TITLE_CENTER, OBJTAB_TITLE_TOP); m_pStatCursor->Draw(title); m_pStatCursor->SetJustify(CF_JUSTIFY_LEFT); m_pStatCursor->SetLoc(OBJTAB_TEXT_LEFT, OBJTAB_TEXT_TOP); m_pStatCursor->DrawFormat(string, OBJTAB_TEXT_WIDTH); // Turn on the updated icon if we're not currently displaying the objectives if(m_nObjLevel == OBJTAB_INVISIBLE || m_nObjLevel == OBJTAB_SCALE_DOWN) m_nObjIcon = OBJICON_VISIBLE; else m_nObjIcon = OBJICON_INVISIBLE; // Play a sound to let the player know that the objectives have changed PlaySoundInfo playSoundInfo; PLAYSOUNDINFO_INIT(playSoundInfo); playSoundInfo.m_dwFlags = PLAYSOUND_LOCAL; playSoundInfo.m_dwFlags |= PLAYSOUND_FILESTREAM; playSoundInfo.m_nPriority = SOUNDPRIORITY_MISC_MEDIUM; _mbsncpy((unsigned char*)playSoundInfo.m_szSoundName, (const unsigned char*)"Sounds\\Events\\bellding1.wav", sizeof(playSoundInfo.m_szSoundName) - 1); m_pClientDE->PlaySound(&playSoundInfo); }
static void copypart( CHAR_TYPE *buf, const CHAR_TYPE *p, int len, int maxlen ) { if( buf != NULL ) { if( len > maxlen ) len = maxlen; #if defined( __WIDECHAR__ ) || defined( __UNIX__ ) || defined( __RDOS__ ) || defined( __RDOSDEV__ ) memcpy( buf, p, len * CHARSIZE ); /*strncpy( buf, p, len ); */ buf[len ] = NULLCHAR; #else len = _mbsnccnt( (unsigned char *)p, len ); /* # chars in len bytes */ _mbsncpy( (unsigned char *)buf, (unsigned char *)p, len ); /* copy the chars */ buf[_mbsnbcnt( (unsigned char *)buf, len )] = NULLCHAR; #endif } }
DBOOL DeathShroud::InitialUpdate(DVector *pMovement) { m_pServerDE = BaseClass::GetServerDE(); if (!m_pServerDE) return DFALSE; if(m_bLoadAnims) { m_Anim_Sound.SetAnimationIndexes(m_hObject); m_Anim_Sound.GenerateHitSpheres(m_hObject); m_Anim_Sound.SetSoundRoot("sounds\\enemies\\DeathShroud"); m_bLoadAnims = DFALSE; } m_InventoryMgr.AddDamageMultiplier(0.5f); AI_Mgr::InitStatics(&m_Anim_Sound); //play ambient looping sound PlaySoundInfo playSoundInfo; PLAYSOUNDINFO_INIT( playSoundInfo ); playSoundInfo.m_dwFlags = PLAYSOUND_3D | PLAYSOUND_ATTACHED | PLAYSOUND_GETHANDLE | PLAYSOUND_REVERB; playSoundInfo.m_dwFlags |= PLAYSOUND_LOOP | PLAYSOUND_CTRL_VOL; _mbsncpy((unsigned char*)playSoundInfo.m_szSoundName, (const unsigned char*)"sounds\\enemies\\deathshroud\\de_loop_2.wav", _MAX_PATH ); playSoundInfo.m_hObject = m_hObject; playSoundInfo.m_nPriority = SOUNDPRIORITY_AI_MEDIUM; playSoundInfo.m_fOuterRadius = 1000; playSoundInfo.m_fInnerRadius = 1000 * 0.1f; playSoundInfo.m_nVolume = 50; g_pServerDE->PlaySound( &playSoundInfo ); m_hLoopSound = playSoundInfo.m_hSound; //fade the deathshroud DVector vColor; DFLOAT fAlpha = 0.0f; m_pServerDE->GetObjectColor(m_hObject,&vColor.x, &vColor.y, &vColor.z, &fAlpha); fAlpha = 0.90f; m_pServerDE->SetObjectColor(m_hObject,vColor.x,vColor.y,vColor.z, fAlpha); return DTRUE; }
void Rotating::StartSound(HSTRING hstrSoundName, DBOOL bLoop) { CServerDE* pServerDE = BaseClass::GetServerDE(); if (!pServerDE) return; // Stop the last sound if there is one... if (m_sndLastSound) { pServerDE->KillSound(m_sndLastSound); m_sndLastSound = DNULL; } if (!hstrSoundName) return; char *pSoundName = pServerDE->GetStringData(hstrSoundName); if (!pSoundName) return; PlaySoundInfo playSoundInfo; PLAYSOUNDINFO_INIT(playSoundInfo); playSoundInfo.m_dwFlags = PLAYSOUND_3D | PLAYSOUND_REVERB; playSoundInfo.m_dwFlags |= PLAYSOUND_ATTACHED; if (bLoop) { playSoundInfo.m_dwFlags |= PLAYSOUND_LOOP | PLAYSOUND_GETHANDLE; } _mbsncpy((unsigned char*)playSoundInfo.m_szSoundName, (const unsigned char*)pSoundName, _MAX_PATH); playSoundInfo.m_hObject = m_hObject; playSoundInfo.m_fOuterRadius = m_fSoundRadius; playSoundInfo.m_fInnerRadius = 200; pServerDE->PlaySound(&playSoundInfo); // Save the handle of the sound... m_sndLastSound = playSoundInfo.m_hSound; }
static void copypart( CHAR_TYPE *buf, const CHAR_TYPE *p, int len, int maxlen ) { if( buf != NULL ) { if( len > maxlen ) len = maxlen; #ifdef __WIDECHAR__ memcpy( buf, p, len * CHARSIZE ); /* 07-jul-91 DJG */ /*strncpy( buf, p, len ); */ buf[ len ] = NULLCHAR; #else #ifdef __UNIX__ memcpy( buf, p, len * CHARSIZE ); buf[ len ] = NULLCHAR; #else len = _mbsnccnt( p, len ); /* # chars in len bytes */ _mbsncpy( buf, p, len ); /* copy the chars */ buf[ _mbsnbcnt( buf, len ) ] = NULLCHAR; #endif #endif } }
static CHAR_TYPE *pcopy( CHAR_TYPE **pdst, CHAR_TYPE *dst, const CHAR_TYPE *b_src, const CHAR_TYPE *e_src ) { /*========================================================================*/ unsigned len; if( pdst == NULL ) return( dst ); *pdst = dst; len = e_src - b_src; if( len >= _MAX_PATH2 ) { len = _MAX_PATH2 - 1; } #if defined( __WIDECHAR__ ) || defined( __UNIX__ ) memcpy( dst, b_src, len * CHARSIZE ); dst[ len ] = NULLCHAR; return( dst + len + 1 ); #else len = _mbsnccnt( (unsigned char *)b_src, len ); /* # chars in len bytes */ _mbsncpy( (unsigned char *)dst, (unsigned char *)b_src, len ); /* copy the chars */ dst[ _mbsnbcnt( (unsigned char *)dst, len ) ] = NULLCHAR; return( dst + _mbsnbcnt( (unsigned char *)dst, len ) + 1 ); #endif }
void CNewStatusBar::ToggleObjectives() { PlaySoundInfo playSoundInfo; PLAYSOUNDINFO_INIT(playSoundInfo); playSoundInfo.m_dwFlags = PLAYSOUND_LOCAL; playSoundInfo.m_dwFlags |= PLAYSOUND_FILESTREAM; playSoundInfo.m_nPriority = SOUNDPRIORITY_MISC_MEDIUM; _mbsncpy((unsigned char*)playSoundInfo.m_szSoundName, (const unsigned char*)"Sounds\\Interface\\MainMenus\\missionobj.wav", sizeof(playSoundInfo.m_szSoundName) - 1); if(m_nObjLevel == OBJTAB_INVISIBLE) { m_nObjLevel = OBJTAB_SCALE_UP; m_fObjUpdateTime = m_pClientDE->GetTime(); m_nObjIcon = OBJICON_INVISIBLE; m_pClientDE->PlaySound (&playSoundInfo); } else if(m_nObjLevel == OBJTAB_STOPPED) { m_nObjLevel = OBJTAB_SCALE_DOWN; m_fObjUpdateTime = m_pClientDE->GetTime(); m_pClientDE->PlaySound (&playSoundInfo); } }
static int add_menu_item (HMENU menu, widget_value *wv, HMENU item) { UINT fuFlags; char *out_string, *p, *q; int return_value; size_t nlen, orig_len; USE_SAFE_ALLOCA; if (menu_separator_name_p (wv->name)) { fuFlags = MF_SEPARATOR; out_string = NULL; } else { if (wv->enabled) fuFlags = MF_STRING; else fuFlags = MF_STRING | MF_GRAYED; if (wv->key != NULL) { out_string = SAFE_ALLOCA (strlen (wv->name) + strlen (wv->key) + 2); p = stpcpy (out_string, wv->name); p = stpcpy (p, "\t"); strcpy (p, wv->key); } else out_string = (char *)wv->name; /* Quote any special characters within the menu item's text and key binding. */ nlen = orig_len = strlen (out_string); if (unicode_append_menu) { /* With UTF-8, & cannot be part of a multibyte character. */ for (p = out_string; *p; p++) { if (*p == '&') nlen++; } } #ifndef NTGUI_UNICODE else { /* If encoded with the system codepage, use multibyte string functions in case of multibyte characters that contain '&'. */ for (p = out_string; *p; p = _mbsinc (p)) { if (_mbsnextc (p) == '&') nlen++; } } #endif /* !NTGUI_UNICODE */ if (nlen > orig_len) { p = out_string; out_string = SAFE_ALLOCA (nlen + 1); q = out_string; while (*p) { if (unicode_append_menu) { if (*p == '&') *q++ = *p; *q++ = *p++; } #ifndef NTGUI_UNICODE else { if (_mbsnextc (p) == '&') { _mbsncpy (q, p, 1); q = _mbsinc (q); } _mbsncpy (q, p, 1); p = _mbsinc (p); q = _mbsinc (q); } #endif /* !NTGUI_UNICODE */ } *q = '\0'; } if (item != NULL) fuFlags = MF_POPUP; else if (wv->title || wv->call_data == 0) { /* Only use MF_OWNERDRAW if GetMenuItemInfo is usable, since we can't deallocate the memory otherwise. */ if (get_menu_item_info) { out_string = (char *) local_alloc (strlen (wv->name) + 1); strcpy (out_string, wv->name); #ifdef MENU_DEBUG DebPrint ("Menu: allocating %ld for owner-draw", out_string); #endif fuFlags = MF_OWNERDRAW | MF_DISABLED; } else fuFlags = MF_DISABLED; } /* Draw radio buttons and tickboxes. */ else if (wv->selected && (wv->button_type == BUTTON_TYPE_TOGGLE || wv->button_type == BUTTON_TYPE_RADIO)) fuFlags |= MF_CHECKED; else fuFlags |= MF_UNCHECKED; } if (unicode_append_menu && out_string) { /* Convert out_string from UTF-8 to UTF-16-LE. */ int utf8_len = strlen (out_string); WCHAR * utf16_string; if (fuFlags & MF_OWNERDRAW) utf16_string = local_alloc ((utf8_len + 1) * sizeof (WCHAR)); else utf16_string = SAFE_ALLOCA ((utf8_len + 1) * sizeof (WCHAR)); utf8to16 ((unsigned char *)out_string, utf8_len, utf16_string); return_value = unicode_append_menu (menu, fuFlags, item != NULL ? (UINT_PTR) item : (UINT_PTR) wv->call_data, utf16_string); #ifndef NTGUI_UNICODE /* Fallback does not apply when always UNICODE */ if (!return_value) { /* On W9x/ME, Unicode menus are not supported, though AppendMenuW apparently does exist at least in some cases and appears to be stubbed out to do nothing. out_string is UTF-8, but since our standard menus are in English and this is only going to happen the first time a menu is used, the encoding is of minor importance compared with menus not working at all. */ return_value = AppendMenu (menu, fuFlags, item != NULL ? (UINT_PTR) item: (UINT_PTR) wv->call_data, out_string); /* Don't use Unicode menus in future, unless this is Windows NT or later, where a failure of AppendMenuW does NOT mean Unicode menus are unsupported. */ if (osinfo_cache.dwPlatformId != VER_PLATFORM_WIN32_NT) unicode_append_menu = NULL; } #endif /* NTGUI_UNICODE */ if (unicode_append_menu && (fuFlags & MF_OWNERDRAW)) local_free (out_string); } else { return_value = AppendMenu (menu, fuFlags, item != NULL ? (UINT_PTR) item : (UINT_PTR) wv->call_data, out_string ); } /* This must be done after the menu item is created. */ if (!wv->title && wv->call_data != 0) { if (set_menu_item_info) { MENUITEMINFO info; memset (&info, 0, sizeof (info)); info.cbSize = sizeof (info); info.fMask = MIIM_DATA; /* Set help string for menu item. Leave it as a pointer to a Lisp_String until it is ready to be displayed, since GC can happen while menus are active. */ if (!NILP (wv->help)) { /* We use XUNTAG below because in a 32-bit build --with-wide-int we cannot pass a Lisp_Object via a DWORD member of MENUITEMINFO. */ /* As of Jul-2012, w32api headers say that dwItemData has DWORD type, but that's a bug: it should actually be ULONG_PTR, which is correct for 32-bit and 64-bit Windows alike. MSVC headers get it right; hopefully, MinGW headers will, too. */ eassert (STRINGP (wv->help)); info.dwItemData = (ULONG_PTR) XUNTAG (wv->help, Lisp_String); } if (wv->button_type == BUTTON_TYPE_RADIO) { /* CheckMenuRadioItem allows us to differentiate TOGGLE and RADIO items, but is not available on NT 3.51 and earlier. */ info.fMask |= MIIM_TYPE | MIIM_STATE; info.fType = MFT_RADIOCHECK | MFT_STRING; info.dwTypeData = out_string; info.fState = wv->selected ? MFS_CHECKED : MFS_UNCHECKED; } set_menu_item_info (menu, item != NULL ? (UINT_PTR) item : (UINT_PTR) wv->call_data, FALSE, &info); } } SAFE_FREE (); return return_value; }
HSURFACE CTextHelper::CreateWrappedSurface (ILTClient* pClientDE, int nWidth, HLTFONT hFont, char* pString, HLTCOLOR foreColor, HLTCOLOR backColor, int nAlignment, LTBOOL bCropped, int nExtraX, int nExtraY) { if (!pString || !pClientDE) return LTNULL; // check if we are supposed to do hard wrapping bool bHardTextWrap = false; { HSTRING hStr = pClientDE->FormatString(IDS_ENABLETEXTHARDWRAP); if (hStr) { const char* pComp = pClientDE->GetStringData(hStr); if (pComp != NULL) { if (stricmp(pComp,"TRUE") == 0) bHardTextWrap = true; } pClientDE->FreeString (hStr); } } // get period or other characters that are not supposed to be at start of a line char sPeriodChars[256] = "."; { HSTRING hStr = pClientDE->FormatString(IDS_EXCLULTLineSTARTCHARS); if (hStr) { const char* pComp = pClientDE->GetStringData(hStr); if (pComp != NULL) { _mbsncpy((unsigned char*)sPeriodChars, (const unsigned char*)pComp, 255); sPeriodChars[255] = '\0'; } pClientDE->FreeString (hStr); } } char* pWorkingString = new char [strlen (pString) + 1]; if (!pWorkingString) return LTNULL; CDynArray<uint32> surfaces (1, 2); // cannot create a dynarray of HSURFACES - compiler error C2926 uint32 nSurfaces = 0; char* ptr = (char*) pString; while (*ptr != '\0') { // copy what's left into the working string strcpy (pWorkingString, ptr); // create a string that will fit into the desired width LTBOOL bDone = LTFALSE; HSURFACE hSurface = LTNULL; while (!bDone) { // create a string surface from the working string to test HSTRING hString = pClientDE->CreateString (pWorkingString); if (!hString) break; hSurface = pClientDE->CreateSurfaceFromString (hFont, hString, foreColor, backColor, nExtraX, nExtraY); if (!hSurface) { pClientDE->FreeString (hString); break; } pClientDE->FreeString (hString); // get the dimensions of the surface uint32 nTestWidth = 0; uint32 nTestHeight = 0; pClientDE->GetSurfaceDims (hSurface, &nTestWidth, &nTestHeight); if (nTestWidth > (uint32)nWidth) { // string too long, remove some and try again char* pSpace; // remove by character if we are hard wrapping if (bHardTextWrap) { pSpace = pWorkingString; // find last hard in string pPrev char* pPrev = NULL; while (pSpace != NULL) { pPrev = pSpace; pSpace = (char*)_mbsinc ((const unsigned char*)pSpace); if (*pSpace == '\0') pSpace = NULL; } if (pPrev == NULL) pSpace = pWorkingString; else { //decrement 1 character pSpace = (char*)_mbsdec ((const unsigned char*)pWorkingString, (const unsigned char*)pPrev); // check if we are on a period then we need to decrement 3 more if ((char*)_mbsspnp((const unsigned char*)pPrev, (const unsigned char*)sPeriodChars) != pPrev) { if (pSpace != NULL) pSpace = (char*)_mbsdec ((const unsigned char*)pWorkingString, (const unsigned char*)pSpace); if (pSpace != NULL) pSpace = (char*)_mbsdec ((const unsigned char*)pWorkingString, (const unsigned char*)pSpace); } } } // remove by word if hard wrap is not on else { pSpace = (char*)_mbsrchr ((const unsigned char*)pWorkingString, ' '); if (!pSpace) pSpace = pWorkingString; while (_mbsnbcmp ((const unsigned char*)pSpace, (const unsigned char*)" ", 1) == 0 && pSpace != pWorkingString) { pSpace = (char*)_mbsdec ((const unsigned char*)pWorkingString, (const unsigned char*)pSpace); if (!pSpace) pSpace = pWorkingString; } } if (pSpace == pWorkingString) { bDone = LTTRUE; } else { pSpace = (char*)_mbsinc ((const unsigned char*)pSpace); *pSpace = '\0'; } pClientDE->DeleteSurface (hSurface); hSurface = LTNULL; } else { // it fits! bDone = LTTRUE; } } // if we got here without bDone being TRUE, there was an error if (!bDone) { delete [] pWorkingString; for (uint32 i = 0; i < nSurfaces; i++) { pClientDE->DeleteSurface ((HSURFACE)surfaces[i]); } return LTNULL; } // if bDone is true but there's no surface, we couldn't make it fit // just create a surface from the string and it will get clipped later if (bDone && !hSurface) { HSTRING hString = pClientDE->CreateString (pWorkingString); hSurface = pClientDE->CreateSurfaceFromString (hFont, hString, foreColor, backColor, nExtraX, nExtraY); if (!hString || !hSurface) { if (hString) pClientDE->FreeString (hString); if (hSurface) pClientDE->DeleteSurface (hSurface); delete [] pWorkingString; for (uint32 i = 0; i < nSurfaces; i++) { pClientDE->DeleteSurface ((HSURFACE)surfaces[i]); } return LTNULL; } pClientDE->FreeString (hString); } // add this surface to the array surfaces[nSurfaces] = (uint32) hSurface; nSurfaces++; // increment ptr to next character in the string ptr += strlen (pWorkingString); char* pPrev = NULL; while (_mbsnbcmp ((const unsigned char*)ptr, (const unsigned char*)" ", 1) == 0 && *ptr) { pPrev = ptr; ptr = (char*)_mbsinc ((const unsigned char*)ptr); if (!ptr) { ptr = pPrev; break; } } } delete [] pWorkingString; // ok, now we should have an array of surfaces that we can combine into one large one... if (!nSurfaces) return LTNULL; // crop the surfaces if they need to be cropped (leave a one-pixel border) if (bCropped) { for (uint32 i = 0; i < nSurfaces; i++) { HSURFACE hCropped = CropSurface (pClientDE, (HSURFACE)surfaces[i], LTNULL); if (hCropped) { pClientDE->DeleteSurface ((HSURFACE)surfaces[i]); surfaces[i] = (uint32) hCropped; } } } // get the final surface height uint32 nTotalHeight = 0; for (uint32 i = 0; i < nSurfaces; i++) { uint32 nSurfWidth = 0; uint32 nSurfHeight = 0; pClientDE->GetSurfaceDims ((HSURFACE)surfaces[i], &nSurfWidth, &nSurfHeight); nTotalHeight += nSurfHeight; } // create the final surface HSURFACE hFinalSurface = pClientDE->CreateSurface (nWidth, nTotalHeight); if (!hFinalSurface) { for (uint32 i = 0; i < nSurfaces; i++) { pClientDE->DeleteSurface ((HSURFACE)surfaces[i]); } return LTNULL; } pClientDE->FillRect ((HSURFACE)hFinalSurface, LTNULL, LTNULL); // draw the string surfaces onto final one int y = 0; for (int i = 0; i < nSurfaces; i++) { uint32 nSurfWidth = 0; uint32 nSurfHeight = 0; pClientDE->GetSurfaceDims ((HSURFACE)surfaces[i], &nSurfWidth, &nSurfHeight); int x = 0; switch (nAlignment) { case TH_ALIGN_CENTER: x = ((int)nWidth - (int)nSurfWidth) / 2; break; case TH_ALIGN_RIGHT: x = (int)nWidth - (int)nSurfWidth; break; } pClientDE->DrawSurfaceToSurface (hFinalSurface, (HSURFACE)surfaces[i], LTNULL, x, y); y += nSurfHeight; // delete this surface since we don't need it anymore pClientDE->DeleteSurface ((HSURFACE)surfaces[i]); } if (bCropped) { HSURFACE hCropped = CropSurface (pClientDE, hFinalSurface, backColor); if (hCropped) { pClientDE->DeleteSurface (hFinalSurface); return hCropped; } } return hFinalSurface; }
static void test_mbcp(void) { int mb_orig_max = *p__mb_cur_max; int curr_mbcp = _getmbcp(); unsigned char *mbstring = (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */ unsigned char *mbstring2 = (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */ unsigned char *mbsonlylead = (unsigned char *)"\xb0\0\xb1\xb2 \xb3"; unsigned char buf[16]; int step; /* _mbtype tests */ /* An SBCS codepage test. The ctype of characters on e.g. CP1252 or CP1250 differs slightly * between versions of Windows. Also Windows 9x seems to ignore the codepage and always uses * CP1252 (or the ACP?) so we test only a few ASCII characters */ _setmbcp(1252); expect_eq(p_mbctype[10], 0, char, "%x"); expect_eq(p_mbctype[50], 0, char, "%x"); expect_eq(p_mbctype[66], _SBUP, char, "%x"); expect_eq(p_mbctype[100], _SBLOW, char, "%x"); expect_eq(p_mbctype[128], 0, char, "%x"); _setmbcp(1250); expect_eq(p_mbctype[10], 0, char, "%x"); expect_eq(p_mbctype[50], 0, char, "%x"); expect_eq(p_mbctype[66], _SBUP, char, "%x"); expect_eq(p_mbctype[100], _SBLOW, char, "%x"); expect_eq(p_mbctype[128], 0, char, "%x"); /* double byte code pages */ test_codepage(932); test_codepage(936); test_codepage(949); test_codepage(950); _setmbcp(936); ok(*p__mb_cur_max == mb_orig_max, "__mb_cur_max shouldn't be updated (is %d != %d)\n", *p__mb_cur_max, mb_orig_max); ok(_ismbblead('\354'), "\354 should be a lead byte\n"); ok(_ismbblead(' ') == FALSE, "' ' should not be a lead byte\n"); ok(_ismbblead(0x1234b0), "0x1234b0 should not be a lead byte\n"); ok(_ismbblead(0x123420) == FALSE, "0x123420 should not be a lead byte\n"); ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n"); ok(_ismbbtrail(' ') == FALSE, "' ' should not be a trail byte\n"); /* _ismbslead */ expect_eq(_ismbslead(mbstring, &mbstring[0]), -1, int, "%d"); expect_eq(_ismbslead(mbstring, &mbstring[1]), FALSE, int, "%d"); expect_eq(_ismbslead(mbstring, &mbstring[2]), -1, int, "%d"); expect_eq(_ismbslead(mbstring, &mbstring[3]), FALSE, int, "%d"); expect_eq(_ismbslead(mbstring, &mbstring[4]), -1, int, "%d"); expect_eq(_ismbslead(mbstring, &mbstring[5]), FALSE, int, "%d"); expect_eq(_ismbslead(mbstring, &mbstring[6]), FALSE, int, "%d"); expect_eq(_ismbslead(mbstring, &mbstring[7]), -1, int, "%d"); expect_eq(_ismbslead(mbstring, &mbstring[8]), FALSE, int, "%d"); expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[0]), -1, int, "%d"); expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[1]), FALSE, int, "%d"); expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[2]), FALSE, int, "%d"); expect_eq(_ismbslead(mbsonlylead, &mbsonlylead[5]), FALSE, int, "%d"); /* _ismbstrail */ expect_eq(_ismbstrail(mbstring, &mbstring[0]), FALSE, int, "%d"); expect_eq(_ismbstrail(mbstring, &mbstring[1]), -1, int, "%d"); expect_eq(_ismbstrail(mbstring, &mbstring[2]), FALSE, int, "%d"); expect_eq(_ismbstrail(mbstring, &mbstring[3]), -1, int, "%d"); expect_eq(_ismbstrail(mbstring, &mbstring[4]), FALSE, int, "%d"); expect_eq(_ismbstrail(mbstring, &mbstring[5]), -1, int, "%d"); expect_eq(_ismbstrail(mbstring, &mbstring[6]), FALSE, int, "%d"); expect_eq(_ismbstrail(mbstring, &mbstring[7]), FALSE, int, "%d"); expect_eq(_ismbstrail(mbstring, &mbstring[8]), -1, int, "%d"); expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[0]), FALSE, int, "%d"); expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[1]), -1, int, "%d"); expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[2]), FALSE, int, "%d"); expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[3]), FALSE, int, "%d"); expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[4]), FALSE, int, "%d"); expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[5]), FALSE, int, "%d"); /* _mbsbtype */ expect_eq(_mbsbtype(mbstring, 0), _MBC_LEAD, int, "%d"); expect_eq(_mbsbtype(mbstring, 1), _MBC_TRAIL, int, "%d"); expect_eq(_mbsbtype(mbstring, 2), _MBC_LEAD, int, "%d"); expect_eq(_mbsbtype(mbstring, 3), _MBC_ILLEGAL, int, "%d"); expect_eq(_mbsbtype(mbstring, 4), _MBC_LEAD, int, "%d"); expect_eq(_mbsbtype(mbstring, 5), _MBC_TRAIL, int, "%d"); expect_eq(_mbsbtype(mbstring, 6), _MBC_SINGLE, int, "%d"); expect_eq(_mbsbtype(mbstring, 7), _MBC_LEAD, int, "%d"); expect_eq(_mbsbtype(mbstring, 8), _MBC_ILLEGAL, int, "%d"); expect_eq(_mbsbtype(mbsonlylead, 0), _MBC_LEAD, int, "%d"); expect_eq(_mbsbtype(mbsonlylead, 1), _MBC_ILLEGAL, int, "%d"); expect_eq(_mbsbtype(mbsonlylead, 2), _MBC_ILLEGAL, int, "%d"); expect_eq(_mbsbtype(mbsonlylead, 3), _MBC_ILLEGAL, int, "%d"); expect_eq(_mbsbtype(mbsonlylead, 4), _MBC_ILLEGAL, int, "%d"); expect_eq(_mbsbtype(mbsonlylead, 5), _MBC_ILLEGAL, int, "%d"); /* _mbsnextc */ expect_eq(_mbsnextc(mbstring), 0xb0b1, int, "%x"); expect_eq(_mbsnextc(&mbstring[2]), 0xb220, int, "%x"); /* lead + invalid tail */ expect_eq(_mbsnextc(&mbstring[3]), 0x20, int, "%x"); /* single char */ /* _mbclen/_mbslen */ expect_eq(_mbclen(mbstring), 2, int, "%d"); expect_eq(_mbclen(&mbstring[2]), 2, int, "%d"); expect_eq(_mbclen(&mbstring[3]), 1, int, "%d"); expect_eq(_mbslen(mbstring2), 4, int, "%d"); expect_eq(_mbslen(mbsonlylead), 0, int, "%d"); /* lead + NUL not counted as character */ expect_eq(_mbslen(mbstring), 4, int, "%d"); /* lead + invalid trail counted */ /* _mbccpy/_mbsncpy */ memset(buf, 0xff, sizeof(buf)); _mbccpy(buf, mbstring); expect_bin(buf, "\xb0\xb1\xff", 3); memset(buf, 0xff, sizeof(buf)); _mbsncpy(buf, mbstring, 1); expect_bin(buf, "\xb0\xb1\xff", 3); memset(buf, 0xff, sizeof(buf)); _mbsncpy(buf, mbstring, 2); expect_bin(buf, "\xb0\xb1\xb2 \xff", 5); memset(buf, 0xff, sizeof(buf)); _mbsncpy(buf, mbstring, 3); expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4\xff", 7); memset(buf, 0xff, sizeof(buf)); _mbsncpy(buf, mbstring, 4); expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4 \xff", 8); memset(buf, 0xff, sizeof(buf)); _mbsncpy(buf, mbstring, 5); expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4 \0\0\xff", 10); memset(buf, 0xff, sizeof(buf)); _mbsncpy(buf, mbsonlylead, 6); expect_bin(buf, "\0\0\0\0\0\0\0\xff", 8); memset(buf, 0xff, sizeof(buf)); _mbsnbcpy(buf, mbstring2, 2); expect_bin(buf, "\xb0\xb1\xff", 3); _mbsnbcpy(buf, mbstring2, 3); expect_bin(buf, "\xb0\xb1\0\xff", 4); _mbsnbcpy(buf, mbstring2, 4); expect_bin(buf, "\xb0\xb1\xb2\xb3\xff", 5); memset(buf, 0xff, sizeof(buf)); _mbsnbcpy(buf, mbsonlylead, 5); expect_bin(buf, "\0\0\0\0\0\xff", 6); /* _mbsinc/mbsdec */ step = _mbsinc(mbstring) - mbstring; ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step); step = _mbsinc(&mbstring[2]) - &mbstring[2]; /* lead + invalid tail */ ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step); step = _mbsninc(mbsonlylead, 1) - mbsonlylead; ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step); step = _mbsninc(mbsonlylead, 2) - mbsonlylead; /* lead + NUL byte + lead + char */ ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step); step = _mbsninc(mbstring2, 0) - mbstring2; ok(step == 0, "_mbsninc adds %d (exp. 2)\n", step); step = _mbsninc(mbstring2, 1) - mbstring2; ok(step == 2, "_mbsninc adds %d (exp. 2)\n", step); step = _mbsninc(mbstring2, 2) - mbstring2; ok(step == 4, "_mbsninc adds %d (exp. 4)\n", step); step = _mbsninc(mbstring2, 3) - mbstring2; ok(step == 5, "_mbsninc adds %d (exp. 5)\n", step); step = _mbsninc(mbstring2, 4) - mbstring2; ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step); step = _mbsninc(mbstring2, 5) - mbstring2; ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step); step = _mbsninc(mbstring2, 17) - mbstring2; ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step); /* functions that depend on locale codepage, not mbcp. * we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet * (as of Wine 0.9.43) */ if (*p__mb_cur_max == 1) { expect_eq(mblen((char *)mbstring, 3), 1, int, "%x"); expect_eq(_mbstrlen((char *)mbstring2), 7, int, "%d"); }