CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Windows/W32Util/Misc.h
Views: 1401
#pragma once12#include <cstdint>3#include <string>4#include <vector>56#include "Common/CommonWindows.h"78namespace W32Util9{10void CenterWindow(HWND hwnd);11BOOL CopyTextToClipboard(HWND hwnd, const char *text);12BOOL CopyTextToClipboard(HWND hwnd, const std::wstring &wtext);13void MakeTopMost(HWND hwnd, bool topMost);14void ExitAndRestart(bool overrideArgs = false, const std::string &args = "");15void SpawnNewInstance(bool overrideArgs = false, const std::string &args = "");16bool ExecuteAndGetReturnCode(const wchar_t *executable, const wchar_t *cmdline, const wchar_t *currentDirectory, DWORD *exitCode);17void GetSelfExecuteParams(std::wstring &workingDirectory, std::wstring &moduleFilename);1819void GetWindowRes(HWND hWnd, int *xres, int *yres);20void ShowFileInFolder(const std::string &path);2122struct ClipboardData {23ClipboardData(const char *format, size_t sz);24ClipboardData(UINT format, size_t sz);25~ClipboardData();2627void Set();2829operator bool() {30return data != nullptr;31}3233UINT format_;34HANDLE handle_;35void *data;36};37}3839struct GenericListViewColumn40{41const wchar_t *name;42float size;43int flags;44};4546struct GenericListViewDef47{48const GenericListViewColumn* columns;49int columnCount;50int* columnOrder;51bool checkbox; // the first column will always have the checkbox. specify a custom order to change its position52};5354#define GLVC_CENTERED 15556typedef struct tagNMLVCUSTOMDRAW *LPNMLVCUSTOMDRAW;5758// 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 if60// the key was pressed between the last call to GetAsyncKeyState61bool KeyDownAsync(int vkey);6263class GenericListControl64{65public:66GenericListControl(HWND hwnd, const GenericListViewDef& def);67virtual ~GenericListControl();68int HandleNotify(LPARAM lParam);69void Update();70int GetSelectedIndex();71HWND GetHandle() { return handle; };72void SetSendInvalidRows(bool enabled) { sendInvalidRows = enabled; };73protected:74void SetIconList(int w, int h, const std::vector<HICON> &icons);75void SetCheckState(int item, bool state);76void SetItemState(int item, uint8_t state);7778virtual bool WindowMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT& returnValue) = 0;79virtual void GetColumnText(wchar_t* dest, int row, int col) = 0;80virtual int GetRowCount() = 0;81virtual void OnDoubleClick(int itemIndex, int column) { };82virtual void OnRightClick(int itemIndex, int column, const POINT& point) { };83virtual void CopyRows(int start, int size);84virtual void OnToggle(int item, bool newValue) { };8586virtual bool ListenRowPrePaint() { return false; }87virtual bool ListenColPrePaint() { return false; }88virtual bool OnRowPrePaint(int row, LPNMLVCUSTOMDRAW msg) { return false; }89virtual bool OnColPrePaint(int row, int col, LPNMLVCUSTOMDRAW msg) { return false; }9091virtual int OnIncrementalSearch(int startRow, const wchar_t *str, bool wrap, bool partial);9293private:94static LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);95void ProcessUpdate();96void ResizeColumns();97void ProcessCopy();98void SelectAll();99100HWND handle;101WNDPROC oldProc;102void *images_ = nullptr;103const GenericListViewColumn* columns;104int columnCount;105wchar_t stringBuffer[256];106bool valid;107bool sendInvalidRows;108// Used for hacky workaround to fix a rare hang (see issue #5184)109volatile bool inResizeColumns;110volatile bool updating;111bool updateScheduled_ = false;112113enum class Action {114CHECK,115IMAGE,116};117struct PendingAction {118Action action;119int item;120int state;121};122std::vector<PendingAction> pendingActions_;123};124125126