Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

DlgLanguage.cpp

Go to the documentation of this file.
00001 //
00002 // DlgLanguage.cpp
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "CoolInterface.h"
00026 #include "DlgLanguage.h"
00027 #include "XML.h"
00028 #include "SkinWindow.h"
00029 
00030 #ifdef _DEBUG
00031 #define new DEBUG_NEW
00032 #undef THIS_FILE
00033 static char THIS_FILE[] = __FILE__;
00034 #endif
00035 
00036 BEGIN_MESSAGE_MAP(CLanguageDlg, CSkinDialog)
00037         //{{AFX_MSG_MAP(CLanguageDlg)
00038         ON_WM_ERASEBKGND()
00039         ON_WM_PAINT()
00040         ON_WM_VSCROLL()
00041         ON_WM_MOUSEWHEEL()
00042         ON_WM_MOUSEMOVE()
00043         ON_WM_LBUTTONDOWN()
00044         ON_WM_LBUTTONUP()
00045         ON_WM_TIMER()
00046         ON_WM_KEYDOWN()
00047         ON_WM_SETCURSOR()
00048         ON_WM_DESTROY()
00049         ON_WM_CLOSE()
00050         ON_WM_CREATE()
00051         //}}AFX_MSG_MAP
00052 END_MESSAGE_MAP()
00053 
00054 #define HEADING_HEIGHT  50
00055 #define ITEM_HEIGHT             40
00056 #define TEXT_MARGIN             0
00057 
00058 
00060 // CLanguageDlg dialog
00061 
00062 CLanguageDlg::CLanguageDlg(CWnd* pParent) : CSkinDialog(CLanguageDlg::IDD, pParent)
00063 {
00064         //{{AFX_DATA_INIT(CLanguageDlg)
00065         //}}AFX_DATA_INIT
00066 }
00067 
00068 void CLanguageDlg::DoDataExchange(CDataExchange* pDX)
00069 {
00070         CSkinDialog::DoDataExchange(pDX);
00071         //{{AFX_DATA_MAP(CLanguageDlg)
00072         //}}AFX_DATA_MAP
00073 }
00074 
00076 // CLanguageDlg message handlers
00077 
00078 BOOL CLanguageDlg::OnInitDialog() 
00079 {
00080         CSkinDialog::OnInitDialog();
00081 
00082         CWaitCursor pCursor;
00083 
00084         //SkinMe( _T("CLanguageDlg"), ID_TOOLS_LANGUAGE );
00085 
00086         m_hArrow        = theApp.LoadStandardCursor( IDC_ARROW );
00087         m_hHand         = theApp.LoadCursor( IDC_HAND );
00088 
00089         m_bmHeader.LoadBitmap( IDB_WIZARD );
00090 
00091         m_fntNormal.CreateFont( -(theApp.m_nDefaultFontSize + 1), 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
00092                 DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
00093                 DEFAULT_PITCH|FF_DONTCARE, theApp.m_sDefaultFont );
00094 
00095         m_fntBold.CreateFont( -(theApp.m_nDefaultFontSize + 5), 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE,
00096                 DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
00097                 DEFAULT_PITCH|FF_DONTCARE, theApp.m_sDefaultFont );
00098 
00099         m_fntSmall.CreateFont( -(theApp.m_nDefaultFontSize - 1), 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
00100                 DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
00101                 DEFAULT_PITCH|FF_DONTCARE, theApp.m_sDefaultFont );
00102 
00103         m_pImages.Create( 32, 32, ILC_COLOR16|ILC_MASK, 1, 1 );
00104 
00105         AddEnglishDefault();
00106         Enumerate();
00107 
00108         m_nHover        = 0;
00109         m_nDown         = 0;
00110         m_bKeyMode      = FALSE;
00111 
00112         CRect rc( 0, 0, 438, HEADING_HEIGHT );
00113 
00114         int nLanguagesToDisplay;
00115 
00116         if( GetSystemMetrics( SM_CYSCREEN ) < 768 )
00117                 nLanguagesToDisplay = min(m_pPaths.GetSize(), 10);
00118         else
00119                 nLanguagesToDisplay = min(m_pPaths.GetSize(), 14);
00120 
00121         rc.bottom += ( nLanguagesToDisplay ) * ITEM_HEIGHT;
00122 
00123         SCROLLINFO pScroll;
00124         ZeroMemory( &pScroll, sizeof(pScroll) );
00125         pScroll.cbSize  = sizeof(pScroll);
00126         pScroll.fMask   = SIF_RANGE|SIF_PAGE|SIF_DISABLENOSCROLL;
00127         pScroll.nMin    = 0;
00128         pScroll.nMax    = m_pPaths.GetSize(); 
00129         pScroll.nPage   = nLanguagesToDisplay + 1;
00130         SetScrollInfo( SB_VERT, &pScroll, TRUE );
00131 
00132         //if ( m_pSkin )
00133         //      m_pSkin->CalcWindowRect( &rc );
00134         //else
00135                 CalcWindowRect( &rc, adjustBorder );
00136 
00137         rc.OffsetRect(  GetSystemMetrics( SM_CXSCREEN ) / 2 -  rc.Width() / 2 - rc.left,
00138                                         GetSystemMetrics( SM_CYSCREEN ) / 2 - rc.Height() / 2 - rc.top );
00139         
00140         SetWindowPos( NULL, rc.left, rc.top, rc.Width(), rc.Height() , 0 );
00141 
00142         SetTimer( 1, 100, NULL );
00143         
00144         return TRUE;
00145 }
00146 
00147 void CLanguageDlg::OnDestroy() 
00148 {
00149         KillTimer( 1 );
00150         CSkinDialog::OnDestroy();
00151 }
00152 
00153 BOOL CLanguageDlg::OnEraseBkgnd(CDC* pDC) 
00154 {
00155         return TRUE;
00156 }
00157 
00158 void CLanguageDlg::OnPaint() 
00159 {
00160         CPaintDC dc( this );
00161         CRect rc;
00162         int nScroll = GetScrollPos( SB_VERT );
00163 
00164         GetClientRect( &rc );
00165 
00166         CDC mdc;
00167         mdc.CreateCompatibleDC( &dc );
00168         CBitmap* pOldBmp = (CBitmap*)mdc.SelectObject( &m_bmHeader );
00169         dc.BitBlt( 0, 0, rc.Width(), HEADING_HEIGHT, &mdc, 0, 0, SRCCOPY );
00170         mdc.SelectObject( pOldBmp );
00171         mdc.DeleteDC();
00172 
00173         rc.top += HEADING_HEIGHT;
00174         
00175         CFont* pOldFont = (CFont*)dc.SelectObject( &m_fntNormal );
00176 
00177         for ( int nCount = 0 ; nCount < m_pPaths.GetSize() ; nCount++ )
00178         {
00179                 if ( nScroll > 0 )
00180                 {
00181                         nScroll --;
00182                 }
00183                 else
00184                 {
00185                         PaintItem( nCount, &dc, &rc );
00186                         rc.OffsetRect( 0, rc.Height() );
00187                 }
00188         }
00189 
00190         dc.SelectObject( pOldFont );
00191 }
00192 
00193 void CLanguageDlg::PaintItem(int nItem, CDC* pDC, CRect* pRect)
00194 {
00195         pRect->bottom = pRect->top + ITEM_HEIGHT;
00196 
00197         BOOL bHover     = m_nHover == ( nItem + 1 );
00198         BOOL bDown      = m_nDown  == ( nItem + 1 );
00199 
00200         CRect rc( pRect );
00201 
00202         pDC->Draw3dRect( &rc, CoolInterface.m_crBackNormal, CoolInterface.m_crBackNormal );
00203         rc.DeflateRect( 1, 1 );
00204 
00205         COLORREF crBack;
00206 
00207         if ( bHover || bDown )
00208         {
00209                 pDC->Draw3dRect( &rc, CoolInterface.m_crBorder, CoolInterface.m_crBorder );
00210                 pDC->SetBkColor( crBack = ( bDown && bHover ? CoolInterface.m_crBackCheckSel : CoolInterface.m_crBackSel ) );
00211         }
00212         else
00213         {
00214                 pDC->Draw3dRect( &rc, CoolInterface.m_crBackNormal, CoolInterface.m_crBackNormal );
00215                 pDC->SetBkColor( crBack = CoolInterface.m_crBackNormal );
00216         }
00217 
00218         rc.DeflateRect( 1, 1 );
00219         
00220         CPoint ptIcon( rc.left + 4, ( rc.top + rc.bottom ) / 2 - 16 );
00221 
00222         if ( bHover != bDown )
00223         {
00224                 pDC->FillSolidRect( ptIcon.x - 1, ptIcon.y - 1, 34, 2, crBack );
00225                 pDC->FillSolidRect( ptIcon.x - 1, ptIcon.y + 1, 2, 32, crBack );
00226 
00227                 ptIcon.Offset( 1, 1 );
00228 
00229                 pDC->SetTextColor( CoolInterface.m_crShadow );
00230                 ImageList_DrawEx( m_pImages.GetSafeHandle(), nItem,
00231                         pDC->GetSafeHdc(), ptIcon.x, ptIcon.y, 32, 32, crBack, CLR_NONE,
00232                         ILD_MASK );
00233 
00234                 ptIcon.Offset( -2, -2 );
00235 
00236                 ImageList_DrawEx( m_pImages.GetSafeHandle(), nItem,
00237                         pDC->GetSafeHdc(), ptIcon.x, ptIcon.y, 32, 32, CLR_NONE, CLR_NONE,
00238                         ILD_NORMAL );
00239 
00240                 pDC->ExcludeClipRect( ptIcon.x, ptIcon.y, ptIcon.x + 34, ptIcon.y + 34 );
00241         }
00242         else
00243         {
00244                 ImageList_DrawEx( m_pImages.GetSafeHandle(), nItem,
00245                         pDC->GetSafeHdc(), ptIcon.x, ptIcon.y, 32, 32, crBack, CLR_NONE,
00246                         ILD_NORMAL );
00247 
00248                 pDC->ExcludeClipRect( ptIcon.x, ptIcon.y, ptIcon.x + 32, ptIcon.y + 32 );
00249         }
00250 
00251         CRect rcText(   rc.left + 46, rc.top + TEXT_MARGIN,
00252                                         rc.right - TEXT_MARGIN, rc.top + 20 + TEXT_MARGIN );
00253 
00254         pDC->SetTextColor( bHover || bDown ? CoolInterface.m_crCmdTextSel : CoolInterface.m_crCmdText );
00255         pDC->SelectObject( &m_fntBold );
00256         pDC->ExtTextOut( rcText.left + 1, rcText.top + 1, ETO_CLIPPED|ETO_OPAQUE, &rcText,
00257                 m_pTitles.GetAt( nItem ), NULL );
00258         pDC->ExcludeClipRect( &rcText );
00259 
00260         rcText.left += 2;
00261         rcText.top = rcText.bottom;
00262         rcText.bottom = rc.bottom - TEXT_MARGIN;
00263 
00264         pDC->SelectObject( &m_fntSmall );
00265         DrawWrappedText( pDC, &rcText, m_pPrompts.GetAt( nItem ) );
00266 
00267         pDC->FillSolidRect( &rc, crBack );
00268 }
00269 
00270 void CLanguageDlg::DrawWrappedText(CDC* pDC, CRect* pBox, LPCTSTR pszText)
00271 {
00272         CPoint pt = pBox->TopLeft();
00273 
00274         LPCTSTR pszWord = pszText;
00275         LPCTSTR pszScan = pszText;
00276 
00277         for ( ; ; pszScan++ )
00278         {
00279                 if ( *pszScan != NULL && (unsigned short)*pszScan > 32 ) continue;
00280                 
00281                 if ( pszWord < pszScan )
00282                 {
00283                         int nLen = pszScan - pszWord + ( *pszScan ? 1 : 0 );
00284                         CSize sz = pDC->GetTextExtent( pszWord, nLen );
00285 
00286                         if ( pt.x > pBox->left && pt.x + sz.cx > pBox->right )
00287                         {
00288                                 pt.x = pBox->left;
00289                                 pt.y += sz.cy;
00290                         }
00291 
00292                         CRect rc( pt.x, pt.y, pt.x + sz.cx, pt.y + sz.cy );
00293 
00294                         pDC->ExtTextOut( pt.x, pt.y, ETO_CLIPPED|ETO_OPAQUE, &rc,
00295                                 pszWord, nLen, NULL );
00296                         pDC->ExcludeClipRect( &rc );
00297                         
00298                         pt.x += sz.cx;
00299                 }
00300 
00301                 pszWord = pszScan + 1;
00302                 if ( ! *pszScan ) break;
00303         }
00304 }
00305 
00306 
00307 void CLanguageDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
00308 {
00309         SCROLLINFO pInfo;
00310         
00311         pInfo.cbSize    = sizeof(pInfo);
00312         pInfo.fMask             = SIF_ALL & ~SIF_TRACKPOS;
00313         
00314         GetScrollInfo( SB_VERT, &pInfo );
00315         int nDelta = pInfo.nPos;
00316         
00317         switch ( nSBCode )
00318         {
00319         case SB_BOTTOM:
00320                 pInfo.nPos = pInfo.nMax - pInfo.nPage;
00321                 break;
00322         case SB_LINEDOWN:
00323                 pInfo.nPos ++;
00324                 break;
00325         case SB_LINEUP:
00326                 pInfo.nPos --;
00327                 break;
00328         case SB_PAGEDOWN:
00329                 pInfo.nPos += pInfo.nPage;
00330                 break;
00331         case SB_PAGEUP:
00332                 pInfo.nPos -= pInfo.nPage;
00333                 break;
00334         case SB_THUMBPOSITION:
00335         case SB_THUMBTRACK:
00336                 pInfo.nPos = nPos;
00337                 break;
00338         case SB_TOP:
00339                 pInfo.nPos = 0;
00340                 break;
00341         }
00342         
00343         pInfo.nPos = max( 0, min( pInfo.nPos, pInfo.nMax - (int)pInfo.nPage + 1 ) );
00344         if ( pInfo.nPos == nDelta ) return;
00345         
00346         SetScrollInfo( SB_VERT, &pInfo, TRUE );
00347 
00348         m_nHover        = 0;
00349         m_nDown         = 0;
00350         Invalidate();
00351 }
00352 
00353 BOOL CLanguageDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
00354 {
00355         OnVScroll( SB_THUMBPOSITION, (int)( GetScrollPos( SB_VERT ) - zDelta / WHEEL_DELTA ), NULL );
00356         return TRUE;
00357 }
00358 
00359 void CLanguageDlg::OnMouseMove(UINT nFlags, CPoint point) 
00360 {
00361         CRect rc;
00362         int nScroll = GetScrollPos( SB_VERT );
00363 
00364         GetClientRect( &rc );
00365         rc.top += HEADING_HEIGHT;
00366 
00367         if ( rc.PtInRect( point ) )
00368         {
00369                 int nHover = ( point.y - rc.top ) / ITEM_HEIGHT + 1 + nScroll;
00370 
00371                 if ( nHover != m_nHover )
00372                 {
00373                         m_nHover = nHover;
00374                         Invalidate();
00375                 }
00376         }
00377         else if ( m_nHover )
00378         {
00379                 m_nHover = 0;
00380                 Invalidate();
00381         }
00382 
00383         m_bKeyMode = FALSE;
00384         
00385         CSkinDialog::OnMouseMove( nFlags, point );
00386 }
00387 
00388 BOOL CLanguageDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
00389 {
00390         if ( nHitTest == HTCLIENT )
00391         {
00392                 CPoint pt;
00393 
00394                 GetCursorPos( &pt );
00395                 ScreenToClient( &pt );
00396 
00397                 SetCursor( pt.y > HEADING_HEIGHT ? m_hHand : m_hArrow );
00398                 return TRUE;
00399         }
00400         
00401         return CSkinDialog::OnSetCursor( pWnd, nHitTest, message );
00402 }
00403 
00404 void CLanguageDlg::OnLButtonDown(UINT nFlags, CPoint point) 
00405 {
00406         m_nDown = m_nHover;
00407         SetCapture();
00408         Invalidate();
00409 }
00410 
00411 void CLanguageDlg::OnLButtonUp(UINT nFlags, CPoint point) 
00412 {
00413         int nSelected = m_nDown && ( m_nDown == m_nHover ) ? m_nDown : 0;
00414 
00415         m_nDown = m_nHover = 0;
00416 
00417         ReleaseCapture();
00418         Invalidate();
00419         UpdateWindow();
00420 
00421         if ( nSelected ) Execute( nSelected );
00422 }
00423 
00424 void CLanguageDlg::OnTimer(UINT nIDEvent) 
00425 {
00426         if ( ! m_nHover || m_bKeyMode ) return;
00427 
00428         CPoint pt;
00429         CRect rc;
00430 
00431         GetClientRect( &rc );
00432         GetCursorPos( &pt );
00433         ScreenToClient( &pt );
00434 
00435         if ( ! rc.PtInRect( pt ) )
00436         {
00437                 m_nHover = 0;
00438                 Invalidate();
00439         }
00440 }
00441 
00442 BOOL CLanguageDlg::PreTranslateMessage(MSG* pMsg) 
00443 {
00444         if ( pMsg->message == WM_KEYDOWN )
00445         {
00446                 OnKeyDown( pMsg->wParam, LOWORD( pMsg->lParam ), HIWORD( pMsg->lParam ) );
00447                 return TRUE;
00448         }
00449         
00450         return CSkinDialog::PreTranslateMessage( pMsg );
00451 }
00452 
00453 void CLanguageDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
00454 {
00455         switch ( nChar )
00456         {
00457         case VK_ESCAPE:
00458                 PostMessage( WM_CLOSE );
00459                 return;
00460         case VK_UP:
00461                 if ( ! m_nDown )
00462                 {
00463                         m_nHover--;
00464                         m_bKeyMode = TRUE;
00465                         if ( m_nHover < 1 ) m_nHover = m_pPaths.GetSize();
00466                         Invalidate();
00467                 }
00468                 return;
00469         case VK_DOWN:
00470                 if ( ! m_nDown )
00471                 {
00472                         m_nHover++;
00473                         m_bKeyMode = TRUE;
00474                         if ( m_nHover > m_pPaths.GetSize() ) m_nHover = 1;
00475                         Invalidate();
00476                 }
00477                 return;
00478         case VK_RETURN:
00479                 if ( m_nHover && ! m_nDown ) Execute( m_nHover );
00480                 return;
00481         }
00482         
00483         CSkinDialog::OnKeyDown( nChar, nRepCnt, nFlags );
00484 }
00485 
00486 void CLanguageDlg::AddEnglishDefault()
00487 {
00488         m_pPaths.Add( _T("") );
00489         m_pTitles.Add( _T("English (Default)") );
00490         m_pPrompts.Add( _T("Click here to select English as your natural language.") );
00491         m_pImages.Add( theApp.LoadIcon( IDI_FLAG_ENGLISH ) );
00492 }
00493 
00494 void CLanguageDlg::Enumerate(LPCTSTR pszPath)
00495 {
00496         WIN32_FIND_DATA pFind;
00497         CString strPath;
00498         HANDLE hSearch;
00499 
00500         strPath.Format( _T("%s\\Skins\\%s*.*"),
00501                 (LPCTSTR)Settings.General.Path, pszPath ? pszPath : _T("") );
00502 
00503         hSearch = FindFirstFile( strPath, &pFind );
00504 
00505         if ( hSearch != INVALID_HANDLE_VALUE )
00506         {
00507                 do
00508                 {
00509                         if ( pFind.cFileName[0] == '.' ) continue;
00510 
00511                         if ( pFind.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
00512                         {
00513                                 strPath.Format( _T("%s%s\\"),
00514                                         pszPath ? pszPath : _T(""), pFind.cFileName );
00515                                 
00516                                 Enumerate( strPath );
00517                         }
00518                         else if (       _tcsistr( pFind.cFileName, _T(".xml") ) != NULL &&
00519                                                 _tcsicmp( pFind.cFileName, _T("Definitions.xml") ) &&
00520                                                 _tcsicmp( pFind.cFileName, _T("Default-en.xml") ) )
00521                         {
00522                                 AddSkin( pszPath, pFind.cFileName );
00523                         }
00524                 }
00525                 while ( FindNextFile( hSearch, &pFind ) );
00526 
00527                 FindClose( hSearch );
00528         }
00529 }
00530 
00531 BOOL CLanguageDlg::AddSkin(LPCTSTR pszPath, LPCTSTR pszName)
00532 {
00533         CString strXML;
00534         CFile pFile;
00535         
00536         strXML = Settings.General.Path + _T("\\Skins\\");
00537         if ( pszPath != NULL ) strXML += pszPath;
00538         strXML += pszName;
00539 
00540     if ( ! pFile.Open( strXML, CFile::modeRead ) ) return FALSE;
00541         
00542         DWORD nSource = (DWORD)pFile.GetLength();
00543         if ( nSource > 4096*1024 ) return FALSE;
00544         
00545         CHAR* pSource = new CHAR[ nSource ];
00546         pFile.Read( pSource, nSource );
00547         pFile.Close();
00548         
00549         BYTE* pByte = (BYTE*)pSource;
00550         DWORD nByte = nSource;
00551         
00552         if ( nByte >= 2 && ( ( pByte[0] == 0xFE && pByte[1] == 0xFF ) || ( pByte[0] == 0xFF && pByte[1] == 0xFE ) ) )
00553         {
00554                 nByte = nByte / 2 - 1;
00555                 
00556                 if ( pByte[0] == 0xFE && pByte[1] == 0xFF )
00557                 {
00558                         pByte += 2;
00559                         
00560                         for ( DWORD nSwap = 0 ; nSwap < nByte ; nSwap ++ )
00561                         {
00562                                 register CHAR nTemp = pByte[ ( nSwap << 1 ) + 0 ];
00563                                 pByte[ ( nSwap << 1 ) + 0 ] = pByte[ ( nSwap << 1 ) + 1 ];
00564                                 pByte[ ( nSwap << 1 ) + 1 ] = nTemp;
00565                         }
00566                 }
00567                 else
00568                 {
00569                         pByte += 2; 
00570                 }
00571                 
00572                 CopyMemory( strXML.GetBuffer( nByte ), pByte, nByte * 2 );
00573                 strXML.ReleaseBuffer( nByte );
00574         }
00575         else
00576         {
00577                 if ( nByte >= 3 && pByte[0] == 0xEF && pByte[1] == 0xBB && pByte[2] == 0xBF )
00578                 {
00579                         pByte += 3; nByte -= 3;
00580                 }
00581                 
00582                 DWORD nWide = MultiByteToWideChar( CP_UTF8, 0, (LPCSTR)pByte, nByte, NULL, 0 );
00583                 
00584                 MultiByteToWideChar( CP_UTF8, 0, (LPCSTR)pByte, nByte, strXML.GetBuffer( nWide ), nWide );
00585                 strXML.ReleaseBuffer( nWide );
00586         }
00587         
00588         delete [] pSource;
00589         
00590         CXMLElement* pXML = NULL;
00591         
00592         int nManifest = strXML.Find( _T("<manifest") );
00593         
00594         if ( nManifest > 0 )
00595         {
00596                 CString strManifest = strXML.Mid( nManifest ).SpanExcluding( _T(">") ) + '>';
00597                 
00598                 if ( CXMLElement* pManifest = CXMLElement::FromString( strManifest ) )
00599                 {
00600                         pXML = new CXMLElement( NULL, _T("skin") );
00601                         pXML->AddElement( pManifest );
00602                 }
00603         }
00604         
00605         if ( pXML == NULL )
00606         {
00607                 pXML = CXMLElement::FromString( strXML, TRUE );
00608                 if ( pXML == NULL ) return FALSE;
00609         }
00610         
00611         strXML.Empty();
00612         
00613         CXMLElement* pManifest = pXML->GetElementByName( _T("manifest") );
00614         
00615         if ( ! pXML->IsNamed( _T("skin") ) || pManifest == NULL ||
00616                  pManifest->GetAttributeValue( _T("type") ).CompareNoCase( _T("language") ) )
00617         {
00618                 delete pXML;
00619                 return FALSE;
00620         }
00621         
00622         CString strName         = pManifest->GetAttributeValue( _T("name"), pszName );
00623         CString strPrompt       = pManifest->GetAttributeValue( _T("prompt") );
00624         CString strIcon         = pManifest->GetAttributeValue( _T("icon") );
00625         CString strGUIDir       = pManifest->GetAttributeValue( _T("dir"), _T("ltr") );
00626         CString strLangCode = pManifest->GetAttributeValue( _T("language") );
00627         
00628         delete pXML;
00629         
00630         if ( pszPath != NULL ) strXML += pszPath;
00631         strXML += pszName;
00632         
00633         m_pPaths.Add( strXML );
00634         m_pTitles.Add( strName );
00635         m_pPrompts.Add( strPrompt );
00636         m_pGUIDirs.Add( strGUIDir );
00637         m_pLangCodes.Add ( strLangCode );
00638         
00639         if ( strIcon.GetLength() )
00640         {
00641                 if ( pszPath )
00642                         strIcon = Settings.General.Path + _T("\\Skins\\") + pszPath + strIcon;
00643                 else
00644                         strIcon = Settings.General.Path + _T("\\Skins\\") + strIcon;
00645         }
00646         else
00647         {
00648                 if ( pszPath )
00649                         strIcon = Settings.General.Path + _T("\\Skins\\") + pszPath + strIcon + pszName;
00650                 else
00651                         strIcon = Settings.General.Path + _T("\\Skins\\") + strIcon + pszName;
00652 
00653                 strIcon = strIcon.Left( strIcon.GetLength() - 3 ) + _T("ico");
00654         }
00655 
00656         HICON hIcon;
00657 
00658         if ( ExtractIconEx( strIcon, 0, &hIcon, NULL, 1 ) != NULL && hIcon != NULL )
00659         {
00660                 m_pImages.Add( hIcon );
00661         }
00662         else
00663         {
00664                 hIcon = theApp.LoadIcon( IDR_MAINFRAME );
00665                 m_pImages.Add( hIcon );
00666         }
00667         
00668         return TRUE;
00669 }
00670 
00671 void CLanguageDlg::Execute(int nSelected)
00672 {
00673         BOOL bRTL = ( nSelected > 1 ) ? ( m_pGUIDirs.GetAt( nSelected - 2 ) == "rtl" ) : FALSE;
00674 
00675         if ( bRTL && theApp.m_dwWindowsVersion < 5 )
00676         {
00677                 CString str;
00678                 LoadString( str, IDS_GENERAL_RTL_NOTSUPPORTED );
00679                 AfxMessageBox( str, MB_SYSTEMMODAL|MB_ICONEXCLAMATION|MB_OK );
00680                 return;
00681         }
00682 
00683         for ( int nItem = 0 ; nItem < m_pPaths.GetSize() ; nItem++ )
00684         {
00685                 theApp.WriteProfileInt( _T("Skins"), m_pPaths.GetAt( nItem ),
00686                         ( nSelected - 1 ) == nItem );
00687         }
00688 
00689         CString strLangCode = _T("en");
00690         if ( nSelected > 1 ) strLangCode = m_pLangCodes.GetAt( nSelected - 2 );
00691 
00692         // required to have schemas reloaded after restart
00693         Settings.General.Language = strLangCode;
00694 
00695         if ( theApp.m_bRTL == bRTL ) 
00696         {
00697                 theApp.WriteProfileInt( _T("Settings"), _T("LanguageRTL"), bRTL );
00698                 EndDialog( IDOK );
00699         }
00700         else
00701         {
00702                 CString str;
00703                 LoadString( str, IDS_GENERAL_RTL_WARNING );
00704 
00705                 theApp.WriteProfileInt( _T("Settings"), _T("LanguageRTL"), bRTL );
00706 
00707                 if ( AfxMessageBox( str, MB_SYSTEMMODAL|MB_ICONQUESTION|MB_YESNO ) == IDYES )
00708                 {
00709                         GetParent()->PostMessage( WM_CLOSE, NULL, NULL );
00710                 }
00711                 EndDialog( IDCANCEL );
00712         }
00713 }
00714 
00715 void CLanguageDlg::OnClose() 
00716 {
00717         EndDialog( IDCANCEL );
00718 }
00719 
00720 int CLanguageDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
00721 {
00722         if (CDialog::OnCreate(lpCreateStruct) == -1)
00723                 return -1;
00724 
00725         return 0;
00726 }

Generated on Thu Dec 15 10:39:39 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2