YSTest: BookmarkUI.cpp 源文件

YSTest PreAlpha_b500_20140530 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
BookmarkUI.cpp
浏览该文件的文档.
1 /*
2 © 2013-2014 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #include "BookmarkUI.h"
29 #include "ShlReader.h"
30
31 namespace YReader
32 {
33
34 namespace
35 {
36
37 using namespace std;
38
40 string
41 ConvertToUIString(Bookmark::PositionType pos, ShlTextReader& shl)
42 {
43 auto line(shl.GetSlice(pos, 48U));
44
45 if(line.size() > 1)
46 {
47 const bool b(line[0] == '\n');
48 const auto i(line.find("\r\n", b));
49
50 if(i != string::npos)
51 line.erase(i);
52 if(b)
53 line.erase(line.begin());
54 }
55 return to_string(pos) + " " + std::move(line);
56 }
58 vector<String>
59 ConvertToUIString(const BookmarkList& lst, ShlTextReader& shl)
60 {
61 vector<String> vec;
62
63 vec.reserve(lst.size());
64 for(const auto pos : lst)
65 vec.push_back(ConvertToUIString(pos, shl));
66 return vec;
67 }
68
69 BookmarkList
70 ConvertToBookmarkList(const vector<String>& lst)
71 {
72 BookmarkList bookmarks;
73
74 bookmarks.reserve(lst.size());
75 for(const auto& str : lst)
76 bookmarks.push_back(stoul(str.GetMBCS()));
77 return bookmarks;
78 }
79
80 } // unnamed namespace;
81
82 BookmarkPanel::BookmarkPanel(const BookmarkList& bm, ShlTextReader& shl)
83 : DialogPanel(Size(MainScreenWidth, MainScreenHeight)),
84 lbPosition({8, 32, 240, 128}),
85 btnAdd(Rect(GetWidth() - 80, 4, 16, 16), 210),
86 btnRemove(Rect(GetWidth() - 60, 4, 16, 16), 210), shell(shl), bookmarks(bm)
87 {
88 const auto stop_routing_after_direct([](KeyEventArgs&& e){
89 if(e.Strategy == RoutedEventArgs::Bubble)
90 e.Handled = true;
91 });
92
93 AddWidgets(*this, lbPosition, btnAdd, btnRemove),
94 yunseq(
95 btnAdd.Text = u"+",
96 btnRemove.Text = u"-",
97 FetchEvent<KeyDown>(lbPosition) += stop_routing_after_direct,
98 FetchEvent<KeyHeld>(lbPosition) += stop_routing_after_direct,
99 FetchEvent<Click>(btnOK) += [this]{
100 bookmarks = ConvertToBookmarkList(lbPosition.GetList());
101 },
102 FetchEvent<Click>(btnAdd) += [this]{
103 auto& lst(lbPosition.GetListRef());
104 auto idx(GetSelected());
105
106 if(idx < 0)
107 idx = lst.size();
108 lst.insert(lst.begin() + idx,
109 String(ConvertToUIString(shell.get().GetReaderPosition(), shell)));
110 lbPosition.AdjustViewForContent();
111 lbPosition.UpdateView();
112 },
113 FetchEvent<Click>(btnRemove) += [this]{
114 auto& lst(lbPosition.GetListRef());
115 const auto idx(GetSelected());
116
117 if(idx >= 0)
118 {
119 lst.erase(lst.begin() + idx);
120 lbPosition.AdjustViewForContent();
121 lbPosition.UpdateView();
122 }
123 }
124 );
125 }
126
127 BookmarkList::difference_type
128 BookmarkPanel::GetSelected() const
129 {
130 return lbPosition.IsSelected() ? lbPosition.GetSelectedIndex() : -1;
131 }
132
133 void
134 BookmarkPanel::LoadBookmarks()
135 {
136 lbPosition.GetListRef() = ConvertToUIString(bookmarks, shell);
137 }
138
139 } // namespace YReader;
140
YSLib::UI::KeyEventArgs
按键输入事件参数类。
Definition: ywgtevt.h:167
YReader::ShlTextReader
文本阅读器 Shell 。
Definition: ShlReader.h:215
YReader::Bookmark::PositionType
size_t PositionType
文件位置类型。
Definition: ReadingList.h:49
BookmarkUI.h
书签界面。
YSLib::UI::AddWidgets
void AddWidgets(_tCon &con, _tWidgets &...wgts)
向部件容器添加子部件。
Definition: yuicont.h:400
YReader::BookmarkPanel::LoadBookmarks
void LoadBookmarks()
Definition: BookmarkUI.cpp:134
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:748
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: ygdibase.h:416
YReader::BookmarkList
vector< Bookmark::PositionType > BookmarkList
书签列表类型。
Definition: ReadingList.h:82
YReader::BookmarkPanel::GetSelected
BookmarkList::difference_type GetSelected() const
Definition: BookmarkUI.cpp:128
YReader::BookmarkPanel::BookmarkPanel
BookmarkPanel(const BookmarkList &, ShlTextReader &)
Definition: BookmarkUI.cpp:82
ystdex::to_string
std::string to_string(unsigned char val)
转换为字符串。
Definition: string.hpp:353
YSLib::UI::RoutedEventArgs::Bubble
气泡事件：向上遍历视图树时触发。
Definition: ywgtevt.h:102
YSLib::Drawing::Size
屏幕区域大小。
Definition: ygdibase.h:249
YReader::BookmarkPanel::shell
std::reference_wrapper< ShlTextReader > shell
Definition: BookmarkUI.h:55
ShlReader.h
Shell 阅读器框架。
YSLib::UI::DialogPanel
对话面板。
Definition: uicontx.h:73
YReader::BookmarkPanel::lbPosition
ListBox lbPosition
Definition: BookmarkUI.h:50