30 #include YFM_YSLib_UI_ExStyle
44 enum class FileCategory
46 Empty = NodeCategory::Empty,
47 Unknown = NodeCategory::Regular,
53 CheckTextFileExtensions(
string ext)
60 const auto i(m.find(ext));
65 const auto& pth(i->second);
67 return !pth.empty() && (pth.front() ==
"text"
71 catch(std::out_of_range&)
77 ClassifyFile(
const Path& pth)
81 case NodeCategory::Regular:
82 return CheckTextFileExtensions(
GetExtensionOf(pth).GetMBCS(CS_Path))
83 ? FileCategory::Text : FileCategory::Binary;
84 case NodeCategory::Unknown:
87 return FileCategory::Empty;
91 return FileCategory::Unknown;
97 CheckReaderEnability(FileBox& fb, RadioBox& hex)
101 switch(ClassifyFile(fb.GetPath()))
103 case FileCategory::Text:
105 case FileCategory::Binary:
106 return hex.GetState() == &hex;
122 unseq_apply([&](
int vk){ke.set(vk, {});}, VK_CONTROL, VK_LCONTROL,
124 return ke.none() && k[VK_CONTROL];
140 float a,
size_t n = 5)
143 vector<Point> pts(n);
145 for(
size_t i = 0; i < n; ++i)
146 pts[i] = {int(-std::cos(PI_4 / n * i + a) * r + pt.X),
147 int(std::sin(PI_4 / n * i + a) * r + pt.Y)};
153 const char TU_Explorer_Main[]{u8R
"NPL(root
154 ($type "Panel")($bounds "0 0 256 192")
156 ($type "Label")($bounds "16 20 220 22"))
158 ($type "Label")($bounds "8 48 240 48"))
160 ($type "Label")($bounds "8 100 240 64"))
163 const char TU_Explorer_Sub[]{u8R
"NPL(root
164 ($type "Panel")($bounds "0 0 256 192")
166 ($type "FileBox")($bounds "0 0 256 170"))
168 ($type "Button")($bounds "170 170 64 22"))
170 ($type "Button")($bounds "0 170 72 22"))
172 ($type "Panel")($bounds "10 40 224 100")($z 128)
174 ($type "DropDownList")($bounds "10 24 80 22"))
176 ($type "RadioButton")($bounds "120 18 100 18"))
178 ($type "RadioButton")($bounds "120 36 100 18"))
180 ($type "CheckButton")($bounds "10 60 72 18"))
182 ($type "Button")($bounds "120 60 30 22"))
184 ($type "Button")($bounds "164 60 30 22"))
187 ($type "Panel")($bounds "10 20 224 144")($z 128)
190 ($bounds "3 3 218 138")
194 ($type "Button")($bounds "8 32 104 22"))
196 ($type "Label")($bounds "4 4 104 22"))
201 ($type "Button")($bounds "8 32 104 22"))
206 ($type "TextBox")($bounds "8 4 104 22"))
208 ($type "Button")($bounds "8 32 104 22"))
210 ($type "CheckButton")($bounds "8 64 104 22"))
221 :
Button({pt, {22, 22}}, 60),
226 FetchEvent<Click>(*
this) += [
this]{
227 shell.get().SwapScreens();
234 const shared_ptr<Desktop>& h_dsk_up,
const shared_ptr<Desktop>& h_dsk_dn)
235 : ShlDS(h_dsk_up, h_dsk_dn),
239 fpsCounter(std::chrono::milliseconds(500)),
240 btnSwitchMain(*this, {234, 170}), btnSwitchSub(*
this, {234, 170})
243 using namespace placeholders;
252 auto& dsk_m(GetMainDesktop());
253 auto& dsk_s(GetSubDesktop());
254 auto& node(dynWgts_Main.WidgetNode);
259 auto& node_sub(dynWgts_Sub.WidgetNode);
264 auto& node_pnlSetting(AccessWidgetNode(node_sub, "pnlSetting"));
272 auto& node_pnlTest1(AccessWidgetNode(node_sub, "pnlTest1"));
273 auto& node_tcTest1(AccessWidgetNode(node_pnlTest1, "tcTest1"));
276 auto& node_pnlPage1(AccessWidgetNode(node_tcTest1, "pnlPage1"));
277 auto& node_pnlPage2(AccessWidgetNode(node_tcTest1, "pnlPage2"));
278 auto& node_pnlPage3(AccessWidgetNode(node_tcTest1, "pnlPage3"));
290 tcTest1.UpdateTabPages();
291 p_border =
make_unique<BorderResizer>(pnlTest1, 4);
294 dsk_m.Add(btnSwitchMain, 96),
297 dsk_s.Add(btnSwitchSub, 96),
300 pnlSetting.SetRenderer(
make_unique<BufferedRenderer>()),
301 pnlTest1.SetRenderer(
make_unique<BufferedRenderer>()),
302 unseq_apply(bind(SetVisibleOf, _1, false), pnlSetting, pnlTest1,
304 unseq_apply(bind(&ShlDS::WrapForSwapScreens, this, _1, ref(SwapMask)),
306 ani.
Reset(&pnlTest1),
308 rbTxt.ShareTo(rbHex),
313 dsk_s.Background = SolidBrush(
FetchGUIState().Colors[Styles::Panel]),
314 root.Background =
nullptr,
315 root_sub.Background =
nullptr,
317 lblPath.AutoWrapLine = true, lblPath.Text = String(path),
318 lblInfo.AutoWrapLine = true, lblInfo.Text = u"文件列表:请选择一个文件。",
320 btnOK.Text = u"确定(
A)",
322 btnMenu.Text = u
"菜单(Ctrl)",
324 btnMenu.Text = u
"菜单(Start)",
326 tbTest.Text = u
"测试文本",
327 ddlStyle.Text = [](
const TextList::ListType& lst){
330 YAssert(!lst.empty(),
"Invalid list found.");
331 return name.empty() ? lst[0] : String(
name);
332 }(ddlStyle.GetList()),
333 rbTxt.Text = u
"文本阅读",
334 rbHex.Text = u
"十六进制浏览",
335 cbFPS.Text = u
"显示 FPS",
336 pnlSetting.Background = SolidBrush({160, 252, 160}),
337 pnlTest1.Background = SolidBrush({248, 248, 120}),
341 btnTestEx.Text = u
"附加测试",
344 btnTestAni.Text = u
"开始动画",
345 cbDisableSetting.Text = u
"禁用设置选择框",
346 lblDragTest.Text = u
"移动设置面板位置",
348 btnEnterTest.Text = u
"边界测试",
352 btnPrevBackground.Text = u
"<<",
354 btnNextBackground.Text = u
">>",
355 fbMain.SetPath(path),
356 dsk_s.BoundControlPtr = [&,
this](
const KeyInput& k)->IWidget*{
362 else if(CheckMenuKey(k))
368 FetchEvent<KeyPress>(dsk_s) += [&](KeyEventArgs&& e){
372 fbMain.GetViewChanged() += [&]{
373 lblPath.Text = String(fbMain.GetPath());
376 fbMain.GetSelected() += [&]{
377 Enable(btnOK, CheckReaderEnability(fbMain, rbHex));
379 FetchEvent<Click>(btnOK) += [&]{
380 if(fbMain.IsSelected())
382 const auto& path(fbMain.GetPath());
384 const auto category(ClassifyFile(path));
386 if(category == FileCategory::Text
387 || category == FileCategory::Binary)
389 const auto h_up(GetMainDesktopHandle());
390 const auto h_dn(GetSubDesktopHandle());
391 const bool b(category == FileCategory::Text
392 && rbTxt.IsSelected());
397 NowShellTo(ystdex::make_shared<ShlTextReader>(path,
400 NowShellTo(ystdex::make_shared<ShlHexBrowser>(path,
406 FetchEvent<Click>(cbFPS) += [
this]{
409 FetchEvent<Click>(rbHex) += [&]{
410 Enable(btnOK, CheckReaderEnability(fbMain, rbHex));
413 FetchEvent<Move>(pnlSetting) += [&]{
419 FetchEvent<TouchDown>(pnlSetting) += [&]{
420 struct ::mallinfo t(::mallinfo());
423 t.arena, t.ordblks, t.uordblks, t.fordblks, t.keepcost);
427 FetchEvent<Click>(pnlSetting) += [&]{
435 FetchEvent<Paint>(pnlPage2) += [&,
this](PaintEventArgs&& e){
443 if(ani.GetConnectionRef().Ready)
449 UpdateClipArea(e, {{},
GetSizeOf(e.GetSender())});
451 FetchEvent<Click>(btnTestEx) += [&](CursorEventArgs&& e){
452 const auto& k(e.GetKeys());
453 auto& btn(polymorphic_downcast<Button&>(e.GetSender()));
455 if(lblTitle.Background)
456 lblTitle.Background =
nullptr;
459 lblInfo.Text = btn.Text + u
", " + String(
to_string(
463 FetchEvent<Click>(btnTestAni) += [&]{
464 auto& conn(ani.GetConnectionRef());
467 yunseq(btnTestAni.Text = u
"开始动画", conn.Ready = {});
470 yunseq(btnTestAni.Text = u
"停止动画", conn.Ready =
true),
475 FetchEvent<Enter>(btnEnterTest) += [](CursorEventArgs&& e){
476 auto& btn(ystdex::polymorphic_downcast<Button&>(e.GetSender()));
478 btn.Text = u
"Enter: " + String(
to_string(e.Position));
481 FetchEvent<Leave>(btnEnterTest) += [](CursorEventArgs&& e){
482 auto& btn(ystdex::polymorphic_downcast<Button&>(e.GetSender()));
484 btn.Text = u
"Leave: " + String(
to_string(e.Position));
487 mhMain.Roots[&btnMenu] = 1u,
488 FetchEvent<Click>(btnMenu) += [
this]{
489 auto& mnu(mhMain[1u]);
491 if(mhMain.IsShowing(1u))
500 FetchEvent<Click>(btnPrevBackground) += [&]{
501 auto& dsk_m(GetMainDesktop());
502 auto& dsk_s(GetSubDesktop());
507 Enable(btnNextBackground);
510 Enable(btnPrevBackground,
false);
511 dsk_m.Background = ImageBrush(
FetchImage(up_i));
514 FetchEvent<Click>(btnNextBackground) += [&]{
515 auto& dsk_m(GetMainDesktop());
516 auto& dsk_s(GetSubDesktop());
521 Enable(btnPrevBackground);
523 if(
size_t(up_i + 1) ==
Image_N)
524 Enable(btnNextBackground,
false);
525 dsk_m.Background = ImageBrush(
FetchImage(up_i));
533 ddlStyle.GetConfirmed() += [&,
this]{
542 new TextList::ListType{u
"测试", u
"关于", u
"设置(X)", u
"退出"}), 1u)));
544 share_raw(
new TextList::ListType{u
"项目1", u
"项目2"}), 2u)));
561 MinGW32::TestFramework(e.Value);
566 mhMain += m1, mhMain += m2,
567 m1 += make_pair(0u, &m2);
578 auto& cbFPS(*p_ChkFPS);
584 using namespace ColorSpace;
586 const u32 t(fpsCounter.Refresh());
590 auto&
g(ystdex::polymorphic_downcast<BufferedRenderer&>(
591 GetMainDesktop().GetRenderer()).GetContext());
595 std::sprintf(strt,
"FPS: %u.%03u",
unsigned(t / 1000),
yconstexpr Padding DefaultMargin(2, 2, 2, 2)
默认边距。
pt pt Y const IWidget &wgt const IWidget &wgt GetSizeOf
无效化:使相对于部件的子部件的指定区域在直接和间接的窗口缓冲区中无效。
pt pt Y const IWidget &wgt GetLocationOf
GValueEventArgs< MTextList::IndexType > IndexEventArgs
索引事件。
YF_API void OnKey_Bound_TouchDown(KeyEventArgs &&)
处理按键事件:按键-指针设备接触开始。
YF_API void SetLocationOf(IWidget &, const Point &)
设置部件左上角所在位置(相对于容器的偏移坐标)。
Color GenerateRandomColor()
YF_API void PostQuitMessage(int nExitCode, Messaging::Priority p=0xF0)
以优先级 p 发起 Shell 终止请求,返回 nExitCode。
YF_API GUIState & FetchGUIState()
取默认图形用户界面公共状态。
void AddWidgetsZ(_tCon &con, ZOrderType z, _tWidgets &...wgts)
向部件容器添加指定 Z 顺序的子部件。
YF_API void FillRect(const Graphics &g, const Rect &, Color c)
填充标准矩形。
YF_API void Invalidate(IWidget &, const Rect &)
无效化:使相对于部件的指定区域在直接和间接的窗口缓冲区中无效。
void InvalidateAll(IWidget &wgt, const Rect &bounds)
void SetInvalidationOf(IWidget &wgt)
MSelector::SelectedArgs TickedArgs
选择框选中状态参数类型。
YF_API MIMEBiMapping & FetchMIMEBiMapping()
取 MIME 类型名和文件扩展名双向映射对象。
YF_API bool Enable(IWidget &, bool=true)
设置部件可用性,且当可用性改变时无效化部件区域。
std::shared_ptr< _type > share_raw(const _pSrc &p)
YF_API void OnTouchHeld_Dragging(CursorEventArgs &&)
处理屏幕接触移动事件:拖放按下部件。
void unseq_apply(_fCallable &&f, _tParams &&...args)
无序调用。
std::uint16_t SDst
屏幕坐标距离。
YF_API void Show(IWidget &)
显示部件。
String GetExtensionOf(const String &fname)
void SetEnabledOf(IWidget &wgt, bool b)
设置部件可用性。
#define DeclDynWidgetN(_t, _n,...)
声明指定节点下的按相同名称访问的动态部件。
void SetList(const shared_ptr< ListType > &)
设置文本列表。
GBinaryGroup< SPos > Point
屏幕二维点(直角坐标表示)。
#define yunseq
无序列依赖表达式组求值。
void OnPaint() override
处理绘制消息:更新到屏幕并刷新 FPS 。
yconstfn const string & name
YF_API void DrawText(const Graphics &g, TextState &ts, const String &str, bool line_wrap)
绘制文本。
WidgetLoader & FetchWidgetLoader()
_pDst polymorphic_downcast(_tSrc *x)
多态类指针向派生类指针转换。
PaintEventArgs &&void Switch(const string &)
std::reference_wrapper< ShlDS > shell
YF_API void RequestFocusCascade(IWidget &)
级联请求部件及上层容器焦点。
errno_t NowShellTo(const shared_ptr< Shell > &hShl)
向句柄指定的 Shell 对象转移线程控制权。
YF_API void SwitchVisibleToFront(IWidget &)
切换部件显示状态并请求提升至前端。
#define DeclDynWidget(_t, _n,...)
声明动态部件。
void DrawPolygon(Graphics &g, const Rect &bounds, _tIn first, _tIn last, Color c)
描画多边形。
unsigned long Reset(COMPtr< _iCOM > &ptr) ynothrow
YF_API void InitExStyles()
初始化扩展样式。
shared_ptr< Image > & FetchImage(size_t)
std::string to_string(unsigned char val)
转换为字符串。
YF_API void ResetDSDesktops(Desktop &, Desktop &)
以默认屏幕复位两个桌面。
ShlExplorer(const IO::Path &=IO::FetchCurrentWorkingDirectory(), const shared_ptr< Desktop > &={}, const shared_ptr< Desktop > &={})
构造:使用指定路径和上下桌面。
#define yconstexpr
指定编译时常量表达式。
YF_API void OnKey_Bound_TouchUp(KeyEventArgs &&)
处理按键事件:按键-指针设备接触结束。
bool ends_with(const _tRange1 &input, const _tRange2 &test, _fPred comp)
判断第一个参数指定的串是否以第二个参数结束。
std::basic_string< _tChar > sfmt(const _tChar *fmt,...)
以 C 标准输出格式的输出 std::basic_string 实例的对象。
void AddButtonToTabBar(TabControl &, const ValueNode &, const string &, const String &, SDst=64)
向标签栏和节点添加按钮。
const ZOrderType DefaultWindowZOrder(128)
默认窗口 Z 顺序值。
void ResizeForContent(TextList &tl)
enable_if_t<!is_array< _type >::value, std::unique_ptr< _type > > make_unique(_tParams &&...args)
使用 new 和指定参数构造指定类型的 std::unique_ptr 实例。
double FetchImageLoadTime()
std::bitset< KeyBitsetWidth > KeyInput
按键并行位宽。
Styles::StyleMap Styles
样式映射。
yconstexpr size_t Image_N(3)
YF_API shared_ptr< TextList::ListType > FetchVisualStyleNames(String=u"<Default>")
取视觉样式名称。
void PostTask(_fCallable &&f, Messaging::Priority prior=Messaging::NormalPriority)
通过消息队列部署后任务。
#define YAssert(_expr, _msg)
YF_API NodeCategory ClassifyNode(const Path &)
按文件系统节点类别对路径分类。
SwitchScreensButton(ShlDS &, const Point &)
#define DeclDynWidgetNode(_t, _n)
声明名称为 node 的节点下的按相同名称访问的动态部件。