home *** CD-ROM | disk | FTP | other *** search
/ Softwarová Záchrana 3 / Softwarova-zachrana-3.bin / pserv.cpl / pserv-2.4.exe / source / ChooseColumnsDialog.cpp < prev    next >
C/C++ Source or Header  |  2005-01-05  |  4KB  |  127 lines

  1. // ChooseColumnsDialog.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "pserv2.h"
  6. #include "ChooseColumnsDialog.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CChooseColumnsDialog dialog
  16.  
  17.  
  18. CChooseColumnsDialog::CChooseColumnsDialog(CListViewEntries* pEntries, CWnd* pParent /*=NULL*/)
  19.     :   CDialog(CChooseColumnsDialog::IDD, pParent),
  20.         m_pEntries( pEntries )
  21. {
  22.     //{{AFX_DATA_INIT(CChooseColumnsDialog)
  23.         // NOTE: the ClassWizard will add member initialization here
  24.     //}}AFX_DATA_INIT
  25. }
  26.  
  27.  
  28. void CChooseColumnsDialog::DoDataExchange(CDataExchange* pDX)
  29. {
  30.     CDialog::DoDataExchange(pDX);
  31.     //{{AFX_DATA_MAP(CChooseColumnsDialog)
  32.     DDX_Control(pDX, IDC_LIST2, m_lbTarget);
  33.     DDX_Control(pDX, IDC_LIST1, m_lbSource);
  34.     //}}AFX_DATA_MAP
  35.  
  36.     if( pDX->m_bSaveAndValidate )
  37.     {
  38.         CString buffer;
  39.  
  40.         for( int i = 0, nItems = m_lbSource.GetCount(); i < nItems; i++ )
  41.         {
  42.             m_lbSource.GetText(i, buffer);
  43.             CListViewColumn* c = m_pEntries->GetColumnByName(buffer);
  44.             if( c )
  45.             {
  46.                 c->m_dwDisplayOrder = -1;
  47.             }
  48.         }
  49.         for( i = 0, nItems = m_lbTarget.GetCount(); i < nItems; i++ )
  50.         {
  51.             m_lbTarget.GetText(i, buffer);
  52.             CListViewColumn* c = m_pEntries->GetColumnByName(buffer);
  53.             if( c )
  54.             {
  55.                 c->m_dwDisplayOrder = i;
  56.             }
  57.         }
  58.         m_pEntries->RefreshDisplayColumns();
  59.     }
  60.     else
  61.     {
  62.         DWORD dwNumberOfColumns = m_pEntries->m_Columns.GetSize();
  63.  
  64.         for( DWORD dwFindColumnIndex = 0; dwFindColumnIndex < dwNumberOfColumns; dwFindColumnIndex++ )
  65.         {
  66.             for( DWORD dwIsColumnIndex = 0; dwIsColumnIndex < dwNumberOfColumns; dwIsColumnIndex++ )
  67.             {
  68.                 CListViewColumn* c = (CListViewColumn*) m_pEntries->m_Columns.GetAt(dwIsColumnIndex);
  69.                 if( c->m_dwDisplayOrder == dwFindColumnIndex )
  70.                 {
  71.                     m_lbTarget.AddString(c->m_strCaption);
  72.                     break;
  73.                 }
  74.             }
  75.         }
  76.         for( DWORD dwIsColumnIndex = 0; dwIsColumnIndex < dwNumberOfColumns; dwIsColumnIndex++ )
  77.         {
  78.             CListViewColumn* c = (CListViewColumn*) m_pEntries->m_Columns.GetAt(dwIsColumnIndex);
  79.             if( c->m_dwDisplayOrder == DWORD(-1) )
  80.             {
  81.                 m_lbSource.AddString(c->m_strCaption);
  82.             }
  83.         }
  84.     }
  85. }
  86.  
  87.  
  88. BEGIN_MESSAGE_MAP(CChooseColumnsDialog, CDialog)
  89.     //{{AFX_MSG_MAP(CChooseColumnsDialog)
  90.     ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  91.     ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  92.     //}}AFX_MSG_MAP
  93. END_MESSAGE_MAP()
  94.  
  95. /////////////////////////////////////////////////////////////////////////////
  96. // CChooseColumnsDialog message handlers
  97. void MoveItems(CListBox& from, CListBox& to)
  98. {
  99.     int nSelCount = from.GetSelCount();
  100.     if( nSelCount )
  101.     {
  102.         ASSERT( nSelCount < 60 );
  103.         int iSelectedItemIndex[60];
  104.         int n = from.GetSelItems(nSelCount, iSelectedItemIndex);
  105.         ASSERT(n==nSelCount);
  106.  
  107.         CString buffer;
  108.         for( int i = nSelCount-1; i >= 0; i-- )
  109.         {
  110.             from.GetText(iSelectedItemIndex[i], buffer);
  111.             from.DeleteString(iSelectedItemIndex[i]);
  112.             to.AddString(buffer);
  113.         }
  114.     }
  115. }
  116.  
  117.  
  118. void CChooseColumnsDialog::OnButton1() 
  119. {
  120.     MoveItems(m_lbSource, m_lbTarget);
  121. }
  122.  
  123. void CChooseColumnsDialog::OnButton2() 
  124. {
  125.     MoveItems(m_lbTarget, m_lbSource);
  126. }
  127.