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

DlgHitColumns.cpp

Go to the documentation of this file.
00001 //
00002 // DlgHitColumns.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 "Schema.h"
00025 #include "DlgHitColumns.h"
00026 
00027 #ifdef _DEBUG
00028 #define new DEBUG_NEW
00029 #undef THIS_FILE
00030 static char THIS_FILE[] = __FILE__;
00031 #endif
00032 
00033 BEGIN_MESSAGE_MAP(CSchemaColumnsDlg, CSkinDialog)
00034         //{{AFX_MSG_MAP(CSchemaColumnsDlg)
00035         ON_CBN_SELCHANGE(IDC_SCHEMAS, OnSelChangeSchemas)
00036         //}}AFX_MSG_MAP
00037 END_MESSAGE_MAP()
00038 
00039 
00041 // CSchemaColumnsDlg dialog
00042 
00043 CSchemaColumnsDlg::CSchemaColumnsDlg(CWnd* pParent ) : CSkinDialog(CSchemaColumnsDlg::IDD, pParent)
00044 {
00045         //{{AFX_DATA_INIT(CSchemaColumnsDlg)
00046         //}}AFX_DATA_INIT
00047 }
00048 
00049 void CSchemaColumnsDlg::DoDataExchange(CDataExchange* pDX)
00050 {
00051         CSkinDialog::DoDataExchange(pDX);
00052         //{{AFX_DATA_MAP(CSchemaColumnsDlg)
00053         DDX_Control(pDX, IDC_COLUMNS, m_wndColumns);
00054         DDX_Control(pDX, IDC_SCHEMAS, m_wndSchemas);
00055         //}}AFX_DATA_MAP
00056 }
00057 
00059 // CSchemaColumnsDlg message handlers
00060 
00061 BOOL CSchemaColumnsDlg::OnInitDialog()
00062 {
00063         CSkinDialog::OnInitDialog();
00064 
00065         SkinMe( _T("CSchemaColumnsDlg"), IDR_SEARCHFRAME );
00066 
00067         m_wndColumns.InsertColumn( 0, _T("Member"), LVCFMT_LEFT, 128, -1 );
00068         m_wndColumns.InsertColumn( 1, _T("Type"), LVCFMT_LEFT, 0, 0 );
00069         ListView_SetExtendedListViewStyle( m_wndColumns.GetSafeHwnd(), LVS_EX_CHECKBOXES );
00070 
00071         m_wndSchemas.Load( m_pSchema ? m_pSchema->m_sURI : _T("") );
00072         m_wndSchemas.m_sNoSchemaText = _T("No Schema Columns");
00073 
00074         OnSelChangeSchemas();
00075 
00076         for ( int nMember = 0 ; nMember < m_wndColumns.GetItemCount() ; nMember++ )
00077         {
00078                 BOOL bChecked = m_pColumns.Find( (LPVOID)m_wndColumns.GetItemData( nMember ) ) != NULL;
00079                 m_wndColumns.SetItemState( nMember, INDEXTOSTATEIMAGEMASK( bChecked + 1 ), LVIS_STATEIMAGEMASK );
00080         }
00081 
00082         return TRUE;
00083 }
00084 
00085 void CSchemaColumnsDlg::OnSelChangeSchemas()
00086 {
00087         CSchema* pSchema = m_wndSchemas.GetSelected();
00088 
00089         m_wndColumns.DeleteAllItems();
00090         if ( ! pSchema ) return;
00091 
00092         CString strMembers = theApp.GetProfileString( _T("Interface"),
00093                 _T("SchemaColumns.") + pSchema->m_sSingular, _T("(EMPTY)") );
00094 
00095         if ( strMembers == _T("(EMPTY)") ) strMembers = pSchema->m_sDefaultColumns;
00096 
00097         for ( POSITION pos = pSchema->GetMemberIterator() ; pos ; )
00098         {
00099                 CSchemaMember* pMember = pSchema->GetNextMember( pos );
00100 
00101                 LV_ITEM pItem;
00102                 ZeroMemory( &pItem, sizeof( pItem ) );
00103 
00104                 pItem.mask              = LVIF_TEXT|LVIF_PARAM;
00105                 pItem.iItem             = m_wndColumns.GetItemCount();
00106                 pItem.lParam    = (LPARAM)pMember;
00107                 pItem.pszText   = (LPTSTR)(LPCTSTR)pMember->m_sTitle;
00108                 pItem.iItem             = m_wndColumns.InsertItem( &pItem );
00109                 pItem.mask              = LVIF_TEXT;
00110                 pItem.iSubItem  = 1;
00111                 pItem.pszText   = (LPTSTR)(LPCTSTR)pMember->m_sType;
00112                 m_wndColumns.SetItem( &pItem );
00113 
00114                 if ( strMembers.Find( _T("|") + pMember->m_sName + _T("|") ) >= 0 )
00115                 {
00116                         m_wndColumns.SetItemState( pItem.iItem, INDEXTOSTATEIMAGEMASK( 2 ),
00117                                 LVIS_STATEIMAGEMASK );
00118                 }
00119         }
00120 }
00121 
00122 void CSchemaColumnsDlg::OnOK()
00123 {
00124         m_pSchema = m_wndSchemas.GetSelected();
00125 
00126         if ( m_pSchema )
00127         {
00128                 m_pColumns.RemoveAll();
00129 
00130                 for ( int nMember = 0 ; nMember < m_wndColumns.GetItemCount() ; nMember++ )
00131                 {
00132                         if ( ListView_GetCheckState( m_wndColumns.GetSafeHwnd(), nMember ) )
00133                         {
00134                                 CSchemaMember* pMember = (CSchemaMember*)m_wndColumns.GetItemData( nMember );
00135                                 m_pColumns.AddTail( pMember );
00136                         }
00137                 }
00138 
00139                 SaveColumns( m_pSchema, &m_pColumns );
00140         }
00141 
00142         CSkinDialog::OnOK();
00143 }
00144 
00146 // CSchemaColumnsDlg load columns utility
00147 
00148 BOOL CSchemaColumnsDlg::LoadColumns(CSchema* pSchema, CPtrList* pColumns)
00149 {
00150         if ( ! pSchema || ! pColumns ) return FALSE;
00151         pColumns->RemoveAll();
00152 
00153         CString strMembers = theApp.GetProfileString( _T("Interface"),
00154                 _T("SchemaColumns.") + pSchema->m_sSingular, _T("(EMPTY)") );
00155 
00156         if ( strMembers == _T("(EMPTY)") ) strMembers = pSchema->m_sDefaultColumns;
00157 
00158         for ( POSITION pos = pSchema->GetMemberIterator() ; pos ; )
00159         {
00160                 CSchemaMember* pMember = pSchema->GetNextMember( pos );
00161                 if ( strMembers.Find( _T("|") + pMember->m_sName + _T("|") ) >= 0 )
00162                         pColumns->AddTail( pMember );
00163         }
00164 
00165         return TRUE;
00166 }
00167 
00169 // CSchemaColumnsDlg save columns utility
00170 
00171 BOOL CSchemaColumnsDlg::SaveColumns(CSchema* pSchema, CPtrList* pColumns)
00172 {
00173         if ( ! pSchema || ! pColumns ) return FALSE;
00174 
00175         CString strMembers;
00176 
00177         for ( POSITION pos = pColumns->GetHeadPosition() ; pos ; )
00178         {
00179                 CSchemaMember* pMember = (CSchemaMember*)pColumns->GetNext( pos );
00180                 strMembers += '|';
00181                 strMembers += pMember->m_sName;
00182                 strMembers += '|';
00183         }
00184 
00185         theApp.WriteProfileString( _T("Interface"),
00186                 _T("SchemaColumns.") + pSchema->m_sSingular, strMembers );
00187 
00188         return TRUE;
00189 }
00190 
00192 // CSchemaColumnsDlg menu builder utility
00193 
00194 CMenu* CSchemaColumnsDlg::BuildColumnMenu(CSchema* pSchema, CPtrList* pColumns)
00195 {
00196         if ( ! pSchema ) return NULL;
00197 
00198         CMenu* pMenu = new CMenu();
00199 
00200         pMenu->CreatePopupMenu();
00201 
00202         UINT nID = 1000;
00203 
00204         for ( POSITION pos = pSchema->GetMemberIterator() ; pos ; nID++ )
00205         {
00206                 CSchemaMember* pMember = pSchema->GetNextMember( pos );
00207                 UINT nFlags = MF_STRING;
00208 
00209                 if ( nID > 1000 && ( ( nID - 1000 ) % 16 ) == 0 ) nFlags |= MF_MENUBREAK;
00210                 if ( pColumns && pColumns->Find( pMember ) != NULL ) nFlags |= MF_CHECKED;
00211 
00212                 pMenu->AppendMenu( nFlags, nID, pMember->m_sTitle );
00213         }
00214 
00215         return pMenu;
00216 }
00217 
00219 // CSchemaColumnsDlg column toggle utility
00220 
00221 BOOL CSchemaColumnsDlg::ToggleColumnHelper(CSchema* pSchema, CPtrList* pSource, CPtrList* pTarget, UINT nToggleID, BOOL bSave)
00222 {
00223         if ( ! pSchema ) return FALSE;
00224 
00225         UINT nID = 1000;
00226 
00227         pTarget->RemoveAll();
00228         pTarget->AddTail( pSource );
00229 
00230         for ( POSITION pos = pSchema->GetMemberIterator() ; pos ; nID++ )
00231         {
00232                 CSchemaMember* pMember = pSchema->GetNextMember( pos );
00233 
00234                 if ( nID == nToggleID )
00235                 {
00236                         if ( pos = pTarget->Find( pMember ) )
00237                         {
00238                                 pTarget->RemoveAt( pos );
00239                         }
00240                         else
00241                         {
00242                                 pTarget->AddTail( pMember );
00243                         }
00244 
00245                         if ( bSave ) SaveColumns( pSchema, pTarget );
00246 
00247                         return TRUE;
00248                 }
00249         }
00250 
00251         return FALSE;
00252 }
00253 

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