Esempio n. 1
0
int NListView::ListView_InvertSelection(HWND hListView)
{
	int nTotalItems = ListView_GetItemCount(hListView);

	int nSelected = 0;

	SendMessage(hListView,WM_SETREDRAW,FALSE,0);

	for(int i = 0;i < nTotalItems;i++)
	{
		if(ListView_GetItemState(hListView,i,LVIS_SELECTED) == LVIS_SELECTED)
		{
			ListView_SelectItem(hListView,i,FALSE);
		}
		else
		{
			ListView_SelectItem(hListView,i,TRUE);
			nSelected++;
		}
	}

	SendMessage(hListView,WM_SETREDRAW,TRUE,0);

	return nSelected;
}
void CFolderView::DirectoryAltered(void)
{
	BOOL bNewItemCreated;

	EnterCriticalSection(&m_csDirectoryAltered);

	bNewItemCreated = m_bNewItemCreated;

	SendMessage(m_hListView,WM_SETREDRAW,(WPARAM)FALSE,(LPARAM)NULL);

	/* Potential problem:
	After a file is created, it may be renamed shortly afterwards.
	If the rename occurs before the file is added here, the
	addition won't be registered (since technically, the file
	does not exist), and the rename operation will not take place.
	Adding an item that does not exist will corrupt the programs
	state.

	Solution:
	If a file does not exist when adding it, temporarily remember
	its filename. On the next rename operation, if the renamed
	file matches the name of the added file, add the file in-place
	with its new name.
	The operation should NOT be queued, as it is possible that
	other actions for the file wil take place before the addition,
	which will again result in an incorrect state.
	*/
	for each(auto af in m_AlteredList)
	{
		/* Only undertake the modification if the unique folder
		index on the modified item and current folder match up
		(i.e. ensure the directory has not changed since these
		files were modified). */
		if(af.iFolderIndex == m_iUniqueFolderIndex)
		{
			switch(af.dwAction)
			{
			case FILE_ACTION_ADDED:
				OnFileActionAdded(af.szFileName);
				break;

			case FILE_ACTION_MODIFIED:
				ModifyItemInternal(af.szFileName);
				break;

			case FILE_ACTION_REMOVED:
				RemoveItemInternal(af.szFileName);
				break;

			case FILE_ACTION_RENAMED_OLD_NAME:
				OnFileActionRenamedOldName(af.szFileName);
				break;

			case FILE_ACTION_RENAMED_NEW_NAME:
				OnFileActionRenamedNewName(af.szFileName);
				break;
			}
		}
	}

	SendMessage(m_hListView,WM_SETREDRAW,(WPARAM)TRUE,(LPARAM)NULL);

	/* Ensure the first dropped item is visible. */
	if(m_iDropped != -1)
	{
		if(!ListView_IsItemVisible(m_hListView,m_iDropped))
			ListView_EnsureVisible(m_hListView,m_iDropped,TRUE);

		m_iDropped = -1;
	}

	SendMessage(m_hOwner,WM_USER_DIRECTORYMODIFIED,m_ID,0);

	if(bNewItemCreated && !m_bNewItemCreated)
		SendMessage(m_hOwner,WM_USER_NEWITEMINSERTED,0,m_iIndexNewItem);

	m_AlteredList.clear();

	list<PastedFile_t>::iterator itr2;
	BOOL bFocusSet = FALSE;
	int iIndex;

	/* Select the specified items, and place the
	focus on the first item. */
	for(itr2 = m_pFileSelectionList.begin();itr2 != m_pFileSelectionList.end();)
	{
		iIndex = LocateFileItemIndex(itr2->szFileName);

		if(iIndex != -1)
		{
			ListView_SelectItem(m_hListView,iIndex,TRUE);

			if(!bFocusSet)
			{
				ListView_FocusItem(m_hListView,iIndex,TRUE);
				ListView_EnsureVisible(m_hListView,iIndex,TRUE);

				bFocusSet = TRUE;
			}

			itr2 = m_pFileSelectionList.erase(itr2);
		}
		else
		{
			++itr2;
		}
	}

	LeaveCriticalSection(&m_csDirectoryAltered);

	return;
}
void CContainer::OnInitColumnDlg(HWND hDlg)
{
    HWND						hListView;
    list<Column_t>				pActiveColumnList;
    list<Column_t>::iterator	itr;
    LVITEM						lvItem;
    LVCOLUMN					lvColumn;
    TCHAR						szText[64];
    int							iItem = 0;

    if(m_bSelectColumnsDlgStateSaved)
    {
        SetWindowPos(hDlg,NULL,m_ptSelectColumns.x,
                     m_ptSelectColumns.y,0,0,SWP_NOSIZE|SWP_NOZORDER);
    }
    else
    {
        CenterWindow(m_hContainer,hDlg);
    }

    hListView = GetDlgItem(hDlg,IDC_COLUMNS_LISTVIEW);

    ListView_SetExtendedListViewStyleEx(hListView,
                                        LVS_EX_CHECKBOXES,LVS_EX_CHECKBOXES);

    lvColumn.mask	= LVCF_WIDTH;
    lvColumn.cx		= 180;
    ListView_InsertColumn(hListView,0,&lvColumn);

    m_pActiveShellBrowser->ExportCurrentColumns(&pActiveColumnList);

    /* MUST set this beforehand. If it is 1 while items are
    been inserted, their checkbox may not appear and the
    dialog may appear corrupted. */
    g_nChecked = 0;

    for(itr = pActiveColumnList.begin(); itr != pActiveColumnList.end(); itr++)
    {
        LoadString(g_hLanguageModule,LookupColumnNameStringIndex(itr->id),
                   szText,SIZEOF_ARRAY(szText));

        lvItem.mask		= LVIF_TEXT | LVIF_PARAM;
        lvItem.iItem	= iItem;
        lvItem.iSubItem	= 0;
        lvItem.pszText	= szText;
        lvItem.lParam	= itr->id;

        ListView_InsertItem(hListView,&lvItem);

        ListView_SetCheckState(hListView,iItem,itr->bChecked);

        iItem++;
    }

    g_nChecked = 0;

    for(itr = pActiveColumnList.begin(); itr != pActiveColumnList.end(); itr++)
    {
        if(itr->bChecked)
            g_nChecked++;
    }

    g_bColumnsSwapped = FALSE;

    ListView_SelectItem(hListView,0,TRUE);
    SetFocus(hListView);
}