165 lines
4.1 KiB
C
Raw Normal View History

2024-02-07 20:59:24 +08:00
#ifndef LUNA_BASE_CONTROLS_H
#define LUNA_BASE_CONTROLS_H
2024-07-21 19:28:47 +08:00
#include "window.h"
2024-02-11 23:49:11 +08:00
#include <CommCtrl.h>
2024-07-21 19:28:47 +08:00
class Menu
{
public:
void dispatch(WPARAM);
2024-07-21 19:28:47 +08:00
struct menuinfos
{
UINT type;
std::function<void()> callback;
std::wstring str;
};
2024-07-21 19:28:47 +08:00
std::vector<menuinfos> menu_callbacks;
HMENU load();
HMENU hmenu;
2024-07-21 19:28:47 +08:00
void add(const std::wstring &, std::function<void()> callback);
void add_checkable(const std::wstring &, bool, std::function<void(bool)> callback);
void add_sep();
};
2024-07-21 19:28:47 +08:00
using maybehavemenu = std::optional<Menu>;
class control : public basewindow
{
public:
mainwindow *parent;
control(mainwindow *);
2024-02-07 20:59:24 +08:00
virtual void dispatch(WPARAM);
2024-02-11 23:49:11 +08:00
virtual void dispatch_2(WPARAM wParam, LPARAM lParam);
maybehavemenu menu;
2024-07-21 19:28:47 +08:00
std::function<maybehavemenu()> on_menu = []() -> maybehavemenu
{ return {}; };
2024-02-07 20:59:24 +08:00
};
2024-07-21 19:28:47 +08:00
class button : public control
{
2024-02-07 20:59:24 +08:00
public:
2024-07-21 19:28:47 +08:00
button(mainwindow *parent);
button(mainwindow *, const std::wstring &); //,int,int,int,int,DWORD=BS_PUSHBUTTON);
2024-02-07 20:59:24 +08:00
void dispatch(WPARAM);
2024-07-21 19:28:47 +08:00
std::function<void()> onclick = []() {};
2024-02-07 20:59:24 +08:00
};
2024-07-21 19:28:47 +08:00
class checkbox : public button
{
2024-02-07 20:59:24 +08:00
public:
2024-07-21 19:28:47 +08:00
checkbox(mainwindow *, const std::wstring &); //,int,int,int,int);
2024-02-07 20:59:24 +08:00
bool ischecked();
2024-02-09 09:25:26 +08:00
void setcheck(bool);
2024-02-07 20:59:24 +08:00
};
2024-07-21 19:28:47 +08:00
class texteditbase : public control
{
2024-02-07 20:59:24 +08:00
public:
2024-07-21 19:28:47 +08:00
texteditbase(mainwindow *);
2024-02-07 20:59:24 +08:00
void dispatch(WPARAM);
2024-07-21 19:28:47 +08:00
std::function<void(const std::wstring &)> ontextchange = [&](const std::wstring &text) {};
void appendtext(const std::wstring &);
2024-02-07 20:59:24 +08:00
void scrolltoend();
2024-02-20 23:24:33 +08:00
void setreadonly(bool);
2024-02-07 20:59:24 +08:00
};
2024-07-21 19:28:47 +08:00
class multilineedit : public texteditbase
{
2024-03-28 11:01:44 +08:00
public:
2024-07-21 19:28:47 +08:00
multilineedit(mainwindow *);
std::wstring getsel();
2024-03-28 11:01:44 +08:00
};
2024-07-21 19:28:47 +08:00
class lineedit : public texteditbase
{
2024-03-28 11:01:44 +08:00
public:
2024-07-21 19:28:47 +08:00
lineedit(mainwindow *);
2024-03-28 11:01:44 +08:00
};
2024-07-21 19:28:47 +08:00
class spinbox : public control
{
HWND hUpDown;
2024-07-21 19:28:47 +08:00
int minv, maxv;
public:
void dispatch(WPARAM);
2024-07-21 19:28:47 +08:00
spinbox(mainwindow *, int);
void setminmax(int, int);
std::pair<int, int> getminmax();
void setcurr(int);
2024-03-28 19:24:07 +08:00
int getcurr();
2024-07-21 19:28:47 +08:00
std::function<void(int)> onvaluechange = [&](int) {};
void setgeo(int, int, int, int);
};
2024-07-21 19:28:47 +08:00
class label : public control
{
2024-02-07 20:59:24 +08:00
public:
2024-07-21 19:28:47 +08:00
label(mainwindow *, const std::wstring &);
2024-02-07 20:59:24 +08:00
};
2024-07-21 19:28:47 +08:00
class listbox : public control
{
2024-02-07 20:59:24 +08:00
public:
2024-07-21 19:28:47 +08:00
listbox(mainwindow *);
2024-02-07 20:59:24 +08:00
void dispatch(WPARAM);
int currentidx();
std::wstring text(int);
2024-07-21 19:28:47 +08:00
std::function<void(int)> oncurrentchange = [](int) {};
2024-02-07 20:59:24 +08:00
void clear();
2024-07-21 19:28:47 +08:00
int additem(const std::wstring &);
2024-02-07 20:59:24 +08:00
void deleteitem(int);
2024-07-21 19:28:47 +08:00
void setdata(int, LONG_PTR);
2024-03-27 16:36:14 +08:00
void setcurrent(int idx);
2024-07-21 19:28:47 +08:00
int insertitem(int, const std::wstring &);
2024-02-07 20:59:24 +08:00
LONG_PTR getdata(int);
int count();
};
2024-07-21 19:28:47 +08:00
class listview : public control
{
int headernum = 1;
2024-04-18 16:19:52 +08:00
bool addicon;
2024-02-11 23:49:11 +08:00
HIMAGELIST hImageList;
2024-07-21 19:28:47 +08:00
std::vector<LONG_PTR> assodata;
std::map<LONG_PTR, int> remapidx;
2024-04-18 16:19:52 +08:00
std::mutex lockdataidx;
2024-07-21 19:28:47 +08:00
2024-02-11 23:49:11 +08:00
public:
2024-07-21 19:28:47 +08:00
listview(mainwindow *, bool, bool);
int insertitem(int, const std::wstring &, HICON hicon = NULL);
void settext(int, int, const std::wstring &);
int insertcol(int, const std::wstring &);
2024-02-11 23:49:11 +08:00
void clear();
int count();
2024-04-18 16:19:52 +08:00
int currentidx();
void setcurrent(int idx);
2024-07-21 19:28:47 +08:00
std::function<void(int)> oncurrentchange = [](int) {};
std::wstring text(int, int = 0);
void setheader(const std::vector<std::wstring> &);
2024-04-18 16:19:52 +08:00
void deleteitem(int);
2024-07-21 19:28:47 +08:00
int additem(const std::wstring &, HICON hicon = NULL);
2024-04-18 16:19:52 +08:00
LONG_PTR getdata(int);
2024-07-21 19:28:47 +08:00
void setdata(int, LONG_PTR);
2024-04-18 16:19:52 +08:00
int querydataidx(LONG_PTR);
2024-02-12 00:17:58 +08:00
void dispatch_2(WPARAM wParam, LPARAM lParam);
2024-07-21 19:28:47 +08:00
void on_size(int, int);
2024-03-28 11:01:44 +08:00
};
2024-07-21 19:28:47 +08:00
class gridlayout : public control
{
struct _c
{
control *ctr;
int row, col, rowrange, colrange;
2024-03-28 11:01:44 +08:00
};
int margin;
2024-07-21 19:28:47 +08:00
int maxrow, maxcol;
std::vector<_c> savecontrol;
std::map<int, int> fixedwidth, fixedheight;
2024-03-28 11:01:44 +08:00
public:
2024-07-21 19:28:47 +08:00
void setgeo(int, int, int, int);
void setfixedwidth(int col, int width);
void setfixedheigth(int row, int height);
void addcontrol(control *, int row, int col, int rowrange = 1, int colrange = 1);
gridlayout(int row = 0, int col = 0);
void setmargin(int m = 10);
2024-02-11 23:49:11 +08:00
};
2024-07-21 19:28:47 +08:00
class FontSelector
{
2024-04-25 15:44:28 +08:00
public:
2024-07-21 19:28:47 +08:00
FontSelector(HWND hwnd, const Font &, std::function<void(const Font &)> callback);
2024-04-25 15:44:28 +08:00
};
2024-02-07 20:59:24 +08:00
#endif