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

DlgFolderProperties.cpp

Go to the documentation of this file.
00001 //
00002 // DlgFolderProperties.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 "Library.h"
00026 #include "LibraryFolders.h"
00027 #include "AlbumFolder.h"
00028 #include "Schema.h"
00029 #include "XML.h"
00030 #include "ShellIcons.h"
00031 #include "CoolInterface.h"
00032 #include "DlgFolderProperties.h"
00033 
00034 #ifdef _DEBUG
00035 #define new DEBUG_NEW
00036 #undef THIS_FILE
00037 static char THIS_FILE[] = __FILE__;
00038 #endif
00039 
00040 IMPLEMENT_DYNAMIC(CFolderPropertiesDlg, CSkinDialog)
00041 
00042 BEGIN_MESSAGE_MAP(CFolderPropertiesDlg, CSkinDialog)
00043         //{{AFX_MSG_MAP(CFolderPropertiesDlg)
00044         ON_WM_DESTROY()
00045         ON_WM_GETMINMAXINFO()
00046         ON_WM_SIZE()
00047         ON_CBN_SELCHANGE(IDC_SCHEMAS, OnSelChangeSchemas)
00048         ON_CBN_CLOSEUP(IDC_SCHEMAS, OnCloseUpSchemas)
00049         ON_WM_PAINT()
00050         ON_EN_CHANGE(IDC_TITLE, OnChangeTitle)
00051         ON_WM_CTLCOLOR()
00052         ON_WM_SETCURSOR()
00053         ON_WM_LBUTTONUP()
00054         ON_EN_CHANGE(IDC_METADATA, OnChangeData)
00055         //}}AFX_MSG_MAP
00056 END_MESSAGE_MAP()
00057 
00058 
00060 // CFolderPropertiesDlg dialog
00061 
00062 CFolderPropertiesDlg::CFolderPropertiesDlg(CWnd* pParent, CAlbumFolder* pFolder) : CSkinDialog( CFolderPropertiesDlg::IDD, pParent )
00063 {
00064         //{{AFX_DATA_INIT(CFolderPropertiesDlg)
00065         //}}AFX_DATA_INIT
00066         m_pFolder       = pFolder;
00067         m_nWidth        = 0;
00068         m_bUpdating     = FALSE;
00069 }
00070 
00071 void CFolderPropertiesDlg::DoDataExchange(CDataExchange* pDX)
00072 {
00073         CSkinDialog::DoDataExchange(pDX);
00074         //{{AFX_DATA_MAP(CFolderPropertiesDlg)
00075         DDX_Control(pDX, IDC_APPLY_METADATA, m_wndApply);
00076         DDX_Control(pDX, IDCANCEL, m_wndCancel);
00077         DDX_Control(pDX, IDOK, m_wndOK);
00078         DDX_Control(pDX, IDC_TITLE, m_wndTitle);
00079         DDX_Control(pDX, IDC_SCHEMAS, m_wndSchemas);
00080         //}}AFX_DATA_MAP
00081 }
00082 
00084 // CFolderPropertiesDlg message handlers
00085 
00086 BOOL CFolderPropertiesDlg::OnInitDialog()
00087 {
00088         CSkinDialog::OnInitDialog();
00089 
00090         SkinMe( _T("CFolderPropertiesDlg"), IDR_LIBRARYFRAME );
00091 
00092         CRect rc;
00093         GetWindowRect( &rc );
00094         m_nWidth = rc.Width();
00095 
00096         m_wndData.Create( WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP, rc, this, IDC_METADATA );
00097 
00098         if ( ! Settings.LoadWindow( _T("CFolderPropertiesDlg"), this ) )
00099         {
00100                 CRect rc;
00101                 GetWindowRect( &rc );
00102                 rc.bottom++;
00103                 MoveWindow( &rc );
00104         }
00105 
00106         CSingleLock pLock( &Library.m_pSection, TRUE );
00107 
00108         if ( LibraryFolders.CheckAlbum( m_pFolder ) )
00109         {
00110                 m_bUpdating = TRUE;
00111                 m_wndTitle.SetWindowText( m_pFolder->m_sName );
00112                 m_wndSchemas.Load( m_pFolder->m_sSchemaURI, CSchema::stFolder );
00113                 if ( m_wndSchemas.GetCurSel() < 0 ) m_wndSchemas.SetCurSel( 0 );
00114 
00115                 OnSelChangeSchemas();
00116 
00117                 if ( m_pFolder->m_pXML ) m_wndData.UpdateData( m_pFolder->m_pXML, FALSE );
00118                 m_bUpdating = FALSE;
00119         }
00120         else
00121         {
00122                 PostMessage( WM_CLOSE );
00123         }
00124 
00125         return TRUE;
00126 }
00127 
00128 void CFolderPropertiesDlg::OnDestroy()
00129 {
00130         Settings.SaveWindow( _T("CFolderPropertiesDlg"), this );
00131         CSkinDialog::OnDestroy();
00132 }
00133 
00134 BOOL CFolderPropertiesDlg::PreTranslateMessage(MSG* pMsg)
00135 {
00136         if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_TAB )
00137         {
00138                 if ( m_wndData.OnTab() ) return TRUE;
00139         }
00140 
00141         return CSkinDialog::PreTranslateMessage( pMsg );
00142 }
00143 
00144 void CFolderPropertiesDlg::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
00145 {
00146         CSkinDialog::OnGetMinMaxInfo( lpMMI );
00147 
00148         if ( m_nWidth )
00149         {
00150                 lpMMI->ptMinTrackSize.x = m_nWidth;
00151                 lpMMI->ptMinTrackSize.y = 256;
00152                 lpMMI->ptMaxTrackSize.x = m_nWidth;
00153         }
00154 }
00155 
00156 void CFolderPropertiesDlg::OnSize(UINT nType, int cx, int cy)
00157 {
00158         if ( nType != 1982 ) CSkinDialog::OnSize( nType, cx, cy );
00159 
00160         if ( ! IsWindow( m_wndData.m_hWnd ) ) return;
00161 
00162         CRect rc, rcClient;
00163         GetClientRect( &rcClient );
00164 
00165         m_wndTitle.GetWindowRect( &rc );
00166         ScreenToClient( &rc );
00167         int nRight = rc.right;
00168 
00169         m_wndSchemas.GetWindowRect( &rc );
00170         ScreenToClient( &rc );
00171         rc.right        = nRight;
00172         rc.left         = rcClient.right - rc.right;
00173 
00174         HDWP hDWP = BeginDeferWindowPos( 4 );
00175 
00176         DeferWindowPos( hDWP, m_wndData, NULL, rc.left, rc.bottom + 18,
00177                 rc.Width(), cy - 24 - 16 - 16 - ( rc.bottom + 18 ), SWP_NOZORDER );
00178 
00179         m_wndApply.GetWindowRect( &rc );
00180         ScreenToClient( &rc );
00181         DeferWindowPos( hDWP, m_wndApply, NULL, rc.left, cy - 32 - 19, 0, 0, SWP_NOSIZE );
00182 
00183         m_wndOK.GetWindowRect( &rc );
00184         ScreenToClient( &rc );
00185 
00186         DeferWindowPos( hDWP, m_wndOK, NULL, rc.left, cy - 32, 0, 0, SWP_NOZORDER|SWP_NOSIZE );
00187         DeferWindowPos( hDWP, m_wndCancel, NULL, rc.right + 8, cy - 32, 0, 0, SWP_NOZORDER|SWP_NOSIZE );
00188 
00189         EndDeferWindowPos( hDWP );
00190 }
00191 
00192 void CFolderPropertiesDlg::OnPaint()
00193 {
00194         CPaintDC dc( this );
00195         CRect rc( 8, 6, 8 + 98, 6 + 98 );
00196 
00197         COLORREF crBack =  CCoolInterface::CalculateColour(
00198                                                 CoolInterface.m_crTipBack, RGB( 255, 255, 255 ), 128 );
00199 
00200         dc.Draw3dRect( &rc, GetSysColor( COLOR_ACTIVECAPTION ), GetSysColor( COLOR_ACTIVECAPTION ) );
00201         rc.DeflateRect( 1, 1 );
00202 
00203         if ( FALSE )
00204         {
00205                 // thumbnail
00206         }
00207         else
00208         {
00209                 CPoint pt = rc.CenterPoint();
00210                 pt.x -= 24; pt.y -= 24;
00211 
00212                 if ( CSchema* pSchema = m_wndSchemas.GetSelected() )
00213                 {
00214                         if ( pSchema->m_nIcon48 >= 0 )
00215                         {
00216                                 ImageList_DrawEx( ShellIcons.GetHandle( 48 ), pSchema->m_nIcon48,
00217                                         dc.GetSafeHdc(), pt.x, pt.y, 48, 48, crBack, CLR_NONE, ILD_NORMAL );
00218                                 dc.ExcludeClipRect( pt.x, pt.y, pt.x + 48, pt.y + 48 );
00219                         }
00220                         else
00221                         {
00222                                 pt.x += 8; pt.y += 8;
00223                                 ImageList_DrawEx( ShellIcons.GetHandle( 32 ), pSchema->m_nIcon32,
00224                                         dc.GetSafeHdc(), pt.x, pt.y, 32, 32, crBack, CLR_NONE, ILD_NORMAL );
00225                                 dc.ExcludeClipRect( pt.x, pt.y, pt.x + 32, pt.y + 32 );
00226                         }
00227                 }
00228                 else
00229                 {
00230                         ImageList_DrawEx( ShellIcons.GetHandle( 48 ), SHI_FOLDER_OPEN,
00231                                 dc.GetSafeHdc(), pt.x, pt.y, 48, 48, crBack, CLR_NONE, ILD_NORMAL );
00232                         dc.ExcludeClipRect( pt.x, pt.y, pt.x + 48, pt.y + 48 );
00233                 }
00234         }
00235 
00236         dc.FillSolidRect( &rc, crBack );
00237 }
00238 
00239 HBRUSH CFolderPropertiesDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
00240 {
00241         HBRUSH hbr = CSkinDialog::OnCtlColor( pDC, pWnd, nCtlColor );
00242 
00243         if ( pWnd == &m_wndApply )
00244         {
00245                 pDC->SetTextColor( RGB( 0, 0, 255 ) );
00246                 pDC->SelectObject( &theApp.m_gdiFontLine );
00247         }
00248 
00249         return hbr;
00250 }
00251 
00252 BOOL CFolderPropertiesDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
00253 {
00254         CPoint point;
00255         CRect rc;
00256 
00257         GetCursorPos( &point );
00258         m_wndApply.GetWindowRect( &rc );
00259 
00260         if ( rc.PtInRect( point ) )
00261         {
00262                 SetCursor( theApp.LoadCursor( IDC_HAND ) );
00263                 return TRUE;
00264         }
00265 
00266         return CSkinDialog::OnSetCursor( pWnd, nHitTest, message );
00267 }
00268 
00269 void CFolderPropertiesDlg::OnLButtonUp(UINT nFlags, CPoint point)
00270 {
00271         CSkinDialog::OnLButtonUp( nFlags, point );
00272 
00273         CRect rc;
00274         m_wndApply.GetWindowRect( &rc );
00275         ScreenToClient( &rc );
00276 
00277         if ( rc.PtInRect( point ) )
00278         {
00279                 DoApply( TRUE );
00280         }
00281 }
00282 
00283 void CFolderPropertiesDlg::OnSelChangeSchemas()
00284 {
00285         m_wndData.SetSchema( m_wndSchemas.GetSelected() );
00286         OnChangeTitle();
00287         Invalidate();
00288 }
00289 
00290 void CFolderPropertiesDlg::OnCloseUpSchemas()
00291 {
00292         if ( CSchema* pSchema = m_wndSchemas.GetSelected() )
00293         {
00294                 PostMessage( WM_KEYDOWN, VK_TAB );
00295         }
00296 }
00297 
00298 void CFolderPropertiesDlg::OnChangeTitle()
00299 {
00300         if ( m_bUpdating ) return;
00301         m_bUpdating = TRUE;
00302 
00303         if ( CSchema* pSchema = m_wndSchemas.GetSelected() )
00304         {
00305                 CString strTitle;
00306                 m_wndTitle.GetWindowText( strTitle );
00307 
00308                 CXMLElement* pXML = new CXMLElement( NULL, pSchema->m_sSingular );
00309                 m_wndData.UpdateData( pXML, TRUE );
00310                 pXML->AddAttribute( pSchema->GetFirstMemberName(), strTitle );
00311                 m_wndData.UpdateData( pXML, FALSE );
00312                 delete pXML;
00313         }
00314 
00315         m_bUpdating = FALSE;
00316 }
00317 
00318 void CFolderPropertiesDlg::OnChangeData()
00319 {
00320         if ( m_bUpdating ) return;
00321         m_bUpdating = TRUE;
00322 
00323         if ( CSchema* pSchema = m_wndSchemas.GetSelected() )
00324         {
00325                 CXMLElement* pXML = new CXMLElement( NULL, pSchema->m_sSingular );
00326                 m_wndData.UpdateData( pXML, TRUE );
00327                 m_wndTitle.SetWindowText( pXML->GetAttributeValue( pSchema->GetFirstMemberName() ) );
00328                 delete pXML;
00329         }
00330 
00331         m_bUpdating = FALSE;
00332 }
00333 
00334 void CFolderPropertiesDlg::OnOK()
00335 {
00336         DoApply( FALSE );
00337         CSkinDialog::OnOK();
00338 }
00339 
00340 void CFolderPropertiesDlg::DoApply(BOOL bMetaToFiles)
00341 {
00342         CWaitCursor pCursor;
00343 
00344         CString str;
00345         m_wndTitle.GetWindowText( str );
00346         if ( str.IsEmpty() ) return;
00347 
00348         CQuickLock oLock( Library.m_pSection );
00349 
00350         if ( LibraryFolders.CheckAlbum( m_pFolder ) )
00351         {
00352                 m_wndTitle.GetWindowText( m_pFolder->m_sName );
00353 
00354                 if ( CSchema* pSchema = m_wndSchemas.GetSelected() )
00355                 {
00356                         CXMLElement* pXML               = pSchema->Instantiate( TRUE );
00357                         CXMLElement* pSingular  = pXML->AddElement( pSchema->m_sSingular );
00358 
00359                         m_wndData.UpdateData( pSingular, TRUE );
00360                         m_pFolder->SetMetadata( pXML );
00361                         delete pXML;
00362                 }
00363                 else
00364                 {
00365                         m_pFolder->SetMetadata( NULL );
00366                 }
00367 
00368                 m_pFolder->m_nUpdateCookie++;
00369 
00370                 m_pFolder->MetaToFiles( bMetaToFiles );
00371 
00372                 Library.Update();
00373         }
00374 }

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