CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Windows/W32Util/ContextMenu.cpp
Views: 1401
1
// Copyright (c) 2021- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#include "Windows/W32Util/ContextMenu.h"
19
#include "Windows/resource.h"
20
21
static HMENU g_hPopupMenus;
22
23
void ContextMenuInit(HINSTANCE inst) {
24
g_hPopupMenus = LoadMenu(inst, (LPCWSTR)IDR_POPUPMENUS);
25
}
26
27
ContextPoint ContextPoint::FromCursor() {
28
ContextPoint result;
29
GetCursorPos(&result.pos_);
30
return result;
31
}
32
33
ContextPoint ContextPoint::FromClient(const POINT &clientPoint) {
34
ContextPoint result;
35
result.pos_ = clientPoint;
36
result.isClient_ = true;
37
return result;
38
}
39
40
ContextPoint ContextPoint::FromEvent(LPARAM lParam) {
41
ContextPoint result;
42
result.pos_.x = LOWORD(lParam);
43
result.pos_.y = HIWORD(lParam);
44
result.isClient_ = true;
45
return result;
46
}
47
48
HMENU GetContextMenu(ContextMenuID which) {
49
return GetSubMenu(g_hPopupMenus, (int)which);
50
}
51
52
int TriggerContextMenu(ContextMenuID which, HWND wnd, const ContextPoint &pt) {
53
POINT pos = pt.pos_;
54
if (pt.isClient_) {
55
ClientToScreen(wnd, &pos);
56
}
57
58
HMENU menu = GetContextMenu(which);
59
if (!menu)
60
return -1;
61
62
return TrackPopupMenuEx(menu, TPM_RIGHTBUTTON | TPM_RETURNCMD, pos.x, pos.y, wnd, 0);
63
}
64
65