2012-11-01 16:19:01 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2022-02-05 19:00:31 -08:00
|
|
|
#include <cstdint>
|
2018-03-22 22:14:19 +01:00
|
|
|
#include <string>
|
2022-02-05 19:00:31 -08:00
|
|
|
#include <vector>
|
2023-08-24 13:04:41 +02:00
|
|
|
|
2013-07-28 21:01:49 -07:00
|
|
|
#include "Common/CommonWindows.h"
|
2012-11-17 22:44:29 +00:00
|
|
|
|
2012-11-01 16:19:01 +01:00
|
|
|
namespace W32Util
|
|
|
|
|
{
|
|
|
|
|
void CenterWindow(HWND hwnd);
|
2013-08-26 19:00:16 +02:00
|
|
|
BOOL CopyTextToClipboard(HWND hwnd, const char *text);
|
2014-02-08 23:58:17 -08:00
|
|
|
BOOL CopyTextToClipboard(HWND hwnd, const std::wstring &wtext);
|
2013-06-10 23:45:12 +02:00
|
|
|
void MakeTopMost(HWND hwnd, bool topMost);
|
2020-05-09 13:52:04 -07:00
|
|
|
void ExitAndRestart(bool overrideArgs = false, const std::string &args = "");
|
2020-07-20 23:25:34 +02:00
|
|
|
void SpawnNewInstance(bool overrideArgs = false, const std::string &args = "");
|
2020-01-04 09:02:10 -08:00
|
|
|
void GetSelfExecuteParams(std::wstring &workingDirectory, std::wstring &moduleFilename);
|
2022-09-24 11:43:52 -07:00
|
|
|
|
2023-08-10 10:28:25 +02:00
|
|
|
void GetWindowRes(HWND hWnd, int *xres, int *yres);
|
2023-08-24 13:04:41 +02:00
|
|
|
void ShowFileInFolder(const std::string &path);
|
2023-08-10 10:28:25 +02:00
|
|
|
|
2022-09-24 11:43:52 -07:00
|
|
|
struct ClipboardData {
|
|
|
|
|
ClipboardData(const char *format, size_t sz);
|
|
|
|
|
ClipboardData(UINT format, size_t sz);
|
|
|
|
|
~ClipboardData();
|
|
|
|
|
|
|
|
|
|
void Set();
|
|
|
|
|
|
|
|
|
|
operator bool() {
|
|
|
|
|
return data != nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINT format_;
|
|
|
|
|
HANDLE handle_;
|
|
|
|
|
void *data;
|
|
|
|
|
};
|
2013-09-29 01:02:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct GenericListViewColumn
|
|
|
|
|
{
|
2018-03-23 04:21:46 +01:00
|
|
|
const wchar_t *name;
|
2013-09-29 01:02:05 +02:00
|
|
|
float size;
|
2014-02-13 10:24:42 +01:00
|
|
|
int flags;
|
2013-09-29 01:02:05 +02:00
|
|
|
};
|
|
|
|
|
|
2014-02-13 10:24:42 +01:00
|
|
|
struct GenericListViewDef
|
|
|
|
|
{
|
|
|
|
|
const GenericListViewColumn* columns;
|
|
|
|
|
int columnCount;
|
|
|
|
|
int* columnOrder;
|
|
|
|
|
bool checkbox; // the first column will always have the checkbox. specify a custom order to change its position
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define GLVC_CENTERED 1
|
|
|
|
|
|
2022-02-13 10:22:38 -08:00
|
|
|
typedef struct tagNMLVCUSTOMDRAW *LPNMLVCUSTOMDRAW;
|
2014-02-13 10:24:42 +01:00
|
|
|
|
2013-11-05 11:29:55 +01:00
|
|
|
// the most significant bit states whether the key is currently down.
|
|
|
|
|
// simply checking if it's != 0 is not enough, as bit0 is set if
|
|
|
|
|
// the key was pressed between the last call to GetAsyncKeyState
|
2017-02-24 20:50:27 +01:00
|
|
|
bool KeyDownAsync(int vkey);
|
2013-11-05 11:29:55 +01:00
|
|
|
|
2013-09-29 01:02:05 +02:00
|
|
|
class GenericListControl
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-02-13 10:24:42 +01:00
|
|
|
GenericListControl(HWND hwnd, const GenericListViewDef& def);
|
2022-02-05 19:00:31 -08:00
|
|
|
virtual ~GenericListControl();
|
2022-02-13 10:22:38 -08:00
|
|
|
int HandleNotify(LPARAM lParam);
|
2013-09-29 01:02:05 +02:00
|
|
|
void Update();
|
|
|
|
|
int GetSelectedIndex();
|
|
|
|
|
HWND GetHandle() { return handle; };
|
2013-09-29 11:19:13 +02:00
|
|
|
void SetSendInvalidRows(bool enabled) { sendInvalidRows = enabled; };
|
2013-09-29 01:02:05 +02:00
|
|
|
protected:
|
2022-02-05 19:00:31 -08:00
|
|
|
void SetIconList(int w, int h, const std::vector<HICON> &icons);
|
2014-02-13 10:24:42 +01:00
|
|
|
void SetCheckState(int item, bool state);
|
2022-02-05 19:00:31 -08:00
|
|
|
void SetItemState(int item, uint8_t state);
|
|
|
|
|
|
2013-09-29 01:02:05 +02:00
|
|
|
virtual bool WindowMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT& returnValue) = 0;
|
|
|
|
|
virtual void GetColumnText(wchar_t* dest, int row, int col) = 0;
|
|
|
|
|
virtual int GetRowCount() = 0;
|
|
|
|
|
virtual void OnDoubleClick(int itemIndex, int column) { };
|
2013-09-29 10:50:18 +02:00
|
|
|
virtual void OnRightClick(int itemIndex, int column, const POINT& point) { };
|
2014-02-08 23:58:17 -08:00
|
|
|
virtual void CopyRows(int start, int size);
|
2014-02-13 10:24:42 +01:00
|
|
|
virtual void OnToggle(int item, bool newValue) { };
|
2021-12-12 11:03:19 -08:00
|
|
|
|
2022-02-13 10:22:38 -08:00
|
|
|
virtual bool ListenRowPrePaint() { return false; }
|
2022-02-13 10:53:01 -08:00
|
|
|
virtual bool ListenColPrePaint() { return false; }
|
2022-02-13 10:22:38 -08:00
|
|
|
virtual bool OnRowPrePaint(int row, LPNMLVCUSTOMDRAW msg) { return false; }
|
2022-02-13 10:53:01 -08:00
|
|
|
virtual bool OnColPrePaint(int row, int col, LPNMLVCUSTOMDRAW msg) { return false; }
|
2022-02-13 10:22:38 -08:00
|
|
|
|
2022-09-18 09:52:38 -07:00
|
|
|
virtual int OnIncrementalSearch(int startRow, const wchar_t *str, bool wrap, bool partial);
|
|
|
|
|
|
2013-09-29 01:02:05 +02:00
|
|
|
private:
|
|
|
|
|
static LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
2021-12-12 11:03:19 -08:00
|
|
|
void ProcessUpdate();
|
2013-09-29 01:02:05 +02:00
|
|
|
void ResizeColumns();
|
2014-02-08 23:58:17 -08:00
|
|
|
void ProcessCopy();
|
2014-02-09 00:06:20 -08:00
|
|
|
void SelectAll();
|
2013-09-29 01:02:05 +02:00
|
|
|
|
|
|
|
|
HWND handle;
|
|
|
|
|
WNDPROC oldProc;
|
2022-02-05 19:00:31 -08:00
|
|
|
void *images_ = nullptr;
|
2013-09-29 01:02:05 +02:00
|
|
|
const GenericListViewColumn* columns;
|
|
|
|
|
int columnCount;
|
|
|
|
|
wchar_t stringBuffer[256];
|
|
|
|
|
bool valid;
|
2013-09-29 11:19:13 +02:00
|
|
|
bool sendInvalidRows;
|
2014-01-22 18:36:40 -05:00
|
|
|
// Used for hacky workaround to fix a rare hang (see issue #5184)
|
|
|
|
|
volatile bool inResizeColumns;
|
2014-02-13 10:24:42 +01:00
|
|
|
volatile bool updating;
|
2021-12-12 11:03:19 -08:00
|
|
|
bool updateScheduled_ = false;
|
2022-12-31 09:58:24 -08:00
|
|
|
|
|
|
|
|
enum class Action {
|
|
|
|
|
CHECK,
|
|
|
|
|
IMAGE,
|
|
|
|
|
};
|
|
|
|
|
struct PendingAction {
|
|
|
|
|
Action action;
|
|
|
|
|
int item;
|
|
|
|
|
int state;
|
|
|
|
|
};
|
|
|
|
|
std::vector<PendingAction> pendingActions_;
|
2018-03-22 22:14:19 +01:00
|
|
|
};
|