2021SC@SDUSC
WeaselPanel
#pragma once
#include <WeaselCommon.h>
#include <WeaselUI.h>
WeaselPanel.cpp引用WeaselPanel.h头文件,头文件中又引用WeaselCommon.h和WeaselUI.h,这两个文件在wtl包中,定义了关于基本布局的一些内容,所以我们先看一下这两个文件,本篇报告先分析一下WeaselCommon.h文件代码。
我们首先介绍一下wtl
WTL是Windows Template Library的缩写,由微软的ATL(Active Template Library)小组开发,主要是基于ATL对Wind32 API的封装。从2.0后,功能逐步完善,成为了一个完整的支持窗口的框架。WTL功能不如MFC完善,但是比MFC更小巧,不依赖MFC的DLL。
它给各种类型的应用程序提供了一个基本的框架,虽然没有MFC那样的文档/视图结构,但是有视图(Views)。在WTL有大量的代码来管理视图,而且加入自己的代码也很容易。WTL有AppWizard,可以生成SDI,MDI和多线程SDI程序,多线程SDI跟IE或Windows Explorer很像,它看起来是打开了很多个程序实例,实际上这些窗口都是属于一个进程。
现在WTL也有GDI类了,然而HDC的封装类就像CWindow一样,只进行了很简单的封装,它几乎没有加入任何新的功能,不过,在WTL,你可以得到播放meta文件和OpenGL支持, WTL有打印机支持,甚至打印预览, 当然也有GDI对象的封装,诸如画笔,画刷,区域等。
WTL还有一些实用类.最重要的是CString,不错,它是从MFC克隆得到的(copy on write),具有MFC版本的所有方法,还有查找文件的API的封装类,以及CRect,CSize and CPoint。在WeaselUI这个包中就使用到了CSize。
WeaselCommon.h
enum TextAttributeType
{
NONE = 0,
HIGHLIGHTED,
LAST_TYPE
};
定义了一个枚举类型的文本属性类型
struct TextRange
{
TextRange() : start(0), end(0) {}
TextRange(int _start, int _end) : start(_start), end(_end) {}
int start;
int end;
};
结构体TextRange定义结构体的文本范围,包括开始start()
和结束end()
struct TextAttribute
{
TextAttribute() : type(NONE) {}
TextAttribute(int _start, int _end, TextAttributeType _type) : range(_start, _end), type(_type) {}
TextRange range;
TextAttributeType type;
};
结构体TextAttribute定义了文本的属性
struct Text
{
Text() : str(L"") {}
Text(std::wstring const& _str) : str(_str) {}
void clear()
{
str.clear();
attributes.clear();
}
bool empty() const
{
return str.empty();
}
std::wstring str;
std::vector<TextAttribute> attributes;
};
结构体Test定义了文本的一些格式,包括test方法,清空clear()方法,empty()方法
struct CandidateInfo
{
CandidateInfo()
{
currentPage = 0;
totalPages = 0;
highlighted = 0;
}
void clear()
{
currentPage = 0;
totalPages = 0;
highlighted = 0;
candies.clear();
labels.clear();
}
bool empty() const
{
return candies.empty();
}
int currentPage;
int totalPages;
int highlighted;
std::vector<Text> candies;
std::vector<Text> comments;
std::vector<Text> labels;
};
结构体CandidateInfo定义了候选信息,声明了CandidateInfo()、clear()、empty() 等方法以及currentPage、totalPages、highlighted等变量,定义了当前页面、全部页面以及选中部分等。
struct Context
{
Context() {}
void clear()
{
preedit.clear();
aux.clear();
cinfo.clear();
}
bool empty() const
{
return preedit.empty() && aux.empty() && cinfo.empty();
}
Text preedit;
Text aux;
CandidateInfo cinfo;
};
结构体Context定义了上下文语境等,实例化了Text的两个对象 preedit和aux,,以及CandidateInfo的一个对象cinfo来调用CandidateInfo,通过调用Text的clear方法来清空一些数据,然后empty方法的返回值为bool类型,返回是否清空的信息。
// 由ime管理
struct Status
{
Status() : ascii_mode(false), composing(false), disabled(false) {}
void reset()
{
schema_name.clear();
ascii_mode = false;
composing = false;
disabled = false;
}
// 输入方法
std::wstring schema_name;
// 转换开关
bool ascii_mode;
// 写作状态
bool composing;
// 维护模式(暂停输入功能)
bool disabled;
};
// 用於向前端告知設置信息
struct Config
{
Config() : inline_preedit(false) {}
void reset()
{
inline_preedit = false;
}
bool inline_preedit;
};
Config结构体定义配置信息,用于向前端告知设置信息。
struct UIStyle
{
enum PreeditType
{
COMPOSITION,
PREVIEW
};
enum LayoutType
{
LAYOUT_VERTICAL = 0,
LAYOUT_HORIZONTAL,
LAYOUT_VERTICAL_FULLSCREEN,
LAYOUT_HORIZONTAL_FULLSCREEN,
LAYOUT_TYPE_LAST
};
PreeditType preedit_type;
LayoutType layout_type;
std::wstring font_face;
int font_point;
bool inline_preedit;
bool display_tray_icon;
std::wstring label_text_format;
// layout
int min_width;
int min_height;
int border;
int margin_x;
int margin_y;
int spacing;
int candidate_spacing;
int hilite_spacing;
int hilite_padding;
int round_corner;
// color scheme
int text_color;
int candidate_text_color;
int label_text_color;
int comment_text_color;
int back_color;
int border_color;
int hilited_text_color;
int hilited_back_color;
int hilited_candidate_text_color;
int hilited_candidate_back_color;
int hilited_label_text_color;
int hilited_comment_text_color;
// per client
int client_caps;
UIStyle() :
font_face(),
font_point(0),
inline_preedit(false),
preedit_type(COMPOSITION),
display_tray_icon(false),
label_text_format(L"%s."),
layout_type(LAYOUT_VERTICAL),
min_width(0),
min_height(0),
border(0),
margin_x(0),
margin_y(0),
spacing(0),
candidate_spacing(0),
hilite_spacing(0),
hilite_padding(0),
round_corner(0),
text_color(0),
candidate_text_color(0),
label_text_color(0),
comment_text_color(0),
back_color(0),
border_color(0),
hilited_text_color(0),
hilited_back_color(0),
hilited_candidate_text_color(0),
hilited_candidate_back_color(0),
hilited_label_text_color(0),
hilited_comment_text_color(0),
client_caps(0) {}
};
}