Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Windows/W32Util/Misc.h
5793 views
1
#pragma once
2
3
#include <cstdint>
4
#include <string>
5
#include <vector>
6
7
#include "Common/CommonWindows.h"
8
9
namespace W32Util {
10
void CenterWindow(HWND hwnd);
11
bool CopyTextToClipboard(HWND hwnd, std::string_view text);
12
void MakeTopMost(HWND hwnd, bool topMost);
13
void ExitAndRestart(bool overrideArgs = false, const std::string &args = "");
14
void SpawnNewInstance(bool overrideArgs = false, const std::string &args = "");
15
bool ExecuteAndGetReturnCode(const wchar_t *executable, const wchar_t *cmdline, const wchar_t *currentDirectory, DWORD *exitCode);
16
void GetSelfExecuteParams(std::wstring &workingDirectory, std::wstring &moduleFilename);
17
18
void GetWindowRes(HWND hWnd, int *xres, int *yres);
19
void ShowFileInFolder(std::string_view path);
20
RECT GetNonclientMenuBorderRect(HWND hwnd);
21
22
struct ClipboardData {
23
ClipboardData(const char *format, size_t sz);
24
ClipboardData(UINT format, size_t sz);
25
~ClipboardData();
26
27
void Set();
28
29
operator bool() {
30
return data != nullptr;
31
}
32
33
UINT format_;
34
HANDLE handle_;
35
void *data;
36
};
37
}
38
39
struct GenericListViewColumn
40
{
41
const wchar_t *name;
42
float size;
43
int flags;
44
};
45
46
struct GenericListViewDef
47
{
48
const GenericListViewColumn* columns;
49
int columnCount;
50
int* columnOrder;
51
bool checkbox; // the first column will always have the checkbox. specify a custom order to change its position
52
};
53
54
#define GLVC_CENTERED 1
55
56
typedef struct tagNMLVCUSTOMDRAW *LPNMLVCUSTOMDRAW;
57
58
// the most significant bit states whether the key is currently down.
59
// simply checking if it's != 0 is not enough, as bit0 is set if
60
// the key was pressed between the last call to GetAsyncKeyState
61
bool KeyDownAsync(int vkey);
62
63
class GenericListControl
64
{
65
public:
66
GenericListControl(HWND hwnd, const GenericListViewDef& def);
67
virtual ~GenericListControl();
68
int HandleNotify(LPARAM lParam);
69
void Update();
70
int GetSelectedIndex();
71
HWND GetHandle() { return handle; };
72
void SetSendInvalidRows(bool enabled) { sendInvalidRows = enabled; };
73
protected:
74
void SetIconList(int w, int h, const std::vector<HICON> &icons);
75
void SetCheckState(int item, bool state);
76
void SetItemState(int item, uint8_t state);
77
78
virtual bool WindowMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT& returnValue) = 0;
79
virtual void GetColumnText(wchar_t* dest, size_t destSize, int row, int col) = 0;
80
virtual int GetRowCount() = 0;
81
virtual void OnDoubleClick(int itemIndex, int column) { };
82
virtual void OnRightClick(int itemIndex, int column, const POINT& point) { };
83
virtual void CopyRows(int start, int size);
84
virtual void OnToggle(int item, bool newValue) { };
85
86
virtual bool ListenRowPrePaint() { return false; }
87
virtual bool ListenColPrePaint() { return false; }
88
virtual bool OnRowPrePaint(int row, LPNMLVCUSTOMDRAW msg) { return false; }
89
virtual bool OnColPrePaint(int row, int col, LPNMLVCUSTOMDRAW msg) { return false; }
90
91
virtual int OnIncrementalSearch(int startRow, const wchar_t *str, bool wrap, bool partial);
92
93
private:
94
static LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
95
void ProcessUpdate();
96
void ResizeColumns();
97
void ProcessCopy();
98
void SelectAll();
99
100
HWND handle;
101
WNDPROC oldProc;
102
void *images_ = nullptr;
103
const GenericListViewColumn* columns;
104
wchar_t stringBuffer[256]; // needs to survive slightly longer than the GetColumnText scope, so needs to be here.
105
int columnCount;
106
bool valid;
107
bool sendInvalidRows;
108
// Used for hacky workaround to fix a rare hang (see issue #5184)
109
volatile bool inResizeColumns;
110
volatile bool updating;
111
bool updateScheduled_ = false;
112
113
enum class Action {
114
CHECK,
115
IMAGE,
116
};
117
struct PendingAction {
118
Action action;
119
int item;
120
int state;
121
};
122
std::vector<PendingAction> pendingActions_;
123
};
124
125