*/
LPCSTR convert(LPCTSTR str, UINT codepage)
{
-#ifndef UNICODE
- return _strdup(str);
-#else
int len = WideCharToMultiByte(codepage, 0, str, -1, 0, 0, 0, 0);
if (len)
{
return ansi;
}
return NULL;
-#endif
}
CString strText;
if (m_szMenuText)
{
-#ifdef UNICODE
strText = m_szMenuText;
-#else
- USES_CONVERSION;
- strText=W2A(m_szMenuText); //SK: see MFC Tech Note 059
-#endif
}
return strText;
}
if (Win32s!=g_Shell)
VERIFY(::GetTextExtentPoint32W(pDC->m_hDC,lpstrText,
wcslen(lpstrText),&size)); //SK should also work on 95
-#ifndef UNICODE //can't be UNICODE for Win32s
- else{//it's Win32suckx
- RECT rect;
- rect.left=rect.top=0;
- size.cy=DrawText(pDC->m_hDC,(LPCTSTR)lpstrText,
- wcslen(lpstrText),&rect,
- DT_SINGLELINE|DT_LEFT|DT_VCENTER|DT_CALCRECT);
- //+3 makes at least three pixels space to the menu border
- size.cx=rect.right-rect.left+3;
- size.cx += 3*(size.cx/wcslen(lpstrText));
- }
-#endif
CSize t = CSize(size);
if(IsNewShell())
mdata = new BCMenuData;
mdata->menuIconNormal = -1;
mdata->xoffset=-1;
-#ifdef UNICODE
mdata->SetWideString((LPCTSTR)string);//SK: modified for dynamic allocation
-#else
- mdata->SetAnsiString(string);
-#endif
mdata->nFlags = nFlags;
mdata->nID = nID;
t=pDC->GetTextExtent(lpstrText,(int)_tcslen(lpstrText));
}
newstring+=string.Mid(j);
-#ifdef UNICODE
m_MenuList[i]->SetWideString(newstring);//SK: modified for dynamic allocation
-#else
- m_MenuList[i]->SetAnsiString(newstring);
-#endif
}
}
pDC->SelectObject (pFont); // Select old font in
if(!mdata)mdata=NewODMenu(j,
(state&0xFF)|MF_BYPOSITION|MF_POPUP|MF_OWNERDRAW,submenu,string);
else if(string.GetLength()>0)
-#ifdef UNICODE
mdata->SetWideString(string); //SK: modified for dynamic allocation
-#else
- mdata->SetAnsiString(string);
-#endif
}
else if(state&MF_SEPARATOR){
mdata=FindMenuList(0);
else{
mdata->nFlags=state|MF_BYPOSITION|MF_OWNERDRAW;
if(string.GetLength()>0)
-#ifdef UNICODE
mdata->SetWideString(string);//SK: modified for dynamic allocation
-#else
- mdata->SetAnsiString(string);
-#endif
ModifyMenu(j,mdata->nFlags,nID,(LPCTSTR)mdata);
}
{
INT_PTR numMenuItems = m_MenuList.GetUpperBound();
if(id<=numMenuItems){
-#ifdef UNICODE
m_MenuList[id]->SetWideString((LPCTSTR)string);
-#else
- m_MenuList[id]->SetAnsiString(string);
-#endif
returnflag=TRUE;
}
}
//struct CMenuItemInfo : public MENUITEMINFO {
struct CMenuItemInfo : public
//MENUITEMINFO
-#ifndef UNICODE //SK: this fixes warning C4097: typedef-name 'MENUITEMINFO' used as synonym for class-name 'tagMENUITEMINFOA'
-tagMENUITEMINFOA
-#else
tagMENUITEMINFOW
-#endif
{
CMenuItemInfo()
{
typedef enum {BCMENU_NONE, BCMENU_HEAD, BCMENU_TAIL, BCMENU_BOTH} BC_Seperator;
// defines for unicode support
-#ifndef UNICODE
-#define AppendMenu AppendMenuA
-#define InsertMenu InsertMenuA
-#define InsertODMenu InsertODMenuA
-#define AppendODMenu AppendODMenuA
-#define AppendODPopupMenu AppendODPopupMenuA
-#define ModifyODMenu ModifyODMenuA
-#define SetImageForPopupFromToolbar SetImageForPopupFromToolbarA
-#else
#define AppendMenu AppendMenuW
#define InsertMenu InsertMenuW
#define InsertODMenu InsertODMenuW
#define ModifyODMenu ModifyODMenuW
#define AppendODPopupMenu AppendODPopupMenuW
#define SetImageForPopupFromToolbar SetImageForPopupFromToolbarW
-#endif
class BCMenu : public CMenu
*/
char * UCS2UTF8_ConvertToUtf8(LPCTSTR strOrigin)
{
-#ifdef UNICODE
// Get the size of UTF-8 string
int str_len = TransformUcs2ToUtf8(strOrigin, _tcslen(strOrigin), NULL, 0);
++str_len; // Space for zero at end
char * str_utf = (char *) malloc(str_len);
ZeroMemory(str_utf, str_len);
str_len = TransformUcs2ToUtf8(strOrigin, _tcslen(strOrigin), str_utf, str_len);
-#else
- char *str_utf = strdup(strOrigin);
-#endif
return str_utf;
}
if (codepage == -1)
codepage = defcodepage;
-#ifdef UNICODE
// Convert input to Unicode, using specified codepage
// TCHAR is wchar_t, so convert into String (str)
DWORD flags = MB_ERR_INVALID_CHARS;
while (flags == 0 && GetLastError() == ERROR_NO_UNICODE_TRANSLATION);
str = _T('?');
return true;
-
-#else
- if (EqualCodepages(codepage, defcodepage))
- {
- // trivial case, they want the bytes in the file interpreted in our current codepage
- // Only caveat is that input (lpd) is not zero-terminated
- str = String(lpd, len);
- return true;
- }
-
- str = CrossConvertToStringA(lpd, len, codepage, defcodepage, lossy);
- return true;
-#endif
}
/**
- * @brief (ANSI build only) Convert from one 8 bit codepage to another
- */
-#ifndef UNICODE
-String CrossConvertToStringA(const char* src, unsigned int srclen, int cpin, int cpout, bool * lossy)
-{
- int wlen = srclen * 2 + 6;
- int clen = wlen * 2 + 6;
- String str;
- str.resize(clen);
- char* cbuff = &*str.begin();
- int nbytes = CrossConvert(src, srclen, cbuff, clen, cpin, cpout, lossy);
- str.resize(nbytes);
- return str;
-}
-#endif
-
-/**
* @brief Convert from one 8-bit codepage to another
*
* destsize must be at least 2
bool convert(UNICODESET unicoding1, int codepage1, const unsigned char * src, int srcbytes, UNICODESET unicoding2, int codepage2, buffer * dest);
int CrossConvert(const char* src, unsigned int srclen, char* dest, unsigned int destsize, int cpin, int cpout, bool * lossy);
-#ifndef UNICODE
-String CrossConvertToStringA(const char* src, unsigned int srclen, int cpin, int cpout, bool * lossy);
-#endif
UNICODESET DetermineEncoding(PBYTE pBuffer, INT64 size, bool * pBom);
FileWriteString(_T(" codepage settings:\r\n"));
WriteItem(2, _T("ANSI codepage"), GetACP());
WriteItem(2, _T("OEM codepage"), GetOEMCP());
-#ifndef UNICODE
- WriteItem(2, _T("multibyte codepage"), _getmbcp());
-#endif
WriteLocaleSettings(GetThreadLocale(), _T("Locale (Thread)"));
WriteLocaleSettings(LOCALE_USER_DEFAULT, _T("Locale (User)"));
WriteLocaleSettings(LOCALE_SYSTEM_DEFAULT, _T("Locale (System)"));
char * regexp_str;
FilterList::EncodingType type;
-#ifdef UNICODE
regexp_str = UCS2UTF8_ConvertToUtf8(filterStr);
type = FilterList::ENC_UTF8;
-#else
- CString tmp_str(filterStr);
- regexp_str = tmp_str.LockBuffer();
- type = FilterList::ENC_ANSI;
-#endif
// Add every "line" of regexps to regexp list
char * token;
m_pFilterList->AddRegExp(token, type);
token = strtok(NULL, sep);
}
-#ifdef UNICODE
UCS2UTF8_Dealloc(regexp_str);
-#else
- tmp_str.UnlockBuffer();
-#endif
}
/**
char * regexp_str;
FilterList::EncodingType type;
-#ifdef UNICODE
regexp_str = UCS2UTF8_ConvertToUtf8(filters.c_str());
type = FilterList::ENC_UTF8;
-#else
- regexp_str = (char *) filters.c_str();
- type = FilterList::ENC_ANSI;
-#endif
m_pCtxt->m_pFilterList->AddRegExp(regexp_str, type);
-#ifdef UNICODE
UCS2UTF8_Dealloc(regexp_str);
-#endif
}
/**
#include "coretools.h"
// shlwapi.h prior to VC6SP6 might lack definition of StrIsIntlEqual
-#ifdef UNICODE
#define StrIsIntlEqual StrIsIntlEqualW
-#else
-#define StrIsIntlEqual StrIsIntlEqualA
-#endif
#ifdef _DEBUG
#define new DEBUG_NEW
char * regexp_str;
FilterList::EncodingType type;
-#ifdef UNICODE
regexp_str = UCS2UTF8_ConvertToUtf8(regExp.c_str());
type = FilterList::ENC_UTF8;
-#else
- regexp_str = &*regExp.begin();
- type = FilterList::ENC_ANSI;
-#endif
m_pMaskFilter->RemoveAllFilters();
m_pMaskFilter->AddRegExp(regexp_str, type);
-#ifdef UNICODE
UCS2UTF8_Dealloc(regexp_str);
-#endif
}
/**
// Include the manifest file for VC6 and VS2003.Net
#if _MSC_VER < 1400
- #ifdef UNICODE
- CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "res\\WinMergeU.exe.manifest"
- #else
- CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "res\\WinMerge.exe.manifest"
- #endif
+ CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "res\\WinMergeU.exe.manifest"
#endif // MSC_VER
*/
bool IsUnicodeBuild()
{
-#ifdef UNICODE
return true;
-#else
- return false;
-#endif
}
#if _MSC_VER <= 1310
/** @brief Is structure initialized? */
static bool f_initialized = false;
-#ifdef UNICODE
// For UNICODE build, there is just one set which is always used
// tab, space, cr, lf, eol
f_initialized = true;
}
-#else
-// For ANSI build, there are various sets for different codepages
-static CMap<int, int, int, int> f_offset; // map codepage to offset
-
-// tab, space, cr, lf, eol
-/** @brief Structure for whitespace characters.
- * Char order is tab, space, cr, lf, eol.
- */
-static struct ViewableWhitespaceChars
- f_specialChars[] = {
- { 0, ">", ".", "$", "!", "&" } // default all-ASCII for unhandled codepages
- , { 850, "\xAF", "\xFA", "\xF5", "\xF4", "\xCF" } // CP-850 MSDOS Multilingual
-
- // CP-932 Windows version of Japanese ShiftJIS
- // \x81\x98 = u+A7
- // \x81\xF7 = u+B6
- , { 932, ">", ".", "\x81\x98", "\x81\xF7", "&" } // CP-932 Japanese
-
- // CP-949 Korean
- // \xA1\xA4 = u+B7
- // \xA1\xD7 = u+A7
- // \xA2\xD2 = u+B6
- // \xA2\xB4 = u+A4
- , { 949, ">", "\xA1\xA4", "\xA1\xD7", "\xA2\xD2", "\xA2\xB4" } // CP-949 Korean
-
- // CP-950 Windows version of Big5 Chinese Traditional
- // \xA1\x6D = u+300A
- // \xA1\x50 = u+B7
- // \xA1\xB1 = u+A7
- // \xA2\x54 = ?
- // \xA1\x3B = u+33A1
- , { 951, "\xA1\x6D", "\xA1\x50", "\xA1\xB1", "\xA2\x54", "\xA1\x3B" } // CP-950 Chinese Traditional
-
- , { 1250, "\xBB", "\xB7", "\xA7", "\xB6", "\xA4" } // CP-1250 Central Europe
- , { 1251, "\xBB", "\xB7", "\xA7", "\xB6", "\xA4" } // CP-1251 Windows Cyrillic
- , { 1252, "\xBB", "\xB7", "\xA7", "\xB6", "\xA4" } // CP-1252 Western Europe
- , { 1253, "\xBB", "\xB7", "\xA7", "\xB6", "\xA4" } // CP-1253 Windows Greek
- , { 1254, "\xBB", "\xB7", "\xA7", "\xB6", "\xA4" } // CP-1254 Windows Turkish
- , { 1255, "\xBB", "\xB7", "\xA7", "\xB6", "\xA5" } // CP-1255 Windows Hebrew
- , { 1256, "\xBB", "\xB7", "\xA7", "\xB6", "\xA4" } // CP-1256 Windows Arabic
- , { 1257, "\xBB", "\xB7", "\xA7", "\xB6", "\xA4" } // CP-1257 Windows Baltic Rim
-};
-
-/**
- * @brief Initialize whitespace chars structure.
- */
-static void initialize()
-{
- for (int i=0; i<sizeof(f_specialChars)/sizeof(f_specialChars[0]); ++i)
- {
- int codepage = f_specialChars[i].c_codepage;
- f_offset[codepage] = i;
- }
-
- f_initialized = true;
-}
-
-#endif
-
/**
* @brief Return viewable whitespace chars.
* @param [in] codepage Used codepage (only efective in ANSI builds).
{
if (!f_initialized)
initialize();
-#ifdef UNICODE
return &f_specialChars;
-#else
- // Use the [0] version by default, if lookup fails to find a better one
- int offset = 0;
- if (f_offset.Lookup(codepage, offset))
- {
- int d=9;
- }
- return &f_specialChars[offset];
-#endif
}
return GetCharWidth() * 3;
// This assumes a fixed width font
// But the UNICODE case handles double-wide glyphs (primarily Chinese characters)
-#ifdef _UNICODE
return GetCharWidthUnicodeChar(ch);
-#else
- return GetCharWidth();
-#endif
}
/**
{
// This assumes a fixed width font
// But the UNICODE case handles double-wide glyphs (primarily Chinese characters)
-#ifdef _UNICODE
int n=0;
for (LPCTSTR p = lpsz; *p; ++p)
n += GetCharWidthUnicodeChar(*p);
return n;
-#else
- return strlen(lpsz) * GetCharWidth();
-#endif
}
/**
/** Does character introduce a multicharacter character? */
static inline bool IsLeadByte(TCHAR ch)
{
-#ifdef UNICODE
return false;
-#else
- return _getmbcp() && IsDBCSLeadByte(ch);
-#endif
}
int CCrystalTextView::CursorPointToCharPos( int nLineIndex, const CPoint &curPoint )
if (result >= 0)
{
-#ifdef UNICODE
pos = ucr::stringlen_of_utf8(compString, ovector[0]);
nLen = ucr::stringlen_of_utf8(compString, ovector[1]) - pos;
-#else
- pos = ovector[0];
- nLen = ovector[1] - ovector[0];
-#endif
}
else
pos = -1;
/** Does character introduce a multicharacter character? */
static inline bool IsLeadByte(TCHAR ch)
{
-#ifdef UNICODE
return false;
-#else
- return _getmbcp() && IsDBCSLeadByte(ch);
-#endif
}
/**