2012-11-01 15:19:01 +00:00
|
|
|
#pragma once
|
|
|
|
|
2013-07-29 04:01:49 +00:00
|
|
|
#include "Common/CommonWindows.h"
|
2012-11-17 22:44:29 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
namespace W32Util
|
|
|
|
{
|
|
|
|
void CenterWindow(HWND hwnd);
|
|
|
|
HBITMAP CreateBitmapFromARGB(HWND someHwnd, DWORD *image, int w, int h);
|
|
|
|
void NiceSizeFormat(size_t size, char *out);
|
2013-08-26 17:00:16 +00:00
|
|
|
BOOL CopyTextToClipboard(HWND hwnd, const char *text);
|
2014-02-09 07:58:17 +00:00
|
|
|
BOOL CopyTextToClipboard(HWND hwnd, const std::wstring &wtext);
|
2013-06-10 21:45:12 +00:00
|
|
|
void MakeTopMost(HWND hwnd, bool topMost);
|
2013-09-28 23:02:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct GenericListViewColumn
|
|
|
|
{
|
|
|
|
wchar_t *name;
|
|
|
|
float size;
|
2014-02-13 09:24:42 +00:00
|
|
|
int flags;
|
2013-09-28 23:02:05 +00:00
|
|
|
};
|
|
|
|
|
2014-02-13 09:24:42 +00: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
|
|
|
|
|
|
|
|
|
2013-11-05 10:29:55 +00: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
|
|
|
|
inline bool KeyDownAsync(int vkey)
|
|
|
|
{
|
|
|
|
return (GetAsyncKeyState(vkey) & 0x8000) != 0;
|
|
|
|
}
|
|
|
|
|
2013-09-28 23:02:05 +00:00
|
|
|
class GenericListControl
|
|
|
|
{
|
|
|
|
public:
|
2014-02-13 09:24:42 +00:00
|
|
|
GenericListControl(HWND hwnd, const GenericListViewDef& def);
|
2013-09-29 08:50:18 +00:00
|
|
|
virtual ~GenericListControl() { };
|
2013-09-28 23:02:05 +00:00
|
|
|
void HandleNotify(LPARAM lParam);
|
|
|
|
void Update();
|
|
|
|
int GetSelectedIndex();
|
|
|
|
HWND GetHandle() { return handle; };
|
2013-09-29 09:19:13 +00:00
|
|
|
void SetSendInvalidRows(bool enabled) { sendInvalidRows = enabled; };
|
2013-09-28 23:02:05 +00:00
|
|
|
protected:
|
2014-02-13 09:24:42 +00:00
|
|
|
void SetCheckState(int item, bool state);
|
2013-09-28 23:02:05 +00: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 08:50:18 +00:00
|
|
|
virtual void OnRightClick(int itemIndex, int column, const POINT& point) { };
|
2014-02-09 07:58:17 +00:00
|
|
|
virtual void CopyRows(int start, int size);
|
2014-02-13 09:24:42 +00:00
|
|
|
virtual void OnToggle(int item, bool newValue) { };
|
2013-09-28 23:02:05 +00:00
|
|
|
private:
|
|
|
|
static LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
|
|
|
void ResizeColumns();
|
2014-02-09 07:58:17 +00:00
|
|
|
void ProcessCopy();
|
2014-02-09 08:06:20 +00:00
|
|
|
void SelectAll();
|
2013-09-28 23:02:05 +00:00
|
|
|
|
|
|
|
HWND handle;
|
|
|
|
WNDPROC oldProc;
|
|
|
|
const GenericListViewColumn* columns;
|
|
|
|
int columnCount;
|
|
|
|
wchar_t stringBuffer[256];
|
|
|
|
bool valid;
|
2013-09-29 09:19:13 +00:00
|
|
|
bool sendInvalidRows;
|
2014-01-22 23:36:40 +00:00
|
|
|
// Used for hacky workaround to fix a rare hang (see issue #5184)
|
|
|
|
volatile bool inResizeColumns;
|
2014-02-13 09:24:42 +00:00
|
|
|
volatile bool updating;
|
2013-09-28 23:02:05 +00:00
|
|
|
};
|