Example #1
0
INT_PTR WINAPI ConEmuAbout::aboutProc(HWND hDlg, UINT messg, WPARAM wParam, LPARAM lParam)
{
	INT_PTR lRc = 0;
	if (DonateBtns_Process(hDlg, messg, wParam, lParam, lRc)
		|| EditIconHint_Process(hDlg, messg, wParam, lParam, lRc))
	{
		SetWindowLongPtr(hDlg, DWLP_MSGRESULT, lRc);
		return TRUE;
	}

	PatchMsgBoxIcon(hDlg, messg, wParam, lParam);

	switch (messg)
	{
		case WM_INITDIALOG:
		{
			gpConEmu->OnOurDialogOpened();
			mh_AboutDlg = hDlg;

			DonateBtns_Add(hDlg, pIconCtrl, IDOK);

			if (mp_DpiAware)
			{
				mp_DpiAware->Attach(hDlg, ghWnd, CDynDialog::GetDlgClass(hDlg));
			}

			RECT rect = {};
			if (GetWindowRect(hDlg, &rect))
			{
				CDpiAware::GetCenteredRect(ghWnd, rect);
				MoveWindowRect(hDlg, rect);
			}

			if ((ghOpWnd && IsWindow(ghOpWnd)) || (WS_EX_TOPMOST & GetWindowLongPtr(ghWnd, GWL_EXSTYLE)))
			{
				SetWindowPos(hDlg, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE|SWP_NOSIZE);
			}

			LPCWSTR pszActivePage = (LPCWSTR)lParam;

			wchar_t* pszTitle = lstrmerge(gpConEmu->GetDefaultTitle(), L" About");
			if (pszTitle)
			{
				SetWindowText(hDlg, pszTitle);
				SafeFree(pszTitle);
			}

			if (hClassIcon)
			{
				SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)hClassIcon);
				SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)CreateNullIcon());
				SetClassLongPtr(hDlg, GCLP_HICON, (LONG_PTR)hClassIcon);
			}

			SetDlgItemText(hDlg, stConEmuAbout, pAboutTitle);
			SetDlgItemText(hDlg, stConEmuUrl, gsHomePage);

			EditIconHint_Set(hDlg, GetDlgItem(hDlg, tAboutSearch), true, L"Search", false, UM_SEARCH, IDOK);
			EditIconHint_Subclass(hDlg);

			wchar_t* pszLabel = GetDlgItemTextPtr(hDlg, stConEmuVersion);
			if (pszLabel)
			{
				wchar_t* pszSet = NULL;

				if (gpUpd)
				{
					wchar_t* pszVerInfo = gpUpd->GetCurVerInfo();
					if (pszVerInfo)
					{
						pszSet = lstrmerge(pszLabel, L" ", pszVerInfo);
						free(pszVerInfo);
					}
				}

				if (!pszSet)
				{
					pszSet = lstrmerge(pszLabel, L" ", L"Please check for updates manually");
				}

				if (pszSet)
				{
					SetDlgItemText(hDlg, stConEmuVersion, pszSet);
					free(pszSet);
				}

				free(pszLabel);
			}

			HWND hTab = GetDlgItem(hDlg, tbAboutTabs);
			INT_PTR nPage = -1;

			for (size_t i = 0; i < countof(Pages); i++)
			{
				TCITEM tie = {};
				tie.mask = TCIF_TEXT;
				tie.pszText = (LPWSTR)Pages[i].Title;
				TabCtrl_InsertItem(hTab, i, &tie);

				if (pszActivePage && (lstrcmpi(pszActivePage, Pages[i].Title) == 0))
					nPage = i;
			}


			if (nPage >= 0)
			{
				TabSelected(hDlg, nPage);
				TabCtrl_SetCurSel(hTab, (int)nPage);
			}
			else if (!pszActivePage)
			{
				TabSelected(hDlg, 0);
			}
			else
			{
				_ASSERTE(pszActivePage==NULL && "Unknown page name?");
			}

			SetFocus(hTab);

			return FALSE;
		}

		case WM_CTLCOLORSTATIC:
			if (GetWindowLongPtr((HWND)lParam, GWLP_ID) == stConEmuUrl)
			{
				SetTextColor((HDC)wParam, GetSysColor(COLOR_HOTLIGHT));
				HBRUSH hBrush = GetSysColorBrush(COLOR_3DFACE);
				SetBkMode((HDC)wParam, TRANSPARENT);
				return (INT_PTR)hBrush;
			}
			else
			{
				SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT));
				HBRUSH hBrush = GetSysColorBrush(COLOR_3DFACE);
				SetBkMode((HDC)wParam, TRANSPARENT);
				return (INT_PTR)hBrush;
			}
			break;

		case WM_SETCURSOR:
			{
				if (GetWindowLongPtr((HWND)wParam, GWLP_ID) == stConEmuUrl)
				{
					SetCursor(LoadCursor(NULL, IDC_HAND));
					SetWindowLongPtr(hDlg, DWLP_MSGRESULT, TRUE);
					return TRUE;
				}
				return FALSE;
			}
			break;

		case WM_COMMAND:
			switch (HIWORD(wParam))
			{
			case BN_CLICKED:
				switch (LOWORD(wParam))
				{
					case IDOK:
					case IDCANCEL:
					case IDCLOSE:
						aboutProc(hDlg, WM_CLOSE, 0, 0);
						return 1;
					case stConEmuUrl:
						ConEmuAbout::OnInfo_HomePage();
						return 1;
				} // BN_CLICKED
				break;
			case EN_SETFOCUS:
				switch (LOWORD(wParam))
				{
				case tAboutText:
					{
						// Do not autosel all text
						HWND hEdit = (HWND)lParam;
						DWORD nStart = 0, nEnd = 0;
						SendMessage(hEdit, EM_GETSEL, (WPARAM)&nStart, (LPARAM)&nEnd);
						if (nStart != nEnd)
						{
							SendMessage(hEdit, EM_SETSEL, nTextSelStart, nTextSelEnd);
						}
					}
					break;
				}
			} // switch (HIWORD(wParam))
			break;

		case WM_NOTIFY:
		{
			LPNMHDR nmhdr = (LPNMHDR)lParam;
			if ((nmhdr->code == TCN_SELCHANGE) && (nmhdr->idFrom == tbAboutTabs))
			{
				int iPage = TabCtrl_GetCurSel(nmhdr->hwndFrom);
				if ((iPage >= 0) && (iPage < (int)countof(Pages)))
					TabSelected(hDlg, iPage);
			}
			break;
		}

		case UM_SEARCH:
			searchProc(hDlg, (HWND)lParam, false);
			break;

		case UM_EDIT_KILL_FOCUS:
			SendMessage((HWND)lParam, EM_GETSEL, (WPARAM)&nTextSelStart, (LPARAM)&nTextSelEnd);
			break;

		case WM_CLOSE:
			//if (ghWnd == NULL)
			gpConEmu->OnOurDialogClosed();
			if (mp_DpiAware)
				mp_DpiAware->Detach();
			EndDialog(hDlg, IDOK);
			//else
			//	DestroyWindow(hDlg);
			break;

		case WM_DESTROY:
			mh_AboutDlg = NULL;
			break;

		default:
			if (mp_DpiAware && mp_DpiAware->ProcessDpiMessages(hDlg, messg, wParam, lParam))
			{
				return TRUE;
			}
	}

	return FALSE;
}
INT_PTR WINAPI ConEmuAbout::aboutProc(HWND hDlg, UINT messg, WPARAM wParam, LPARAM lParam)
{
	static struct {LPCWSTR Title; LPCWSTR Text;} Pages[] =
	{
		{L"About", pAbout},
		{L"Command line", pCmdLine},
		{L"Tasks", pAboutTasks},
		{L"-new_console", pNewConsoleHelpFull},
		{L"Console", pConsoleHelpFull},
		{L"Macro", pGuiMacro},
		{L"DosBox", pDosBoxHelpFull},
		{L"Contributors", pAboutContributors},
		{L"License", pAboutLicense},
	};

	INT_PTR lRc = 0;
	if (DonateBtns_Process(hDlg, messg, wParam, lParam, lRc))
	{
		SetWindowLongPtr(hDlg, DWLP_MSGRESULT, lRc);
		return TRUE;
	}

	PatchMsgBoxIcon(hDlg, messg, wParam, lParam);

	switch (messg)
	{
		case WM_INITDIALOG:
		{
			gpConEmu->OnOurDialogOpened();
			mh_AboutDlg = hDlg;

			if ((ghOpWnd && IsWindow(ghOpWnd)) || (WS_EX_TOPMOST & GetWindowLongPtr(ghWnd, GWL_EXSTYLE)))
			{
				SetWindowPos(hDlg, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE|SWP_NOSIZE);
			}

			LPCWSTR pszActivePage = (LPCWSTR)lParam;

			wchar_t* pszTitle = lstrmerge(gpConEmu->GetDefaultTitle(), L" About");
			if (pszTitle)
			{
				SetWindowText(hDlg, pszTitle);
				SafeFree(pszTitle);
			}

			if (hClassIcon)
			{
				SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)hClassIcon);
				SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hClassIconSm);
				SetClassLongPtr(hDlg, GCLP_HICON, (LONG_PTR)hClassIcon);
			}

			SetDlgItemText(hDlg, stConEmuAbout, pAboutTitle);
			SetDlgItemText(hDlg, stConEmuUrl, gsHomePage);

			DonateBtns_Add(hDlg, pIconCtrl, IDOK);

			HWND hTab = GetDlgItem(hDlg, tbAboutTabs);
			size_t nPage = 0;

			for (size_t i = 0; i < countof(Pages); i++)
			{
				TCITEM tie = {};
				tie.mask = TCIF_TEXT;
				tie.pszText = (LPWSTR)Pages[i].Title;
				TabCtrl_InsertItem(hTab, i, &tie);

				if (pszActivePage && (lstrcmpi(pszActivePage, Pages[i].Title) == 0))
					nPage = i;
			}

			SetDlgItemText(hDlg, tAboutText, Pages[nPage].Text);

			if (nPage != 0)
			{
				TabCtrl_SetCurSel(hTab, (int)nPage);
			}
			else
			{
				_ASSERTE(pszActivePage==NULL && "Unknown page name?");
			}

			SetFocus(hTab);

			return FALSE;
		}

		case WM_CTLCOLORSTATIC:
			if (GetWindowLongPtr((HWND)lParam, GWLP_ID) == stConEmuUrl)
			{
				SetTextColor((HDC)wParam, GetSysColor(COLOR_HOTLIGHT));
				HBRUSH hBrush = GetSysColorBrush(COLOR_3DFACE);
				SetBkMode((HDC)wParam, TRANSPARENT);
				return (INT_PTR)hBrush;
			}
			else
			{
				SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT));
				HBRUSH hBrush = GetSysColorBrush(COLOR_3DFACE);
				SetBkMode((HDC)wParam, TRANSPARENT);
				return (INT_PTR)hBrush;
			}
			break;

		case WM_SETCURSOR:
			{
				if (GetWindowLongPtr((HWND)wParam, GWLP_ID) == stConEmuUrl)
				{
					SetCursor(LoadCursor(NULL, IDC_HAND));
					SetWindowLongPtr(hDlg, DWLP_MSGRESULT, TRUE);
					return TRUE;
				}
				return FALSE;
			}
			break;

		case WM_COMMAND:
			if (HIWORD(wParam) == BN_CLICKED)
			{
				switch (LOWORD(wParam))
				{
					case IDOK:
					case IDCANCEL:
					case IDCLOSE:
						aboutProc(hDlg, WM_CLOSE, 0, 0);
						return 1;
					case stConEmuUrl:
						ConEmuAbout::OnInfo_HomePage();
						return 1;
				}
			}
			break;

		case WM_NOTIFY:
		{
			LPNMHDR nmhdr = (LPNMHDR)lParam;
			if ((nmhdr->code == TCN_SELCHANGE) && (nmhdr->idFrom == tbAboutTabs))
			{
				int iPage = TabCtrl_GetCurSel(nmhdr->hwndFrom);
				if ((iPage >= 0) && (iPage < (int)countof(Pages)))
					SetDlgItemText(hDlg, tAboutText, Pages[iPage].Text);
			}
			break;
		}

		case WM_CLOSE:
			//if (ghWnd == NULL)
			gpConEmu->OnOurDialogClosed();
			EndDialog(hDlg, IDOK);
			//else
			//	DestroyWindow(hDlg);
			break;

		case WM_DESTROY:
			mh_AboutDlg = NULL;
			break;

		default:
			return FALSE;
	}

	return FALSE;
}