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;
}
Пример #2
0
static LRESULT CALLBACK PluginListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WM_CHAR:
		if (wParam == '\b') {
			if (szFilter.GetLength() > 0)
				szFilter.Truncate(szFilter.GetLength() - 1);
		}
		else {
			szFilter.AppendChar(wParam);

			for (int i = 0; i < arPluginList.getCount(); i++) {
				PluginListItemData *p = arPluginList[i];
				if (!_tcsnicmp(szFilter, p->fileName, szFilter.GetLength())) {
					LVFINDINFO lvfi;
					lvfi.flags = LVFI_PARAM;
					lvfi.lParam = (LPARAM)p;
					int idx = ListView_FindItem(hwnd, 0, &lvfi);
					if (idx != -1) {
						ListView_SetItemState(hwnd, idx, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
						ListView_EnsureVisible(hwnd, idx, FALSE);
						if (timerID != 0)
							KillTimer(hwnd, timerID);
						timerID = SetTimer(hwnd, 1, 1500, 0);
						return TRUE;
					}
				}
			}

			szFilter.Truncate(szFilter.GetLength() - 1);
			MessageBeep((UINT)-1);
		}
		return TRUE;

	case WM_TIMER:
		if (wParam == 1) {
			KillTimer(hwnd, timerID);
			timerID = 0;
			szFilter.Empty();
		}
		break;

	case WM_LBUTTONDOWN:
		LVHITTESTINFO hi;
		hi.pt.x = LOWORD(lParam);
		hi.pt.y = HIWORD(lParam);
		ListView_SubItemHitTest(hwnd, &hi);
		// Dynamically load/unload a plugin
		if ((hi.iSubItem == 0) && (hi.flags & LVHT_ONITEMICON)) {
			LVITEM lvi = { 0 };
			lvi.mask = LVIF_IMAGE | LVIF_PARAM;
			lvi.stateMask = -1;
			lvi.iItem = hi.iItem;
			lvi.iSubItem = 0;
			if (ListView_GetItem(hwnd, &lvi)) {
				lvi.mask = LVIF_IMAGE;
				PluginListItemData *dat = (PluginListItemData*)lvi.lParam;
				if (lvi.iImage == 3) {
					// load plugin
					if (LoadPluginDynamically(dat)) {
						lvi.iImage = 2;
						ListView_SetItem(hwnd, &lvi);
					}
				}
				else if (lvi.iImage == 2) {
					// unload plugin
					if (UnloadPluginDynamically(dat)) {
						lvi.iImage = 3;
						ListView_SetItem(hwnd, &lvi);
					}
				}
				LoadStdPlugins();
			}
		}
	}

	return mir_callNextSubclass(hwnd, PluginListWndProc, msg, wParam, lParam);
}
Пример #3
0
void ScrollDown(LOGWIN * dat) {
	if (dat->Scroll)
		ListView_EnsureVisible(dat->hList, ListView_GetItemCount(dat->hList) - 1, FALSE);
}
Пример #4
0
static INT_PTR CALLBACK LogDlgProc(HWND hwndDlg,UINT message,WPARAM wParam,LPARAM lParam)
{
	LOGWIN *dat = (LOGWIN*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

	switch(message) {
	case WM_INITDIALOG:
		{
			dat = (LOGWIN*)lParam;

			dat->hwnd = hwndDlg;
			dat->Scroll = 1;
			dat->Paused = 0;
			dat->hList = GetDlgItem(hwndDlg, IDC_LIST);

			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
			mir_subclassWindow(dat->hList, SubclassProc);

			// init buttons
			for(int i = 0; i < SIZEOF(ctrls); i++) {
				HWND hwnd = GetDlgItem(hwndDlg,ctrls[i].control);
				SendMessage(hwnd, ctrls[i].type, 0, 0);
				SendMessage(hwnd, BM_SETIMAGE,IMAGE_ICON,(LPARAM)hIcons[i+ICON_FIRST]);
				SendMessage(hwnd, BUTTONADDTOOLTIP,(WPARAM)TranslateTS(ctrls[i].tooltip), BATF_TCHAR);
			}

			CheckDlgButton(hwndDlg, IDC_SCROLL, dat->Scroll ? BST_CHECKED : BST_UNCHECKED);
			SendDlgItemMessage(hwndDlg,IDC_SCROLL,BM_SETIMAGE,IMAGE_ICON,(LPARAM)hIcons[(dat->Scroll?ICON_SCROLL:ICON_NOSCROLL)]);

			if (gSingleMode) {
				ShowWindow(GetDlgItem(hwndDlg, IDC_PAUSEALL), SW_HIDE);
				ShowWindow(GetDlgItem(hwndDlg, IDC_STARTALL), SW_HIDE);
				ShowWindow(GetDlgItem(hwndDlg, IDC_CLOSE), SW_HIDE);
			}

			// init listview
			LVITEM lvi = {0};
			LVCOLUMN sLC;
			//ListView_SetUnicodeFormat(dat->hList, TRUE);
			ListView_SetImageList(dat->hList, gImg, LVSIL_SMALL);
			sLC.mask = LVCF_FMT | LVCF_WIDTH;
			sLC.fmt = LVCFMT_LEFT;
			sLC.cx = 630;
			ListView_InsertColumn(dat->hList, 0, &sLC);
			ListView_SetExtendedListViewStyle(dat->hList, LVS_EX_FULLROWSELECT);

			lvi.mask = LVIF_TEXT;
			if (gIcons) {
				lvi.mask |= LVIF_IMAGE;
				lvi.iImage = IMG_INFO;
			}

			lvi.pszText = TranslateT("*** Console started ***");
			ListView_InsertItem(dat->hList, &lvi);

			SendMessage(hwndDlg, WM_SIZE, 0, 0);
		}
		break;

	case HM_DUMP:
		if (!lParam) break;
		if (dat && !dat->Paused) {
			LVITEM lvi = {0};
			int last = 0x7fffffff;
			TCHAR szBreak;
			DWORD len, tmplen;
			DWORD wraplen = gWrapLen;
			TCHAR *str = ((DUMPMSG*)lParam)->szMsg;

			lvi.iItem = 0x7fffffff;

			str = _tcstok(str, _T("\n"));

			if (gIcons && str != NULL) {
				lvi.mask = LVIF_TEXT | LVIF_IMAGE;

				if (_tcsstr(str, _T("Data received"))) {
					if (gSeparator) ListView_InsertItem(dat->hList, &lvi);
					lvi.iImage = IMG_IN;
				}
				else if (_tcsstr(str, _T("Data sent"))) {
					if (gSeparator) ListView_InsertItem(dat->hList, &lvi);
					lvi.iImage = IMG_OUT;
				}
				else {
					if (gSeparator && dat->newline) {
						ListView_InsertItem(dat->hList, &lvi);
						dat->newline = 0;
					}
					lvi.iImage = IMG_INFO;
				}
			}
			else lvi.mask = LVIF_TEXT;

			while (str != NULL) {
				lvi.pszText = &str[0];
				tmplen = len = (DWORD)_tcslen(lvi.pszText);

				while(len > wraplen) {
					szBreak = lvi.pszText[wraplen];
					lvi.pszText[wraplen] = 0;
					last = ListView_InsertItem(dat->hList, &lvi);
					lvi.pszText[wraplen] = szBreak;
					len -= wraplen;
					lvi.pszText = &str[0] + tmplen - len;

					dat->newline = 1;
					lvi.iImage = IMG_EMPTY;
				}

				if (len && lvi.pszText[len-1] == '\r')
					lvi.pszText[len-1] = 0;

				last = ListView_InsertItem(dat->hList, &lvi);

				str = _tcstok(NULL, _T("\n"));

				if (str) dat->newline = 1;
				lvi.iImage = IMG_EMPTY;
			}

			if ( gVisible && dat == pActive && dat->Scroll == 1 )
				ListView_EnsureVisible(dat->hList, last, FALSE);

			if (last > gLimit) {
				int idx = last - gLimit + gLimit/4; // leave only 75% of LIMIT

				while (idx >= 0) {
					ListView_DeleteItem(dat->hList, idx);
					idx--;
				}
			}
		}

		mir_free((DUMPMSG*)lParam);
		return TRUE;

	case WM_SIZE:
		{
			UTILRESIZEDIALOG urd = { sizeof(urd) };
			urd.hInstance = hInst;
			urd.hwndDlg = hwndDlg;
			urd.lpTemplate = MAKEINTRESOURCEA(IDD_LOG);
			urd.pfnResizer = LogResize;
			SetWindowPos(hwndDlg, HWND_TOP, rcTabs.left, rcTabs.top, rcTabs.right - rcTabs.left, rcTabs.bottom - rcTabs.top, SWP_SHOWWINDOW);
			CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd);
		}
		break;

	case WM_COMMAND:
		if (!dat)
			break;

		switch(LOWORD(wParam)) {
		case IDC_PAUSE:
			{
				LVITEM lvi = {0};
				dat->Paused = !(dat->Paused);
				lvi.mask = LVIF_TEXT | LVIF_IMAGE;
				lvi.iImage = IMG_INFO;
				lvi.iItem = 0x7FFFFFFF;
				lvi.pszText = (dat->Paused) ? TranslateT("*** Console paused ***") : TranslateT("*** Console resumed ***");
				ListView_InsertItem(dat->hList, &lvi);
				CheckDlgButton(hwndDlg, IDC_PAUSE, (dat->Paused) ? BST_CHECKED : BST_UNCHECKED);
				SendDlgItemMessage(hwndDlg,IDC_PAUSE,BM_SETIMAGE,IMAGE_ICON,(LPARAM)hIcons[((dat->Paused)?ICON_PAUSED:ICON_STARTED)]);
				break;
			}
		case IDC_SCROLL:
			dat->Scroll = !(dat->Scroll);
			CheckDlgButton(hwndDlg, IDC_SCROLL, (dat->Scroll) ? BST_CHECKED : BST_UNCHECKED);
			SendDlgItemMessage(hwndDlg,IDC_SCROLL,BM_SETIMAGE,IMAGE_ICON,(LPARAM)hIcons[((dat->Scroll)?ICON_SCROLL:ICON_NOSCROLL)]);
			break;

		case IDC_COPY:
			{
				int idx = 0;
				TCHAR szText[128];
				TCHAR *src, *dst, *buf;
				int flags = LVNI_BELOW;
				int count = ListView_GetSelectedCount(dat->hList);

				if (count)
					flags |= LVNI_SELECTED;
				else
					count = ListView_GetItemCount(dat->hList);

				dst = buf = (TCHAR*)malloc((count*(sizeof(szText)+1)+1)*sizeof(TCHAR));
				if (!buf) break;

				while ((idx = ListView_GetNextItem(dat->hList, idx, flags)) > 0)
				{
					ListView_GetItemText(dat->hList, idx, 0, szText, SIZEOF(szText)-1);
					src = szText;
					while (*dst++ = *src++);
					dst--;
					*dst++ = '\r';
					*dst++ = '\n';
					*dst = 0;
				}

				if (dst - buf > 0 && OpenClipboard(hwndDlg)) {
					EmptyClipboard();
					HGLOBAL hClipboardData = GlobalAlloc(GMEM_DDESHARE, (dst-buf+1)*sizeof(TCHAR));
					if (hClipboardData) {
						TCHAR *pchData = (TCHAR*)GlobalLock(hClipboardData);
						_tcscpy(pchData, buf);
						GlobalUnlock(hClipboardData);
						SetClipboardData(CF_UNICODETEXT,hClipboardData);
					}
					CloseClipboard();
				}
				free(buf);
				break;
			}
		case IDC_DELETE:
			{
				int idx = 0;
				int count = ListView_GetSelectedCount(dat->hList);

				if ( !count ) break;

				if ( count == ListView_GetItemCount(dat->hList)) {
					LVITEM lvi = {0};
					ListView_DeleteAllItems(dat->hList);
					lvi.mask = LVIF_TEXT | LVIF_IMAGE;
					lvi.iImage = IMG_INFO;
					lvi.pszText = TranslateT("*** Console cleared ***");
					ListView_InsertItem(dat->hList, &lvi);
					dat->newline = 0;
					break;
				}

				while ((idx = ListView_GetNextItem(dat->hList, idx, LVNI_BELOW|LVNI_SELECTED)) > 0)
				{
					ListView_DeleteItem(dat->hList, idx);
					idx--;
				}
			}
			break;

		case IDC_SAVE:
			{
				TCHAR szFile[MAX_PATH];

				if (!Openfile(szFile, ListView_GetSelectedCount(dat->hList))) break;

				FILE *fp = _tfopen(szFile, _T("wt"));
				if (fp) {
					int idx = 0;
					TCHAR szText[128];
					int flags = LVNI_BELOW;
					if (ListView_GetSelectedCount(dat->hList))
						flags |= LVNI_SELECTED;

					while ((idx = ListView_GetNextItem(dat->hList, idx, flags)) > 0)
					{
						ListView_GetItemText(dat->hList, idx, 0, szText, SIZEOF(szText));
						_ftprintf(fp, _T("%s\n"), szText);
					}
					fclose(fp);
				}
				break;
			}
		case IDC_OPTIONS:
			CallServiceSync(MS_NETLIB_LOGWIN,0,0);
			break;
		case IDC_STARTALL:
			SendMessage(hwndConsole, HM_PAUSEALL, 0, 0);
			break;
		case IDC_PAUSEALL:
			SendMessage(hwndConsole, HM_PAUSEALL, 0, 1);
			break;
		case IDC_CLOSE:
			if (tabCount > 1)
				SendMessage(hwndDlg, WM_CLOSE, 0, 0);
			break;
		}
		break;

	case WM_CLOSE:
		DestroyWindow(hwndDlg);
		break;

	case WM_DESTROY:
		SendMessage(hwndConsole, HM_REMOVE, 0, (LPARAM)dat);
		break;
	}

	return FALSE;
}
Пример #5
0
static void ApplyDownloads(void *param)
{
	HWND hDlg = (HWND)param;

	//////////////////////////////////////////////////////////////////////////////////////
	// if we need to escalate priviledges, launch a atub

	if (!PrepareEscalation()) {
		DestroyWindow(hDlg);
		return;
	}

	//////////////////////////////////////////////////////////////////////////////////////
	// ok, let's unpack all zips

	AutoHandle pipe(hPipe);
	HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES);
	OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
	TCHAR tszBuff[2048], tszFileTemp[MAX_PATH], tszFileBack[MAX_PATH];

	mir_sntprintf(tszFileBack, SIZEOF(tszFileBack), _T("%s\\Backups"), tszRoot);
	SafeCreateDirectory(tszFileBack);

	mir_sntprintf(tszFileTemp, SIZEOF(tszFileTemp), _T("%s\\Temp"), tszRoot);
	SafeCreateDirectory(tszFileTemp);

	HANDLE nlc = NULL;
	for (int i=0; i < todo.getCount(); ++i) {
		ListView_EnsureVisible(hwndList, i, FALSE);
		if (!todo[i].bEnabled) {
			ListView_SetItemText(hwndList, i, 2, TranslateT("Skipped."));
			continue;
		}

		// download update
		ListView_SetItemText(hwndList, i, 2, TranslateT("Downloading..."));

		FILEURL *pFileUrl = &todo[i].File;
		if (!DownloadFile(pFileUrl->tszDownloadURL, pFileUrl->tszDiskPath, pFileUrl->CRCsum, nlc)) {
			ListView_SetItemText(hwndList, i, 2, TranslateT("Failed!"));
		}
		else
			ListView_SetItemText(hwndList, i, 2, TranslateT("Succeeded."));
	}
	Netlib_CloseHandle(nlc);

	if (todo.getCount() > 0) {
		ShowPopup(0, LPGENT("Plugin Updater"), TranslateT("Download complete"), 2, 0);

		TCHAR *tszMirandaPath = Utils_ReplaceVarsT(_T("%miranda_path%"));

		for (int i = 0; i < todo.getCount(); i++) {
			if (!todo[i].bEnabled)
				continue;

			TCHAR tszBackFile[MAX_PATH];
			FILEINFO& p = todo[i];
			if (p.bDeleteOnly) { // we need only to backup the old file
				TCHAR *ptszRelPath = p.tszNewName + _tcslen(tszMirandaPath) + 1;
				mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, ptszRelPath);
				BackupFile(p.tszNewName, tszBackFile);
				continue;
			}

			// if file name differs, we also need to backup the old file here
			// otherwise it would be replaced by unzip
			if ( _tcsicmp(p.tszOldName, p.tszNewName)) {
				TCHAR tszSrcPath[MAX_PATH];
				mir_sntprintf(tszSrcPath, SIZEOF(tszSrcPath), _T("%s\\%s"), tszMirandaPath, p.tszOldName);
				mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, p.tszOldName);
				BackupFile(tszSrcPath, tszBackFile);
			}

			if ( unzip(p.File.tszDiskPath, tszMirandaPath, tszFileBack,false))
				SafeDeleteFile(p.File.tszDiskPath);  // remove .zip after successful update
		}
	}

	PopupDataText temp;
	temp.Title = TranslateT("Plugin Updater");
	temp.Text = tszBuff;
	lstrcpyn(tszBuff, TranslateT("Download complete. Do you want to go to plugins option page?"), SIZEOF(tszBuff));
	int rc = MessageBox(hDlg, temp.Text, temp.Title, MB_YESNO | MB_ICONQUESTION);
	if (rc == IDYES)
		CallFunctionAsync(OpenPluginOptions, 0);

	CloseWindow(hDlg);
	DestroyWindow(hDlg);
	hwndDialog = NULL;
	return;
}
Пример #6
0
INT_PTR CLogger::DlgProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
	switch (uMsg) {
	case WM_INITDIALOG:
		{
			HWND hwndList=GetDlgItem(hDlg,IDC_LOG_LIST);
			LVCOLUMN lvc;
			LVITEM lvi;

			ListView_SetExtendedListViewStyle(hwndList,LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP);
			lvc.mask=LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;
			lvc.fmt=LVCFMT_LEFT;
			lvc.cx=80;
			lvc.pszText=TEXT("日時");
			ListView_InsertColumn(hwndList,0,&lvc);
			lvc.pszText=TEXT("内容");
			ListView_InsertColumn(hwndList,1,&lvc);

			lvi.iItem=0;
			lvi.mask=LVIF_TEXT;
			m_Lock.Lock();
			ListView_SetItemCount(hwndList,(int)m_LogList.size());
			for (auto itr=m_LogList.begin();itr!=m_LogList.end();++itr) {
				const CLogItem *pLogItem=*itr;
				TCHAR szTime[64];

				lvi.iSubItem=0;
				pLogItem->FormatTime(szTime,lengthof(szTime));
				lvi.pszText=szTime;
				ListView_InsertItem(hwndList,&lvi);
				lvi.iSubItem=1;
				lvi.pszText=const_cast<LPTSTR>(pLogItem->GetText());
				ListView_SetItem(hwndList,&lvi);
				lvi.iItem++;
			}
			for (int i=0;i<2;i++)
				ListView_SetColumnWidth(hwndList,i,LVSCW_AUTOSIZE_USEHEADER);
			if (!m_LogList.empty())
				ListView_EnsureVisible(hwndList,(int)m_LogList.size()-1,FALSE);
			m_Lock.Unlock();

			DlgCheckBox_Check(hDlg,IDC_LOG_OUTPUTTOFILE,m_fOutputToFile);
		}
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_LOG_CLEAR:
			ListView_DeleteAllItems(GetDlgItem(hDlg,IDC_LOG_LIST));
			Clear();
			return TRUE;

		case IDC_LOG_COPY:
			CopyToClipboard(GetAppClass().GetUICore()->GetMainWindow());
			return TRUE;

		case IDC_LOG_SAVE:
			{
				TCHAR szFileName[MAX_PATH];

				GetDefaultLogFileName(szFileName);
				if (!SaveToFile(szFileName,false)) {
					::MessageBox(hDlg,TEXT("保存ができません。"),NULL,MB_OK | MB_ICONEXCLAMATION);
				} else {
					TCHAR szMessage[MAX_PATH+64];

					StdUtil::snprintf(szMessage,lengthof(szMessage),
									  TEXT("ログを \"%s\" に保存しました。"),szFileName);
					::MessageBox(hDlg,szMessage,TEXT("ログ保存"),MB_OK | MB_ICONINFORMATION);
				}
			}
			return TRUE;
		}
		return TRUE;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->code) {
		case PSN_APPLY:
			{
				bool fOutput=DlgCheckBox_IsChecked(hDlg,IDC_LOG_OUTPUTTOFILE);

				if (fOutput!=m_fOutputToFile) {
					CBlockLock Lock(&m_Lock);

					if (fOutput && m_LogList.size()>0) {
						TCHAR szFileName[MAX_PATH];

						GetDefaultLogFileName(szFileName);
						SaveToFile(szFileName,true);
					}
					m_fOutputToFile=fOutput;

					m_fChanged=true;
				}
			}
			return TRUE;
		}
		break;
	}

	return FALSE;
}
Пример #7
0
			void ListView::Item::Show() const
			{
				ListView_EnsureVisible( control, index, false );
			}
Пример #8
0
BOOL CALLBACK RulesDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	int			i, iCount;
	char		str[256];
	static HWND	hWndList;
	LV_COLUMN	lvC;
	LV_ITEM		lvI;
	LV_DISPINFO *pItem;
	char		tempString1[256], tempString2[256];

	switch (uMsg)
	{
	case WM_INITDIALOG:
		hWndList = GetDlgItem(hDlg, IDC_LIST);
		ListView_SetExtendedListViewStyleEx(hWndList, LVS_EX_GRIDLINES, LVS_EX_GRIDLINES );
		ListView_SetExtendedListViewStyleEx(hWndList, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES  );
		lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT; 
	
		lvC.cx = 525;       
		lvC.pszText = "Rule";
		lvC.iSubItem = 0;
		lvC.fmt = LVCFMT_LEFT;
		ListView_InsertColumn(hWndList, 0, &lvC);

		PopulateRulesList(hWndList, 0);

		SendDlgItemMessage(hDlg, IDC_RULE, EM_SETLIMITTEXT, (WPARAM) 255, 0);

		if (bEnableFilter == TRUE)
			CheckRadioButton(hDlg, IDC_RADIO_FILTER, IDC_RADIO_NOFILTER, IDC_RADIO_FILTER);
		else
		{
			CheckRadioButton(hDlg, IDC_RADIO_FILTER, IDC_RADIO_NOFILTER, IDC_RADIO_NOFILTER);
			SendMessage(hDlg, WM_COMMAND, MAKEWPARAM(IDC_RADIO_NOFILTER, 0), 0);
		}
		
		RestoreWindowPosition(hDlg);

		return TRUE;



	case WM_NOTIFY: 
        switch (((LPNMHDR) lParam)->code) 
		{
        case LVN_ENDLABELEDIT:
            pItem = (LV_DISPINFO *) lParam;
			ListView_SetItemText(hWndList, pItem->item.iItem, 0, pItem->item.pszText);
            return TRUE;
		}
		break;



	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		case IDC_ADD:
			GetDlgItemText(hDlg, IDC_RULE, str, 255);
			iCount = getnumtokens(str);

			if ((iCount != 8) && (iCount != 3)) 
			{
				MessageBox(hDlg, "Incorrect number of parameters, please correct rule.", APP_NAME, MB_ICONEXCLAMATION | MB_OK);
				return TRUE;
			}
			
			lvI.mask = LVIF_TEXT;
			lvI.iSubItem = 0; 
			lvI.cchTextMax = 255;

			i = ListView_GetItemCount(hWndList);
			lvI.iItem = i;
			lvI.pszText = str;
			ListView_InsertItem(hWndList, &lvI);

			SetDlgItemText(hDlg, IDC_RULE, "");
			ListView_SetCheckState(hWndList, i, TRUE);
			ListView_EnsureVisible(hWndList, i, FALSE);
			return TRUE;


		case IDC_DELETE:
			lvI.mask = LVIF_STATE;
			lvI.stateMask =LVIS_SELECTED;
			lvI.iSubItem = 0;
			
			iCount = ListView_GetItemCount( hWndList );
			for( i = 0; i < iCount; i++ )           
			{        
				lvI.iItem = i;
				ListView_GetItem(hWndList, &lvI);
				if( lvI.state == LVIS_SELECTED )
				{
					ListView_DeleteItem(hWndList, i);
					--iCount;  --i;
				}
			}
			return TRUE;


		case IDC_CANCEL:
			SaveWindowPosition(hDlg);
			EndDialog(hDlg, FALSE);
			return TRUE;


		case IDC_SAVE:
			lvI.mask = LVIF_TEXT;
			lvI.iSubItem = 0; 
			lvI.cchTextMax = 255;

			memset(rule_text, 0, sizeof(rule_text));
			iCount = ListView_GetItemCount(hWndList);
			for (i = 0; i < iCount; i++)
			{
				lvI.iItem = i;
				lvI.pszText = rule_text[i].rule;
				ListView_GetItem(hWndList, &lvI);
				rule_text[i].bEnabled = ListView_GetCheckState(hWndList, i);
			}

			if (SendDlgItemMessage(hDlg, IDC_RADIO_FILTER, BM_GETCHECK, 0, 0) == BST_CHECKED)
				bEnableFilter = TRUE;
			else
				bEnableFilter = FALSE;

			SaveWindowPosition(hDlg);
			EndDialog(hDlg, TRUE);
			return TRUE;


		case IDC_RADIO_NOFILTER:
			EnableWindow(GetDlgItem(hDlg, IDC_ADD), FALSE);
			EnableWindow(GetDlgItem(hDlg, IDC_DELETE), FALSE);
			EnableWindow(GetDlgItem(hDlg, IDC_RULE), FALSE);
			EnableWindow(GetDlgItem(hDlg, IDC_MOVEUP), FALSE);
			EnableWindow(GetDlgItem(hDlg, IDC_MOVEDOWN), FALSE);
			EnableWindow(GetDlgItem(hDlg, IDC_DEFAULT), FALSE);
			EnableWindow(hWndList, FALSE);
			return TRUE;


		case IDC_RADIO_FILTER:
			EnableWindow(GetDlgItem(hDlg, IDC_ADD), TRUE);
			EnableWindow(GetDlgItem(hDlg, IDC_DELETE), TRUE);
			EnableWindow(GetDlgItem(hDlg, IDC_RULE), TRUE);
			EnableWindow(GetDlgItem(hDlg, IDC_MOVEUP), TRUE);
			EnableWindow(GetDlgItem(hDlg, IDC_MOVEDOWN), TRUE);
			EnableWindow(GetDlgItem(hDlg, IDC_DEFAULT), TRUE);
			EnableWindow(hWndList, TRUE);
			return TRUE;


		case IDC_MOVEUP:
			iCount = ListView_GetItemCount( hWndList );
			for( i = 1; i < iCount; i++ )           
			{        
				if( ListView_GetItemState(hWndList, i, LVIS_SELECTED) == LVIS_SELECTED )
				{
					ListView_GetItemText(hWndList, i-1, 0, tempString1, sizeof(tempString1));
					ListView_GetItemText(hWndList, i,   0, tempString2, sizeof(tempString2));
					ListView_SetItemText(hWndList, i-1, 0, tempString2);
					ListView_SetItemText(hWndList, i,   0, tempString1);

					ListView_SetItemState(hWndList, i-1, LVIS_SELECTED, LVIS_SELECTED	);
					ListView_SetItemState(hWndList, i, 0, LVIS_SELECTED);

					break;
				}
			}
			return TRUE;


		case IDC_MOVEDOWN:
			iCount = ListView_GetItemCount( hWndList );
			for( i = iCount-2; i >= 0; i-- )           
			{        
				if( ListView_GetItemState(hWndList, i, LVIS_SELECTED) == LVIS_SELECTED )
				{
					ListView_GetItemText(hWndList, i+1, 0, tempString1, sizeof(tempString1));
					ListView_GetItemText(hWndList, i,   0, tempString2, sizeof(tempString2));
					ListView_SetItemText(hWndList, i+1, 0, tempString2);
					ListView_SetItemText(hWndList, i,   0, tempString1);

					ListView_SetItemState(hWndList, i+1, LVIS_SELECTED, LVIS_SELECTED);
					ListView_SetItemState(hWndList, i, 0, LVIS_SELECTED);
					break;
				}
			}
			return TRUE;


		case IDC_DEFAULT:
			i = MessageBox(hDlg, "This action will erase existing rules.  Proceed with setting up default rules?", "Network Spy", MB_YESNO | MB_ICONWARNING);
			if (i == IDYES)
			{
				SetupDefaultRules();
				PopulateRulesList(hWndList, 0);
			}
			return TRUE;

		}
		break;

	
	case WM_CLOSE:
		SaveWindowPosition(hDlg);
		EndDialog(hDlg, 0);
		return TRUE;
	
	}
	return FALSE;
}
Пример #9
0
INT_PTR CALLBACK ChangeInfoDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	ChangeInfoData* dat = (ChangeInfoData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

	switch(msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);

		dat = new ChangeInfoData();
		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);

		dat->hwndDlg = hwndDlg;
		dat->ppro = (CIcqProto*)lParam;
		dat->hwndList = GetDlgItem(hwndDlg, IDC_LIST);

		ListView_SetExtendedListViewStyle(dat->hwndList, LVS_EX_FULLROWSELECT);
		dat->iEditItem = -1;
		{
			HFONT hFont;
			LOGFONT lf;

			dat->hListFont = (HFONT)SendMessage(dat->hwndList, WM_GETFONT, 0, 0);
			GetObject(dat->hListFont, sizeof(lf), &lf);
			lf.lfHeight -= 5;
			hFont = CreateFontIndirect(&lf);
			SendMessage(dat->hwndList, WM_SETFONT, (WPARAM)hFont, 0);
		}
		{ // Prepare ListView Columns
			LV_COLUMN lvc = {0};
			RECT rc;

			GetClientRect(dat->hwndList, &rc);
			rc.right -= GetSystemMetrics(SM_CXVSCROLL);
			lvc.mask = LVCF_WIDTH;
			lvc.cx = rc.right / 3;
			ListView_InsertColumn(dat->hwndList, 0, &lvc);
			lvc.cx = rc.right - lvc.cx;
			ListView_InsertColumn(dat->hwndList, 1, &lvc);
		}
		{ // Prepare Setting Items
			LV_ITEM lvi = {0};
			lvi.mask = LVIF_PARAM | LVIF_TEXT;

			for (lvi.iItem = 0; lvi.iItem < settingCount; lvi.iItem++) 
			{
				TCHAR text[MAX_PATH];

				lvi.lParam = lvi.iItem;
				lvi.pszText = text;
				utf8_to_tchar_static(setting[lvi.iItem].szDescription, text, SIZEOF(text));
				ListView_InsertItem(dat->hwndList, &lvi);
			}
		}

		SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
		return TRUE;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->idFrom) {
		case 0:
			switch (((LPNMHDR)lParam)->code) {
			case PSN_PARAMCHANGED:
				dat->ppro = (CIcqProto*)((PSHNOTIFY*)lParam)->lParam;
				dat->LoadSettingsFromDb(0);
				{
					char *pwd = dat->ppro->GetUserPassword(TRUE);
					strcpy(dat->Password, (pwd) ? pwd : "" ); /// FIXME
				}
				break;

			case PSN_INFOCHANGED:
				dat->LoadSettingsFromDb(1);
				break;

			case PSN_KILLACTIVE:
				dat->EndStringEdit(1);
				dat->EndListEdit(1);
				break;

			case PSN_APPLY:
				if (dat->ChangesMade()) 
				{
					if (MessageBox(hwndDlg, TranslateT("You've made some changes to your ICQ details but it has not been saved to the server. Are you sure you want to close this dialog?"), TranslateT("Change ICQ Details"), MB_YESNOCANCEL) != IDYES)
					{
						SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
						return TRUE;
					}
				}
				break;
			}
			break;

		case IDC_LIST:
			switch (((LPNMHDR)lParam)->code) {
			case LVN_GETDISPINFO:
				if (dat->iEditItem != -1) 
				{
					if (dat->editTopIndex != ListView_GetTopIndex(dat->hwndList)) 
					{
						dat->EndStringEdit(1);
						dat->EndListEdit(1);
					}
				}
				break;

			case NM_CUSTOMDRAW:
				{
					LPNMLVCUSTOMDRAW cd=(LPNMLVCUSTOMDRAW)lParam;

					switch(cd->nmcd.dwDrawStage) {
					case CDDS_PREPAINT:
						SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_NOTIFYITEMDRAW);
						return TRUE;

					case CDDS_ITEMPREPAINT:
						{
							RECT rcItem;

							if (dat->iEditItem != -1) 
							{
								if (dat->editTopIndex != ListView_GetTopIndex(dat->hwndList)) 
								{
									dat->EndStringEdit(1);
									dat->EndListEdit(1);
								}
							}

							ListView_GetItemRect(dat->hwndList, cd->nmcd.dwItemSpec, &rcItem, LVIR_BOUNDS);

							if (GetWindowLongPtr(dat->hwndList, GWL_STYLE) & WS_DISABLED)
							{  // Disabled List
								SetTextColor(cd->nmcd.hdc, cd->clrText);
								FillRect(cd->nmcd.hdc, &rcItem, GetSysColorBrush(COLOR_3DFACE));
							}
							else if ((cd->nmcd.uItemState & CDIS_SELECTED || dat->iEditItem == (int)cd->nmcd.dwItemSpec)
								&& setting[cd->nmcd.lItemlParam].displayType != LI_DIVIDER)
							{  // Selected item
								SetTextColor(cd->nmcd.hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
								FillRect(cd->nmcd.hdc, &rcItem, GetSysColorBrush(COLOR_HIGHLIGHT));
							}
							else
							{ // Unselected item
								SetTextColor(cd->nmcd.hdc, GetSysColor(COLOR_WINDOWTEXT));
								FillRect(cd->nmcd.hdc, &rcItem, GetSysColorBrush(COLOR_WINDOW));
							}

							HFONT hoFont = (HFONT)SelectObject(cd->nmcd.hdc, dat->hListFont);

							if (setting[cd->nmcd.lItemlParam].displayType == LI_DIVIDER)
							{
								RECT rcLine;
								SIZE textSize;
								char str[MAX_PATH];
								char *szText = ICQTranslateUtfStatic(setting[cd->nmcd.lItemlParam].szDescription, str, MAX_PATH);

								SetTextColor(cd->nmcd.hdc, GetSysColor(COLOR_3DSHADOW));
								DrawTextUtf(cd->nmcd.hdc, szText, &rcItem, DT_CENTER|DT_NOCLIP|DT_NOPREFIX|DT_SINGLELINE|DT_VCENTER, &textSize);
								rcLine.top = (rcItem.top + rcItem.bottom) / 2 - 1;
								rcLine.bottom = rcLine.top + 2;
								rcLine.left = rcItem.left + 3;
								rcLine.right = (rcItem.left + rcItem.right - textSize.cx) / 2 - 3;
								DrawEdge(cd->nmcd.hdc, &rcLine, BDR_SUNKENOUTER, BF_RECT);
								rcLine.left = (rcItem.left + rcItem.right + textSize.cx) / 2 + 3;
								rcLine.right = rcItem.right - 3;
								DrawEdge(cd->nmcd.hdc, &rcLine, BDR_SUNKENOUTER, BF_RECT);
							}
							else
							{
								RECT rcItemDescr, rcItemValue;
								char str[MAX_PATH];

								ListView_GetSubItemRect(dat->hwndList, cd->nmcd.dwItemSpec, 0, LVIR_BOUNDS, &rcItemDescr);
								ListView_GetSubItemRect(dat->hwndList, cd->nmcd.dwItemSpec, 1, LVIR_BOUNDS, &rcItemValue);

								rcItemDescr.right = rcItemValue.left;
								rcItemDescr.left += 2;
								DrawTextUtf(cd->nmcd.hdc, ICQTranslateUtfStatic(setting[cd->nmcd.lItemlParam].szDescription, str, MAX_PATH), &rcItemDescr, DT_END_ELLIPSIS|DT_LEFT|DT_NOCLIP|DT_NOPREFIX|DT_SINGLELINE|DT_VCENTER, NULL);

								dat->PaintItemSetting(cd->nmcd.hdc, &rcItemValue, cd->nmcd.lItemlParam, cd->nmcd.uItemState);
							}
							SelectObject(cd->nmcd.hdc, hoFont);

							SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_SKIPDEFAULT);

							return TRUE;
						}
					}
					break;
				}
			case NM_CLICK:
				{  
					LPNMLISTVIEW nm=(LPNMLISTVIEW)lParam;
					LV_ITEM lvi;
					RECT rc;

					dat->EndStringEdit(1);
					dat->EndListEdit(1);
					if (nm->iSubItem != 1) break;
					lvi.mask = LVIF_PARAM|LVIF_STATE;
					lvi.stateMask = 0xFFFFFFFF;
					lvi.iItem = nm->iItem; lvi.iSubItem = nm->iSubItem;
					ListView_GetItem(dat->hwndList, &lvi);
					if (!(lvi.state & LVIS_SELECTED)) break;
					ListView_EnsureVisible(dat->hwndList, lvi.iItem, FALSE);
					ListView_GetSubItemRect(dat->hwndList, lvi.iItem, lvi.iSubItem, LVIR_BOUNDS, &rc);
					dat->editTopIndex = ListView_GetTopIndex(dat->hwndList);
					switch (setting[lvi.lParam].displayType & LIM_TYPE) {
					case LI_STRING:
					case LI_LONGSTRING:
					case LI_NUMBER:
						dat->BeginStringEdit(nm->iItem, &rc, lvi. lParam, 0);
						break;
					case LI_LIST:
						dat->BeginListEdit(nm->iItem, &rc, lvi. lParam, 0);
						break;
					}
					break;
				}
			case LVN_KEYDOWN:
				{  
					LPNMLVKEYDOWN nm=(LPNMLVKEYDOWN)lParam;
					LV_ITEM lvi;
					RECT rc;

					dat->EndStringEdit(1);
					dat->EndListEdit(1);
					if(nm->wVKey==VK_SPACE || nm->wVKey==VK_RETURN || nm->wVKey==VK_F2) nm->wVKey=0;
					if(nm->wVKey && (nm->wVKey<'0' || (nm->wVKey>'9' && nm->wVKey<'A') || (nm->wVKey>'Z' && nm->wVKey<VK_NUMPAD0) || nm->wVKey>=VK_F1))
						break;
					lvi.mask=LVIF_PARAM|LVIF_STATE;
					lvi.stateMask=0xFFFFFFFF;
					lvi.iItem = ListView_GetNextItem(dat->hwndList, -1, LVNI_ALL|LVNI_SELECTED);
					if (lvi.iItem==-1) break;
					lvi.iSubItem=1;
					ListView_GetItem(dat->hwndList,&lvi);
					ListView_EnsureVisible(dat->hwndList,lvi.iItem,FALSE);
					ListView_GetSubItemRect(dat->hwndList,lvi.iItem,lvi.iSubItem,LVIR_BOUNDS,&rc);
					dat->editTopIndex = ListView_GetTopIndex(dat->hwndList);
					switch(setting[lvi.lParam].displayType & LIM_TYPE) {
					case LI_STRING:
					case LI_LONGSTRING:
					case LI_NUMBER:
						dat->BeginStringEdit(lvi.iItem,&rc,lvi.lParam,nm->wVKey);
						break;
					case LI_LIST:
						dat->BeginListEdit(lvi.iItem,&rc,lvi.lParam,nm->wVKey);
						break;
					}
					SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
					return TRUE;
				}
			case NM_KILLFOCUS:
				if (!IsStringEditWindow(GetFocus())) dat->EndStringEdit(1);
				if (!IsListEditWindow(GetFocus())) dat->EndListEdit(1);
				break;
			}
			break;
		}
		break;
	case WM_KILLFOCUS:
		dat->EndStringEdit(1);
		dat->EndListEdit(1);
		break;
	case WM_COMMAND:
		switch(LOWORD(wParam)) {
		case IDCANCEL:
			SendMessage(GetParent(hwndDlg), msg, wParam, lParam);
			break;

		case IDC_SAVE:
			if (!dat->SaveSettingsToDb(hwndDlg))
				break;

			EnableDlgItem(hwndDlg, IDC_SAVE, FALSE);
			EnableDlgItem(hwndDlg, IDC_LIST, FALSE);
			SetDlgItemText(hwndDlg, IDC_UPLOADING, TranslateT("Upload in progress..."));
			EnableDlgItem(hwndDlg, IDC_UPLOADING, TRUE);
			ShowDlgItem(hwndDlg, IDC_UPLOADING, SW_SHOW);
			dat->hAckHook = HookEventMessage(ME_PROTO_ACK, hwndDlg, DM_PROTOACK);

			if (!dat->UploadSettings()) 
			{
				EnableDlgItem(hwndDlg, IDC_SAVE, TRUE);
				EnableDlgItem(hwndDlg, IDC_LIST, TRUE);
				ShowDlgItem(hwndDlg, IDC_UPLOADING, SW_HIDE);
				UnhookEvent(dat->hAckHook); 
				dat->hAckHook = NULL;
			}
			break;
		}
		break;

	case WM_SIZE:
		{ // make the dlg resizeable
			UTILRESIZEDIALOG urd = {0};

			if (IsIconic(hwndDlg)) break;
			urd.cbSize = sizeof(urd);
			urd.hInstance = hInst;
			urd.hwndDlg = hwndDlg;
			urd.lParam = 0; // user-defined
			urd.lpTemplate = MAKEINTRESOURCEA(IDD_INFO_CHANGEINFO);
			urd.pfnResizer = ChangeInfoDlg_Resize;
			CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM) &urd);

			{ // update listview column widths
				RECT rc;

				GetClientRect(dat->hwndList, &rc);
				rc.right -= GetSystemMetrics(SM_CXVSCROLL);
				ListView_SetColumnWidth(dat->hwndList, 0, rc.right / 3);
				ListView_SetColumnWidth(dat->hwndList, 1, rc.right - rc.right / 3);
			}
			break;
		}

	case DM_PROTOACK:
		{
			ACKDATA *ack=(ACKDATA*)lParam;
			int i,done;

			if (ack->type != ACKTYPE_SETINFO) break;
			if (ack->result == ACKRESULT_SUCCESS)
			{
				for (i=0; i < SIZEOF(dat->hUpload); i++)
					if (dat->hUpload[i] && ack->hProcess == dat->hUpload[i]) break;

				if (i == SIZEOF(dat->hUpload)) break;
				dat->hUpload[i] = NULL;
				for (done = 0, i = 0; i < SIZEOF(dat->hUpload); i++)
					done += dat->hUpload[i] == NULL;
				TCHAR buf[MAX_PATH];
				mir_sntprintf(buf, sizeof(buf), TranslateT("Upload in progress...%d%%"), 100*done/(SIZEOF(dat->hUpload)));
				SetDlgItemText(hwndDlg, IDC_UPLOADING, buf);
				if (done < SIZEOF(dat->hUpload)) break;

				dat->ClearChangeFlags();
				UnhookEvent(dat->hAckHook); 
				dat->hAckHook = NULL;
				EnableDlgItem(hwndDlg, IDC_LIST, TRUE);
				EnableDlgItem(hwndDlg, IDC_UPLOADING, FALSE);
				SetDlgItemText(hwndDlg, IDC_UPLOADING, TranslateT("Upload complete"));
				SendMessage(GetParent(hwndDlg), PSM_FORCECHANGED, 0, 0);
			}
			else if (ack->result==ACKRESULT_FAILED)
			{
				UnhookEvent(dat->hAckHook); 
				dat->hAckHook = NULL;
				EnableDlgItem(hwndDlg, IDC_LIST, TRUE);
				EnableDlgItem(hwndDlg, IDC_UPLOADING, FALSE);
				SetDlgItemText(hwndDlg, IDC_UPLOADING, TranslateT("Upload FAILED"));
				SendMessage(GetParent(hwndDlg), PSM_FORCECHANGED, 0, 0);
				EnableDlgItem(hwndDlg, IDC_SAVE, TRUE);
			}
			break;
		}
	case WM_DESTROY:
		if (dat->hAckHook) 
		{
			UnhookEvent(dat->hAckHook);
			dat->hAckHook = NULL;
		}
		{
			HFONT hFont = (HFONT)SendMessage(dat->hwndList, WM_GETFONT, 0, 0);
			DeleteObject(hFont);
		}
		dat->FreeStoredDbSettings();
		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
		delete dat;
		break;
	}
	return FALSE;
}
Пример #10
0
static INT_PTR CALLBACK LangOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	HWND hwndList = GetDlgItem(hwndDlg, IDC_LANGLIST);
	LVITEM lvi;

	switch(msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		hwndLangOpt = hwndDlg;
		ListView_SetExtendedListViewStyle(hwndList, LVS_EX_FULLROWSELECT|LVS_EX_LABELTIP);
		ListView_SetImageList(hwndList, CreateRadioImages(ListView_GetBkColor(hwndList), ListView_GetTextColor(hwndList)), LVSIL_STATE); /* auto-destroyed */
		{	
			LVCOLUMN lvc;
			lvc.mask = LVCF_TEXT;
			lvc.pszText = TranslateT("Installed Languages");
			ListView_InsertColumn(hwndList, 0, &lvc);
		}
		if ( ServiceExists(MS_FLAGS_LOADFLAGICON))
			ListView_SetImageList(hwndList, ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR24, 8, 8), LVSIL_SMALL); 
		
		TCHAR szPath[MAX_PATH];
		GetPackPath(szPath, SIZEOF(szPath), FALSE, _T(""));
		SetDlgItemText(hwndDlg, IDC_SKINROOTFOLDER, szPath);

		SendMessage(hwndDlg, M_RELOADLIST, 0, 0);
		SendMessage(hwndDlg, M_SHOWFILECOL, 0, 1);
		return TRUE;

	case M_RELOADLIST:
		/* init list */
		ListView_DeleteAllItems(hwndList);
		ListView_DeleteColumn(hwndList, 1); /* if present */
		{
			HIMAGELIST himl = ListView_GetImageList(hwndList, LVSIL_SMALL);
			ImageList_RemoveAll(himl);
			/* enum all packs */
			EnumPacks(InsertPackItemEnumProc, _T("langpack_*.txt"), "Miranda Language Pack Version 1", (WPARAM)hwndList, (LPARAM)himl);
			/* make it use current langpack locale for sort */
			ListView_SortItems(hwndList, CompareListItem, CallService(MS_LANGPACK_GETLOCALE, 0, 0));
			//CheckDlgButton(hwndDlg, IDC_ENABLEAUTOUPDATES, db_get_b(NULL, "LangMan", "EnableAutoUpdates", SETTING_ENABLEAUTOUPDATES_DEFAULT) != 0);
			/* show selection */
			int iItem = ListView_GetNextItem(hwndList, -1, LVNI_SELECTED);
			if (iItem != -1)
				ListView_EnsureVisible(hwndList, iItem, FALSE);
		}
		return TRUE;

	case M_SHOWFILECOL:
		if ((BOOL)lParam && ListView_GetItemCount(hwndList) > 1) {
			/* add column */
			LVCOLUMN lvc;
			ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE_USEHEADER);
			lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
			lvc.pszText = TranslateT("File");
			lvc.cx = 160;
			ListView_InsertColumn(hwndList, lvc.iSubItem = 1, &lvc);
			ListView_SetColumnWidth(hwndList, 0, ListView_GetColumnWidth(hwndList, 0) - lvc.cx);

			/* add text */
			lvi.mask = LVIF_PARAM;
			lvi.iSubItem = 0;
			for (lvi.iItem = 0; ListView_GetItem(hwndList, &lvi); ++lvi.iItem) {
				LANGPACK_INFO *pack = (LANGPACK_INFO*)lvi.lParam;
				ListView_SetItemText(hwndList, lvi.iItem, 1, (pack->flags&LPF_DEFAULT) ? TranslateT("built-in") : pack->szFileName);
			}
		}
		else {
			ListView_DeleteColumn(hwndList, 1);
			ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE_USEHEADER);
		}
		return TRUE;

	case WM_DESTROY:
		ListView_DeleteAllItems(GetDlgItem(hwndDlg, IDC_LANGLIST));
		return TRUE;

	case WM_THEMECHANGED:
	case WM_SETTINGCHANGE:
		{
			HIMAGELIST himl = ListView_SetImageList(hwndList, CreateRadioImages(ListView_GetBkColor(hwndList), ListView_GetTextColor(hwndList)), LVSIL_STATE); /* auto-destroyed */
			if (himl != NULL)
				ImageList_Destroy(himl);
		}
		break;

	case WM_CTLCOLORLISTBOX: /* mimic readonly edit */
		return (BOOL)SendMessage(hwndDlg, WM_CTLCOLORSTATIC, wParam, lParam);

	case WM_COMMAND:
		switch(LOWORD(wParam)) {
		case IDC_LANGEMAIL:
			{
				char buf[512];
				lstrcpyA(buf, "mailto:");
				if (GetWindowTextA(GetDlgItem(hwndDlg, LOWORD(wParam)), &buf[7], sizeof(buf)-7))
					CallService(MS_UTILS_OPENURL, FALSE, (LPARAM)buf);
				return TRUE;
			}

		case IDC_MORELANG:
			CallService(MS_UTILS_OPENURL, TRUE, (LPARAM)"http://miranda-ng.org/");
			return TRUE;
		}
		break;

	case WM_CONTEXTMENU:
		if (GetDlgCtrlID((HWND)wParam) == IDC_LANGLIST) {
			/* get item */
			LVHITTESTINFO hti;
			POINTSTOPOINT(hti.pt, MAKEPOINTS(lParam));
			if (hti.pt.x == -1 && hti.pt.y == -1) {
				/* keyboard invoked */
				hti.iItem = ListView_GetNextItem((HWND)wParam, -1, LVNI_SELECTED);
				if (hti.iItem != -1)
					break;

				RECT rc;
				if (!ListView_GetItemRect((HWND)wParam, hti.iItem, &rc, LVIR_SELECTBOUNDS))
					break;

				hti.pt.x = rc.left + (rc.right - rc.left) / 2;
				hti.pt.y = rc.top + (rc.bottom - rc.top) / 2;
				ClientToScreen((HWND)wParam, &hti.pt);
			}
			else {
				ScreenToClient((HWND)wParam, &hti.pt);
				if (ListView_HitTest((HWND)wParam, &hti) == -1 || !(hti.flags&LVHT_ONITEM))
					break;
				POINTSTOPOINT(hti.pt, MAKEPOINTS(lParam));
			}

			/* param */
			lvi.iItem = hti.iItem;
			lvi.iSubItem = 0;
			lvi.mask = LVIF_PARAM;
			if (!ListView_GetItem((HWND)wParam, &lvi))
				break;

			/* context menu */
			LANGPACK_INFO *pack = (LANGPACK_INFO*)lvi.lParam;
			if (!(pack->flags & LPF_DEFAULT)) {
				HMENU hContextMenu = CreatePopupMenu();
				if (hContextMenu != NULL) {
					AppendMenu(hContextMenu, MF_STRING, 2, TranslateT("&Remove..."));
					if (TrackPopupMenuEx(hContextMenu, TPM_RETURNCMD | TPM_NONOTIFY | TPM_TOPALIGN | TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_HORPOSANIMATION | TPM_VERPOSANIMATION, hti.pt.x, hti.pt.y, (HWND)wParam, NULL))
						DeletePackFile(hwndDlg, (HWND)wParam, hti.iItem, pack);
					DestroyMenu(hContextMenu);
				}
			}
			return TRUE;
		}
		break;

	case WM_NOTIFYFORMAT:
		SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, NFR_UNICODE);
		return TRUE;

	case WM_NOTIFY:
		NMHDR *nmhdr = (NMHDR*)lParam;
		switch (nmhdr->idFrom) {
		case IDC_LANGLIST:
			switch (nmhdr->code) {
			case LVN_DELETEITEM:
				lvi.iItem = ((NMLISTVIEW*)lParam)->iItem; /* nmlv->lParam is invalid */
				lvi.iSubItem = 0;
				lvi.mask = LVIF_PARAM;
				if (ListView_GetItem(nmhdr->hwndFrom, &lvi))
					mir_free((LANGPACK_INFO*)lvi.lParam);
				break;

			case LVN_ITEMCHANGED:
				{
					NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
					if (!(nmlv->uChanged&LVIF_STATE))
						break;

					/* display info and check radio item */
					if (nmlv->uNewState&LVIS_SELECTED && !(nmlv->uOldState&LVIS_SELECTED)) {
						ListView_SetItemState(nmhdr->hwndFrom, nmlv->iItem, INDEXTOSTATEIMAGEMASK(2), LVIS_STATEIMAGEMASK);
						DisplayPackInfo(hwndDlg, (LANGPACK_INFO*)nmlv->lParam);
					}
					/* disable all other radio items */
					else if (nmlv->uNewState&INDEXTOSTATEIMAGEMASK(2)) {
						for (int iItem = ListView_GetItemCount(nmhdr->hwndFrom) - 1; iItem != -1; --iItem)
							if (iItem != nmlv->iItem)
								ListView_SetItemState(nmhdr->hwndFrom, iItem, INDEXTOSTATEIMAGEMASK(1), LVIS_STATEIMAGEMASK);

						/* enable apply */
						if (nmlv->uOldState) {
							SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
							ShowWindow(GetDlgItem(hwndDlg, IDC_RESTART), SW_SHOW);
						}
					}
				}
				break;

			case LVN_KEYDOWN:
				{
					int iItem = ListView_GetNextItem(nmhdr->hwndFrom, -1, LVNI_SELECTED);
					switch (((NMLVKEYDOWN*)lParam)->wVKey) {
					case VK_SPACE:
						ListView_SetItemState(nmhdr->hwndFrom, iItem, INDEXTOSTATEIMAGEMASK(2), LVIS_STATEIMAGEMASK);
						break;

					case VK_DELETE:
						lvi.iItem = iItem;
						lvi.iSubItem = 0;
						lvi.mask = LVIF_PARAM;
						if (ListView_GetItem(nmhdr->hwndFrom, &lvi)) {
							LANGPACK_INFO *pack = (LANGPACK_INFO*)lvi.lParam;
							if (!(pack->flags&LPF_DEFAULT))
								DeletePackFile(hwndDlg, nmhdr->hwndFrom, iItem, pack);
						}
						break;
					}
				}
				break;

			case NM_CLICK:
				LVHITTESTINFO hti;
				lParam = GetMessagePos();
				POINTSTOPOINT(hti.pt, MAKEPOINTS(lParam));
				ScreenToClient(nmhdr->hwndFrom, &hti.pt);
				if (ListView_HitTest(nmhdr->hwndFrom, &hti) != -1)
					if (hti.flags&(LVHT_ONITEMSTATEICON | LVHT_ONITEMICON)) /* one of them */
						ListView_SetItemState(nmhdr->hwndFrom, hti.iItem, LVIS_SELECTED, LVIS_SELECTED);
			}
			break;

		case 0:
			switch (nmhdr->code) {
			case PSN_APPLY:
				lvi.mask = LVIF_STATE | LVIF_PARAM;
				lvi.stateMask = LVIS_STATEIMAGEMASK;
				lvi.iSubItem = 0;
				for (lvi.iItem = 0; ListView_GetItem(hwndList, &lvi); ++lvi.iItem) {
					LANGPACK_INFO *pack = (LANGPACK_INFO*)lvi.lParam;
					if (lvi.state&INDEXTOSTATEIMAGEMASK(2) && !(pack->flags & LPF_ENABLED)) {
						if(!(pack->flags & LPF_DEFAULT))
							db_set_ws(NULL, "LangMan", "Langpack", pack->szFileName);
						else
							db_unset(NULL, "LangMan", "Langpack");
						TCHAR szPath[MAX_PATH];
						GetPackPath(szPath, SIZEOF(szPath), FALSE, pack->szFileName);
						CallService(MS_LANGPACK_RELOAD, 0, (LPARAM)szPath);
						pack->flags |= LPF_ENABLED;
						CloseWindow(GetParent(hwndDlg));
						DestroyWindow(GetParent(hwndDlg));
					}
					else pack->flags &= ~LPF_ENABLED;
				}
				return TRUE;
			}
		}
		break;
	}
	return FALSE;
}
Пример #11
0
inline void CListView::MakeItemVisible(size_t nItem)
{
	(void)ListView_EnsureVisible(m_hWnd, nItem, FALSE);
}
Пример #12
0
HRESULT CShellBrowser::BrowseFolder(LPCITEMIDLIST pidlDirectory,UINT wFlags)
{
	SetCursor(LoadCursor(NULL,IDC_WAIT));

	LPITEMIDLIST pidl = ILClone(pidlDirectory);

	if(m_bFolderVisited)
	{
		SaveColumnWidths();
	}

	/* The path may not be absolute, in which case it will
	need to be completed. */
	BOOL StoreHistory = TRUE;
	HRESULT hr = ParsePath(&pidl,wFlags,&StoreHistory);

	if(hr != S_OK)
	{
		SetCursor(LoadCursor(NULL,IDC_ARROW));
		return E_FAIL;
	}

	EmptyIconFinderQueue();
	EmptyThumbnailsQueue();
	EmptyColumnQueue();
	EmptyFolderQueue();

	/* TODO: Wait for any background threads to finish processing. */

	EnterCriticalSection(&m_csDirectoryAltered);
	m_FilesAdded.clear();
	m_FileSelectionList.clear();
	LeaveCriticalSection(&m_csDirectoryAltered);

	TCHAR szParsingPath[MAX_PATH];
	GetDisplayName(pidl,szParsingPath,SIZEOF_ARRAY(szParsingPath),SHGDN_FORPARSING);

	/* TODO: Method callback. */
	SendMessage(m_hOwner,WM_USER_STARTEDBROWSING,m_ID,reinterpret_cast<WPARAM>(szParsingPath));

	StringCchCopy(m_CurDir,SIZEOF_ARRAY(m_CurDir),szParsingPath);

	if(StoreHistory)
	{
		m_pPathManager->StoreIdl(pidl);
	}

	if(m_bFolderVisited)
	{
		ResetFolderMemoryAllocations();
	}

	m_nTotalItems = 0;

	BrowseVirtualFolder(pidl);

	CoTaskMemFree(pidl);

	/* Stop the list view from redrawing itself each time is inserted.
	Redrawing will be allowed once all items have being inserted.
	(reduces lag when a large number of items are going to be inserted). */
	SendMessage(m_hListView,WM_SETREDRAW,FALSE,NULL);

	ListView_DeleteAllItems(m_hListView);

	/* Window updates needs these to be set. */
	m_NumFilesSelected		= 0;
	m_NumFoldersSelected	= 0;

	m_ulTotalDirSize.QuadPart = 0;
	m_ulFileSelectionSize.QuadPart = 0;

	SetActiveColumnSet();
	SetCurrentViewModeInternal(m_ViewMode);

	InsertAwaitingItems(FALSE);

	VerifySortMode();
	SortFolder(m_SortMode);

	ListView_EnsureVisible(m_hListView,0,FALSE);

	/* Allow the listview to redraw itself once again. */
	SendMessage(m_hListView,WM_SETREDRAW,TRUE,NULL);

	m_bFolderVisited = TRUE;

	SetCursor(LoadCursor(NULL,IDC_ARROW));

	m_iUniqueFolderIndex++;

	return S_OK;
}
Пример #13
0
void HISTORY::redrawList()
{
	ListView_SetItemState(hwndHistoryList, historyCursorPos, LVIS_FOCUSED|LVIS_SELECTED, LVIS_FOCUSED|LVIS_SELECTED);
	ListView_EnsureVisible(hwndHistoryList, historyCursorPos, FALSE);
	InvalidateRect(hwndHistoryList, 0, FALSE);
}
Пример #14
0
BOOL onListChar(HWND hWnd, HWND hwndList, WORD ch)
{
	int i = 0;
	PNHMenuWindow data;
	int curIndex, topIndex, pageSize;
	boolean is_accelerator = FALSE;

	data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA);

	switch( ch ) {
	case MENU_FIRST_PAGE:
		i = 0;
		ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED);
		ListView_EnsureVisible(hwndList, i, FALSE);
	return -2;

	case MENU_LAST_PAGE:
		i = max(0, data->menu.size-1);
		ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED);
		ListView_EnsureVisible(hwndList, i, FALSE);
	return -2;

	case MENU_NEXT_PAGE:
		topIndex = ListView_GetTopIndex( hwndList );
		pageSize = ListView_GetCountPerPage( hwndList );
        curIndex = ListView_GetNextItem(hwndList, -1,	LVNI_FOCUSED);
        /* Focus down one page */
		i = min(curIndex+pageSize, data->menu.size-1);
		ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED);
        /* Scrollpos down one page */
        i = min(topIndex+(2*pageSize - 1), data->menu.size-1);
		ListView_EnsureVisible(hwndList, i, FALSE);
	return -2;

	case MENU_PREVIOUS_PAGE:
		topIndex = ListView_GetTopIndex( hwndList );
		pageSize = ListView_GetCountPerPage( hwndList );
        curIndex = ListView_GetNextItem(hwndList, -1,	LVNI_FOCUSED);
        /* Focus up one page */
		i = max(curIndex-pageSize, 0);
		ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED);
        /* Scrollpos up one page */
		i = max(topIndex-pageSize, 0);
		ListView_EnsureVisible(hwndList, i, FALSE);
	break;

	case MENU_SELECT_ALL:
		if( data->how == PICK_ANY ) {
			reset_menu_count(hwndList, data);
			for(i=0; i<data->menu.size; i++ ) {
				SelectMenuItem(hwndList, data, i, -1);
			}
			return -2;
		}
	break;

	case MENU_UNSELECT_ALL:
		if( data->how == PICK_ANY ) {
			reset_menu_count(hwndList, data);
			for(i=0; i<data->menu.size; i++ ) {
				SelectMenuItem(hwndList, data, i, 0);
			}
			return -2;
		}
	break;

	case MENU_INVERT_ALL:
		if( data->how == PICK_ANY ) {
			reset_menu_count(hwndList, data);
			for(i=0; i<data->menu.size; i++ ) {
				SelectMenuItem(
					hwndList, 
					data, 
					i, 
					NHMENU_IS_SELECTED(data->menu.items[i])? 0 : -1
				);
			}
			return -2;
		}
	break;

	case MENU_SELECT_PAGE:
		if( data->how == PICK_ANY ) {
			int from, to;
			reset_menu_count(hwndList, data);
			topIndex = ListView_GetTopIndex( hwndList );
			pageSize = ListView_GetCountPerPage( hwndList );
			from = max(0, topIndex);
			to = min(data->menu.size, from+pageSize);
			for(i=from; i<to; i++ ) {
				SelectMenuItem(hwndList, data, i, -1);
			}
			return -2;
		}
	break;

	case MENU_UNSELECT_PAGE:
		if( data->how == PICK_ANY ) {
			int from, to;
			reset_menu_count(hwndList, data);
			topIndex = ListView_GetTopIndex( hwndList );
			pageSize = ListView_GetCountPerPage( hwndList );
			from = max(0, topIndex);
			to = min(data->menu.size, from+pageSize);
			for(i=from; i<to; i++ ) {
				SelectMenuItem(hwndList, data, i, 0);
			}
			return -2;
		}
	break;

	case MENU_INVERT_PAGE:
		if( data->how == PICK_ANY ) {
			int from, to;
			reset_menu_count(hwndList, data);
			topIndex = ListView_GetTopIndex( hwndList );
			pageSize = ListView_GetCountPerPage( hwndList );
			from = max(0, topIndex);
			to = min(data->menu.size, from+pageSize);
			for(i=from; i<to; i++ ) {
				SelectMenuItem(
					hwndList, 
					data, 
					i, 
					NHMENU_IS_SELECTED(data->menu.items[i])? 0 : -1
				);
			}
			return -2;
		}
	break;

	case MENU_SEARCH:
	    if( data->how==PICK_ANY || data->how==PICK_ONE ) {
			char buf[BUFSZ];
			int  selected_item;
			
			reset_menu_count(hwndList, data);
			mswin_getlin("Search for:", buf);
			if (!*buf || *buf == '\033') return -2;
			selected_item = -1;
			for(i=0; i<data->menu.size; i++ ) {
				if( NHMENU_IS_SELECTABLE(data->menu.items[i])
					&& strstr(data->menu.items[i].str, buf) ) {
					if (data->how == PICK_ANY) {
						SelectMenuItem(
							hwndList, 
							data, 
							i, 
							NHMENU_IS_SELECTED(data->menu.items[i])? 0 : -1
						);
						/* save the first item - we will move focus to it */
						if( selected_item == -1 ) selected_item = i;
					} else if( data->how == PICK_ONE ) {
						SelectMenuItem(
							hwndList, 
							data, 
							i, 
							-1
						);
						selected_item = i;
						break;
					}
				}
			} 

			if( selected_item>0 ) {
				ListView_SetItemState(hwndList, selected_item, LVIS_FOCUSED, LVIS_FOCUSED);
				ListView_EnsureVisible(hwndList, selected_item, FALSE);
			}
		} else {
			mswin_nhbell();
	    }
	return -2;

	case ' ':
		/* ends menu for PICK_ONE/PICK_NONE
		   select item for PICK_ANY */
		if( data->how==PICK_ONE || data->how==PICK_NONE ) {
			data->done = 1;
			data->result = 0;
			return -2;
		} else if( data->how==PICK_ANY ) {
			i = ListView_GetNextItem(hwndList, -1,	LVNI_FOCUSED);
			if( i>=0 ) {
				SelectMenuItem(
					hwndList, 
					data, 
					i, 
					NHMENU_IS_SELECTED(data->menu.items[i])? 0 : -1
				);
			}
			return -2;
		}
	break;

	default:
		if( strchr(data->menu.gacc, ch) &&
			!(ch=='0' && data->menu.counting) ) {
			/* matched a group accelerator */
			if (data->how == PICK_ANY || data->how == PICK_ONE) {
				reset_menu_count(hwndList, data);
				for(i=0; i<data->menu.size; i++ ) {
					if( NHMENU_IS_SELECTABLE(data->menu.items[i]) &&
						data->menu.items[i].group_accel == ch ) {
						if( data->how == PICK_ANY ) {
							SelectMenuItem(
								hwndList, 
								data, 
								i, 
								NHMENU_IS_SELECTED(data->menu.items[i])? 0 : -1
							);
						} else if( data->how == PICK_ONE ) {
							SelectMenuItem(
								hwndList, 
								data, 
								i, 
								-1
							);
							data->result = 0;
							data->done = 1;
							return -2;
						}
					}
				}
				return -2;
			} else {
				mswin_nhbell();
				return -2;
			}
		}

		if (isdigit(ch)) {
			int count;
			i = ListView_GetNextItem(hwndList, -1,	LVNI_FOCUSED);
			if( i>=0 ) {
				count = data->menu.items[i].count;
				if( count==-1 ) count=0;
				count *= 10L;
				count += (int)(ch - '0');
				if (count != 0)	/* ignore leading zeros */ {
					data->menu.counting = TRUE;
					data->menu.items[i].count = min(100000, count);
					ListView_RedrawItems( hwndList, i, i ); /* update count mark */
				}
			}
			return -2;
		}

		is_accelerator = FALSE;
		for(i=0; i<data->menu.size; i++) {
			if( data->menu.items[i].accelerator == ch ) {
				is_accelerator = TRUE;
				break;
			}
		}

		if( (ch>='a' && ch<='z') ||
			(ch>='A' && ch<='Z') || is_accelerator) {
			if (data->how == PICK_ANY || data->how == PICK_ONE) {
				for(i=0; i<data->menu.size; i++ ) {
					if( data->menu.items[i].accelerator == ch ) {
						if( data->how == PICK_ANY ) {
							SelectMenuItem(
								hwndList, 
								data, 
								i, 
								NHMENU_IS_SELECTED(data->menu.items[i])? 0 : -1
							);
							ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED);
							ListView_EnsureVisible(hwndList, i, FALSE);
							return -2;
						} else if( data->how == PICK_ONE ) {
							SelectMenuItem(
								hwndList, 
								data, 
								i, 
								-1
							);
							data->result = 0;
							data->done = 1;
							return -2;
						}
					}
				}
			}
		}
	break;
	}

	reset_menu_count(hwndList, data);
	return -1;
}
Пример #15
0
void Searcher::Find()
{
	FINDTEXTEX ft;
	TCHAR str[128];
	int curSel = 0;
	bool isStart = false;
	bool finished = false;
	ft.chrg.cpMin = 0;
	ft.chrg.cpMax = -1;
	ft.lpstrText = str;
	if (context->currentGroup.size() < 1) {
		SendMessage(context->editWindow,EM_SETOPTIONS,ECOOP_AND,~ECO_NOHIDESEL);
		lastFindSelection = -1;
		return;
	}

	GetWindowText(context->findWindow, str, SIZEOF(str));
	if (!str[0]) {
		TCHAR buf[256];
		mir_sntprintf(buf, SIZEOF(buf), TranslateT("\"%s\" not found"), str);
		MessageBox(context->hWnd, buf, TranslateT("Search"), MB_OK | MB_ICONINFORMATION);
		return;
	}
	if (!matchCase) {
		std::locale loc;
		std::transform(str, str + _tcslen(str), str, std::bind2nd(std::ptr_fun(mytoupper), &loc));
	}
	
	bool findBack1 = findBack ^ !searchForInMes;
	bool findBack2 = findBack ^ !searchForInLG;
	int adder1 = findBack1 ? -1 : 1;
	int adder2 = findBack2 ? -1 : 1;
	WPARAM findStyle = (findBack1 ? 0 : FR_DOWN) | (matchCase ? FR_MATCHCASE : 0) | (matchWholeWords ? FR_WHOLEWORD : 0);
	if (lastFindSelection >= 0 && lastFindSelection < (int)context->currentGroup.size()) {
		if (onlyIn && context->currentGroup[lastFindSelection].isMe || onlyOut && !context->currentGroup[lastFindSelection].isMe)
			curSel = lastFindSelection + adder1;
		else {
			SendDlgItemMessage(context->hWnd,IDC_EDIT,EM_EXGETSEL,0,(LPARAM)&ft.chrg);
			if (findBack1) {
				ft.chrg.cpMin = ft.chrg.cpMin < context->currentGroup[lastFindSelection].endPos ? ft.chrg.cpMin : context->currentGroup[lastFindSelection].endPos; 
				ft.chrg.cpMax = context->currentGroup[lastFindSelection].startPos;
			}
			else {
				ft.chrg.cpMin = ft.chrg.cpMax > context->currentGroup[lastFindSelection].startPos ? ft.chrg.cpMax : context->currentGroup[lastFindSelection].startPos;
				ft.chrg.cpMax = context->currentGroup[lastFindSelection].endPos;
			}
			SendMessage(context->editWindow,EM_FINDTEXTEX, findStyle,(LPARAM)&ft);
			if (ft.chrgText.cpMin < 0 || ft.chrgText.cpMax < 0)
				curSel = lastFindSelection + adder1;
			else {
				if (isFindContactChanged && startFindContact == context->hContact && isFindSelChanged && context->selected == startFindSel && ((!findBack1 && ft.chrg.cpMin >= startFindPos) || (findBack1 && ft.chrg.cpMax <= startFindPos)))
					finished = true;
				else {
					curSel = lastFindSelection;
					SendMessage(context->editWindow,EM_EXSETSEL,0,(LPARAM)&ft.chrgText);
					SendMessage(context->editWindow,EM_SETOPTIONS,ECOOP_OR,ECO_NOHIDESEL);
					lastFindSelection = curSel;
					return;
				}
			}
		}
	}
	else {
		isStart = true;
		SendMessage(context->editWindow,EM_SETOPTIONS,ECOOP_OR,ECO_NOHIDESEL);
		SendMessage(context->editWindow,EM_EXGETSEL,0,(LPARAM)&ft.chrg);
		startFindPos = findBack1 ? ft.chrg.cpMin : (ft.chrg.cpMax >= 0 ? ft.chrg.cpMax : ft.chrg.cpMin);
		startFindSel = context->selected;
		if (startFindPos < 0)
			startFindPos = 0;
		isFindSelChanged = false;
		startFindContact = context->hContact;
		isFindContactChanged = !allUsers;
		if (findBack1) {
			for (curSel = (int)context->currentGroup.size() - 1; curSel >= 0; --curSel)
				if (context->currentGroup[curSel].startPos < startFindPos)
					break;
		}
		else
			for (; curSel < (int)context->currentGroup.size(); ++curSel)
				if (context->currentGroup[curSel].endPos > startFindPos)
					break;
	}

	if (!finished) {
		for (; curSel < (int)context->currentGroup.size() && curSel >= 0; curSel += adder1) {
			if (onlyIn && context->currentGroup[curSel].isMe || onlyOut && !context->currentGroup[curSel].isMe)
				continue;

			if (CompareStr(context->currentGroup[curSel].description, str)) {
				if (findBack1) {
					ft.chrg.cpMin = context->currentGroup[curSel].endPos;
					ft.chrg.cpMax = context->currentGroup[curSel].startPos;
					if (!isFindSelChanged && ft.chrg.cpMin > startFindPos)
						ft.chrg.cpMin = startFindPos;
				}
				else {
					ft.chrg.cpMin = context->currentGroup[curSel].startPos;
					ft.chrg.cpMax = context->currentGroup[curSel].endPos;
					if (!isFindSelChanged && ft.chrg.cpMin < startFindPos)
						ft.chrg.cpMin = startFindPos;
				}
				SendMessage(context->editWindow,EM_FINDTEXTEX, findStyle,(LPARAM)&ft);
				if (!(ft.chrgText.cpMin < 0 || ft.chrgText.cpMax < 0)) {
					if (isFindContactChanged && startFindContact == context->hContact && isFindSelChanged && context->selected == startFindSel && ((!findBack1 && ft.chrg.cpMin >= startFindPos) || (findBack1 && ft.chrg.cpMax <= startFindPos))) {
						finished = true;
						break;
					}
					SendMessage(context->editWindow,EM_EXSETSEL,0,(LPARAM)&ft.chrgText);
					SendMessage(context->editWindow,EM_SETOPTIONS,ECOOP_OR,ECO_NOHIDESEL);
					lastFindSelection = curSel;
					return;
				}
			}
		}
	}
	
	if (isFindContactChanged && startFindContact == context->hContact && isFindSelChanged && context->selected == startFindSel)
		finished = true;

	if (!finished) {
		isFindSelChanged = true;
		if (onlyGroup) {
			if (IsInSel(context->selected, str)) {
				CHARRANGE ch;
				ch.cpMin = ch.cpMax = findBack1 ? MAXLONG : 0;
				SendMessage(context->editWindow,EM_EXSETSEL,0,(LPARAM)&ch);
				lastFindSelection = findBack1 ? (int)context->currentGroup.size() - 1 : 0;
				Find();
				return;
			}
		}
		else {
			for (int sel = context->selected + adder2; ; sel += adder2) {
				if (sel < 0) {
					isFindContactChanged = true;
					if (allUsers) {
						MCONTACT hNext = context->hContact;
						do
						{
							hNext = context->GetNextContact(hNext, adder2);
						}
							while(hNext != startFindContact && !context->SearchInContact(hNext, str, this));
						context->SelectContact(hNext);
					}

					sel = (int)context->eventList.size() - 1;
				}
				else if (sel >= (int)context->eventList.size()) {
					isFindContactChanged = true;
					if (allUsers) {
						MCONTACT hNext = context->hContact;
						do
						{
							hNext = context->GetNextContact(hNext, adder2);
						}
							while(hNext != startFindContact && !context->SearchInContact(hNext, str, this));
						context->SelectContact(hNext);
					}

					sel = 0;
				}
				if (IsInSel(sel, str)) {
					LVITEM item = {0};
					item.mask = LVIF_STATE;
					item.iItem = context->selected;
					item.state = 0;
					item.stateMask = LVIS_SELECTED;
					ListView_SetItem(context->listWindow, &item);
					item.iItem = sel;
					item.state = LVIS_SELECTED;
					ListView_SetItem(context->listWindow, &item);
					ListView_EnsureVisible(context->listWindow, sel, FALSE);		
					CHARRANGE ch;
					ch.cpMin = ch.cpMax = findBack1 ? MAXLONG : 0;
					SendMessage(context->editWindow,EM_EXSETSEL,0,(LPARAM)&ch);
					SendMessage(context->editWindow,EM_SETOPTIONS,ECOOP_OR,ECO_NOHIDESEL);
					lastFindSelection = findBack1 ? (int)context->currentGroup.size() - 1 : 0;
					isFindSelChanged = true;
					Find();
					return;
				}
				if (startFindContact == context->hContact && sel == startFindSel)
					break;
			}
		}
	}
	
	if (startFindContact != context->hContact)
		context->SelectContact(startFindContact);

	if (startFindSel != context->selected) {
		LVITEM item = {0};
		item.mask = LVIF_STATE;
		item.iItem = context->selected;
		item.state = 0;
		item.stateMask = LVIS_SELECTED;
		ListView_SetItem(context->listWindow, &item);
		item.iItem = startFindSel;
		item.state = LVIS_SELECTED;
		ListView_SetItem(context->listWindow, &item);
		ListView_EnsureVisible(context->listWindow, startFindSel, FALSE);			
		context->SelectEventGroup(startFindSel);
		SendMessage(context->editWindow,EM_SETOPTIONS,ECOOP_OR,ECO_NOHIDESEL);
	}
	ft.chrgText.cpMin = startFindPos;
	ft.chrgText.cpMax = startFindPos;
	SendMessage(context->editWindow,EM_EXSETSEL,0,(LPARAM)&ft.chrgText);
	SendMessage(context->editWindow,EM_SETOPTIONS,ECOOP_AND,~ECO_NOHIDESEL);
	lastFindSelection = -1;
	if (isStart) {
		TCHAR buf[256];
		GetWindowText(context->findWindow, str, SIZEOF(str));
		mir_sntprintf(buf, SIZEOF(buf), TranslateT("\"%s\" not found"), str);
		MessageBox(context->hWnd, buf, TranslateT("Search"), MB_OK | MB_ICONINFORMATION);
	}
	else MessageBox(context->hWnd, TranslateTS(onlyGroup ? LPGENT("You have reached the end of the group.") : LPGENT("You have reached the end of the history.")), TranslateT("Search"), MB_OK | MB_ICONINFORMATION);
}