コード例 #1
0
static LRESULT CALLBACK WndProcTocTree(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    WindowInfo *win = FindWindowInfoByHwnd(hwnd);
    if (!win)
        return CallWindowProc(DefWndProcTocTree, hwnd, message, wParam, lParam);

    switch (message) {
        case WM_ERASEBKGND:
            return FALSE;
        case WM_CHAR:
            if (VK_ESCAPE == wParam && gGlobalPrefs->escToExit && MayCloseWindow(win))
                CloseWindow(win, true);
            break;
        case WM_KEYDOWN:
            // consistently expand/collapse whole (sub)trees
            if (VK_MULTIPLY == wParam && IsShiftPressed())
                TreeView_ExpandRecursively(hwnd, TreeView_GetRoot(hwnd), TVE_EXPAND);
            else if (VK_MULTIPLY == wParam)
                TreeView_ExpandRecursively(hwnd, TreeView_GetSelection(hwnd), TVE_EXPAND, true);
            else if (VK_DIVIDE == wParam && IsShiftPressed()) {
                HTREEITEM root = TreeView_GetRoot(hwnd);
                if (!TreeView_GetNextSibling(hwnd, root))
                    root = TreeView_GetChild(hwnd, root);
                TreeView_ExpandRecursively(hwnd, root, TVE_COLLAPSE);
            }
            else if (VK_DIVIDE == wParam)
                TreeView_ExpandRecursively(hwnd, TreeView_GetSelection(hwnd), TVE_COLLAPSE, true);
            else
                break;
            TreeView_EnsureVisible(hwnd, TreeView_GetSelection(hwnd));
            return 0;
        case WM_MOUSEWHEEL:
        case WM_MOUSEHWHEEL:
            // scroll the canvas if the cursor isn't over the ToC tree
            if (!IsCursorOverWindow(win->hwndTocTree))
                return SendMessage(win->hwndCanvas, message, wParam, lParam);
            break;
#ifdef DISPLAY_TOC_PAGE_NUMBERS
        case WM_SIZE:
        case WM_HSCROLL:
            // Repaint the ToC so that RelayoutTocItem is called for all items
            PostMessage(hwnd, WM_APP_REPAINT_TOC, 0, 0);
            break;
        case WM_APP_REPAINT_TOC:
            InvalidateRect(hwnd, nullptr, TRUE);
            UpdateWindow(hwnd);
            break;
#endif
    }
    return CallWindowProc(DefWndProcTocTree, hwnd, message, wParam, lParam);
}
コード例 #2
0
ファイル: AppTools.cpp プロジェクト: vipontes/sumatrapdf
// selects all text in an edit box if it's selected either
// through a keyboard shortcut or a non-selecting mouse click
// (or responds to Ctrl+Backspace as nowadays expected)
bool ExtendedEditWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    UNUSED(lParam);

    static bool delayFocus = false;

    switch (message) {
    case WM_LBUTTONDOWN:
        delayFocus = GetFocus() != hwnd;
        return true;

    case WM_LBUTTONUP:
        if (delayFocus) {
            DWORD sel = Edit_GetSel(hwnd);
            if (LOWORD(sel) == HIWORD(sel))
                PostMessage(hwnd, UWM_DELAYED_SET_FOCUS, 0, 0);
            delayFocus = false;
        }
        return true;

    case WM_KILLFOCUS:
        return false; // for easier debugging (make setting a breakpoint possible)

    case WM_SETFOCUS:
        if (!delayFocus)
            PostMessage(hwnd, UWM_DELAYED_SET_FOCUS, 0, 0);
        return true;

    case UWM_DELAYED_SET_FOCUS:
        Edit_SelectAll(hwnd);
        return true;

    case WM_KEYDOWN:
        if (VK_BACK != wParam || !IsCtrlPressed() || IsShiftPressed())
            return false;
        PostMessage(hwnd, UWM_DELAYED_CTRL_BACK, 0, 0);
        return true;

    case UWM_DELAYED_CTRL_BACK:
        {
            ScopedMem<WCHAR> text(win::GetText(hwnd));
            int selStart = LOWORD(Edit_GetSel(hwnd)), selEnd = selStart;
            // remove the rectangle produced by Ctrl+Backspace
            if (selStart > 0 && text[selStart - 1] == '\x7F') {
                memmove(text + selStart - 1, text + selStart, str::Len(text + selStart - 1) * sizeof(WCHAR));
                win::SetText(hwnd, text);
                selStart = selEnd = selStart - 1;
            }
            // remove the previous word (and any spacing after it)
            for (; selStart > 0 && str::IsWs(text[selStart - 1]); selStart--);
            for (; selStart > 0 && !str::IsWs(text[selStart - 1]); selStart--);
            Edit_SetSel(hwnd, selStart, selEnd);
            SendMessage(hwnd, WM_CLEAR, 0, 0);
        }
        return true;

    default:
        return false;
    }
}
コード例 #3
0
ファイル: TreeCtrl.cpp プロジェクト: jingyu9575/sumatrapdf
static bool HandleKey(HWND hwnd, WPARAM wp) {
    // consistently expand/collapse whole (sub)trees
    if (VK_MULTIPLY == wp && IsShiftPressed()) {
        TreeViewExpandRecursively(hwnd, TreeView_GetRoot(hwnd), TVE_EXPAND, false);
    } else if (VK_MULTIPLY == wp) {
        TreeViewExpandRecursively(hwnd, TreeView_GetSelection(hwnd), TVE_EXPAND, true);
    } else if (VK_DIVIDE == wp && IsShiftPressed()) {
        HTREEITEM root = TreeView_GetRoot(hwnd);
        if (!TreeView_GetNextSibling(hwnd, root))
            root = TreeView_GetChild(hwnd, root);
        TreeViewExpandRecursively(hwnd, root, TVE_COLLAPSE, false);
    } else if (VK_DIVIDE == wp) {
        TreeViewExpandRecursively(hwnd, TreeView_GetSelection(hwnd), TVE_COLLAPSE, true);
    } else {
        return false;
    }
    TreeView_EnsureVisible(hwnd, TreeView_GetSelection(hwnd));
    return true;
}
コード例 #4
0
ファイル: WallChangerDlg.cpp プロジェクト: tsaikd/MagicKD
// Delete Picture File and Remove from Enable List if posiable
// If Delete success, then return true
bool CWallChangerDlg::DeletePicFile(LPCTSTR sFilePath, bool bAskForSure/* = true*/)
{
	if (!PathFileExists(sFilePath))
		return false;

	bool bRes;
	if (bAskForSure)
		bRes = RemoveFileDlg(sFilePath, GetSafeHwnd(), !IsShiftPressed());
	else
		bRes = (DeleteFile(sFilePath) == TRUE);

	if (!PathFileExists(sFilePath))
		::g_pWallEnablePicList->RemoveFind(sFilePath);
	return bRes;
}
コード例 #5
0
ファイル: Favorites.cpp プロジェクト: wyrover/sumatrapdf
static LRESULT OnFavTreeNotify(WindowInfo* win, LPNMTREEVIEW pnmtv) {
    switch (pnmtv->hdr.code) {
        // TVN_SELCHANGED intentionally not implemented (mouse clicks are handled
        // in NM_CLICK, and keyboard navigation in NM_RETURN and TVN_KEYDOWN)

        case TVN_KEYDOWN: {
            TV_KEYDOWN* ptvkd = (TV_KEYDOWN*)pnmtv;
            if (VK_TAB == ptvkd->wVKey) {
                if (win->tabsVisible && IsCtrlPressed()) {
                    TabsOnCtrlTab(win, IsShiftPressed());
                } else {
                    AdvanceFocus(win);
                }
                return 1;
            }
            break;
        }

        case NM_CLICK: {
            // Determine which item has been clicked (if any)
            TVHITTESTINFO ht = {0};
            DWORD pos = GetMessagePos();
            ht.pt.x = GET_X_LPARAM(pos);
            ht.pt.y = GET_Y_LPARAM(pos);
            MapWindowPoints(HWND_DESKTOP, pnmtv->hdr.hwndFrom, &ht.pt, 1);
            TreeView_HitTest(pnmtv->hdr.hwndFrom, &ht);

            if ((ht.flags & TVHT_ONITEM)) {
                GoToFavForTVItem(win, pnmtv->hdr.hwndFrom, ht.hItem);
            }
            break;
        }

        case NM_RETURN:
            GoToFavForTVItem(win, pnmtv->hdr.hwndFrom);
            break;

        case NM_CUSTOMDRAW:
            return CDRF_DODEFAULT;
    }
    return -1;
}
コード例 #6
0
static LRESULT OnTocTreeNotify(WindowInfo *win, LPNMTREEVIEW pnmtv)
{
    switch (pnmtv->hdr.code)
    {
        case TVN_SELCHANGED:
            // When the focus is set to the toc window the first item in the treeview is automatically
            // selected and a TVN_SELCHANGEDW notification message is sent with the special code pnmtv->action == 0x00001000.
            // We have to ignore this message to prevent the current page to be changed.
            if (TVC_BYKEYBOARD == pnmtv->action || TVC_BYMOUSE == pnmtv->action)
                GoToTocLinkForTVItem(win, pnmtv->hdr.hwndFrom, pnmtv->itemNew.hItem, TVC_BYMOUSE == pnmtv->action);
            // The case pnmtv->action==TVC_UNKNOWN is ignored because
            // it corresponds to a notification sent by
            // the function TreeView_DeleteAllItems after deletion of the item.
            break;

        case TVN_KEYDOWN: {
            TV_KEYDOWN *ptvkd = (TV_KEYDOWN *)pnmtv;
            if (VK_TAB == ptvkd->wVKey) {
                if (win->tabsVisible && IsCtrlPressed())
                    TabsOnCtrlTab(win, IsShiftPressed());
                else
                    AdvanceFocus(win);
                return 1;
            }
            break;
        }
        case NM_CLICK: {
            // Determine which item has been clicked (if any)
            TVHITTESTINFO ht = { 0 };
            DWORD pos = GetMessagePos();
            ht.pt.x = GET_X_LPARAM(pos);
            ht.pt.y = GET_Y_LPARAM(pos);
            MapWindowPoints(HWND_DESKTOP, pnmtv->hdr.hwndFrom, &ht.pt, 1);
            TreeView_HitTest(pnmtv->hdr.hwndFrom, &ht);

            // let TVN_SELCHANGED handle the click, if it isn't on the already selected item
            if ((ht.flags & TVHT_ONITEM) && TreeView_GetSelection(pnmtv->hdr.hwndFrom) == ht.hItem)
                GoToTocLinkForTVItem(win, pnmtv->hdr.hwndFrom, ht.hItem);
            break;
        }
        case NM_RETURN:
            GoToTocLinkForTVItem(win, pnmtv->hdr.hwndFrom);
            break;

        case NM_CUSTOMDRAW:
#ifdef DISPLAY_TOC_PAGE_NUMBERS
            if (win->AsEbook())
                return CDRF_DODEFAULT;
            switch (((LPNMCUSTOMDRAW)pnmtv)->dwDrawStage) {
            case CDDS_PREPAINT:
                return CDRF_NOTIFYITEMDRAW;
            case CDDS_ITEMPREPAINT:
                return CDRF_DODEFAULT | CDRF_NOTIFYPOSTPAINT;
            case CDDS_ITEMPOSTPAINT:
                RelayoutTocItem((LPNMTVCUSTOMDRAW)pnmtv);
                // fall through
            default:
                return CDRF_DODEFAULT;
            }
            break;
#else
            return CDRF_DODEFAULT;
#endif

        case TVN_GETINFOTIP:
            CustomizeTocInfoTip((LPNMTVGETINFOTIP)pnmtv);
            break;
    }
    return -1;
}
コード例 #7
0
void FPhATEdPreviewViewportClient::ProcessClick(class FSceneView& View, class HHitProxy* HitProxy, FKey Key, EInputEvent Event, uint32 HitX, uint32 HitY)
{
	if( Key == EKeys::LeftMouseButton )
	{
		if (HitProxy && HitProxy->IsA(HPhATEdBoneProxy::StaticGetType()))
		{
			HPhATEdBoneProxy* BoneProxy = (HPhATEdBoneProxy*)HitProxy;

			SharedData->HitBone(BoneProxy->BodyIndex, BoneProxy->PrimType, BoneProxy->PrimIndex, IsCtrlPressed() || IsShiftPressed());
		}
		else if (HitProxy && HitProxy->IsA(HPhATEdConstraintProxy::StaticGetType()))
		{
			HPhATEdConstraintProxy* ConstraintProxy = (HPhATEdConstraintProxy*)HitProxy;

			SharedData->HitConstraint(ConstraintProxy->ConstraintIndex, IsCtrlPressed() || IsShiftPressed());
		}
		else
		{	
			HitNothing();
		}
	}
	else if( Key == EKeys::RightMouseButton )
	{
		if (HitProxy)
		{
			if (HitProxy->IsA(HPhATEdBoneProxy::StaticGetType()) && SharedData->EditingMode == FPhATSharedData::PEM_BodyEdit)
			{
				HPhATEdBoneProxy* BoneProxy = (HPhATEdBoneProxy*)HitProxy;

				bool bAlreadySelected = false;
				
				//find out if body is already selected
				for(int32 i=0; i<SharedData->SelectedBodies.Num(); ++i)
				{
					if(SharedData->SelectedBodies[i].Index == BoneProxy->BodyIndex && SharedData->SelectedBodies[i].PrimitiveType == BoneProxy->PrimType && SharedData->SelectedBodies[i].PrimitiveIndex == BoneProxy->PrimIndex)
					{
						bAlreadySelected = true;
						break;
					}
				}

				// Select body under cursor if not already selected	(if ctrl is held down we only add, not remove)
				if (!bAlreadySelected)
				{
					FPhATSharedData::FSelection Selection(BoneProxy->BodyIndex, BoneProxy->PrimType, BoneProxy->PrimIndex);
					SharedData->SetSelectedBody(&Selection, IsCtrlPressed());
				}

				// Pop up menu, if we have a body selected.
				if (SharedData->GetSelectedBody())
				{
					OpenBodyMenu();
				}
			}
			else if (HitProxy->IsA(HPhATEdConstraintProxy::StaticGetType()) && SharedData->EditingMode == FPhATSharedData::PEM_ConstraintEdit)
			{
				HPhATEdConstraintProxy* ConstraintProxy = (HPhATEdConstraintProxy*)HitProxy;

				bool bAlreadySelected = false;

				//find out if constraint is already selected
				for(int32 i=0; i<SharedData->SelectedConstraints.Num(); ++i)
				{
					if(SharedData->SelectedConstraints[i].Index == ConstraintProxy->ConstraintIndex)
					{
						bAlreadySelected = true;
						break;
					}
				}

				// Select constraint under cursor if not already selected (if ctrl is held down we only add, not remove)
				if (!bAlreadySelected)
				{
					SharedData->SetSelectedConstraint(ConstraintProxy->ConstraintIndex, IsCtrlPressed());
				}

				// Pop up menu, if we have a constraint selected.
				if (SharedData->GetSelectedConstraint())
				{
					OpenConstraintMenu();
				}
			}
		}
	}
}