#ifndef LUNA_BASE_CONTROLS_H #define LUNA_BASE_CONTROLS_H #include"window.h" #include class Menu{ public: void dispatch(WPARAM); struct menuinfos{ UINT type; std::function callback; std::wstring str; }; std::vectormenu_callbacks; HMENU load(); HMENU hmenu; void add(const std::wstring&,std::function callback); void add_checkable(const std::wstring&,bool,std::function callback); void add_sep(); }; using maybehavemenu=std::optional; class control:public basewindow{ public: mainwindow* parent; control(mainwindow*); virtual void dispatch(WPARAM); virtual void dispatch_2(WPARAM wParam, LPARAM lParam); maybehavemenu menu; std::function on_menu=[]()->maybehavemenu{return {};}; }; class button:public control{ public: button(mainwindow* parent); button(mainwindow*,const std::wstring&);//,int,int,int,int,DWORD=BS_PUSHBUTTON); void dispatch(WPARAM); std::function onclick=[](){}; }; class checkbox:public button{ public: checkbox(mainwindow*,const std::wstring&);//,int,int,int,int); bool ischecked(); void setcheck(bool); }; class texteditbase:public control{ public: texteditbase(mainwindow*); void dispatch(WPARAM); std::function ontextchange=[&](const std::wstring &text){}; void appendtext(const std::wstring&); void scrolltoend(); void setreadonly(bool); }; class multilineedit:public texteditbase{ public: multilineedit(mainwindow*); }; class lineedit:public texteditbase{ public: lineedit(mainwindow*); }; class spinbox:public control{ HWND hUpDown; int minv,maxv; public: void dispatch(WPARAM); spinbox(mainwindow*,int); void setminmax(int,int); std::pairgetminmax(); void setcurr(int); int getcurr(); std::function onvaluechange=[&](int){}; void setgeo(int,int,int,int); }; class label:public control{ public: label(mainwindow*,const std::wstring&); }; class listbox:public control{ public: listbox(mainwindow*); void dispatch(WPARAM); int currentidx(); std::wstring text(int); std::function oncurrentchange=[](int){}; void clear(); int additem(const std::wstring&); void deleteitem(int); void setdata(int,LONG_PTR); void setcurrent(int idx); int insertitem(int,const std::wstring&); LONG_PTR getdata(int); int count(); }; class listview:public control{ int headernum=1; HIMAGELIST hImageList; public: listview(mainwindow*); int insertitem(int,const std::wstring&,HICON hicon); int insertcol(int,const std::wstring& ); void clear(); int count(); std::function oncurrentchange=[](int){}; std::wstring text(int,int=0); void setheader(const std::vector&); void autosize(); int additem(const std::wstring&,HICON hicon); void dispatch_2(WPARAM wParam, LPARAM lParam); void on_size(int,int); }; class gridlayout:public control{ struct _c{ control* ctr; int row,col,rowrange,colrange; }; int margin; int maxrow,maxcol; std::vector<_c>savecontrol; std::mapfixedwidth,fixedheight; public: 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); }; #endif