Exemplo n.º 1
0
/*
 * TextInputSetText:  Set the contents of the text input box to the given string.
 *   If focus is True, set focus to text input box.
 */
void TextInputSetText(char *text, Bool focus)
{
   int len;

   ComboBox_SetText(hwndInput, text);
   len = ComboBox_GetTextLength(hwndInput);

   if (focus)
      SetFocus(hwndInput);

   ComboBox_SetEditSel(hwndInput, len, len);  // Move caret to end of text
}
Exemplo n.º 2
0
void CSearchDialog::SaveEntry(int comboBoxId, boost::circular_buffer<std::wstring> &buffer)
{
	TCHAR entry[MAX_PATH];
	GetDlgItemText(m_hDlg, comboBoxId, entry, SIZEOF_ARRAY(entry));

	std::wstring strEntry(entry);
	auto itr = std::find_if(buffer.begin(), buffer.end(),
		[strEntry] (const std::wstring Pattern)
	{
		return Pattern.compare(strEntry) == 0;
	});

	HWND hComboBox = GetDlgItem(m_hDlg, comboBoxId);
	ComboBox_SetCurSel(hComboBox, -1);

	if(itr != buffer.end())
	{
		/* Remove the current element from both the list and the
		combo box. It will be reinserted at the front of both below. */
		auto index = std::distance(buffer.begin(), itr);
		SendMessage(hComboBox, CB_DELETESTRING, index, 0);

		buffer.erase(itr);
	}

	buffer.push_front(entry);

	SendMessage(hComboBox, CB_INSERTSTRING, 0, reinterpret_cast<LPARAM>(entry));
	ComboBox_SetCurSel(hComboBox, 0);
	ComboBox_SetEditSel(hComboBox, -1, -1);

	if(ComboBox_GetCount(hComboBox) > buffer.capacity())
	{
		SendMessage(hComboBox, CB_DELETESTRING, ComboBox_GetCount(hComboBox) - 1, 0);
	}
}
BOOL CALLBACK playlists_dropdown::SortDialogProc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp) {
	switch (msg)
	{
	case WM_INITDIALOG:
		{
			uSetWindowLong(wnd, DWL_USER, lp);
			HWND hCombo = uGetDlgItem(wnd, IDC_SORT_STRING);
			cfg::sort_string.setup_dropdown(hCombo);
			if (!cfg::sort_string.is_empty()) {
				ComboBox_SetCurSel(hCombo, 0);
				ComboBox_SetEditSel(hCombo, 0, -1);
			}
			SetFocus(hCombo);
		}
		return 1;

	case WM_CONTEXTMENU:
		{
			const HWND source = (HWND) wp;
			if (source != NULL && source == GetDlgItem(wnd, IDC_SORT_STRING)) {
				cfg::sort_string.on_context(source, lp);
				return TRUE;
			}
		}
		break;

	case WM_COMMAND:
		switch (wp)
		{
		case IDOK:
			{
				uGetDlgItemText(wnd, IDC_SORT_STRING, *reinterpret_cast< pfc::string_base * >(uGetWindowLong(wnd, DWL_USER)));
				pfc::string8 pattern;
				if (uGetDlgItemText(wnd, IDC_SORT_STRING, pattern)) {
					cfg::sort_string.add_item(pattern);
				}
				EndDialog(wnd, 1);
			}
			break;

		case IDCANCEL:
			EndDialog(wnd, 0);
			break;

		case IDC_FIELDS:
			{
				HMENU menu = CreatePopupMenu();
				uAppendMenu(menu, MF_STRING | MF_GRAYED | MF_DISABLED, 0, "Copy to clipboard:");
				uAppendMenu(menu, MF_SEPARATOR, 0, 0);
				for (int i = 1; i < tabsize(g_fields_list); i++) {
					if (!g_fields_list[i].label) break; // Only basic fields
					uAppendMenu(menu, MF_STRING, i, g_fields_list[i].label);
				}
				RECT rc;
				GetWindowRect(GetDlgItem(wnd, IDC_FIELDS), &rc);
				int cmd = TrackPopupMenu(menu, TPM_NONOTIFY | TPM_RETURNCMD, rc.left, rc.bottom, 0, GetDlgItem(wnd, IDC_FIELDS), 0);
				DestroyMenu(menu);
				if (cmd >= 0 && cmd < tabsize(g_fields_list) && !!g_fields_list[cmd].label) {
					uSetClipboardString(g_fields_list[cmd].label);
				}
			}
			break;
		}
		break;

	case WM_CLOSE:
		EndDialog(wnd, 0);
		break;
	}
	return 0;
}
Exemplo n.º 4
0
INT_PTR CALLBACK PhpChoiceDlgProc(
    _In_ HWND hwndDlg,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam
    )
{
    switch (uMsg)
    {
    case WM_INITDIALOG:
        {
            PCHOICE_DIALOG_CONTEXT context = (PCHOICE_DIALOG_CONTEXT)lParam;
            ULONG type;
            SIZE_T i;
            HWND comboBoxHandle;
            HWND checkBoxHandle;
            RECT checkBoxRect;
            RECT rect;
            ULONG diff;

            SetProp(hwndDlg, PhMakeContextAtom(), (HANDLE)context);
            PhCenterWindow(hwndDlg, GetParent(hwndDlg));

            SetWindowText(hwndDlg, context->Title);
            SetWindowText(GetDlgItem(hwndDlg, IDC_MESSAGE), context->Message);

            type = context->Flags & PH_CHOICE_DIALOG_TYPE_MASK;

            // Select the control to show, depending on the type. This is
            // because it is impossible to change the style of the combo box
            // after it is created.
            switch (type)
            {
            case PH_CHOICE_DIALOG_USER_CHOICE:
                comboBoxHandle = GetDlgItem(hwndDlg, IDC_CHOICEUSER);
                ShowWindow(GetDlgItem(hwndDlg, IDC_CHOICEUSER), SW_SHOW);
                break;
            case PH_CHOICE_DIALOG_PASSWORD:
                comboBoxHandle = GetDlgItem(hwndDlg, IDC_CHOICESIMPLE);
                ShowWindow(GetDlgItem(hwndDlg, IDC_CHOICESIMPLE), SW_SHOW);

                // Disable combo box features since it isn't a combo box.
                context->SavedChoicesSettingName = NULL;
                break;
            case PH_CHOICE_DIALOG_CHOICE:
            default:
                comboBoxHandle = GetDlgItem(hwndDlg, IDC_CHOICE);
                ShowWindow(GetDlgItem(hwndDlg, IDC_CHOICE), SW_SHOW);
                break;
            }

            context->ComboBoxHandle = comboBoxHandle;

            checkBoxHandle = GetDlgItem(hwndDlg, IDC_OPTION);

            if (type == PH_CHOICE_DIALOG_PASSWORD)
            {
                // Nothing
            }
            else if (type == PH_CHOICE_DIALOG_USER_CHOICE && context->SavedChoicesSettingName)
            {
                PPH_STRING savedChoices = PhGetStringSetting(context->SavedChoicesSettingName);
                ULONG_PTR indexOfDelim;
                PPH_STRING savedChoice;

                i = 0;

                // Split the saved choices using the delimiter.
                while (i < savedChoices->Length / 2)
                {
                    // BUG BUG BUG - what if the user saves "\s"?
                    indexOfDelim = PhFindStringInString(savedChoices, i, L"\\s");

                    if (indexOfDelim == -1)
                        indexOfDelim = savedChoices->Length / 2;

                    savedChoice = PhSubstring(savedChoices, i, indexOfDelim - i);

                    if (savedChoice->Length != 0)
                    {
                        PPH_STRING unescaped;

                        unescaped = PhUnescapeStringForDelimiter(savedChoice, '\\');
                        ComboBox_InsertString(comboBoxHandle, -1, unescaped->Buffer);
                        PhDereferenceObject(unescaped);
                    }

                    PhDereferenceObject(savedChoice);

                    i = indexOfDelim + 2;
                }

                PhDereferenceObject(savedChoices);
            }
            else
            {
                for (i = 0; i < context->NumberOfChoices; i++)
                {
                    ComboBox_AddString(comboBoxHandle, context->Choices[i]);
                }

                context->SavedChoicesSettingName = NULL; // make sure we don't try to save the choices
            }

            if (type == PH_CHOICE_DIALOG_PASSWORD)
            {
                if (*context->SelectedChoice)
                    SetWindowText(comboBoxHandle, (*context->SelectedChoice)->Buffer);

                Edit_SetSel(comboBoxHandle, 0, -1);
            }
            else if (type == PH_CHOICE_DIALOG_USER_CHOICE || type == PH_CHOICE_DIALOG_CHOICE)
            {
                // If we failed to choose a default choice based on what was specified,
                // select the first one if possible, or set the text directly.
                if (!(*context->SelectedChoice) || PhSelectComboBoxString(
                    comboBoxHandle, (*context->SelectedChoice)->Buffer, FALSE) == CB_ERR)
                {
                    if (type == PH_CHOICE_DIALOG_USER_CHOICE && *context->SelectedChoice)
                    {
                        SetWindowText(comboBoxHandle, (*context->SelectedChoice)->Buffer);
                    }
                    else if (type == PH_CHOICE_DIALOG_CHOICE && context->NumberOfChoices != 0)
                    {
                        ComboBox_SetCurSel(comboBoxHandle, 0);
                    }
                }

                if (type == PH_CHOICE_DIALOG_USER_CHOICE)
                    ComboBox_SetEditSel(comboBoxHandle, 0, -1);
            }

            if (context->Option)
            {
                SetWindowText(checkBoxHandle, context->Option);

                if (context->SelectedOption)
                    Button_SetCheck(checkBoxHandle, *context->SelectedOption ? BST_CHECKED : BST_UNCHECKED);
            }
            else
            {
                // Hide the check box and move the buttons up.

                ShowWindow(checkBoxHandle, SW_HIDE);
                GetWindowRect(checkBoxHandle, &checkBoxRect);
                MapWindowPoints(NULL, hwndDlg, (POINT *)&checkBoxRect, 2);
                GetWindowRect(GetDlgItem(hwndDlg, IDOK), &rect);
                MapWindowPoints(NULL, hwndDlg, (POINT *)&rect, 2);
                diff = rect.top - checkBoxRect.top;

                // OK
                rect.top -= diff;
                rect.bottom -= diff;
                SetWindowPos(GetDlgItem(hwndDlg, IDOK), NULL, rect.left, rect.top,
                    rect.right - rect.left, rect.bottom - rect.top,
                    SWP_NOACTIVATE | SWP_NOZORDER);

                // Cancel
                GetWindowRect(GetDlgItem(hwndDlg, IDCANCEL), &rect);
                MapWindowPoints(NULL, hwndDlg, (POINT *)&rect, 2);
                rect.top -= diff;
                rect.bottom -= diff;
                SetWindowPos(GetDlgItem(hwndDlg, IDCANCEL), NULL, rect.left, rect.top,
                    rect.right - rect.left, rect.bottom - rect.top,
                    SWP_NOACTIVATE | SWP_NOZORDER);

                // Window
                GetWindowRect(hwndDlg, &rect);
                rect.bottom -= diff;
                SetWindowPos(hwndDlg, NULL, rect.left, rect.top,
                    rect.right - rect.left, rect.bottom - rect.top,
                    SWP_NOACTIVATE | SWP_NOZORDER);
            }

            SendMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM)comboBoxHandle, TRUE);
        }
        break;
    case WM_DESTROY:
        {
            RemoveProp(hwndDlg, PhMakeContextAtom());
        }
        break;
    case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
            case IDCANCEL:
                EndDialog(hwndDlg, IDCANCEL);
                break;
            case IDOK:
                {
                    PCHOICE_DIALOG_CONTEXT context = (PCHOICE_DIALOG_CONTEXT)GetProp(hwndDlg, PhMakeContextAtom());
                    PPH_STRING selectedChoice;

                    if ((context->Flags & PH_CHOICE_DIALOG_TYPE_MASK) != PH_CHOICE_DIALOG_PASSWORD)
                    {
                        selectedChoice = PH_AUTO(PhGetWindowText(context->ComboBoxHandle));
                        *context->SelectedChoice = selectedChoice;
                    }
                    else
                    {
                        // Password values are never auto-dereferenced.
                        selectedChoice = PhGetWindowText(context->ComboBoxHandle);
                        *context->SelectedChoice = selectedChoice;
                    }

                    if (context->Option && context->SelectedOption)
                        *context->SelectedOption = Button_GetCheck(GetDlgItem(hwndDlg, IDC_OPTION)) == BST_CHECKED;

                    if (context->SavedChoicesSettingName)
                    {
                        PH_STRING_BUILDER savedChoices;
                        ULONG i;
                        ULONG choicesToSave = PH_CHOICE_DIALOG_SAVED_CHOICES;
                        PPH_STRING choice;
                        PPH_STRING escaped;

                        PhInitializeStringBuilder(&savedChoices, 100);

                        // Push the selected choice to the top, then save the others.

                        if (selectedChoice->Length != 0)
                        {
                            escaped = PhEscapeStringForDelimiter(selectedChoice, '\\');
                            PhAppendStringBuilder(&savedChoices, &escaped->sr);
                            PhDereferenceObject(escaped);
                            PhAppendStringBuilder2(&savedChoices, L"\\s");
                        }

                        for (i = 1; i < choicesToSave; i++)
                        {
                            choice = PhGetComboBoxString(context->ComboBoxHandle, i - 1);

                            if (!choice)
                                break;

                            // Don't save the choice if it's the same as the one
                            // entered by the user (since we already saved it above).
                            if (PhEqualString(choice, selectedChoice, FALSE))
                            {
                                PhDereferenceObject(choice);
                                choicesToSave++; // useless for now, but may be needed in the future
                                continue;
                            }

                            escaped = PhEscapeStringForDelimiter(choice, '\\');
                            PhAppendStringBuilder(&savedChoices, &escaped->sr);
                            PhDereferenceObject(escaped);
                            PhDereferenceObject(choice);

                            PhAppendStringBuilder2(&savedChoices, L"\\s");
                        }

                        if (PhEndsWithString2(savedChoices.String, L"\\s", FALSE))
                            PhRemoveEndStringBuilder(&savedChoices, 2);

                        PhSetStringSetting2(context->SavedChoicesSettingName, &savedChoices.String->sr);
                        PhDeleteStringBuilder(&savedChoices);
                    }

                    EndDialog(hwndDlg, IDOK);
                }
                break;
            }
        }
        break;
    }

    return FALSE;
}
Exemplo n.º 5
0
void TextInputSetFocus(Bool forward)
{
   SetFocus(hwndInput);
   ComboBox_SetEditSel(hwndInput, 0, -1);  // select all text
}
Exemplo n.º 6
0
void CSearchDialog::OnSearch()
{
	if(!m_bSearching)
	{
		ShowWindow(GetDlgItem(m_hDlg,IDC_LINK_STATUS),SW_HIDE);
		ShowWindow(GetDlgItem(m_hDlg,IDC_STATIC_STATUS),SW_SHOW);

		m_AwaitingSearchItems.clear();
		m_SearchItemsMapInternal.clear();

		ListView_DeleteAllItems(GetDlgItem(m_hDlg,IDC_LISTVIEW_SEARCHRESULTS));

		TCHAR szBaseDirectory[MAX_PATH];
		TCHAR szSearchPattern[MAX_PATH];

		/* Get the directory and name, and remove leading and
		trailing whitespace. */
		GetDlgItemText(m_hDlg,IDC_COMBO_DIRECTORY,szBaseDirectory,
			SIZEOF_ARRAY(szBaseDirectory));
		PathRemoveBlanks(szBaseDirectory);
		GetDlgItemText(m_hDlg,IDC_COMBO_NAME,szSearchPattern,
			SIZEOF_ARRAY(szSearchPattern));
		PathRemoveBlanks(szSearchPattern);

		BOOL bSearchSubFolders = IsDlgButtonChecked(m_hDlg,IDC_CHECK_SEARCHSUBFOLDERS) ==
			BST_CHECKED;

		BOOL bUseRegularExpressions = IsDlgButtonChecked(m_hDlg,IDC_CHECK_USEREGULAREXPRESSIONS) ==
			BST_CHECKED;

		BOOL bCaseInsensitive = IsDlgButtonChecked(m_hDlg,IDC_CHECK_CASEINSENSITIVE) ==
			BST_CHECKED;

		/* Turn search patterns of the form '???' into '*???*', and
		use this modified string to search. */
		if(!bUseRegularExpressions && lstrlen(szSearchPattern) > 0)
		{
			if(szSearchPattern[0] != '*' &&
				szSearchPattern[lstrlen(szSearchPattern) - 1] != '*')
			{

				TCHAR szTemp[MAX_PATH];

				StringCchPrintf(szTemp,SIZEOF_ARRAY(szTemp),_T("*%s*"),
					szSearchPattern);
				StringCchCopy(szSearchPattern,SIZEOF_ARRAY(szSearchPattern),
					szTemp);
			}
		}

		DWORD dwAttributes = 0;

		if(IsDlgButtonChecked(m_hDlg,IDC_CHECK_ARCHIVE) == BST_CHECKED)
			dwAttributes |= FILE_ATTRIBUTE_ARCHIVE;

		if(IsDlgButtonChecked(m_hDlg,IDC_CHECK_HIDDEN) == BST_CHECKED)
			dwAttributes |= FILE_ATTRIBUTE_HIDDEN;

		if(IsDlgButtonChecked(m_hDlg,IDC_CHECK_READONLY) == BST_CHECKED)
			dwAttributes |= FILE_ATTRIBUTE_READONLY;

		if(IsDlgButtonChecked(m_hDlg,IDC_CHECK_SYSTEM) == BST_CHECKED)
			dwAttributes |= FILE_ATTRIBUTE_SYSTEM;

		m_pSearch = new CSearch(m_hDlg,szBaseDirectory,szSearchPattern,
			dwAttributes,bUseRegularExpressions,bCaseInsensitive,bSearchSubFolders);
		m_pSearch->AddRef();

		/* Save the search directory and search pattern (only if they are not
		the same as the most recent entry). */
		BOOL bSaveEntry = FALSE;

		if(m_sdps->m_SearchDirectories.empty() ||
			lstrcmp(szBaseDirectory,
			m_sdps->m_SearchDirectories.begin()->c_str()) != 0)
		{
			bSaveEntry = TRUE;
		}

		if(bSaveEntry)
		{
			/* TODO: Switch to circular buffer. */
			m_sdps->m_SearchDirectories.push_front(szBaseDirectory);

			HWND hComboBox = GetDlgItem(m_hDlg,IDC_COMBO_DIRECTORY);
			SendMessage(hComboBox,CB_INSERTSTRING,0,reinterpret_cast<LPARAM>(szBaseDirectory));

			ComboBox_SetCurSel(hComboBox,0);
		}

		bSaveEntry = FALSE;

		if(m_sdps->m_pSearchPatterns->empty() ||
			lstrcmp(szSearchPattern,m_sdps->m_pSearchPatterns->begin()->c_str()) != 0)
		{
			bSaveEntry = TRUE;
		}

		if(bSaveEntry)
		{
			TCHAR szSearchPatternOriginal[MAX_PATH];
			GetDlgItemText(m_hDlg,IDC_COMBO_NAME,szSearchPatternOriginal,
				SIZEOF_ARRAY(szSearchPatternOriginal));

			std::wstring strSearchPatternOriginal(szSearchPatternOriginal);
			auto itr = std::find_if(m_sdps->m_pSearchPatterns->begin(),m_sdps->m_pSearchPatterns->end(),
				[strSearchPatternOriginal](const std::wstring Pattern){return Pattern.compare(strSearchPatternOriginal) == 0;});

			HWND hComboBox = GetDlgItem(m_hDlg,IDC_COMBO_NAME);

			ComboBox_SetCurSel(hComboBox,-1);

			/* Remove the current element from both the list and the
			combo box. It will be reinserted at the front of both below. */
			if(itr != m_sdps->m_pSearchPatterns->end())
			{
				auto index = std::distance(m_sdps->m_pSearchPatterns->begin(),itr);
				SendMessage(hComboBox,CB_DELETESTRING,index,0);

				m_sdps->m_pSearchPatterns->erase(itr);
			}

			m_sdps->m_pSearchPatterns->push_front(szSearchPatternOriginal);

			SendMessage(hComboBox,CB_INSERTSTRING,0,reinterpret_cast<LPARAM>(szSearchPatternOriginal));
			ComboBox_SetCurSel(hComboBox,0);
			ComboBox_SetEditSel(hComboBox,-1,-1);

			if(ComboBox_GetCount(hComboBox) > m_sdps->m_pSearchPatterns->capacity())
			{
				SendMessage(hComboBox,CB_DELETESTRING,ComboBox_GetCount(hComboBox) - 1,0);
			}
		}

		GetDlgItemText(m_hDlg,IDSEARCH,m_szSearchButton,SIZEOF_ARRAY(m_szSearchButton));

		TCHAR szTemp[64];

		LoadString(GetInstance(),IDS_STOP,szTemp,SIZEOF_ARRAY(szTemp));
		SetDlgItemText(m_hDlg,IDSEARCH,szTemp);

		m_bSearching = TRUE;

		/* Create a background thread, and search using it... */
		HANDLE hThread = CreateThread(NULL,0,NSearchDialog::SearchThread,
			reinterpret_cast<LPVOID>(m_pSearch),0,NULL);
		CloseHandle(hThread);
	}
	else
	{
		m_bStopSearching = TRUE;

		if(m_pSearch != NULL)
		{
			/* Note that m_pSearch does not need to be
			released here. Once the search object finishes,
			it will send a WM_APP_SEARCHFINISHED message.
			The handler for this message will then release
			m_pSearch. */
			m_pSearch->StopSearching();
		}
	}
}