YSTest: HexBrowser.h 源文件

YSTest PreAlpha_b400_20130424 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
HexBrowser.h
浏览该文件的文档.
1 ﻿/*
2 Copyright by FrankHB 2011 - 2013.
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 #ifndef INC_YReader_HexBrowser_h_
29 #define INC_YReader_HexBrowser_h_ 1
30
31 #include <YSLib/UI/scroll.h>
32 #include <YSLib/Service/yfile.h>
33 #include <YSLib/Service/TextLayout.h>
34 #include <Helper/GUIApplication.h>
35
36 YSL_BEGIN
37
38 YSL_BEGIN_NAMESPACE(UI)
39
40
45 class HexModel
46 {
47 private:
53 unique_ptr<File> pSource;
54
55 public:
56 HexModel()
57 : pSource(new File())
58 {}
59 HexModel(const_path_t path)
60 : pSource(new File(path))
61 {}
62 DefDelCopyCtor(HexModel)
63 DefDeMoveCtor(HexModel)
64
65 DefDeMoveAssignment(HexModel)
66 HexModel&
67 operator=(unique_ptr<File>&& file_ptr)
68 {
69 pSource = std::move(file_ptr);
70 return *this;
71 }
72
73 DefPred(const ynothrow, Valid, bool(GetSource()))
74
75 private:
76 DefGetter(const ynothrow, File&, Source, *pSource)
77
78 public:
79 DefGetterMem(const ynothrow, FILE*, Ptr, GetSource())
80
81 DefGetterMem(const ynothrow, ptrdiff_t, Position, GetSource())
82 DefGetterMem(const ynothrow, size_t, Size, GetSource())
83
84 DefFwdTmpl(const, ptrdiff_t, SetPosition,
85 GetSource().Seek(args...))
86
87 DefFwdFn(const, int, CheckEOF, GetSource().CheckEOF())
88 };
89
90
96 class HexView
97 {
98 public:
99 static yconstexpr size_t ItemPerLine = 8;
100
101 typedef std::uintptr_t IndexType;
102 typedef vector<char> DataType;
103
104 protected:
105 Drawing::TextState TextState;
106
107 private:
108 IndexType item_num;
109
110 protected:
115 DataType datCurrent;
116
117 public:
119 HexView(FontCache& = FetchDefaultFontCache());
120
121 public:
125 DefGetter(const ynothrow, SDst, ItemHeight,
126 GetTextLineHeightExOf(TextState))
127 DefGetter(const ynothrow, IndexType, ItemNum, item_num)
128
129 protected:
130 PDefH(IndexType, UpdateItemNum, SDst h)
131 ImplRet(item_num = FetchResizedLineN(TextState, h))
132 };
133
134
139 class HexViewArea : public ScrollableContainer,
140 protected HexView
141 {
142 public:
143 using HexView::ItemPerLine;
144 using HexView::IndexType;
145 using HexView::DataType;
151 typedef GValueEventArgs<bool> ViewArgs;
156 DeclDelegate(HViewEvent, ViewArgs)
157
158 private:
162 HexModel model;
163
164 public:
169 DeclEvent(HViewEvent, ViewChanged)
170
172 explicit
173 HexViewArea(const Drawing::Rect& = {},
174 FontCache& = FetchDefaultFontCache());
175
176 using HexView::GetItemHeight;
177 using HexView::GetItemNum;
178 DefGetter(const ynothrow, const HexModel&, Model, model)
179
180 void
181 Load(const_path_t);
182
186 void
187 LocateViewPosition(u32);
188
193 void
194 Refresh(PaintEventArgs&&) override;
195
196 void
197 Reset();
198
199 void
200 UpdateData(u32);
201
209 void
210 UpdateView(bool = false);
211 };
212
213 YSL_END_NAMESPACE(UI)
214
215 YSL_END
216
217 #endif
218