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