void CSortingListControl::LoadPersistentAttributes()
{
	CArray<int, int> arr;
	arr.SetSize(GetHeaderCtrl()->GetItemCount());

	GetColumnOrderArray(arr.GetData(), arr.GetSize());	
	CPersistence::GetColumnOrder(m_name, arr);
	SetColumnOrderArray(arr.GetSize(), arr.GetData());

	for (int i=0; i < arr.GetSize(); i++)
		arr[i]= GetColumnWidth(i);
	CPersistence::GetColumnWidths(m_name, arr);
	for (i=0; i < arr.GetSize(); i++)
	{
		// To avoid "insane" settings we set the column width to
		// maximal twice the default width.
		int maxWidth= GetColumnWidth(i) * 2;
		int w= min(arr[i], maxWidth);
		SetColumnWidth(i, w);
	}

	// Not so good: CPersistence::GetSorting(m_name, GetHeaderCtrl()->GetItemCount(), m_sorting.column1, m_sorting.ascending1, m_sorting.column2, m_sorting.ascending2);
	// We refrain from saving the sorting because it is too likely, that
	// users start up with insane settings and don't get it.
}
Esempio n. 2
0
int CDownloadedListView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	LRESULT lRes = DefWindowProc();

	if (Misc::IsVistalater())
		UxTheme_Wrap::SetWindowTheme(m_hWnd, L"Explorer", 0);

	SetExtendedListViewStyle(LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP | LVS_EX_INFOTIP | LVS_EX_DOUBLEBUFFER);

	CImageList ImageList;
	ImageList.Create(16, 16, ILC_COLOR32 | ILC_MASK, 2, 1);
	CBitmap bmpOK = AtlLoadBitmap(IDB_DLOK);
	CBitmap	bmpError = AtlLoadBitmap(IDB_DLERROR);
	ImageList.Add(bmpOK, RGB(255, 0, 255));
	ImageList.Add(bmpError, RGB(255, 0, 255));
	SetImageList(ImageList, LVSIL_SMALL);

	struct Column {
		LPCTSTR	columnName;
		int		columnType;
		int		columnFormat;
		int		defaultcolumnWidth;
	};
	Column	clm[] = {
		{ _T("!")			, LVCOLSORT_CUSTOM	, LVCFMT_LEFT	,  20 },
		{ _T("ファイル名")	, LVCOLSORT_TEXT	, LVCFMT_LEFT	, 160 },
		{ _T("URL")			, LVCOLSORT_TEXT	, LVCFMT_LEFT	, 300 },
		{ _T("ファイルパス"), LVCOLSORT_TEXT	, LVCFMT_LEFT	, 300 },
		{ _T("日付")		, LVCOLSORT_TEXT	, LVCFMT_LEFT	, 120 },
		{ _T("サイズ")		, LVCOLSORT_CUSTOM	, LVCFMT_RIGHT	, 100 },
	};

	int nCount = _countof(clm);
	for (int i = 0; i < nCount; ++i) {
		InsertColumn(i, clm[i].columnName, clm[i].columnFormat, clm[i].defaultcolumnWidth);
		SetColumnSortType(i, clm[i].columnType);
	}

	// 設定を読み込む
	CString strIniFile = Misc::GetFullPath_ForExe(_T("Download.ini"));
	CIniFileI pr(strIniFile, _T("DownloadedListView"));
	for (int i = 0; i < nCount; ++i) {
		CString strWidth = _T("ColumnWidth");
		strWidth.Append(i);
		
		SetColumnWidth(i, pr.GetValue(strWidth, clm[i].defaultcolumnWidth));
	}

	unique_ptr<int[]> pColumnOrder(new int[nCount]);
	for (int i = 0; i < nCount; i++) {
		CString strColumnOrder = _T("ColumnOrder");
		strColumnOrder.Append(i);
		pColumnOrder[i] = pr.GetValue(strColumnOrder, i);
	}
	SetColumnOrderArray(nCount, pColumnOrder.get());

	return 0;
}
Esempio n. 3
0
void CReportCtrl::ResetHeaderState()
{
	int	cols = m_Columns;
	int	*pColOrder = new int[cols];
	for (int i = 0; i < cols; i++) {
		SetColumnWidth(i, m_Column[i].Width);
		pColOrder[i] = i;
	}
	SetColumnOrderArray(cols, pColOrder);
	delete pColOrder;
	Invalidate();
}
Esempio n. 4
0
bool CReportCtrl::LoadHeaderState(LPCTSTR Key, LPCTSTR SubKey)
{
	DWORD	hsz = CalcHeaderStateSize(m_Columns);
	HEADER_STATE	*ph = (HEADER_STATE *)new BYTE[hsz];
	ZeroMemory(ph, hsz);
	bool	retc = CPersist::GetBinary(Key, SubKey, ph, &hsz) != 0;
	if (retc) {
		SortRows(ph->SortCol, ph->SortDir);
		int	cols = ph->Columns;
		int	*pColWidth = &ph->ColInfo[cols];
		for (int i = 0; i < cols; i++)
			SetColumnWidth(i, pColWidth[i]);
		SetColumnOrderArray(cols, ph->ColInfo);
	}
	delete ph;
	return(retc);
}
BOOL CListCtrl::LoadColumnsState(HKEY hRootKey,LPCSTR lpKey,LPCSTR lpSubKey)
{
	CRegKey RegKey;
	if (lpKey==NULL)
		RegKey.m_hKey=hRootKey;
	else if (RegKey.OpenKey(hRootKey,lpKey,CRegKey::openExist|CRegKey::samRead)!=ERROR_SUCCESS)
		return FALSE;
	DWORD nDataLength=RegKey.QueryValueLength(lpSubKey);
	if (nDataLength<4)
	{
		if (lpKey==NULL)
			RegKey.m_hKey=NULL;
		return FALSE;
	}
	int* pData=(int*)new BYTE[nDataLength];
	DWORD dwRet=RegKey.QueryValue(lpSubKey,(LPSTR)pData,nDataLength);
	if (lpKey==NULL)
		RegKey.m_hKey=NULL;
	if (dwRet<nDataLength)
	{
		delete[] (BYTE*)pData;
		return FALSE;
	}

	if ((pData[0]*2+1)*sizeof(int)!=nDataLength)
	{
		delete[] (BYTE*)pData;
		return FALSE;
	}
	BOOL nOrderOK=FALSE;
	for (int i=0;i<pData[0];i++)
	{
		SetColumnWidth(i,pData[1+i]);
		if (pData[1+pData[0]+i]!=0)
			nOrderOK=TRUE;
	}	
	if (nOrderOK)
		SetColumnOrderArray(pData[0],pData+1+pData[0]);
	delete[] (BYTE*)pData;
	return TRUE;
}
/*
This function loads the columns order as the columns can be re-arranged with drag & drop
You should call it BEFORE you fill in the contents or it might not redraw properly
*/
int CMultiColumnSortListCtrl::LoadColumnOrder()
{
	ASSERT( m_strUniqueName.GetLength() );	//You must set a unique name for every listctrl

	int iNumColumns = GetColumnCount();

	//set the colum order
	CString strEntry( m_strUniqueName );
	CString strValue, strSubString;
	CString strSection( m_strColumnOrderSection );

	strValue = AfxGetApp()->GetProfileString( strSection, strEntry, "" );

	if( !strValue.IsEmpty() )
	{
		LPINT pnOrder = (LPINT)malloc(iNumColumns*sizeof(int));
		ASSERT(pnOrder != NULL);

		if( pnOrder )
		{
			for( int nIndex = 0; nIndex < iNumColumns; nIndex++ )
			{
				
				AfxExtractSubString(strSubString, strValue, nIndex, ',');
				if( !strSubString.IsEmpty() )
				{
					pnOrder[nIndex] = atoi( (LPCTSTR)strSubString );
				}
			}

			SetColumnOrderArray( iNumColumns, pnOrder );

			free(pnOrder);
		}
	}

	return 1;
}
Esempio n. 7
0
/*******************************************************************************
  Function Name  : ShowColumn
  Input(s)       : nCol, bShow
  Output         : BOOL
  Functionality  : Shows/Hides a Column nCol based on boolean bShow.
  Member of      : CRxMsgList
  Author(s)      : Arunkumar K
  Date Created   : 20-05-2010
  Modifications  :
*******************************************************************************/
BOOL CRxMsgList::ShowColumn(int nCol, bool bShow)
{
    SetRedraw(FALSE);
    ColumnState& columnState = GetColumnState(nCol);
    int nColCount = GetHeaderCtrl()->GetItemCount();
    int* pOrderArray = new int[nColCount];
    VERIFY( GetColumnOrderArray(pOrderArray, nColCount) );

    if (bShow)
    {
        // Restore the position of the column
        int nCurIndex = -1;

        for(int i = 0; i < nColCount ; ++i)
        {
            if (pOrderArray[i]==nCol)
            {
                nCurIndex = i;
            }
            else if (nCurIndex!=-1)
            {
                // We want to move it to the original position,
                // and after the last hidden column
                if ( (i <= columnState.m_OrgPosition)
                        || !IsColumnVisible(pOrderArray[i])
                   )
                {
                    pOrderArray[nCurIndex] = pOrderArray[i];
                    pOrderArray[i] = nCol;
                    nCurIndex = i;
                }
            }
        }
    }
    else
    {
        // Move the column to the front of the display order list
        int nCurIndex(-1);

        for(int i = nColCount-1; i >=0 ; --i)
        {
            if (pOrderArray[i]==nCol)
            {
                // Backup the current position of the column
                columnState.m_OrgPosition = i;
                nCurIndex = i;
            }
            else if (nCurIndex!=-1)
            {
                pOrderArray[nCurIndex] = pOrderArray[i];
                pOrderArray[i] = nCol;
                nCurIndex = i;
            }
        }
    }

    VERIFY( SetColumnOrderArray(nColCount, pOrderArray) );
    delete [] pOrderArray;

    if (bShow)
    {
        // Restore the column width
        columnState.m_Visible = true;
        VERIFY( SetColumnWidth(nCol, columnState.m_OrgWidth) );
    }
    else
    {
        // Backup the column width
        if(GetColumnWidth(nCol) == 0)
        {
            columnState.m_Visible = false;
        }
        else
        {
            int orgWidth = GetColumnWidth(nCol);
            VERIFY( SetColumnWidth(nCol, 0) );
            columnState.m_Visible = false;
            columnState.m_OrgWidth = orgWidth;
        }
    }

    SetRedraw(TRUE);
    Invalidate(FALSE);
    return TRUE;
}