1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#ifndef ENV_SHELL_H
#define ENV_SHELL_H
#include "env.h"
#include <QFileInfo>
#include <QPoint>
namespace env
{
class ShellMenu
{
public:
ShellMenu(QMainWindow* mw);
// noncopyable
ShellMenu(const ShellMenu&) = delete;
ShellMenu& operator=(const ShellMenu&) = delete;
ShellMenu(ShellMenu&&) = default;
ShellMenu& operator=(ShellMenu&&) = default;
void addFile(QFileInfo fi);
int fileCount() const;
void exec(const QPoint& pos);
HMENU getMenu();
bool wndProc(HWND hwnd, UINT m, WPARAM wp, LPARAM lp, LRESULT* out);
void invoke(const QPoint& p, int cmd);
private:
QMainWindow* m_mw;
std::vector<QFileInfo> m_files;
COMPtr<IContextMenu> m_cm;
COMPtr<IContextMenu2> m_cm2;
COMPtr<IContextMenu3> m_cm3;
HMenuPtr m_menu;
void create();
std::vector<LPCITEMIDLIST> createIdls(const std::vector<QFileInfo>& files);
COMPtr<IShellItemArray> createItemArray(std::vector<LPCITEMIDLIST>& idls);
void createContextMenu(IShellItemArray* array);
void createPopupMenu(IContextMenu* cm);
COMPtr<IShellItem> createShellItem(const std::wstring& path);
COMPtr<IPersistIDList> getPersistIDList(IShellItem* item);
CoTaskMemPtr<LPITEMIDLIST> getIDList(IPersistIDList* pidlist);
HMenuPtr createDummyMenu(const QString& what);
void onMenuSelect(HWND hwnd, HMENU hmenu, int item, HMENU hmenuPopup, UINT flags);
};
class ShellMenuCollection
{
public:
ShellMenuCollection(QMainWindow* mw);
void addDetails(QString s);
void add(QString name, ShellMenu m);
void exec(const QPoint& pos);
private:
struct MenuInfo
{
QString name;
ShellMenu menu;
};
QMainWindow* m_mw;
std::vector<QString> m_details;
std::vector<MenuInfo> m_menus;
MenuInfo* m_active;
bool wndProc(HWND hwnd, UINT m, WPARAM wp, LPARAM lp, LRESULT* out);
void onMenuSelect(HWND hwnd, HMENU hmenu, int item, HMENU hmenuPopup, UINT flags);
};
} // namespace env
#endif // ENV_SHELL_H
|