CUString CLanguage::GetMainMenuItem( const DWORD nID, const DWORD nItem ) { CUString strRet; strRet = GetSubMenuItem( nID ); DWORD dwIndex = 0; int nStart = 0; int nStop = strRet.GetLength(); for ( dwIndex = 0; dwIndex < nItem; dwIndex++ ) { nStart = strRet.Find( '#', nStart + 1 ); if ( -1 == nStart ) { break; } } if ( -1 != nStart ) { nStop = strRet.Find( '#', nStart + 1 ); if ( -1 == nStop ) { nStop = strRet.GetLength(); } } if ( nStop - nStart > 2 ) { strRet = strRet.Mid( nStart + 1, nStop - nStart - 1 ); } return strRet; }
void CLanguage::SearchLanguageFiles( ) { CUString strSearchName; CFileFind fileFind; BOOL bFound = FALSE; // PVOID pTest = (PVOID)m_strLanguageDir; //CString str; //CString str1 =_T( "CSTRING1" ); //CString str2 =_T( "CSTRING2" ); //CUString str3( _W("CUSTRING" )); // str.Format( _W( "%s" ),str1 ); // str.Format( _W( "%s" ),(LPCWSTR)str3 ); // str.Format( _W( "%s\\lang\\*%s" ), // str1, // str3); // CUString* p1 = &str3; // CString* p2 = &str1; // build the filename search string strSearchName.Format( _W( "%s\\lang\\*%s" ), (LPCWSTR)m_strLanguageDir, (LPCWSTR)m_strLangFileExt ); CUStringConvert strCnv; bFound = fileFind.FindFile( strCnv.ToT( strSearchName ) ); while ( bFound ) { bFound = fileFind.FindNextFile(); CUString strFileName = fileFind.GetFileName(); CUString strLanguage = strFileName.Left( strFileName.GetLength() - m_strLangFileExt.GetLength() ); m_vLangFiles.push_back( strLanguage ); } sort( m_vLangFiles.begin(), m_vLangFiles.end() ); }
CUString EncodeUTF8( CUString &str ) { CUString ret = ""; if( str.GetLength() == 6 ) { ret = str.SubStr( 2,6 ); unsigned long index; index = strtoul( ret.GetStr(), 0, 16 ); if( 0x00 <= index && index <= 0x7F ) { char buf[4]; sprintf( buf, "%c", (char)index ); ret = buf; } else if( 0x80 <= index && index <= 0x07FF ) { // 2byte; int enc_ch1 = 0xC0; // 11000000 int enc_ch2 = 0x80; // 10000000 char ch1 = (char)strtoul( ret.SubStr(0,2).GetStr(), 0, 16 ); char ch2 = (char)strtoul( ret.SubStr(2,4).GetStr(), 0, 16 ); if( ch1 & (1 << (3-1) ) ) { enc_ch1 |= (1 << (5-1) ); } if( ch1 & (1 << (2-1) ) ) { enc_ch1 |= (1 << (4-1) ); } if( ch1 & (1 << (1-1) ) ) { enc_ch1 |= (1 << (3-1) ); } if( ch2 & (1 << (8-1) ) ) { enc_ch1 |= (1 << (2-1) ); } if( ch2 & (1 << (7-1) ) ) { enc_ch1 |= (1 << (1-1) ); } if( ch2 & (1 << (6-1) ) ) { enc_ch2 |= (1 << (6-1) ); } if( ch2 & (1 << (5-1) ) ) { enc_ch2 |= (1 << (5-1) ); } if( ch2 & (1 << (4-1) ) ) { enc_ch2 |= (1 << (4-1) ); } if( ch2 & (1 << (3-1) ) ) { enc_ch2 |= (1 << (3-1) ); } if( ch2 & (1 << (2-1) ) ) { enc_ch2 |= (1 << (2-1) ); } if( ch2 & (1 << (1-1) ) ) { enc_ch2 |= (1 << (1-1) ); } //dumptoBin( enc_ch1 ); dumptoBin( enc_ch2 ); char buf[4]; sprintf( buf, "%c%c", enc_ch1, enc_ch2 ); ret = buf; } else if( 0x0800 <= index && index <= 0xFFFF ) { // 3byte; char enc_ch1 = 0xE0; // 11100000 char enc_ch2 = 0x80; // 10000000 char enc_ch3 = 0x80; // 10000000 char ch1 = (char)strtoul( ret.SubStr(0,2).GetStr(), 0, 16 ); char ch2 = (char)strtoul( ret.SubStr(2,4).GetStr(), 0, 16 ); if( ch1 & (1 << (8-1) ) ) { enc_ch1 |= (1 << (4-1) ); } if( ch1 & (1 << (7-1) ) ) { enc_ch1 |= (1 << (3-1) ); } if( ch1 & (1 << (6-1) ) ) { enc_ch1 |= (1 << (2-1) ); } if( ch1 & (1 << (5-1) ) ) { enc_ch1 |= (1 << (1-1) ); } if( ch1 & (1 << (4-1) ) ) { enc_ch2 |= (1 << (6-1) ); } if( ch1 & (1 << (3-1) ) ) { enc_ch2 |= (1 << (5-1) ); } if( ch1 & (1 << (2-1) ) ) { enc_ch2 |= (1 << (4-1) ); } if( ch1 & (1 << (1-1) ) ) { enc_ch2 |= (1 << (3-1) ); } if( ch2 & (1 << (8-1) ) ) { enc_ch2 |= (1 << (2-1) ); } if( ch2 & (1 << (7-1) ) ) { enc_ch2 |= (1 << (1-1) ); } if( ch2 & (1 << (6-1) ) ) { enc_ch3 |= (1 << (6-1) ); } if( ch2 & (1 << (5-1) ) ) { enc_ch3 |= (1 << (5-1) ); } if( ch2 & (1 << (4-1) ) ) { enc_ch3 |= (1 << (4-1) ); } if( ch2 & (1 << (3-1) ) ) { enc_ch3 |= (1 << (3-1) ); } if( ch2 & (1 << (2-1) ) ) { enc_ch3 |= (1 << (2-1) ); } if( ch2 & (1 << (1-1) ) ) { enc_ch3 |= (1 << (1-1) ); } //dumptoBin( enc_ch1 ); dumptoBin( enc_ch2 ); dumptoBin( enc_ch3 ); char buf[4]; sprintf( buf, "%c%c%c", enc_ch1, enc_ch2, enc_ch3 ); ret = buf; } } return ret; }
void COpenFileDlg::AddRecursiveFiles( const CUString& strDir,int nItem ) { CFileFind fileFind; CUString pathAndFileType = strDir + CUString( _W( "\\*.*" )); BOOL bStop=FALSE; CUStringConvert strCnv; // Iterate through the items in the listbox and populate the listconrol. if (fileFind.FindFile( strCnv.ToT( pathAndFileType ) ) ) { do { bStop=(fileFind.FindNextFile()==0); CUString strFileName = CUString( fileFind.GetFileName() ); CUString strFileRoot = CUString( fileFind.GetRoot() ); CUString strFileType; if ( TRUE == fileFind.IsDirectory() && FALSE == fileFind.IsDots() && TRUE == m_bRecursiveDir ) { AddRecursiveFiles( strDir + CUString( _W( "\\" ) ) + strFileName, nItem ); } if (fileFind.IsDirectory()==FALSE && fileFind.IsDots()==FALSE) { int nPos=strFileName.ReverseFind( _T( '.' ) ); if (nPos>0) { CUString strExt; strExt = strFileName.Right(strFileName.GetLength()-nPos-1); strFileType = strExt; strExt.MakeUpper(); if ( CompareExt( strExt ) == TRUE ) { CUString strFileSize; CUString strFileDate; CTime fileTime; // Get the data/time stamp of this file fileFind.GetLastWriteTime( fileTime ); // Format date time string strFileDate.Format( _W( "%4d/%02d/%02d %02d:%02d" ), fileTime.GetYear(), fileTime.GetMonth(), fileTime.GetDay(), fileTime.GetHour(), fileTime.GetMinute() ); strFileSize.Format( _W( "%10.2f" ), fileFind.GetLength() / ( 1024.0 * 1024.0 ) ); CUStringConvert strCnv; m_ctrlRequestedFiles.InsertItem( nItem, strCnv.ToT( strFileName )); m_ctrlRequestedFiles.SetItemText( nItem, FILE_OPEN_TYPE, strCnv.ToT( strFileType ) ); m_ctrlRequestedFiles.SetItemText( nItem, FILE_OPEN_DATE ,strCnv.ToT( strFileDate ) ); m_ctrlRequestedFiles.SetItemText( nItem, FILE_OPEN_PATH, strCnv.ToT( strFileRoot ) ); m_ctrlRequestedFiles.SetItemText( nItem, FILE_OPEN_SIZE, strCnv.ToT( strFileSize ) ); m_ctrlRequestedFiles.SetItemData( nItem, (DWORD)fileTime.GetTime() ); nItem++; } } } } while (bStop!=TRUE); } m_bSortAscending=TRUE; }
BOOL CLanguage::InitDialogStrings( CDialog* pDialog, long lSection ) { short nCtrlID; CUString sText; CWnd* pWndCtrl; DWORD nIndex = 0; CUStringConvert strCnv; CUString strLang = GetDialogString( MAKELPARAM( 0, lSection ) ); if( !strLang.IsEmpty() ) { pDialog->SetWindowText( strCnv.ToT( strLang ) ); } else { CString strMissing; pDialog->GetWindowText( strMissing ); ReportMissingID( MAKELPARAM( 0, lSection ), CUString( strMissing ), 2 ); } // test if the dialog has child windows if( pWndCtrl = pDialog->GetWindow( GW_CHILD | GW_HWNDFIRST ) ) { // lool through all controls (windows) and replace text do { nCtrlID = pWndCtrl->GetDlgCtrlID(); if ( !pWndCtrl->IsKindOf( RUNTIME_CLASS( CEdit ) ) && !pWndCtrl->IsKindOf( RUNTIME_CLASS( CListCtrl ) ) && !pWndCtrl->IsKindOf( RUNTIME_CLASS( CSpinButtonCtrl) ) ) { if( nCtrlID > 0 ) { // check if the Id is in the range of common strings if( (nCtrlID >= COMMON_IDMIN) && (nCtrlID <= COMMON_IDMAX) ) { strLang = GetString( nCtrlID ); } else { strLang = GetDialogString( MAKELPARAM( nCtrlID, lSection ) ); } if( !strLang.IsEmpty() ) { if ( pWndCtrl->IsKindOf( RUNTIME_CLASS( CComboBox ) ) ) { CUString strAdd; int nPos = -1; // remove old strings ((CComboBox*)pWndCtrl)->ResetContent(); while ( ( nPos = strLang.Find( '\n' ) ) >= 0 ) { ((CComboBox*)pWndCtrl)->AddString( strCnv.ToT( strLang.Left( nPos ) ) ); strLang = strLang.Mid( nPos + 1 ); nPos++; } if ( strLang.GetLength() > nPos ) { ((CComboBox*)pWndCtrl)->AddString( strCnv.ToT( strLang.Mid( nPos ) ) ); } } else { pDialog->SetDlgItemText( nCtrlID, strCnv.ToT( strLang ) ); } } else { CString strMissing; if ( pWndCtrl->IsKindOf( RUNTIME_CLASS( CComboBox ) ) ) { int nIndex = 0; int nItems = ((CComboBox*)pWndCtrl)->GetCount(); for ( nIndex =0; nIndex < nItems; nIndex++ ) { CString strTmp; ((CComboBox*)pWndCtrl)->GetLBText( nIndex, strTmp ); strMissing += strTmp; if ( nIndex < nItems - 1 ) { strMissing += _T( "\n" ); } } } else { pDialog->GetDlgItemText( nCtrlID, strMissing ); } if ( !strMissing.IsEmpty() ) { ReportMissingID( MAKELPARAM( nCtrlID, lSection ), CUString( strMissing ), 2 ); } } } } pWndCtrl = pWndCtrl->GetWindow( GW_HWNDNEXT ); } while( (pWndCtrl != NULL) && (pWndCtrl != pDialog->GetWindow( GW_CHILD | GW_HWNDFIRST )) ); } return TRUE; }
CUString FormatTrackNameString( CUString strFormat, ENUM_FILENAME_CONVERTS nType ) { int i; switch ( nType ) { case FILENAME_CONVERT_NONE: // do noting break; case FILENAME_CONVERT_LOWER: strFormat.MakeLower(); break; case FILENAME_CONVERT_UPPER: strFormat.MakeUpper(); break; case FILENAME_CONVERT_FC_UPPER: strFormat.MakeLower(); if ( strFormat.GetLength() > 0 ) { CUString strTmp( strFormat.Left( 1 ) ); strTmp.MakeUpper(); strFormat.SetAt( 0, strTmp.GetAt( 0 ) ); } break; case FILENAME_CONVERT_FCEW_UPPER: strFormat.MakeLower(); for ( i=0; i < strFormat.GetLength()-1; i++ ) { if ( i == 0 ) { CUString strTmp( strFormat.Mid( 0, 1 ) ); strTmp.MakeUpper(); strFormat.SetAt( 0, strTmp.GetAt( 0 ) ); } else { if ( ( 0 == _istalnum( strFormat.GetAt( i ) ) ) && ( _T( '\'' ) != strFormat.GetAt( i ) ) ) { CUString strTmp( strFormat.Mid( i+1, 1 ) ); strTmp.MakeUpper(); strFormat.SetAt( i+1, strTmp.GetAt( 0 ) ); } } } break; case FILENAME_CONVERT_SWAP_ARTIST_TRACK: i = strFormat.Find( _W( " / " ) ); if ( i > 0 ) { CUString str1; CUString str2; str1 = strFormat.Left( i ); str2 = strFormat.Mid( i + 3 ); strFormat = str2 + _W( " / " ) + str1; } break; default: ASSERT( FALSE ); } return strFormat; }
DWORD GetNumReplaceCharacters() { return ILLEGAL_FNAME_CHARS.GetLength(); }
CUString FixFileNameString(const CUString& strIn) { int nLoc=0; int nOldPos=-1; CUString strRILC=g_config.GetRILC(); CUString strToTest(strIn); // Remove any trailing spaces strToTest.TrimLeft(); // Remove any leading spaces strToTest.TrimRight(); for ( nLoc=0; nLoc< ILLEGAL_FNAME_CHARS.GetLength() ; nLoc++) { int nPos=0; int nChar = 0x20; int nRes = swscanf(strRILC.Mid(nLoc*3,2), _W( "%2X" ), &nChar ); if ( ( EOF == nRes ) || ( 0 == nRes ) ) { nChar = 0x20; } while ( nPos < strToTest.GetLength() ) { if ( strToTest.GetAt( nPos ) == ILLEGAL_FNAME_CHARS[ nLoc ] ) { // nChar can be zero, if this is the case, we have to strip // the illegal character, and not replace it if ( nChar ) { // replace character strToTest.SetAt( nPos, (char)(nChar) ); // advance to next character nPos++; } else { // No replacement available, thus // delete the illegal character from the string strToTest= strToTest.Left(nPos) + strToTest.Right(strToTest.GetLength() - nPos - 1 ); } } else { // advance to next character nPos++; } } nPos = strToTest.GetLength() - 1 ; while ( nPos >= 0 ) { if ( '.' != strToTest.GetAt( nPos ) ) break; strToTest = strToTest.Left( strToTest.GetLength() -1 ); nPos--; } } return strToTest; }
void BuildFileName( CUString strFormat, CUString strArray[NUMFILENAME_IDS], CUString& strName,CUString& strDir) { CUString strTmp( strFormat ); int nPos = 0; int i; for ( i=0; i<NUMFILENAME_IDS; i++ ) { strArray[i] = FixFileNameString( strArray[i] ); } // loop through all the tokens while ( (( nPos = strTmp.Find( _T( '%' ),nPos ) ) >=0 ) && ( nPos + 1 < strTmp.GetLength() ) ) { ENUM_FILENAME_CONVERTS convertType = FILENAME_CONVERT_NONE; int nPercentID = 0; int nSkipChars = 2; WCHAR chEval = strTmp.GetAt( nPos + 1 ); if ( _W( 'l' ) == chEval ) { convertType = FILENAME_CONVERT_LOWER; chEval = strTmp.GetAt( nPos + 2 ); nSkipChars++; } if ( _W( 'u' ) == chEval ) { convertType = FILENAME_CONVERT_UPPER; chEval = strTmp.GetAt( nPos + 2 ); nSkipChars++; } if ( _W( 'c' ) == chEval ) { convertType = FILENAME_CONVERT_FCEW_UPPER; chEval = strTmp.GetAt( nPos + 2 ); nSkipChars++; } if ( _W( 'f' ) == chEval ) { convertType = FILENAME_CONVERT_FC_UPPER; chEval = strTmp.GetAt( nPos + 2 ); nSkipChars++; } // Get %ID number switch ( chEval ) { case '1': nPercentID = 0; break; case '2': nPercentID = 1; break; case '3': nPercentID = 2; break; case '4': nPercentID = 3; break; case '5': nPercentID = 4; break; case '6': nPercentID = 5; break; case '7': nPercentID = 6; break; case '8': nPercentID = 7; break; case 'Y': nPercentID = 8; break; case 'G': nPercentID = 9; break; case 'A': nPercentID = 10; break; default: nPercentID = -1; nPos++; break; } if ( nPercentID >= 0 && nPercentID < NUMFILENAME_IDS ) { CUString strLeft( strTmp.Left( nPos ) ); CUString strMid( strArray[ nPercentID ] ); CUString strRight( strTmp.Right( strTmp.GetLength() - nPos - nSkipChars ) ); // do filename mangling strMid = FormatTrackNameString( strMid, convertType ); strTmp = strLeft + strMid + strRight; } else { // Delete token // strTmp = strTmp.Left( nPos ) + strTmp.Right( strTmp.GetLength() - nPos - 1 ); } } // Split result in a directory and file name portion // Search for last backslash nPos = strTmp.ReverseFind( _T( '\\' ) ); if ( nPos >= 2 ) { // OK, we've found the backsplash, do the split strDir = strTmp.Left( nPos + 1 ); strName = strTmp.Right( strTmp.GetLength() - nPos - 1 ); } else { // Only a filename, just assign the string to the filename and clear the directory strDir = _T( "" ); strName = strTmp; } strDir.TrimLeft(); strDir.TrimRight(); // remove spaces before the directory separator and double backslashes INT nIndex = 0; while ( nIndex < strDir.GetLength() ) { if ( _T( '\\' ) == strDir[ nIndex ] ) { if ( nIndex > 0 ) { if ( ( _T( '\\' ) == strDir[ nIndex - 1 ] ) || ( _T( ' ' ) == strDir[ nIndex - 1 ] )) { strDir = strDir.Left( nIndex ) + strDir.Mid( nIndex + 1 ); nIndex = 0; continue; } } } if ( _T( ' ' ) == strDir[ nIndex ] ) { if ( nIndex > 0 ) { if ( ( _T( '\\' ) == strDir[ nIndex - 1 ] ) ) { strDir = strDir.Left( nIndex ) + strDir.Mid( nIndex + 1 ); nIndex = 0; continue; } } } nIndex++; } strDir.TrimLeft(); strDir.TrimRight(); strName.TrimLeft(); strName.TrimRight(); }
BOOL ISndStreamWinAmp::OpenStream( const CUString& strFileName ) { DWORD i = 0; BOOL bFound = FALSE; LTRACE2( _T( "ISndStreamWinAmp::OpenStream( %s )" ), strFileName ); int nPos = 0; CUString strExt( _T( "wav" ) ); g_bFinished = FALSE; g_bInitialized = FALSE; g_bOutOpened = FALSE; g_eFinished.ResetEvent(); FlushFIFO( ); nPos = strFileName.ReverseFind('.'); if ( nPos >= 0 ) { strExt = strFileName.Right( strFileName.GetLength() - nPos - 1 ); strExt.MakeLower(); } // Set the buffer size SetBufferSize( 9000 ); SetFileName( strFileName ); int nRet = 0; // loop through the available plugings for ( i=0; i < gs_vWinAmpProps.size(); i++ ) { m_WinAmpProp = gs_vWinAmpProps[i]; // m_WinAmpProp.pModule->Init( ); // check if the module can handle the file format if ( ( nRet = m_WinAmpProp.pModule->IsOurFile( (LPSTR)GetDosFileName( strFileName ) ) ) ) { bFound = TRUE; break; } /* if ( ( 0 == strExt.CompareNoCase( _T( "flac" ) ) ) && ( 0 == strExt.CompareNoCase( m_WinAmpProp.strExt ) ) ) { bFound = TRUE; break; } */ CUString strPluginExt( m_WinAmpProp.pModule->FileExtensions, CP_UTF8 ); strPluginExt.MakeLower(); // check first on extention if ( strPluginExt.Find( strExt ) >=0 ) { bFound = TRUE; break; } // m_WinAmpProp.pModule->Quit( ); } if ( !bFound ) { LTRACE2( _T( "ISndStreamWinAmp::OpenStream Failed, no proper plugin found!" ) ); return FALSE; } if ( 0 == m_WinAmpProp.pModule->UsesOutputPlug ) { LTRACE2( _T( "ISndStreamWinAmp::OpenStream; Failed, does not use Output Plugin " ) ); return FALSE; } LTRACE2( _T( "ISndStreamWinAmp::OpenStream found proper plugin ( %s )" ) , m_WinAmpProp.pModule->description ); // setup proper function calls m_WinAmpProp.pModule->SetInfo = SetInfo; m_WinAmpProp.pModule->SAAddPCMData = SAAddPCMData; m_WinAmpProp.pModule->SAGetMode = SAGetMode; m_WinAmpProp.pModule->SAAdd = SAAdd; m_WinAmpProp.pModule->VSAAddPCMData = VSAAddPCMData; m_WinAmpProp.pModule->VSAGetMode = VSAGetMode; m_WinAmpProp.pModule->VSAAdd = VSAAdd; m_WinAmpProp.pModule->VSASetInfo = VSASetInfo; m_WinAmpProp.pModule->dsp_isactive = dsp_isactive; m_WinAmpProp.pModule->dsp_dosamples = dsp_dosamples; m_WinAmpProp.pModule->EQSet = EQSet; m_WinAmpProp.pModule->SAVSADeInit = WMIN_SAVSADeInit; m_WinAmpProp.pModule->SAVSAInit = WMIN_SAVSAInit; m_WinAmpProp.pModule->outMod = &g_OutModule; g_OutModule.version = OUT_VER; g_OutModule.description = g_lpszOutModuleName; g_OutModule.id = 33; g_OutModule.Config = OutConfig; g_OutModule.About = OutAbout; g_OutModule.Init = OutInit; g_OutModule.Quit = OutQuit; g_OutModule.Open = OutOpen; g_OutModule.Close = OutClose; g_OutModule.Write = OutWrite; g_OutModule.CanWrite = OutCanWrite; g_OutModule.IsPlaying = OutIsPlaying; g_OutModule.Pause = OutPause; g_OutModule.SetVolume = OutSetVolume; g_OutModule.SetPan = OutSetPan; g_OutModule.Flush = OutFlush; g_OutModule.GetOutputTime = OutGetOutputTime; g_OutModule.GetWrittenTime = OutGetWrittenTime; SetChannels( 2 ); SetSampleRate( 44100 ); SetBitRate( 176000 * 8 ); // m_dwSamples=wfInfo.samples; m_dwTotalFileSize = 1000; m_dwCurrentFilePos = 0; // start the decoding thread if ( 0 != m_WinAmpProp.pModule->Play( (LPSTR)GetDosFileName( strFileName ) ) ) { return FALSE; } // Wait till output device has been opened by the // input plugin while ( FALSE == g_bOutOpened ) { ::Sleep( 5 ); } SetChannels( g_nNumChannels ); SetSampleRate( g_nOutSampleRate ); SetBitRate( g_nBitRate ); g_bInitialized = TRUE; // return Success return TRUE; }
HRESULT CSwatchesList::OnDraw(ATL_DRAWINFO& di) { RECT& rc = *(RECT*)di.prcBounds; HDC hDC = di.hdcDraw; if (m_swatches) { Draw3DRect(hDC, m_areaRect.left-1, m_areaRect.top-1, m_areaRect.Width()+2, m_areaRect.Height()+2, RGB(0,0,0), RGB(0,0,0)); long scrollposY; m_vert->get_pos(&scrollposY); if (IntersectClipRect(hDC, m_areaRect.left, m_areaRect.top, m_areaRect.right, m_areaRect.bottom)) { POINT oldOrg; SetViewportOrgEx(hDC, m_areaRect.left, m_areaRect.top - scrollposY, &oldOrg); // For CMYK conversion /* TCHAR colorDirectory[MAX_PATH]; DWORD cbSize = sizeof(colorDirectory); GetColorDirectory(NULL, colorDirectory, &cbSize); HPROFILE hDestProfile = NULL; { TCHAR profilePath[MAX_PATH]; _makepath(profilePath, NULL, colorDirectory, "sRGB Color Space Profile.ICM", NULL); PROFILE profile = {0}; profile.dwType = PROFILE_FILENAME; profile.pProfileData = profilePath; profile.cbDataSize = (_tcslen(profilePath)+1)*sizeof(TCHAR); hDestProfile = OpenColorProfile(&profile, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING); ATLASSERT(hDestProfile); } HPROFILE hTargetProfile = NULL; { TCHAR profilePath[MAX_PATH]; _makepath(profilePath, NULL, colorDirectory, targetProfile, NULL); PROFILE profile = {0}; profile.dwType = PROFILE_FILENAME; profile.pProfileData = profilePath; profile.cbDataSize = (_tcslen(profilePath)+1)*sizeof(TCHAR); hTargetProfile = OpenColorProfile(&profile, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING); ATLASSERT(hTargetProfile); } LOGCOLORSPACE lcp = {0}; lcp.lcsSignature = LCS_SIGNATURE; lcp.lcsVersion = 0x400; lcp.lcsSize = sizeof(lcp); lcp.lcsCSType = LCS_sRGB; lcp.lcsFilename;// = NULL; // ?? HTRANSFORM hTransform = CreateColorTransform(&lcp, hDestProfile, hTargetProfile, BEST_MODE); ATLASSERT(hTransform); */ // Pattern for drawing ColorType symbols WORD bmdata[8] = { 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, }; HBITMAP hPatBitmap = CreateBitmap(8, 8, 1, 1, bmdata); ATLASSERT(hPatBitmap); HBRUSH hPatBrush = CreatePatternBrush(hPatBitmap); ATLASSERT(hPatBrush); DeleteObject(hPatBitmap); // HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); LOGFONT lf; GetObject(hFont, sizeof(lf), &lf); lf.lfWeight = FW_BOLD; HFONT hFontSelected = CreateFontIndirect(&lf); HFONT hOldFont = (HFONT)GetCurrentObject(hDC, OBJ_FONT); long nswatches; m_swatches->get_length(&nswatches); int y = 0; for (int i = 0; i < nswatches; i++) { CComPtr<IPDSwatch> swatch; m_swatches->item(i, &swatch); //Rectangle(hDC, itemrect.left, itemrect.top, itemrect.right+1, itemrect.bottom+1); MoveToEx(hDC, 0, y+m_itemHeight, NULL); LineTo(hDC, m_areaRect.Width()+1, y+m_itemHeight); CRect itemrect(0, y+1, m_areaRect.Width(), y+m_itemHeight-1); // itemrect.top += 1; // itemrect.bottom -= 1; bool bSelected = IsSwatchSelected(swatch); if (bSelected) FillSolidRect(hDC, itemrect.left, itemrect.top+1, itemrect.Width(), itemrect.Height()-1, (bSelected)? GetSysColor(COLOR_HIGHLIGHT): GetSysColor(COLOR_WINDOW)); int swatchSize = m_itemHeight-4; int swatchTop = (m_itemHeight-swatchSize)/2; // CRect swatchRect(itemrect.left + 4, itemrect.top+itemrect.Height()/2-8, itemrect.left + 4 + 16, itemrect.top+itemrect.Height()/2-8+16); CRect swatchRect(itemrect.left + 4, itemrect.top+swatchTop, itemrect.left + 4 + swatchSize, itemrect.top+swatchTop+swatchSize); if (bSelected) { SelectObject(hDC, hFontSelected); SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHTTEXT)); } else { SelectObject(hDC, hFont); SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT)); } SetBkMode(hDC, TRANSPARENT); BSTR bname; swatch->get_name(&bname); _bstr_t name = _bstr_t(bname, false); PDSwatchType swatchType; swatch->get_swatchType(&swatchType); CRect trect = itemrect; trect.left = swatchRect.right + 4; trect.right -= 30; if (swatchType == SWATCH_NONE) { FillSolidRect(hDC, &swatchRect, RGB(255, 255, 255)); HPEN hPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0)); HPEN hOldPen = (HPEN)SelectObject(hDC, hPen); MoveToEx(hDC, swatchRect.left+1, swatchRect.bottom-1, NULL); LineTo(hDC, swatchRect.right-1, swatchRect.top+1); SelectObject(hDC, hOldPen); DeleteObject(hPen); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, GetStockObject(NULL_BRUSH)); Rectangle(hDC, swatchRect.left, swatchRect.top, swatchRect.right, swatchRect.bottom); SelectObject(hDC, hOldBrush); } else if (swatchType == SWATCH_COLOR || swatchType == SWATCH_TINT) { CComPtr<IPDColor> color; CComQIPtr<IPDSwatchColor> swatchColor; if (swatchType == SWATCH_COLOR) { swatchColor = swatch; swatchColor->get_color(&color); } else { CComQIPtr<IPDSwatchTint> swatchTint = swatch; swatchTint->get_swatchColor(&swatchColor); swatchTint->get_finalColor(&color); CRect trect2 = trect; trect.right -= 28; trect2.left = trect.right; double tint; swatchTint->get_tint(&tint); CUString str; str.Format("%d %%", (int)(tint*100)); DrawText(hDC, str, str.GetLength(), &trect2, DT_SINGLELINE | DT_VCENTER); } PDColorMode colorMode; color->get_colorMode(&colorMode); COLORREF clr; if (colorMode == COLORMODE_RGB) { double red; color->getChannel(0, &red); double green; color->getChannel(1, &green); double blue; color->getChannel(2, &blue); clr = RGB(red, green, blue); } else if (colorMode == COLORMODE_CMYK) { /* if (hTransform) { double cyan; color->getChannel(0, &cyan); double magenta; color->getChannel(1, &magenta); double yellow; color->getChannel(2, &yellow); double black; color->getChannel(3, &black); COLOR incolor; incolor.cmyk.cyan = cyan*65535/255; incolor.cmyk.magenta = magenta*65535/255; incolor.cmyk.yellow = yellow*65535/255; incolor.cmyk.black = black*65535/255; COLOR outcolor; BOOL bSuccess = TranslateColors(hTransform, &incolor, 1, COLOR_CMYK, &outcolor, COLOR_RGB); ATLASSERT(bSuccess); clr = RGB( outcolor.rgb.red*255.0/65535, outcolor.rgb.green*255.0/65535, outcolor.rgb.blue*255.0/65535); } else */ clr = -1; } if (clr != -1) { HBRUSH hBrush = CreateSolidBrush(clr); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush); Rectangle(hDC, swatchRect.left, swatchRect.top, swatchRect.right, swatchRect.bottom); SelectObject(hDC, hOldBrush); DeleteObject(hBrush); } { CRect rc(itemrect.right-15, itemrect.top+4, itemrect.right-15+10, itemrect.top+4+10); if (colorMode == COLORMODE_RGB) { Rectangle(hDC, rc.left, rc.top-1, rc.right+1, rc.bottom+1); FillSolidRect(hDC, rc.left+1, rc.top, 3, rc.Height(), RGB(255, 0, 0)); FillSolidRect(hDC, rc.left+4, rc.top, 3, rc.Height(), RGB(0, 255, 0)); FillSolidRect(hDC, rc.left+7, rc.top, 3, rc.Height(), RGB(0, 0, 255)); } else if (colorMode == COLORMODE_CMYK) { // { HBRUSH hBrush = CreateSolidBrush(RGB(255, 0, 255)); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush); POINT pts[3] = { rc.left, rc.top, rc.left+rc.Width(), rc.top, rc.left+rc.Width()/2, rc.top+rc.Height()/2, }; Polygon(hDC, pts, 3); SelectObject(hDC, hOldBrush); DeleteObject(hBrush); } // { HBRUSH hBrush = CreateSolidBrush(RGB(255, 255, 0)); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush); POINT pts[3] = { rc.right, rc.top, rc.right, rc.top+rc.Height(), rc.right-rc.Width()/2, rc.top+rc.Height()/2, }; Polygon(hDC, pts, 3); SelectObject(hDC, hOldBrush); DeleteObject(hBrush); } // { HBRUSH hBrush = CreateSolidBrush(RGB(0, 0, 0)); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush); POINT pts[3] = { rc.left, rc.bottom, rc.left+rc.Width(), rc.bottom, rc.left+rc.Width()/2, rc.bottom-rc.Height()/2, }; Polygon(hDC, pts, 3); SelectObject(hDC, hOldBrush); DeleteObject(hBrush); } // { HBRUSH hBrush = CreateSolidBrush(RGB(0, 255, 255)); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush); POINT pts[3] = { rc.left, rc.top, rc.left, rc.top+rc.Height(), rc.left+rc.Width()/2, rc.top+rc.Height()/2, }; Polygon(hDC, pts, 3); SelectObject(hDC, hOldBrush); DeleteObject(hBrush); } } } { CRect rc(m_areaRect.right-28, y+4, m_areaRect.right-28+10, y+4+10); PDColorType colorType; swatchColor->get_colorType(&colorType); int oldBkMode = SetBkMode(hDC, OPAQUE); COLORREF oldTextClr = SetTextColor(hDC, RGB(100,100,100)); COLORREF oldBkClr = SetBkColor(hDC, RGB(255,255,255)); if (colorType == COLORTYPE_PROCESS) { HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hPatBrush); Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); SelectObject(hDC, hOldBrush); } else if (colorType == COLORTYPE_SPOT) { Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); HPEN hPen = CreatePen(PS_SOLID, 1, RGB(120, 120, 120)); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hPatBrush); HPEN hOldPen = (HPEN)SelectObject(hDC, hPen); Ellipse(hDC, rc.left+2, rc.top+2, rc.right-2, rc.bottom-2); SelectObject(hDC, hOldBrush); SelectObject(hDC, hOldPen); DeleteObject(hPen); } else ATLASSERT(0); SetBkMode(hDC, oldBkMode); SetTextColor(hDC, oldTextClr); SetBkColor(hDC, oldBkClr); } } else if (swatchType == SWATCH_GRADIENT) { Gdiplus::Graphics graphics(hDC); CComQIPtr<IPDSwatchGradient> swatchGradient = swatch; CComPtr<IPDGradient> gradient; swatchGradient->get_gradient(&gradient); PDGradientType gradientType; gradient->get_type(&gradientType); Gdiplus::Rect rc(swatchRect.left, swatchRect.top, swatchRect.Width(), swatchRect.Height()); CArray<Gdiplus::REAL, Gdiplus::REAL> offsets; CArray<Gdiplus::Color,Gdiplus::Color&> colors; CreateGradient(offsets, colors, gradient); if (gradientType == GRADIENT_LINEAR) { Gdiplus::LinearGradientBrush brush(rc, Gdiplus::Color(0,0,0), Gdiplus::Color(0,0,0), Gdiplus::LinearGradientModeHorizontal); brush.SetInterpolationColors(colors.GetData(), offsets.GetData(), colors.GetSize()); graphics.FillRectangle(&brush, rc); } else if (gradientType == GRADIENT_RADIAL) { Gdiplus::GraphicsPath path; path.AddEllipse(rc); Gdiplus::PathGradientBrush brush(&path); brush.SetInterpolationColors(colors.GetData(), offsets.GetData(), colors.GetSize()); graphics.FillRectangle(&brush, rc); } else ATLASSERT(0); } else if (swatchType == SWATCH_PATTERN) { Gdiplus::Graphics graphics(hDC); CComQIPtr<IPDSwatchPattern> swatchPattern = swatch; CComPtr<IPDObjectGroup> objectGroup; swatchPattern->get_objectGroup(&objectGroup); RectD bbox; objectGroup->getExpandedBBox(&bbox); int width = swatchRect.Width(); int height = (bbox.Height * width/bbox.Width);//+0.5; if (height > swatchRect.Height()) { height = swatchRect.Height(); width = (bbox.Width * height/bbox.Height);//+0.5; } ATLASSERT(width <= bbox.Width); double magnify = width/bbox.Width; int left = (swatchRect.Width()-width)/2; int top = (swatchRect.Height()-height)/2; CComPtr<IPDRenderer> renderer; renderer.CoCreateInstance(CLSID_PDRenderer); if (renderer) { Gdiplus::Bitmap bitmap(width, height); { Gdiplus::Graphics bmgraphics(&bitmap); bmgraphics.FillRectangle(&Gdiplus::SolidBrush(Gdiplus::Color(255, 255, 255)), 0, 0, width, height); // Gdiplus::Graphics& bmgraphics = graphics; // CComQIPtr<IPDObjectTransformable> transformable = objectGroup; // RectD bounds; // transformable->get_bounds(&bounds); // bmgraphics.TranslateTransform(swatchRect.left+left, swatchRect.top+top); bmgraphics.ScaleTransform(magnify, magnify); bmgraphics.TranslateTransform(-bbox.X, -bbox.Y); // bmgraphics.TranslateTransform(-bounds.X, -bounds.Y); renderer->put_magnify(magnify); renderer->put_targetHDC((HDC)&bmgraphics); renderer->RenderObject(objectGroup); } graphics.DrawImage(&bitmap, swatchRect.left+left, swatchRect.top+top); } } DrawText(hDC, name, name.length(), &trect, DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS); y += m_itemHeight; } SelectObject(hDC, hOldFont); DeleteObject(hFontSelected); DeleteObject(hPatBrush); /* if (hTransform) DeleteColorTransform(hTransform); if (hDestProfile) CloseColorProfile(hDestProfile); */ SetViewportOrgEx(hDC, oldOrg.x, oldOrg.y, NULL); } } return S_OK; }