mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-11-30 16:48:21 +01:00
@@ -1,53 +1,84 @@
|
||||
# The LCUI Project
|
||||
|
||||
[](https://gitter.im/lc-soft/LCUI?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[](https://travis-ci.org/lc-soft/LCUI)
|
||||
|
||||

|
||||
|
||||
[](https://gitter.im/lc-soft/LCUI?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[](https://travis-ci.org/lc-soft/LCUI)
|
||||
[](https://sourceforge.net/projects/lc-ui)
|
||||
[](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
|
||||
|
||||
## Description
|
||||
|
||||
The LCUI project is create by a China developer, and his English is
|
||||
not very good, so, some files will appear chinese character,
|
||||
please understand. thanks.
|
||||
[中文版说明文档](README.zh-cn.md)
|
||||
|
||||
Please read the file `docs/CHANGES.md`, it contains IMPORTANT INFORMATION.
|
||||
LCUI is a freely available software library to create GUI application.
|
||||
|
||||
It is written in C, support the use XML and CSS describe the graphical
|
||||
interface, you can use it to make some simple effects, like in this example:
|
||||
|
||||
Read the file `INSTALL` for installation instructions.
|
||||

|
||||
|
||||
See the file `docs/LICENSE.TXT` for the available licenses.
|
||||
Author is from China, but his English is not very good, so, some
|
||||
files will appear chinese character, please understand. thanks.
|
||||
|
||||
Please read the file `docs/CHANGES.md`, it contains IMPORTANT INFORMATION.
|
||||
|
||||
Read the file `INSTALL` for installation instructions.
|
||||
|
||||
See the file `docs/LICENSE.TXT` for the available licenses.
|
||||
|
||||
## Documentation
|
||||
|
||||
API reference documentation has not yet been prepared, development to
|
||||
more mature in this project will consider writing it.
|
||||
At this stage, you can refer to the header files, source code, and
|
||||
sample programs .
|
||||
Tutorial: https://lcui.lc-soft.io/guide/
|
||||
|
||||
API reference documentation has not yet been prepared, you can refer to the
|
||||
header files, source code, and sample programs.
|
||||
|
||||
## Building
|
||||
|
||||
To bootstrap the build you need to run `./configure` (in the root of the
|
||||
source tree).
|
||||
### Bootstrap
|
||||
|
||||
To bootstrap the build you need to run `./configure` (in the root of the
|
||||
source tree).
|
||||
|
||||
In the simplest case you would run:
|
||||
|
||||
git clone https://github.com/lc-soft/LCUI.git
|
||||
cd LCUI
|
||||
git submodule update --init
|
||||
./autogen.sh
|
||||
./configure
|
||||
|
||||
Please note that if you downloaded the source code (rather than cloned
|
||||
via git) you likely miss the submodules and the build will therefor fail.
|
||||
### Prerequisites
|
||||
|
||||
If you want to build full-featured LCUI, we suggest you install the following
|
||||
dependent libraries:
|
||||
|
||||
* [libpng](http://www.libpng.org/pub/png/libpng.html) — PNG image compression library
|
||||
* [libjpeg](http://www.ijg.org/) — JPEG image compression library
|
||||
* [libxml2](http://xmlsoft.org/) — The XML C parser and toolkit
|
||||
* [libx11-dev](https://www.x.org/) — X11 client-side library
|
||||
* [freetype](https://www.freetype.org/) — Font engine
|
||||
|
||||
If you system is Ubuntu, you can run following command to install dependencies:
|
||||
|
||||
apt-get install libpng-dev libjpeg-dev libxml2-dev libfreetype6-dev libx11-dev
|
||||
|
||||
### Building On Windows
|
||||
|
||||
LCUI is mainly develop in the Windows environment, you can use VisualStudio
|
||||
to open file `build/VS2012/LCUI.sln` and compile LCUI.
|
||||
|
||||
## Bugs
|
||||
|
||||
Please report bugs by e-mail to `lc-soft@live.cn`. Don't forget to
|
||||
send a detailed explanation of the problem -- there is nothing
|
||||
worse than receiving a terse message that only says `it doesn't work`.
|
||||
Please report bugs by e-mail to `lc-soft@live.cn`. Don't forget to send a
|
||||
detailed explanation of the problem -- there is nothing worse than receiving
|
||||
a terse message that only says `it doesn't work`.
|
||||
|
||||
## Contributing
|
||||
|
||||
You can send pull requests via GitHub. Patches should:
|
||||
**You can send pull requests via GitHub.**
|
||||
|
||||
Patches should:
|
||||
|
||||
1. Follow the style of the existing code.
|
||||
2. One commit should do exactly one thing.
|
||||
@@ -69,6 +100,12 @@ You can send pull requests via GitHub. Patches should:
|
||||
make it easier for us (and avoid any legal issues) we prefer if
|
||||
patches are released as public domain.
|
||||
|
||||
**You can donate support the development of LCUI.**
|
||||
|
||||
I'm currently an independent developer and your contributions are useful.
|
||||
I have setup an [LCUI Patreon page](https://www.patreon.com/lcsoft) if you
|
||||
want to donate and enable me to spend more time improving the library.
|
||||
One-off donations are also greatly appreciated. Thanks!
|
||||
|
||||
### GitHub Workflow
|
||||
|
||||
@@ -106,9 +143,9 @@ If a lot of changes has happened upstream you can replay your local changes
|
||||
|
||||
This will fetch changes and re-apply your commits on top of these.
|
||||
|
||||
This is generally better than merge, as it will give a clear picture of
|
||||
which commits are local to your branch. It will also “prune” any of your
|
||||
local commits if the same changes have been applied upstream.
|
||||
This is generally better than merge, as it will give a clear picture of which
|
||||
commits are local to your branch. It will also “prune” any of your local
|
||||
commits if the same changes have been applied upstream.
|
||||
|
||||
You can use `-i` with `rebase` for an “interactive” rebase. This allows
|
||||
you to drop, re-arrange, merge, and reword commits, e.g.:
|
||||
@@ -123,7 +160,8 @@ The LCUI Project is released under the GNU General Public License as published
|
||||
option) any later version.
|
||||
|
||||
## Thanks to
|
||||
Liu Chao <lc-soft@live.cn>
|
||||
|
||||
Liu Chao <lc-soft@live.cn>
|
||||
|
||||
Special thanks to Liu Chao for his great work on the LCUI's development.
|
||||
|
||||
|
||||
+59
-67
@@ -1,17 +1,24 @@
|
||||
# The LCUI Project
|
||||
|
||||
[](https://gitter.im/lc-soft/LCUI?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
||||
[](https://travis-ci.org/lc-soft/LCUI)
|
||||
|
||||

|
||||
|
||||
[](https://gitter.im/lc-soft/LCUI?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[](https://travis-ci.org/lc-soft/LCUI)
|
||||
[](https://sourceforge.net/projects/lc-ui)
|
||||
[](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
|
||||
|
||||
## 说明
|
||||
|
||||
LCUI 是一个简单的跨平台图形界面库,适用于开发一些简单的小程序,其诞生目的主要是方便作者开发图形界面程序。
|
||||
LCUI 是一个简单的跨平台图形界面库,其诞生目的主要是方便作者开发图形界面程序,
|
||||
源代码主要由 C 语言编写,支持使用 XML 和 CSS 代码来描述图像界面,适用于开发一
|
||||
些简单的小程序,可以实现一些简单的效果,类似于这样:
|
||||
|
||||
LCUI 是一个自由软件项目,基于 GNU通用公共许可协议 发布,该许可协议要求 LCUI 及 LCUI 衍生软件无论以何种形式发布,都必须确保收受者能收到或得到源码。
|
||||

|
||||
|
||||
此项目主要由作者利用闲余时间进行开发和维护,项目的活跃度通常会受到各种因素的影响,大多数时间内都处于低活跃度状态。
|
||||
LCUI 是一个自由软件项目,基于 [GNU通用公共许可协议](http://www.gnu.org/licenses/gpl-2.0.html)
|
||||
发布,该许可协议要求 LCUI 及 LCUI 衍生软件无论以何种形式发布,都必须确保收受者
|
||||
能收到或得到该版本的源代码。此项目主要由作者利用闲余时间进行开发和维护,项目的
|
||||
活跃度通常会受到各种因素的影响,大多数时间内都处于低活跃度状态。
|
||||
|
||||
请阅读 `docs/CHANGES.zh-cn.md` 文件了解新版本的更新内容。
|
||||
|
||||
@@ -19,51 +26,23 @@ LCUI 是一个自由软件项目,基于 GNU通用公共许可协议 发布,
|
||||
|
||||
阅读 `docs/LICENSE.TXT` 文件了解 GPLv2 许可协议的具体内容。
|
||||
|
||||
项目主页:http://www.lcui.org
|
||||
项目主页:http://lcui.lc-soft.io
|
||||
|
||||
联系邮箱:lc-soft@live.cn
|
||||
|
||||
项目托管:https://github.com/lc-soft/LCUI
|
||||
|
||||
LCUI 的相关信息与资料可以在项目主页中找到,如果遇到问题、发现BUG或者有好的建议和
|
||||
想法,可以在项目主页上留言或发送邮件告诉我们。
|
||||
|
||||
我们已经使用 GitHub 托管 LCUI 项目,网址在上面,欢迎您参与 LCUI 项目的优化和改进。
|
||||
|
||||
## 文件目录结构
|
||||
|
||||
以下是各个目录内容的相关说明:
|
||||
```
|
||||
|
||||
/ 项目文件目录
|
||||
/bin/ 在编译生成后库文件的存放目录
|
||||
/build/ 参与项目编译、构建和生成的相关文件
|
||||
/build/VS2012/ VisualStudio 2012 工程文件
|
||||
/docs/ 相关文档
|
||||
/include/ 头文件
|
||||
/src/ 源文件
|
||||
/src/gui/ 图形界面
|
||||
/src/gui/widget/ 预置的图形界面组件
|
||||
/src/font/ 文字和字体
|
||||
/src/draw/ 图形绘制
|
||||
/src/bmp/ 位图文件读写
|
||||
/src/thread/ 各平台下的线程操作接口的封装
|
||||
/src/util/ 一些常用工具集
|
||||
/src/platform/ 平台相关支持
|
||||
/src/platform/windows windows 平台支持
|
||||
/src/platform/linux linux 平台支持
|
||||
/test/ 测试(示例)程序
|
||||
|
||||
```
|
||||
Github:https://github.com/lc-soft/LCUI
|
||||
|
||||
## 文档
|
||||
|
||||
你可以访问LCUI的项目主页浏览开发文档,开发文档也托管在GitHub上,地址:https://github.com/lc-soft/LCUI-Documentation
|
||||
教程:https://lcui.lc-soft.io/guide/
|
||||
|
||||
如果你通过LCUI的源代码和示例程序领悟到了一些些有趣的东西,可以帮助我们完善开发文档,与其他人分享你的成果。
|
||||
目前还没有 API 参考文档,你可以参考头文件、源代码、示例程序以及作者开发过的相
|
||||
关程序来了解基本用法。
|
||||
|
||||
## 构建
|
||||
|
||||
### 引导
|
||||
|
||||
你需要运行 `./configure` (在源码根目录中) 以引导项目的构建。
|
||||
|
||||
在最简单的情况下,你可以运行:
|
||||
@@ -74,41 +53,50 @@ LCUI 的相关信息与资料可以在项目主页中找到,如果遇到问题
|
||||
|
||||
如果未找到 ./configure,请运行 ./autogen.sh 脚本生成它。
|
||||
|
||||
在 LCUI 的项目主页上发布的源码包,一般是比较稳定的版本,你只需要这样做:
|
||||
在 `./configure` 执行完后,运行以下命令编译源代码并安装 LCUI 的函数库和头文件:
|
||||
|
||||
1. 解压LCUI的源码包。
|
||||
2. 进入解压后得到的新文件夹。
|
||||
3. 运行源码根目录中的configure脚本,以对系统环境进行检测。
|
||||
4. 使用make命令编译 LCUI 的源代码。
|
||||
5. 等待编译成功完成,如果在编译过程中遇到错误,请检查您的系统中是否有完整的编译环境。
|
||||
6. 使用make install命令安装 LCUI 的函数库和头文件。
|
||||
make
|
||||
make install
|
||||
|
||||
windows系统上构建本项目方法,有两种:
|
||||
如果需要运行示例程序,可运行命令来编译生成示例程序:
|
||||
|
||||
1. 使用 Visual Studio 2012 或更高版本,你只需要使用它打开 `build/VS2012/` 目录下的
|
||||
`LCUI.sln` 文件,然后生成解决方案即可,生成成功后,在 `bin/` 目录下可找到库文件。
|
||||
2. 使用 Cygwin 或 MSYS,可按照上述1至6的步骤进行构建,在完成步骤3后,请修改
|
||||
`include/LCUI/config.h` 文件,定义 `LCUI_BUILD_IN_WIN32` 宏,若有
|
||||
`LCUI_BUILD_IN_LINUX` 宏,请删除它。该方法并未实际测试,如有其它方法请告知。
|
||||
cd test
|
||||
make
|
||||
|
||||
### 系统需求
|
||||
### 依赖项
|
||||
|
||||
* 字体处理:freetype2
|
||||
* XML 解析:libxml2
|
||||
* 线程支持:pthread
|
||||
* 图片处理:libpng 和 libjpeg
|
||||
如果你想构建全特性的 LCUI,建议安装以下依赖库:
|
||||
|
||||
为了你能正常使用 LCUI 全部功能,请先确保您的计算机已经安装了上述的函数库,并保持较新的版本。
|
||||
理论上,LCUI 能在 GNU/Linux 系统环境中正常工作,LCUI 的图形输出,需要内核支持 FrameBuffer。
|
||||
* [libpng](http://www.libpng.org/pub/png/libpng.html) — PNG 图像压缩库
|
||||
* [libjpeg](http://www.ijg.org/) — JPEG 图像压缩库
|
||||
* [libxml2](http://xmlsoft.org/) — XML 解析器及相关工具集
|
||||
* [libx11-dev](https://www.x.org/) — X11 客户端库
|
||||
* [freetype](https://www.freetype.org/) — 字体渲染引擎
|
||||
|
||||
如果你的系统是 Ubuntu,可运行以下命令来安装依赖:
|
||||
|
||||
apt-get install libpng-dev libjpeg-dev libxml2-dev libfreetype6-dev libx11-dev
|
||||
|
||||
|
||||
### 在 Windows 中构建
|
||||
|
||||
LCUI 主要是在 Windows 系统环境下开发的,你可以使用 VisualStudio 打开
|
||||
`/build/VS2012/LCUI.sln` 文件,然后编译生成 LCUI。如果你用的是其它 IDE,请尝
|
||||
试按该 IDE 的方式创建项目并将源文件添加至项目内,然后编译。
|
||||
|
||||
上述的依赖库除 libx11 外,都可以在 Windows 下编译生成,如果觉得手动编译它们很
|
||||
麻烦,想要现成可用的依赖库和头文件,可以联系作者。
|
||||
|
||||
## 贡献
|
||||
|
||||
你可以通过GitHub向本项目提交合并请求,补丁应符合以下要求:
|
||||
**你可以通过 GitHub 向本项目提交合并请求**
|
||||
|
||||
补丁应符合以下要求:
|
||||
|
||||
1. 遵循现有代码风格,请参考 `docs/CodingStyle.zh-cn.md` 文件。
|
||||
2. 一次提交应该做完整的一件事。
|
||||
3. 提交信息的第一行为摘要行,长度应低于80个字符,如果需要描述修改原因,请在摘要行后留空行,然后再补充。
|
||||
4. 修复之前的提交(已经合并)中存在的bug,提交信息的摘要行应该以 `修复` 或含义类似的词语开头,表示修复
|
||||
4. 修复之前的提交(已经合并)中存在的 bug,提交信息的摘要行应该以 `修复` 或含义类似的词语开头,表示修复
|
||||
了它。如果你修复的是 issues 列表中未解决的问题,需在摘要行中加上 issues 列表中对应问题的编号。
|
||||
5. 衍合你的分支至源项目的 master 分支。我们不希望落拉取到冗余的合并请求。
|
||||
6. **要清楚什么许可证适用于你的补丁:** 该代码库中的文件基于GPLv2(或更高版本),但(原
|
||||
@@ -116,17 +104,21 @@ windows系统上构建本项目方法,有两种:
|
||||
以后不会进入任何非自由的衍生工具,因此,如果补丁发布于公共领域,会为我们带来方便(以及
|
||||
避免任何法律问题)。
|
||||
|
||||
**你可以通过捐赠来支持 LCUI 的开发**
|
||||
|
||||
### GitHub流程
|
||||
作者目前是一名独立开发者,你的贡献是非常有帮助的,如果你想通过捐赠来让作者能够花更多的时间来改进该项目,
|
||||
可以访问作者在 [Patreon](https://www.patreon.com/lcsoft) 上设立的页面。
|
||||
|
||||
### GitHub 流程
|
||||
|
||||
开发补丁应遵循以下流程:
|
||||
|
||||
#### 初始设置
|
||||
|
||||
1. 在GitHub上进行Fork (点击 Fork 按钮)
|
||||
2. Clone到计算机: `git clone git@github.com:你的用户名/LCUI.git`
|
||||
1. 在 GitHub 上进行Fork (点击 Fork 按钮)
|
||||
2. Clone 到计算机: `git clone git@github.com:你的用户名/LCUI.git`
|
||||
3. cd 到代码库中: `cd LCUI`
|
||||
4. 设置远程仓库记录,假设该记录名为upstream,那么命令为: `git remote add -f upstream git://github.com/lc-soft/LCUI.git`
|
||||
4. 设置远程仓库记录,假设该记录名为 upstream,那么命令为: `git remote add -f upstream git://github.com/lc-soft/LCUI.git`
|
||||
|
||||
#### 添加Feature
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "helloworld", "helloworld\he
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LCUITest", "LCUITest\LCUITest.vcxproj", "{D639E1FA-B41B-40E5-8EC8-6FA3E5D946E7}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testtouch", "testtouch\testtouch.vcxproj", "{E5E79245-9412-49C8-8FE7-3AF7A7111E2F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|ARM = Debug|ARM
|
||||
@@ -33,6 +35,14 @@ Global
|
||||
{D639E1FA-B41B-40E5-8EC8-6FA3E5D946E7}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{D639E1FA-B41B-40E5-8EC8-6FA3E5D946E7}.Release|Win32.Build.0 = Release|Win32
|
||||
{D639E1FA-B41B-40E5-8EC8-6FA3E5D946E7}.Release|x64.ActiveCfg = Release|Win32
|
||||
{E5E79245-9412-49C8-8FE7-3AF7A7111E2F}.Debug|ARM.ActiveCfg = Debug|Win32
|
||||
{E5E79245-9412-49C8-8FE7-3AF7A7111E2F}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{E5E79245-9412-49C8-8FE7-3AF7A7111E2F}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{E5E79245-9412-49C8-8FE7-3AF7A7111E2F}.Debug|x64.ActiveCfg = Debug|Win32
|
||||
{E5E79245-9412-49C8-8FE7-3AF7A7111E2F}.Release|ARM.ActiveCfg = Release|Win32
|
||||
{E5E79245-9412-49C8-8FE7-3AF7A7111E2F}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{E5E79245-9412-49C8-8FE7-3AF7A7111E2F}.Release|Win32.Build.0 = Release|Win32
|
||||
{E5E79245-9412-49C8-8FE7-3AF7A7111E2F}.Release|x64.ActiveCfg = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
Binary file not shown.
@@ -113,7 +113,7 @@
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>libxml2.lib;libpng16.lib;libjpeg.lib;freetype253.lib;zlib.lib;kernel32.lib;user32.lib;gdi32.lib;</AdditionalDependencies>
|
||||
@@ -148,12 +148,13 @@
|
||||
<ClInclude Include="..\..\..\include\LCUI\font\textlayer.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\font\textstyle.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\gui\builder.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\gui\css_library.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\gui\css_parser.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\gui\messagebox.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\gui\widget.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\gui\widget\button.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\gui\widget\scrollbar.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\gui\widget\sidebar.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\gui\widget\textedit.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\gui\widget\textview.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\gui\widget_base.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\gui\widget_event.h" />
|
||||
@@ -170,7 +171,6 @@
|
||||
<ClInclude Include="..\..\..\include\LCUI\graph.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\input.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\ime.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\lib.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\main.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\platform.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\platform\windows\windows_display.h" />
|
||||
@@ -180,12 +180,14 @@
|
||||
<ClInclude Include="..\..\..\include\LCUI\surface.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\thread.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\timer.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\util.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\util\delay.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\util\dict.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\util\dirent.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\util\event.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\util\framectrl.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\util\linkedlist.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\util\memdebug.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\util\parse.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\util\rbtree.h" />
|
||||
<ClInclude Include="..\..\..\include\LCUI\util\rect.h" />
|
||||
@@ -214,10 +216,12 @@
|
||||
<ClCompile Include="..\..\..\src\font\textlayer.c" />
|
||||
<ClCompile Include="..\..\..\src\font\textstyle.c" />
|
||||
<ClCompile Include="..\..\..\src\gui\builder.c" />
|
||||
<ClCompile Include="..\..\..\src\gui\css_library.c" />
|
||||
<ClCompile Include="..\..\..\src\gui\css_parser.c" />
|
||||
<ClCompile Include="..\..\..\src\gui\widget\button.c" />
|
||||
<ClCompile Include="..\..\..\src\gui\widget\scrollbar.c" />
|
||||
<ClCompile Include="..\..\..\src\gui\widget\sidebar.c" />
|
||||
<ClCompile Include="..\..\..\src\gui\widget\textedit.c" />
|
||||
<ClCompile Include="..\..\..\src\gui\widget\textview.c" />
|
||||
<ClCompile Include="..\..\..\src\gui\widget_background.c" />
|
||||
<ClCompile Include="..\..\..\src\gui\widget_base.c" />
|
||||
@@ -231,6 +235,7 @@
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MaxSpeed</Optimization>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\src\ime.c" />
|
||||
<ClCompile Include="..\..\..\src\keyboard.c" />
|
||||
<ClCompile Include="..\..\..\src\main.c" />
|
||||
<ClCompile Include="..\..\..\src\platform\windows\windows_display.c" />
|
||||
<ClCompile Include="..\..\..\src\platform\windows\windows_events.c" />
|
||||
@@ -243,13 +248,12 @@
|
||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)include;$(SolutionDir)include\..\..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\src\timer.c" />
|
||||
<ClCompile Include="..\..\..\src\util\delay.c" />
|
||||
<ClCompile Include="..\..\..\src\util\dict.c" />
|
||||
<ClCompile Include="..\..\..\src\util\dirent.c" />
|
||||
<ClCompile Include="..\..\..\src\util\event.c" />
|
||||
<ClCompile Include="..\..\..\src\util\framectrl.c" />
|
||||
<ClCompile Include="..\..\..\src\util\linkedlist.c" />
|
||||
<ClCompile Include="..\..\..\src\util\mem_debug.c" />
|
||||
<ClCompile Include="..\..\..\src\util\memdebug.c" />
|
||||
<ClCompile Include="..\..\..\src\util\parse.c" />
|
||||
<ClCompile Include="..\..\..\src\util\rbtree.c" />
|
||||
<ClCompile Include="..\..\..\src\util\rect.c" />
|
||||
|
||||
@@ -96,9 +96,6 @@
|
||||
<ClInclude Include="..\..\..\include\LCUI\draw\border.h">
|
||||
<Filter>头文件\LCUI\draw</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\include\LCUI\gui\messagebox.h">
|
||||
<Filter>头文件\LCUI\gui</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\include\LCUI\draw\line.h">
|
||||
<Filter>头文件\LCUI\draw</Filter>
|
||||
</ClInclude>
|
||||
@@ -195,9 +192,6 @@
|
||||
<ClInclude Include="..\..\..\include\LCUI\platform\windows\windows_keyboard.h">
|
||||
<Filter>头文件\LCUI\platform\windows</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\include\LCUI\lib.h">
|
||||
<Filter>头文件\LCUI</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\include\LCUI\main.h">
|
||||
<Filter>头文件\LCUI</Filter>
|
||||
</ClInclude>
|
||||
@@ -237,6 +231,18 @@
|
||||
<ClInclude Include="..\..\..\include\LCUI\util\time.h">
|
||||
<Filter>头文件\LCUI\util</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\include\LCUI\gui\widget\textedit.h">
|
||||
<Filter>头文件\LCUI\gui\widget</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\include\LCUI\util\memdebug.h">
|
||||
<Filter>头文件\LCUI\util</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\include\LCUI\util.h">
|
||||
<Filter>头文件\LCUI</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\include\LCUI\gui\css_library.h">
|
||||
<Filter>头文件\LCUI\gui</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\..\src\draw\border.c">
|
||||
@@ -272,9 +278,6 @@
|
||||
<ClCompile Include="..\..\..\src\bmp\jpeg.c">
|
||||
<Filter>源文件\bmp</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\src\bmp\load_image.c">
|
||||
<Filter>源文件\bmp</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\src\bmp\png.c">
|
||||
<Filter>源文件\bmp</Filter>
|
||||
</ClCompile>
|
||||
@@ -368,9 +371,6 @@
|
||||
<ClCompile Include="..\..\..\src\timer.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\src\util\delay.c">
|
||||
<Filter>源文件\util</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\src\util\dict.c">
|
||||
<Filter>源文件\util</Filter>
|
||||
</ClCompile>
|
||||
@@ -386,9 +386,6 @@
|
||||
<ClCompile Include="..\..\..\src\util\linkedlist.c">
|
||||
<Filter>源文件\util</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\src\util\mem_debug.c">
|
||||
<Filter>源文件\util</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\src\util\parse.c">
|
||||
<Filter>源文件\util</Filter>
|
||||
</ClCompile>
|
||||
@@ -404,6 +401,21 @@
|
||||
<ClCompile Include="..\..\..\src\util\time.c">
|
||||
<Filter>源文件\util</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\src\bmp\load_image.c">
|
||||
<Filter>源文件\bmp</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\src\gui\widget\textedit.c">
|
||||
<Filter>源文件\gui\widget</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\src\keyboard.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\src\util\memdebug.c">
|
||||
<Filter>源文件\util</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\src\gui\css_library.c">
|
||||
<Filter>源文件\gui</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\..\README" />
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{E5E79245-9412-49C8-8FE7-3AF7A7111E2F}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>testtouch</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140_xp</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRules />
|
||||
<CodeAnalysisRuleAssemblies />
|
||||
<OutDir>$(SolutionDir)..\..\bin\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\..\bin\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRules />
|
||||
<CodeAnalysisRuleAssemblies />
|
||||
<OutDir>$(SolutionDir)..\..\bin\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\..\bin\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)\include;$(SolutionDir)\include\..\..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<CompileAs>CompileAsC</CompileAs>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>LCUI_D.lib;LCUIMain.lib;</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)\include;$(SolutionDir)\include\..\..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<DisableSpecificWarnings>4819</DisableSpecificWarnings>
|
||||
<BrowseInformation>true</BrowseInformation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>LCUI.lib</AdditionalDependencies>
|
||||
</Link>
|
||||
<Bscmake>
|
||||
<PreserveSbr>true</PreserveSbr>
|
||||
</Bscmake>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\..\test\testtouch.c" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="源文件">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="头文件">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="资源文件">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\..\test\testtouch.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
+33
-36
@@ -1,9 +1,6 @@
|
||||
# -*- Autoconf -*-
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
#
|
||||
# 具体用法,可参考Automake的中文文档:
|
||||
# http://www.linuxforum.net/books/autoconf.html
|
||||
# 也可以到这看英文版的:
|
||||
# http://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/index.html
|
||||
|
||||
AC_PREREQ([2.68])
|
||||
@@ -56,7 +53,7 @@ if test "x$with_iconv" != "xno"; then
|
||||
AC_CHECK_LIB([iconv], [iconv_open], [
|
||||
want_iconv=yes
|
||||
LCUI_LIBADD="$LCUI_LIBADD -liconv"
|
||||
AC_DEFINE_UNQUOTED(USE_LIBICONV, 1, Define to 1 if you have the libiconv)
|
||||
AC_DEFINE_UNQUOTED([USE_LIBICONV], 1, [Define to 1 if you have the libiconv.])
|
||||
], want_iconv=no)
|
||||
|
||||
fi
|
||||
@@ -65,45 +62,44 @@ want_thread=no
|
||||
thread_name=pthread
|
||||
AC_ARG_WITH(pthread, [ --with-pthread use pthread (default)])
|
||||
if test "x$with_pthread" != "xno"; then
|
||||
##检测是否有pthread头文件及函数库,测试调用pthread_create函数
|
||||
AC_CHECK_HEADERS([pthread.h],[
|
||||
AC_CHECK_LIB([pthread], [pthread_create], [
|
||||
want_thread=yes
|
||||
LCUI_LIBS="$LCUI_LIBS -lpthread"
|
||||
AC_DEFINE_UNQUOTED(LCUI_THREAD_PTHREAD, 1, Define to 1 if you using pthread support)
|
||||
], want_thread=no)
|
||||
], want_thread=no)
|
||||
AX_PTHREAD([
|
||||
want_thread=yes
|
||||
CC="$PTHREAD_CC"
|
||||
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
|
||||
LCUI_LIBS="$LCUI_LIBS $PTHREAD_LIBS"
|
||||
AC_DEFINE_UNQUOTED([LCUI_THREAD_PTHREAD], 1, [Define to 1 if you are using pthread support.])
|
||||
], [AC_MSG_ERROR([The support could not be configured for the POSIX thread programming interface.])])
|
||||
fi
|
||||
|
||||
##检测是否有libxml2库,必须有 libxml2 库才能启用 LCUIBuilder 功能模块
|
||||
enable_builder=yes
|
||||
AC_ARG_ENABLE(lcui-builder, AC_HELP_STRING([--enable-lcui-builder],
|
||||
[enable lcui-builder function module [[default=no]]]), enable_builder=$enableval)
|
||||
[enable lcui-builder function module [[default=no]]]), [enable_builder=$enableval])
|
||||
if test "$enable_builder" = "yes"; then
|
||||
AC_CHECK_HEADERS([libxml/parser.h],[
|
||||
AC_CHECK_LIB([xml2], [xmlParseFile], [
|
||||
enable_builder=yes
|
||||
CFLAGS="$CFLAGS -I/usr/include/libxml2"
|
||||
LCUI_LIBS="$LCUI_LIBS -lxml2"
|
||||
AC_DEFINE_UNQUOTED(USE_LCUI_BUILDER, 1, Define to 1 if you enabled LCUIBuilder function module)
|
||||
], enable_builder=no)
|
||||
], enable_builder=no)
|
||||
CFLAGS="$CFLAGS -I/usr/include/libxml2"
|
||||
AC_DEFINE_UNQUOTED([USE_LCUI_BUILDER], 1, [Define to 1 if you enabled LCUIBuilder function module.])
|
||||
], [enable_builder=no])
|
||||
], [enable_builder=no])
|
||||
fi
|
||||
|
||||
##检测是否有freetype库
|
||||
want_font_engine=yes
|
||||
font_engine_name=none
|
||||
AC_ARG_ENABLE(font-engine, AC_HELP_STRING([--enable-font-engine],
|
||||
[turn on font-engine [[default=yes]]]), want_font_engine=$enableval)
|
||||
[turn on font-engine [[default=yes]]]), [want_font_engine=$enableval])
|
||||
if test "$want_font_engine" = yes; then
|
||||
AC_CHECK_HEADERS([ft2build.h], [
|
||||
AC_CHECK_LIB([freetype], [FT_Init_FreeType], [
|
||||
want_font_engine=yes
|
||||
CFLAGS="$CFLAGS -I/usr/include/freetype2"
|
||||
LCUI_LIBS="$LCUI_LIBS -lfreetype"
|
||||
font_engine_name=freetype2
|
||||
AC_DEFINE_UNQUOTED(LCUI_FONT_ENGINE_FREETYPE, 1, Define to 1 if you have the FreeType font engine)
|
||||
], want_font_engine=no)
|
||||
LCUI_LIBS="$LCUI_LIBS `pkg-config --libs freetype2`"
|
||||
CFLAGS="$CFLAGS `pkg-config --cflags-only-I freetype2`"
|
||||
AC_DEFINE_UNQUOTED([LCUI_FONT_ENGINE_FREETYPE], 1, [Define to 1 if you have the FreeType font engine.])
|
||||
], [want_font_engine=no])
|
||||
], [want_font_engine=no])
|
||||
else
|
||||
want_font_engine=no
|
||||
@@ -113,18 +109,18 @@ fi
|
||||
want_video_output=yes
|
||||
video_driver_name=framebuffer
|
||||
AC_ARG_ENABLE(video-output, AC_HELP_STRING([--enable-video-output],
|
||||
[turn on video-output [[default=yes]]]), want_video_output=$enableval)
|
||||
[turn on video-output [[default=yes]]]), [want_video_output=$enableval])
|
||||
if test "$want_video_output" = yes; then
|
||||
AC_CHECK_HEADERS([linux/fb.h],[
|
||||
video_driver_name=framebuffer
|
||||
AC_DEFINE_UNQUOTED(LCUI_VIDEO_DRIVER_FRAMEBUFFER, 1, Define to 1 if you select FrameBuffer for video support)
|
||||
AC_DEFINE_UNQUOTED([LCUI_VIDEO_DRIVER_FRAMEBUFFER], 1, [Define to 1 if you select FrameBuffer for video support.])
|
||||
], [video_driver_name=none])
|
||||
AC_CHECK_HEADERS([X11/Xlib.h],[
|
||||
AC_CHECK_LIB([X11], [XOpenDisplay], [
|
||||
CFLAGS="$CFLAGS `pkg-config --cflags-only-I x11`"
|
||||
LCUI_LIBS="$LCUI_LIBS `pkg-config --libs x11`"
|
||||
video_driver_name=x11
|
||||
AC_DEFINE_UNQUOTED(LCUI_VIDEO_DRIVER_X11, 1, Define to 1 if you select XWindow for video support)
|
||||
LCUI_LIBS="$LCUI_LIBS `pkg-config --libs x11`"
|
||||
CFLAGS="$CFLAGS `pkg-config --cflags-only-I x11`"
|
||||
AC_DEFINE_UNQUOTED([LCUI_VIDEO_DRIVER_X11], 1, [Define to 1 if you select XWindow for video support.])
|
||||
], [])
|
||||
], [])
|
||||
else
|
||||
@@ -138,8 +134,8 @@ if test "x$with_ts" != "xno"; then
|
||||
AC_CHECK_LIB([ts], [ts_open], [
|
||||
want_ts=yes
|
||||
LCUI_LIBS="$LCUI_LIBS -lts"
|
||||
AC_DEFINE_UNQUOTED(USE_TSLIB, 1, Define to 1 if you have the tslib)
|
||||
], want_ts=no)
|
||||
AC_DEFINE_UNQUOTED([USE_TSLIB], 1, [Define to 1 if you have the tslib])
|
||||
], [want_ts=no])
|
||||
fi
|
||||
|
||||
want_png=no
|
||||
@@ -148,10 +144,11 @@ if test "x$with_png" != "xno"; then
|
||||
AC_CHECK_HEADERS([png.h],[
|
||||
AC_CHECK_LIB([png], [png_sig_cmp],[
|
||||
want_png=yes
|
||||
LCUI_LIBS="$LCUI_LIBS -lpng"
|
||||
AC_DEFINE_UNQUOTED(USE_LIBPNG, 1, Define to 1 if you have the libpng)
|
||||
],want_png=no)
|
||||
],want_png=no)
|
||||
LCUI_LIBS="$LCUI_LIBS `pkg-config --libs libpng`"
|
||||
CFLAGS="$CFLAGS `pkg-config --cflags-only-I libpng`"
|
||||
AC_DEFINE_UNQUOTED([USE_LIBPNG], 1, [Define to 1 if you have the libpng.])
|
||||
], [want_png=no])
|
||||
], [want_png=no])
|
||||
fi
|
||||
|
||||
want_jpeg=no
|
||||
@@ -161,9 +158,9 @@ if test "x$with_jpeg" != "xno"; then
|
||||
AC_CHECK_LIB([jpeg], [jpeg_start_decompress],[
|
||||
want_jpeg=yes
|
||||
LCUI_LIBS="$LCUI_LIBS -ljpeg"
|
||||
AC_DEFINE_UNQUOTED(USE_LIBJPEG, 1, Define to 1 if you have the libjpeg)
|
||||
],want_jpeg=no)
|
||||
],want_jpeg=no)
|
||||
AC_DEFINE_UNQUOTED([USE_LIBJPEG], 1, [Define to 1 if you have the libjpeg])
|
||||
], [want_jpeg=no])
|
||||
], [want_jpeg=no])
|
||||
fi
|
||||
|
||||
# DEBUG option
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
测试程序默认打开本文件目录中的msyh.ttf文件,也就是微软雅黑字体,你可以将其它字体放在本文件目录下,在程序调用LCUI_Init()函数前用Set_Default_Font()函数自定义字体文件所在位置,或者设置环境变量LCUI_FONTFILE,这样LCUI初始化后就会使用该字体文件。
|
||||
|
||||
Binary file not shown.
+12
-18
@@ -39,8 +39,8 @@
|
||||
* ****************************************************************************/
|
||||
|
||||
/* 为了解决结构体被重复定义,用宏进行头文件保护(其它地方出现类似的内容,将不再注释) */
|
||||
#ifndef __LCUI_H__ /* 如果没有定义 __LCUI_H__ 宏 */
|
||||
#define __LCUI_H__ /* 定义 __LCUI_H__ 宏 */
|
||||
#ifndef LCUI_H /* 如果没有定义 LCUI_H 宏 */
|
||||
#define LCUI_H /* 定义 LCUI_H 宏 */
|
||||
|
||||
#define LCUI_VERSION "1.0.0"
|
||||
|
||||
@@ -101,19 +101,9 @@ typedef struct LCUI_Pos_ {
|
||||
} LCUI_Pos;
|
||||
|
||||
typedef struct LCUI_Size_ {
|
||||
int w, h;
|
||||
int width, height;
|
||||
} LCUI_Size;
|
||||
|
||||
typedef struct LCUI_String_ {
|
||||
char *string;
|
||||
uint_t length;
|
||||
} LCUI_String;
|
||||
|
||||
typedef struct LCUI_WString_ {
|
||||
wchar_t *string;
|
||||
uint_t length;
|
||||
} LCUI_WString;
|
||||
|
||||
typedef struct LCUI_Rect_ {
|
||||
union { int x, left; };
|
||||
union { int y, top; };
|
||||
@@ -140,6 +130,7 @@ typedef enum LCUI_StyleType {
|
||||
SVT_IMAGE,
|
||||
SVT_STYLE,
|
||||
SVT_VALUE,
|
||||
SVT_BOOL,
|
||||
SVT_STRING,
|
||||
SVT_WSTRING
|
||||
} LCUI_StyleType;
|
||||
@@ -152,6 +143,7 @@ typedef enum LCUI_StyleType {
|
||||
#define SVT_scale SVT_SCALE
|
||||
#define SVT_style SVT_STYLE
|
||||
#define SVT_data SVT_DATA
|
||||
#define SVT_bool SVT_BOOL
|
||||
#define SVT_image SVT_IMAGE
|
||||
#define SVT_string SVT_STRING
|
||||
#define SVT_wstring SVT_WSTRING
|
||||
@@ -234,13 +226,14 @@ typedef enum LCUI_StyleValue {
|
||||
SV_FLOAT_LEFT,
|
||||
SV_FLOAT_RIGHT,
|
||||
SV_BLOCK,
|
||||
SV_INLINE_BLOCK
|
||||
SV_INLINE_BLOCK,
|
||||
SV_NOWRAP
|
||||
} LCUI_StyleValue;
|
||||
|
||||
typedef struct LCUI_StyleRec_ {
|
||||
LCUI_BOOL is_valid:1;
|
||||
LCUI_BOOL is_changed:1;
|
||||
LCUI_StyleType type:30;
|
||||
LCUI_BOOL is_valid:2;
|
||||
LCUI_BOOL is_changed:2;
|
||||
unsigned short int type;
|
||||
union {
|
||||
int value;
|
||||
int val_int;
|
||||
@@ -262,6 +255,7 @@ typedef struct LCUI_StyleRec_ {
|
||||
LCUI_Color val_color;
|
||||
LCUI_Graph *image;
|
||||
LCUI_Graph *val_image;
|
||||
LCUI_BOOL val_bool;
|
||||
};
|
||||
} LCUI_StyleRec, *LCUI_Style;
|
||||
|
||||
@@ -312,4 +306,4 @@ LCUI_END_HEADER
|
||||
#include <LCUI/util.h>
|
||||
#include <LCUI/main.h>
|
||||
|
||||
#endif /* __LCUI_H__ */
|
||||
#endif /* LCUI_H */
|
||||
|
||||
@@ -8,8 +8,9 @@ EXTRA_DIST=platform.h platform/linux/linux_display.h \
|
||||
platform/linux/linux_events.h platform/linux/linux_mouse.h \
|
||||
platform/linux/linux_keyboard.h platform/linux/linux_fbdisplay.h \
|
||||
platform/linux/linux_x11display.h platform/linux/linux_x11events.h \
|
||||
platform/windows/windows_display.h platform/windows/windows_events.h \
|
||||
platform/windows/windows_mouse.h platform/windows/windows_keyboard.h
|
||||
platform/linux/linux_x11mouse.h platform/windows/windows_display.h \
|
||||
platform/windows/windows_events.h platform/windows/windows_mouse.h \
|
||||
platform/windows/windows_keyboard.h
|
||||
|
||||
# Headers to install
|
||||
pkginclude_HEADERS = $(INSTINCLUDES)
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef __LCUI_CURSOR_H__
|
||||
#define __LCUI_CURSOR_H__
|
||||
#ifndef LCUI_CURSOR_H
|
||||
#define LCUI_CURSOR_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef __LCUI_DISPLAY_H__
|
||||
#define __LCUI_DISPLAY_H__
|
||||
#ifndef LCUI_DISPLAY_CONTROL_H
|
||||
#define LCUI_DISPLAY_CONTROL_H
|
||||
|
||||
#include <LCUI/gui/widget.h>
|
||||
#include <LCUI/surface.h>
|
||||
|
||||
+2
-9
@@ -39,17 +39,10 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef __LCUI_DRAW_H__
|
||||
#define __LCUI_DRAW_H__
|
||||
#ifndef LCUI_DRAW_H
|
||||
#define LCUI_DRAW_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
/* 打开文件时的错误 */
|
||||
#define FILE_ERROR_OPEN_ERROR -1
|
||||
#define FILE_ERROR_SHORT_FILE -2
|
||||
#define FILE_ERROR_BIG_FILE -3
|
||||
#define FILE_ERROR_UNKNOWN_FORMAT -4
|
||||
#define FILE_ERROR_MALLOC_ERROR -5
|
||||
|
||||
#include <LCUI/draw/line.h>
|
||||
#include <LCUI/draw/border.h>
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ***************************************************************************/
|
||||
|
||||
#ifndef __LCUI_DRAW_BACKGROUND_H__
|
||||
#define __LCUI_DRAW_BACKGROUND_H__
|
||||
#ifndef LCUI_DRAW_BACKGROUND_H
|
||||
#define LCUI_DRAW_BACKGROUND_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ***************************************************************************/
|
||||
|
||||
#ifndef __LCUI_DRAW_BORDER_H__
|
||||
#define __LCUI_DRAW_BORDER_H__
|
||||
#ifndef LCUI_DRAW_BORDER_H
|
||||
#define LCUI_DRAW_BORDER_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ***************************************************************************/
|
||||
|
||||
#ifndef __LCUI_DRAW_BOXSHADOW_H__
|
||||
#define __LCUI_DRAW_BOXSHADOW_H__
|
||||
#ifndef LCUI_DRAW_BOXSHADOW_H
|
||||
#define LCUI_DRAW_BOXSHADOW_H
|
||||
|
||||
LCUI_API LCUI_BoxShadow BoxShadow( int x, int y, int blur, LCUI_Color color );
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
#ifndef __LCUI_DRAW_LINE_H__
|
||||
#define __LCUI_DRAW_LINE_H__
|
||||
#ifndef LCUI_DRAW_LINE_H
|
||||
#define LCUI_DRAW_LINE_H
|
||||
/* 绘制水平线 */
|
||||
LCUI_API void
|
||||
Graph_DrawHorizLine( LCUI_Graph *graph, LCUI_Color color, int size, LCUI_Pos start, int end_x );
|
||||
|
||||
+2
-2
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ***************************************************************************/
|
||||
|
||||
#ifndef __LCUI_FONT_H__
|
||||
#define __LCUI_FONT_H__
|
||||
#ifndef LCUI_FONT_H
|
||||
#define LCUI_FONT_H
|
||||
|
||||
#include <LCUI/font/fontlibrary.h>
|
||||
#include <LCUI/font/textstyle.h>
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef __LCUI_CHARSET_H__
|
||||
#define __LCUI_CHARSET_H__
|
||||
#ifndef LCUI_CHARSET_H
|
||||
#define LCUI_CHARSET_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef __LCUI_FONT_LIBRARY_H__
|
||||
#define __LCUI_FONT_LIBRARY_H__
|
||||
#ifndef LCUI_FONT_LIBRARY_H
|
||||
#define LCUI_FONT_LIBRARY_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
|
||||
@@ -37,17 +37,11 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef __LCUI_TEXTLAYER_H__
|
||||
#define __LCUI_TEXTLAYER_H__
|
||||
#ifndef LCUI_TEXTLAYER_H
|
||||
#define LCUI_TEXTLAYER_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
/** 文本添加类型 */
|
||||
enum TextAddType {
|
||||
TEXT_ADD_TYPE_INSERT, /**< 插入至插入点处 */
|
||||
TEXT_ADD_TYPE_APPEND /**< 追加至文本末尾 */
|
||||
};
|
||||
|
||||
typedef struct TextCharRec_ {
|
||||
wchar_t char_code; /**< 字符码 */
|
||||
LCUI_TextStyle *style; /**< 该字符使用的样式数据 */
|
||||
@@ -85,14 +79,17 @@ typedef struct LCUI_TextLayerRec_ {
|
||||
int new_offset_y; /**< 新的Y轴坐标偏移量 */
|
||||
int insert_x; /**< 光标所在列数 */
|
||||
int insert_y; /**< 光标所在行数 */
|
||||
int max_width; /**< 最大文本宽度 */
|
||||
int width; /**< 实际文本宽度 */
|
||||
int fixed_width; /**< 固定文本宽度 */
|
||||
int fixed_height; /**< 固定文本高度 */
|
||||
int max_width; /**< 最大文本宽度,当未设置固定宽度时,文字排版将按最大宽度进行 */
|
||||
int max_height; /**< 最大文本高度 */
|
||||
int length; /**< 文本长度 */
|
||||
LCUI_BOOL is_mulitiline_mode; /**< 是否启用多行文本模式 */
|
||||
LCUI_BOOL is_autowrap_mode; /**< 是否启用自动换行模式 */
|
||||
LCUI_BOOL is_using_style_tags; /**< 是否使用文本样式标签 */
|
||||
LCUI_BOOL is_using_buffer; /**< 是否使用缓存空间来存储文本位图 */
|
||||
LinkedList dirty_rect; /**< 脏矩形记录 */
|
||||
|
||||
int text_align; /**< 文本的对齐方式 */
|
||||
TextRowListRec rowlist; /**< 文本行列表 */
|
||||
LCUI_TextStyle text_style; /**< 文本全局样式 */
|
||||
@@ -119,15 +116,6 @@ LCUI_API int TextLayer_GetRowTextLength( LCUI_TextLayer layer, int row );
|
||||
/** 添加 更新文本排版 的任务 */
|
||||
LCUI_API void TextLayer_AddUpdateTypeset( LCUI_TextLayer layer, int start_row );
|
||||
|
||||
/** 设置文本颜色 */
|
||||
LCUI_API void TextLayer_SetFontColor( LCUI_TextLayer layer, LCUI_Color color );
|
||||
|
||||
/** 设置文本所使用的字体字族 */
|
||||
LCUI_API void TextLayer_SetFontFamily( LCUI_TextLayer layer, const char *family_name );
|
||||
|
||||
/** 设置文本的字体像素大小 */
|
||||
LCUI_API void TextLayer_SetFontPixelSize( LCUI_TextLayer layer, int pixel_size );
|
||||
|
||||
/** 设置文本对齐方式 */
|
||||
LCUI_API void TextLayer_SetTextAlign( LCUI_TextLayer layer, int align );
|
||||
|
||||
@@ -137,7 +125,7 @@ LCUI_API void TextLayer_SetOffset( LCUI_TextLayer layer, int offset_x, int offse
|
||||
LCUI_API LCUI_TextLayer TextLayer_New(void);
|
||||
|
||||
/** 销毁TextLayer */
|
||||
LCUI_API void TextLayer_Destroy( LCUI_TextLayer *layer );
|
||||
LCUI_API void TextLayer_Destroy( LCUI_TextLayer layer );
|
||||
|
||||
/** 标记指定范围内容的文本行的矩形为无效 */
|
||||
LCUI_API void TextLayer_InvalidateRowsRect( LCUI_TextLayer layer,
|
||||
@@ -196,17 +184,26 @@ LCUI_API int TextLayer_GetTextW( LCUI_TextLayer layer, int start_pos,
|
||||
/** 获取文本位图缓存 */
|
||||
LCUI_API LCUI_Graph* TextLayer_GetGraphBuffer( LCUI_TextLayer layer );
|
||||
|
||||
/** 计算并获取文本的宽度 */
|
||||
LCUI_API int TextLayer_GetWidth( LCUI_TextLayer layer );
|
||||
|
||||
/** 计算并获取文本的高度 */
|
||||
LCUI_API int TextLayer_GetHeight( LCUI_TextLayer layer );
|
||||
|
||||
/** 设置固定尺寸 */
|
||||
LCUI_API int TextLayer_SetFixedSize( LCUI_TextLayer layer, int width, int height );
|
||||
|
||||
/** 设置最大尺寸 */
|
||||
LCUI_API int TextLayer_SetMaxSize( LCUI_TextLayer layer, LCUI_Size new_size );
|
||||
LCUI_API int TextLayer_SetMaxSize( LCUI_TextLayer layer, int width, int height );
|
||||
|
||||
/** 设置是否启用多行文本模式 */
|
||||
LCUI_API void TextLayer_SetMultiline( LCUI_TextLayer layer, int is_true );
|
||||
|
||||
/** 删除文本光标的当前坐标右边的文本 */
|
||||
LCUI_API int TextLayer_Delete( LCUI_TextLayer layer, int n_char );
|
||||
LCUI_API int TextLayer_TextDelete( LCUI_TextLayer layer, int n_char );
|
||||
|
||||
/** 退格删除文本,即删除文本光标的当前坐标左边的文本 */
|
||||
LCUI_API int TextLayer_Backspace( LCUI_TextLayer layer, int n_char );
|
||||
LCUI_API int TextLayer_TextBackspace( LCUI_TextLayer layer, int n_char );
|
||||
|
||||
/** 设置是否启用自动换行模式 */
|
||||
LCUI_API void TextLayer_SetAutoWrap( LCUI_TextLayer layer, int is_true );
|
||||
@@ -214,12 +211,6 @@ LCUI_API void TextLayer_SetAutoWrap( LCUI_TextLayer layer, int is_true );
|
||||
/** 设置是否使用样式标签 */
|
||||
LCUI_API void TextLayer_SetUsingStyleTags( LCUI_TextLayer layer, LCUI_BOOL is_true );
|
||||
|
||||
/** 计算并获取文本的宽度 */
|
||||
LCUI_API int TextLayer_GetWidth( LCUI_TextLayer layer );
|
||||
|
||||
/** 计算并获取文本的高度 */
|
||||
LCUI_API int TextLayer_GetHeight( LCUI_TextLayer layer );
|
||||
|
||||
/** 重新载入各个文字的字体位图 */
|
||||
LCUI_API void TextLayer_ReloadCharBitmap( LCUI_TextLayer layer );
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef __LCUI_TEXTSTYLE_H__
|
||||
#define __LCUI_TEXTSTYLE_H__
|
||||
#ifndef LCUI_TEXTSTYLE_H
|
||||
#define LCUI_TEXTSTYLE_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
@@ -86,6 +86,8 @@ typedef struct LCUI_TextStyle {
|
||||
/** 初始化字体样式数据 */
|
||||
LCUI_API void TextStyle_Init ( LCUI_TextStyle *data );
|
||||
|
||||
LCUI_API int TextStyle_Copy( LCUI_TextStyle *dst, LCUI_TextStyle *src );
|
||||
|
||||
LCUI_API void TextStyle_Destroy( LCUI_TextStyle *data );
|
||||
|
||||
/**
|
||||
@@ -97,11 +99,10 @@ LCUI_API int TextStyle_SetFont( LCUI_TextStyle *ts, const char *str );
|
||||
|
||||
/*-------------------------- StyleTag --------------------------------*/
|
||||
|
||||
#define TagList_Init LinkedList_Init
|
||||
#define StyleTags_Init LinkedList_Init
|
||||
|
||||
LCUI_API void TagList_Clear( LinkedList *tags );
|
||||
LCUI_API void StyleTags_Clear( LinkedList *tags );
|
||||
|
||||
/** 获取当前的文本样式 */
|
||||
LCUI_API LCUI_TextStyle* StyleTags_GetTextStyle( LinkedList *tags );
|
||||
|
||||
/** 在字符串中获取样式的结束标签,输出的是标签名 */
|
||||
|
||||
@@ -36,8 +36,8 @@
|
||||
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果s
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ***************************************************************************/
|
||||
#ifndef __LCUI_GRAPH_H__
|
||||
#define __LCUI_GRAPH_H__
|
||||
#ifndef LCUI_GRAPH_H
|
||||
#define LCUI_GRAPH_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
@@ -223,4 +223,4 @@ LCUI_END_HEADER
|
||||
|
||||
#include <LCUI/draw.h>
|
||||
|
||||
#endif /* __LCUI_GRAPH_H__ */
|
||||
#endif /* LCUI_GRAPH_H */
|
||||
|
||||
@@ -2,5 +2,5 @@ AUTOMAKE_OPTIONS=foreign
|
||||
SUBDIRS=widget
|
||||
# Headers to install
|
||||
pkginclude_HEADERS = widget_base.h widget_task.h widget_library.h \
|
||||
widget_event.h widget_paint.h widget.h css_parser.h builder.h
|
||||
widget_event.h widget_paint.h widget.h css_library.h css_parser.h builder.h
|
||||
pkgincludedir=$(prefix)/include/LCUI/gui
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef __LCUI_BUILDER_H__
|
||||
#define __LCUI_BUILDER_H__
|
||||
#ifndef LCUI_BUILDER_H
|
||||
#define LCUI_BUILDER_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
|
||||
@@ -0,0 +1,249 @@
|
||||
/* ***************************************************************************
|
||||
* css_library.h -- css library operation module.
|
||||
*
|
||||
* Copyright (C) 2015-2016 by Liu Chao <lc-soft@live.cn>
|
||||
*
|
||||
* This file is part of the LCUI project, and may only be used, modified, and
|
||||
* distributed under the terms of the GPLv2.
|
||||
*
|
||||
* (GPLv2 is abbreviation of GNU General Public License Version 2)
|
||||
*
|
||||
* By continuing to use, modify, or distribute this file you indicate that you
|
||||
* have read the license and understand and accept it fully.
|
||||
*
|
||||
* The LCUI project is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for more details.
|
||||
*
|
||||
* You should have received a copy of the GPLv2 along with this file. It is
|
||||
* usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* css_library.h -- CSS 样式库操作模块
|
||||
*
|
||||
* 版权所有 (C) 2015-2016 归属于 刘超 <lc-soft@live.cn>
|
||||
*
|
||||
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
|
||||
*
|
||||
* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
|
||||
*
|
||||
* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。
|
||||
*
|
||||
* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特
|
||||
* 定用途的隐含担保,详情请参照GPLv2许可协议。
|
||||
*
|
||||
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef LCUI_CSS_LIBRARY_H
|
||||
#define LCUI_CSS_LIBRARY_H
|
||||
|
||||
#define MAX_SELECTOR_LEN 1024
|
||||
#define MAX_SELECTOR_DEPTH 32
|
||||
|
||||
/** 样式属性名 */
|
||||
enum LCUI_StyleKeyName {
|
||||
// position start
|
||||
key_left,
|
||||
key_right,
|
||||
key_top,
|
||||
key_bottom,
|
||||
key_position,
|
||||
// position end
|
||||
|
||||
// display start
|
||||
key_visible,
|
||||
key_display,
|
||||
// display end
|
||||
|
||||
key_z_index,
|
||||
key_opacity,
|
||||
key_box_sizing,
|
||||
key_width,
|
||||
key_min_width,
|
||||
key_max_width,
|
||||
key_height,
|
||||
key_min_height,
|
||||
key_max_height,
|
||||
|
||||
// margin start
|
||||
key_margin_top,
|
||||
key_margin_right,
|
||||
key_margin_bottom,
|
||||
key_margin_left,
|
||||
// margin end
|
||||
|
||||
// padding start
|
||||
key_padding_top,
|
||||
key_padding_right,
|
||||
key_padding_bottom,
|
||||
key_padding_left,
|
||||
// padding end
|
||||
|
||||
key_vertical_align,
|
||||
|
||||
// border start
|
||||
key_border_color,
|
||||
key_border_style,
|
||||
key_border_width,
|
||||
key_border_top_width,
|
||||
key_border_top_style,
|
||||
key_border_top_color,
|
||||
key_border_right_width,
|
||||
key_border_right_style,
|
||||
key_border_right_color,
|
||||
key_border_bottom_width,
|
||||
key_border_bottom_style,
|
||||
key_border_bottom_color,
|
||||
key_border_left_width,
|
||||
key_border_left_style,
|
||||
key_border_left_color,
|
||||
key_border_top_left_radius,
|
||||
key_border_top_right_radius,
|
||||
key_border_bottom_left_radius,
|
||||
key_border_bottom_right_radius,
|
||||
// border end
|
||||
|
||||
// background start
|
||||
key_background_color,
|
||||
key_background_image,
|
||||
key_background_size,
|
||||
key_background_size_width,
|
||||
key_background_size_height,
|
||||
key_background_repeat,
|
||||
key_background_repeat_x,
|
||||
key_background_repeat_y,
|
||||
key_background_position,
|
||||
key_background_position_x,
|
||||
key_background_position_y,
|
||||
key_background_origin,
|
||||
// background end
|
||||
|
||||
// box shadow start
|
||||
key_box_shadow_x,
|
||||
key_box_shadow_y,
|
||||
key_box_shadow_spread,
|
||||
key_box_shadow_blur,
|
||||
key_box_shadow_color,
|
||||
// box shadow end
|
||||
|
||||
key_pointer_events,
|
||||
key_focusable,
|
||||
STYLE_KEY_TOTAL
|
||||
};
|
||||
|
||||
#define key_display_start key_visible
|
||||
#define key_display_end key_display
|
||||
#define key_position_start key_left
|
||||
#define key_position_end key_position
|
||||
#define key_margin_start key_margin_top
|
||||
#define key_margin_end key_margin_left
|
||||
#define key_padding_start key_padding_top
|
||||
#define key_padding_end key_padding_left
|
||||
#define key_border_start key_border_color
|
||||
#define key_border_end key_border_bottom_right_radius
|
||||
#define key_background_start key_background_color
|
||||
#define key_background_end key_background_origin
|
||||
#define key_box_shadow_start key_box_shadow_x
|
||||
#define key_box_shadow_end key_box_shadow_color
|
||||
|
||||
typedef struct LCUI_StyleSheetRec_ {
|
||||
LCUI_Style sheet;
|
||||
int length;
|
||||
} LCUI_StyleSheetRec, *LCUI_StyleSheet;
|
||||
|
||||
/** 选择器结点结构 */
|
||||
typedef struct LCUI_SelectorNodeRec_ {
|
||||
char *id; /**< ID */
|
||||
char *type; /**< 类型名称 */
|
||||
char **classes; /**< 样式类列表 */
|
||||
char **status; /**< 状态列表 */
|
||||
char *fullname; /**< 全名,由 id、type、classes、status 组合而成 */
|
||||
int rank; /**< 权值 */
|
||||
} LCUI_SelectorNodeRec, *LCUI_SelectorNode;
|
||||
|
||||
/** 选择器结构 */
|
||||
typedef struct LCUI_SelectorRec_ {
|
||||
int rank; /**< 权值,决定优先级 */
|
||||
int batch_num; /**< 批次号 */
|
||||
int length; /**< 选择器结点长度 */
|
||||
unsigned int hash; /**< 哈希值 */
|
||||
LCUI_SelectorNode *nodes; /**< 选择器结点列表 */
|
||||
} LCUI_SelectorRec, *LCUI_Selector;
|
||||
|
||||
#define SetStyle(S, NAME, VAL, TYPE) S->sheet[NAME].is_valid = TRUE, \
|
||||
S->sheet[NAME].is_changed = TRUE, \
|
||||
S->sheet[NAME].type = SVT_##TYPE, \
|
||||
S->sheet[NAME].val_##TYPE = VAL
|
||||
|
||||
#define LCUI_FindStyleSheet(S, L) LCUI_FindStyleSheetFromGroup(0, NULL, S, L)
|
||||
|
||||
LCUI_API LCUI_StyleSheet StyleSheet( void );
|
||||
|
||||
LCUI_API void StyleSheet_Clear( LCUI_StyleSheet ss );
|
||||
|
||||
LCUI_API void StyleSheet_Delete( LCUI_StyleSheet ss );
|
||||
|
||||
LCUI_API int StyleSheet_Merge( LCUI_StyleSheet dest, LCUI_StyleSheet src );
|
||||
|
||||
LCUI_API int StyleSheet_Replace( LCUI_StyleSheet dest, LCUI_StyleSheet src );
|
||||
|
||||
LCUI_API LCUI_Selector Selector( const char *selector );
|
||||
|
||||
LCUI_API void Selector_Update( LCUI_Selector s );
|
||||
|
||||
LCUI_API void Selector_Delete( LCUI_Selector s );
|
||||
|
||||
LCUI_API int SelectorNode_GetNames( LCUI_SelectorNode sn, LinkedList *names );
|
||||
|
||||
LCUI_API int SelectorNode_Update( LCUI_SelectorNode node );
|
||||
|
||||
/**
|
||||
* 匹配选择器节点
|
||||
* 左边的选择器必须包含右边的选择器的所有属性。
|
||||
*/
|
||||
LCUI_API LCUI_BOOL SelectorNode_Match( LCUI_SelectorNode sn1,
|
||||
LCUI_SelectorNode sn2 );
|
||||
|
||||
LCUI_API int LCUI_PutStyleSheet( LCUI_Selector selector,
|
||||
LCUI_StyleSheet in_ss, const char *space );
|
||||
|
||||
/**
|
||||
* 从指定组中查找样式表
|
||||
* @param[in] group 组号
|
||||
* @param[in] name 选择器结点名称,若为 NULL,则根据选择器结点生成名称
|
||||
* @param[in] s 选择器
|
||||
* @param[out] list 找到的样式表列表
|
||||
*/
|
||||
LCUI_API int LCUI_FindStyleSheetFromGroup( int group, const char *name,
|
||||
LCUI_Selector s, LinkedList *list );
|
||||
|
||||
LCUI_API void LCUI_GetStyleSheet( LCUI_Selector s, LCUI_StyleSheet out_ss );
|
||||
|
||||
LCUI_API int LCUI_SetStyleName( int key, const char *name );
|
||||
|
||||
LCUI_API int LCUI_AddStyleName( const char *name );
|
||||
|
||||
LCUI_API int LCUI_AddStyleValue( int key, const char *name );
|
||||
|
||||
LCUI_API int LCUI_GetStyleValue( const char *str );
|
||||
|
||||
LCUI_API const char *LCUI_GetStyleValueName( int val );
|
||||
|
||||
LCUI_API const char *LCUI_GetStyleName( int key );
|
||||
|
||||
LCUI_API int LCUI_GetStyleTotal( void );
|
||||
|
||||
LCUI_API void LCUI_PrintStyleSheet( LCUI_StyleSheet ss );
|
||||
|
||||
LCUI_API void LCUI_PrintSelector( LCUI_Selector selector );
|
||||
|
||||
LCUI_API void LCUI_PrintCSSLibrary( void );
|
||||
|
||||
LCUI_API void LCUI_InitCSSLibrary( void );
|
||||
|
||||
LCUI_API void LCUI_ExitCSSLibrary( void );
|
||||
|
||||
#endif
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef __LCUI_CSS_PARSER_H__
|
||||
#define __LCUI_CSS_PARSER_H__
|
||||
#ifndef LCUI_CSS_PARSER_H
|
||||
#define LCUI_CSS_PARSER_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
@@ -49,26 +49,25 @@ typedef struct LCUI_StyleParserRec_ {
|
||||
int (*parse)(LCUI_StyleSheet, int, const char*);
|
||||
} LCUI_StyleParserRec, *LCUI_StyleParser;
|
||||
|
||||
LCUI_API int ParseStyleOption( const char *str );
|
||||
LCUI_API int LCUI_GetStyleValue( const char *str );
|
||||
|
||||
LCUI_API const char *GetStyleName( int key );
|
||||
LCUI_API const char *LCUI_GetStyleValueName( int val );
|
||||
|
||||
LCUI_API const char *LCUI_GetStyleName( int key );
|
||||
|
||||
/** 初始化 LCUI 的 CSS 代码解析功能 */
|
||||
void LCUICSS_Init(void);
|
||||
LCUI_API void LCUI_InitCSSParser( void );
|
||||
|
||||
/** 从文件中载入CSS样式数据,并导入至样式库中 */
|
||||
LCUI_API int LCUICSS_LoadFile( const char *filepath );
|
||||
LCUI_API int LCUI_LoadCSSFile( const char *filepath );
|
||||
|
||||
/** 从字符串中载入CSS样式数据,并导入至样式库中 */
|
||||
LCUI_API int LCUICSS_LoadString( const char *str );
|
||||
LCUI_API int LCUI_LoadCSSString( const char *str, const char *space );
|
||||
|
||||
void LCUICSS_Destroy(void);
|
||||
|
||||
/** 获取当前记录的样式属性的总数 */
|
||||
int LCUICSS_GetStyleTotal(void);
|
||||
LCUI_API void LCUI_ExitCSSParser(void);
|
||||
|
||||
/** 注册新的属性和对应的属性值解析器 */
|
||||
LCUI_API int LCUICSS_AddParser( LCUI_StyleParser sp );
|
||||
LCUI_API int LCUI_AddCSSParser( LCUI_StyleParser sp );
|
||||
|
||||
LCUI_END_HEADER
|
||||
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
/* ***************************************************************************
|
||||
* messagebox.h -- MessageBox for LCUI
|
||||
*
|
||||
* Copyright (C) 2012-2013 by
|
||||
* Liu Chao
|
||||
*
|
||||
* This file is part of the LCUI project, and may only be used, modified, and
|
||||
* distributed under the terms of the GPLv2.
|
||||
*
|
||||
* (GPLv2 is abbreviation of GNU General Public License Version 2)
|
||||
*
|
||||
* By continuing to use, modify, or distribute this file you indicate that you
|
||||
* have read the license and understand and accept it fully.
|
||||
*
|
||||
* The LCUI project is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for more details.
|
||||
*
|
||||
* You should have received a copy of the GPLv2 along with this file. It is
|
||||
* usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* messagebox.h -- LCUI 的消息框
|
||||
*
|
||||
* 版权所有 (C) 2012-2013 归属于
|
||||
* 刘超
|
||||
*
|
||||
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
|
||||
*
|
||||
* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
|
||||
*
|
||||
* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。
|
||||
*
|
||||
* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特
|
||||
* 定用途的隐含担保,详情请参照GPLv2许可协议。
|
||||
*
|
||||
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
#ifndef __LCUI_GUI_MESSAGEBOX_H__
|
||||
#define __LCUI_GUI_MESSAGEBOX_H__
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
typedef enum {
|
||||
MB_ICON_NONE,
|
||||
MB_ICON_ERROR,
|
||||
MB_ICON_HELP,
|
||||
MB_ICON_INFO,
|
||||
MB_ICON_WARNING
|
||||
} MB_ICON_TYPE;
|
||||
|
||||
typedef enum {
|
||||
MB_BTN_OK,
|
||||
MB_BTN_OKCANCEL,
|
||||
MB_BTN_ABORTRETRYIGNORE,
|
||||
MB_BTN_RETRYCANCEL,
|
||||
MB_BTN_YESNO,
|
||||
MB_BTN_YESNOCANCEL
|
||||
} MB_BTN_TYPE;
|
||||
|
||||
typedef enum {
|
||||
MB_BTN_IS_OK,
|
||||
MB_BTN_IS_CANCEL,
|
||||
MB_BTN_IS_ABORT,
|
||||
MB_BTN_IS_RETRY,
|
||||
MB_BTN_IS_IGNORE,
|
||||
MB_BTN_IS_YES,
|
||||
MB_BTN_IS_NO,
|
||||
MB_BTN_IS_QUIT
|
||||
} MB_BTN;
|
||||
|
||||
/* LCUI的消息框
|
||||
* 参数:
|
||||
* icon_type : 指定消息框中显示的图标,可取以下值:
|
||||
* MB_ICON_NONE 无图标
|
||||
* MB_ICON_ERROR “错误”图标
|
||||
* MB_ICON_HELP ”帮助“图标
|
||||
* MB_ICON_INFO “信息”图标
|
||||
* MB_ICON_WARNING “警告”图标
|
||||
* text : 消息框内显示的消息内容
|
||||
* title : 消息框的标题文本
|
||||
* button : 指定消息框内显示的按钮,可取以下值:
|
||||
* MB_BTN_OK : 一个“确定”按钮
|
||||
* MB_BTN_OKCANCEL : “确定”和“取消”按钮
|
||||
* MB_BTN_ABORTRETRYIGNORE : “终止”、"重试"和“忽略”按钮
|
||||
* MB_BTN_RETRYCANCEL : "重试"和“取消”按钮
|
||||
* MB_BTN_YESNO : "是"和“否”按钮
|
||||
* MB_BTN_YESNOCANCEL : “是”、"否"和“取消”按钮
|
||||
* 返回值:
|
||||
* -1 : button参数的值异常
|
||||
* -2 : 无法获取消息框关闭时所点击的按钮ID
|
||||
* 正常则会返回按钮的ID,有以下值:
|
||||
* MB_BTN_IS_OK : "确定"按钮
|
||||
* MB_BTN_IS_CANCEL: "取消"按钮
|
||||
* MB_BTN_IS_ABORT : "终止"按钮
|
||||
* MB_BTN_IS_RETRY : "重试"按钮
|
||||
* MB_BTN_IS_IGNORE: "忽略"按钮
|
||||
* MB_BTN_IS_YES : "是"按钮
|
||||
* MB_BTN_IS_NO : "否"按钮
|
||||
* MB_BTN_IS_QUIT : 窗口右上角的关闭按钮
|
||||
* */
|
||||
LCUI_API int
|
||||
LCUI_MessageBoxW( MB_ICON_TYPE icon_type, const wchar_t *text,
|
||||
const wchar_t *title, MB_BTN_TYPE button );
|
||||
|
||||
/* UTF-8版的LCUI_MessageBox */
|
||||
LCUI_API int
|
||||
LCUI_MessageBox( MB_ICON_TYPE icon_type, const char *text,
|
||||
const char *title, MB_BTN_TYPE button );
|
||||
|
||||
/* ASCII版的LCUI_MessageBox */
|
||||
LCUI_API int
|
||||
LCUI_MessageBoxA( MB_ICON_TYPE icon_type, const char *text,
|
||||
const char *title, MB_BTN_TYPE button );
|
||||
|
||||
LCUI_END_HEADER
|
||||
|
||||
#endif
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef __LCUI_WIDGET_BUILD_H__
|
||||
#define __LCUI_WIDGET_BUILD_H__
|
||||
#ifndef LCUI_WIDGET_BUILD_H
|
||||
#define LCUI_WIDGET_BUILD_H
|
||||
|
||||
#include <LCUI/graph.h>
|
||||
#include <LCUI/thread.h>
|
||||
|
||||
@@ -36,8 +36,8 @@
|
||||
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
#ifndef __LCUI_BUTTON_H__
|
||||
#define __LCUI_BUTTON_H__
|
||||
#ifndef LCUI_BUTTON_H
|
||||
#define LCUI_BUTTON_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef __LCUI_SCROLLBAR_H__
|
||||
#define __LCUI_SCROLLBAR_H__
|
||||
#ifndef LCUI_SCROLLBAR_H
|
||||
#define LCUI_SCROLLBAR_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef __LCUI_SIDEBAR_WIDGET_H__
|
||||
#define __LCUI_SIDEBAR_WIDGET_H__
|
||||
#ifndef LCUI_SIDEBAR_WIDGET_H
|
||||
#define LCUI_SIDEBAR_WIDGET_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/* ***************************************************************************
|
||||
* textedit.c -- textedit widget, used to allow user edit text.
|
||||
*
|
||||
* Copyright (C) 2016 by Liu Chao <lc-soft@live.cn>
|
||||
*
|
||||
* This file is part of the LCUI project, and may only be used, modified, and
|
||||
* distributed under the terms of the GPLv2.
|
||||
*
|
||||
* (GPLv2 is abbreviation of GNU General Public License Version 2)
|
||||
*
|
||||
* By continuing to use, modify, or distribute this file you indicate that you
|
||||
* have read the license and understand and accept it fully.
|
||||
*
|
||||
* The LCUI project is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for more details.
|
||||
*
|
||||
* You should have received a copy of the GPLv2 along with this file. It is
|
||||
* usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* textedit.c -- 文本编辑部件,用于让用户编辑文本。
|
||||
*
|
||||
* 版权所有 (C) 2016 归属于 刘超 <lc-soft@live.cn>
|
||||
*
|
||||
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
|
||||
*
|
||||
* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
|
||||
*
|
||||
* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。
|
||||
*
|
||||
* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特
|
||||
* 定用途的隐含担保,详情请参照GPLv2许可协议。
|
||||
*
|
||||
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
#ifndef LCUI_TEXTBOX_H
|
||||
#define LCUI_TEXTBOX_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
#define TextEdit_New() Widget_New("textedit")
|
||||
|
||||
/** 指定文本框是否处理控制符 */
|
||||
LCUI_API void TextEdit_SetUsingStyleTags( LCUI_Widget widget, LCUI_BOOL is_true );
|
||||
|
||||
/** 指定文本框是否启用多行文本显示 */
|
||||
LCUI_API void TextEdit_SetMultiline( LCUI_Widget widget, LCUI_BOOL is_true );
|
||||
|
||||
/** 清空文本内容 */
|
||||
LCUI_API void TextEdit_ClearText( LCUI_Widget widget );
|
||||
|
||||
/** 获取文本内容 */
|
||||
LCUI_API int TextEdit_GetTextW( LCUI_Widget widget, int start, int max_len, wchar_t *buf );
|
||||
|
||||
/** 获取文本长度 */
|
||||
LCUI_API int TextEdit_GetTextLength( LCUI_Widget w );
|
||||
|
||||
/** 设置文本编辑框内的光标,指定是否闪烁、闪烁时间间隔 */
|
||||
LCUI_API void TextEdit_SetCaretBlink( LCUI_Widget w, LCUI_BOOL enabled, int time );
|
||||
|
||||
/** 为文本框设置文本(宽字符版) */
|
||||
LCUI_API int TextEdit_SetTextW( LCUI_Widget widget, const wchar_t *wstr );
|
||||
|
||||
LCUI_API int TextEdit_SetText( LCUI_Widget widget, const char *utf8_str );
|
||||
|
||||
/** 为文本框追加文本(宽字符版) */
|
||||
LCUI_API int TextEdit_AppendTextW( LCUI_Widget widget, const wchar_t *wstr );
|
||||
|
||||
/** 为文本框插入文本(宽字符版) */
|
||||
LCUI_API int TextEdit_InsertTextW( LCUI_Widget widget, const wchar_t *wstr );
|
||||
|
||||
/** 设置占位符,当文本编辑框内容为空时显示占位符 */
|
||||
LCUI_API int TextEdit_SetPlaceHolderW( LCUI_Widget w, const wchar_t *wstr );
|
||||
|
||||
LCUI_API int TextEdit_SetPlaceHolder( LCUI_Widget w, const char *str );
|
||||
|
||||
LCUI_END_HEADER
|
||||
|
||||
#endif
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef __LCUI_TEXTVIEW_H__
|
||||
#define __LCUI_TEXTVIEW_H__
|
||||
#ifndef LCUI_TEXTVIEW_H
|
||||
#define LCUI_TEXTVIEW_H
|
||||
|
||||
#include <LCUI/font.h>
|
||||
|
||||
@@ -57,6 +57,8 @@ LCUI_API void TextView_GetTextStyle( LCUI_Widget w, LCUI_TextStyle *style );
|
||||
|
||||
LCUI_API void TextView_SetTextAlign( LCUI_Widget w, int align );
|
||||
|
||||
LCUI_API void TextView_SetAutoWrap( LCUI_Widget w, LCUI_BOOL autowrap );
|
||||
|
||||
LCUI_END_HEADER
|
||||
|
||||
#endif
|
||||
|
||||
+25
-126
@@ -37,25 +37,23 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef __LCUI_WIDGET_BASE_H__
|
||||
#define __LCUI_WIDGET_BASE_H__
|
||||
#ifndef LCUI_WIDGET_BASE_H
|
||||
#define LCUI_WIDGET_BASE_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
/** 如果没有包含 widget_build.h 头文件 */
|
||||
#ifndef __LCUI_WIDGET_BUILD_H__
|
||||
typedef struct LCUI_WidgetBase* LCUI_Widget;
|
||||
#endif
|
||||
#include <LCUI/gui/css_library.h>
|
||||
#include <LCUI/gui/css_parser.h>
|
||||
|
||||
/** 部件样式 */
|
||||
typedef struct LCUI_WidgetStyle {
|
||||
LCUI_BOOL visible; /**< 是否可见 */
|
||||
LCUI_BOOL focusable; /**< 是否能够得到焦点 */
|
||||
int left, top; /**< 左边界、顶边界的偏移距离 */
|
||||
int right, bottom; /**< 右边界、底边界的偏移距离 */
|
||||
int z_index; /**< 堆叠顺序,该值越高,部件显示得越靠前 */
|
||||
float opacity; /**< 不透明度,有效范围从 0.0 (完全透明)到 1.0(完全不透明) */
|
||||
LCUI_StyleValue position; /**< 定位方式 */
|
||||
LCUI_StyleValue float_mode; /**< 浮动模式 */
|
||||
LCUI_StyleValue display; /**< 显示方式,决定以何种布局显示该部件 */
|
||||
LCUI_StyleValue box_sizing; /**< 以何种方式计算宽度和高度 */
|
||||
LCUI_StyleValue vertical_align; /**< 垂直对齐方式 */
|
||||
@@ -67,107 +65,6 @@ typedef struct LCUI_WidgetStyle {
|
||||
int pointer_events; /**< 事件的处理方式 */
|
||||
} LCUI_WidgetStyle;
|
||||
|
||||
/** 样式属性名 */
|
||||
enum LCUI_StyleKeyName {
|
||||
key_position_start,
|
||||
key_left,
|
||||
key_right,
|
||||
key_top,
|
||||
key_bottom,
|
||||
key_position,
|
||||
key_position_end,
|
||||
key_display_start,
|
||||
key_visible,
|
||||
key_display,
|
||||
key_display_end,
|
||||
key_z_index,
|
||||
key_opacity,
|
||||
key_box_sizing,
|
||||
key_width,
|
||||
key_min_width,
|
||||
key_max_width,
|
||||
key_height,
|
||||
key_min_height,
|
||||
key_max_height,
|
||||
key_margin_top,
|
||||
key_margin_right,
|
||||
key_margin_bottom,
|
||||
key_margin_left,
|
||||
key_padding_top,
|
||||
key_padding_right,
|
||||
key_padding_bottom,
|
||||
key_padding_left,
|
||||
key_vertical_align,
|
||||
key_border_start,
|
||||
key_border_color,
|
||||
key_border_style,
|
||||
key_border_width,
|
||||
key_border_top_width,
|
||||
key_border_top_style,
|
||||
key_border_top_color,
|
||||
key_border_right_width,
|
||||
key_border_right_style,
|
||||
key_border_right_color,
|
||||
key_border_bottom_width,
|
||||
key_border_bottom_style,
|
||||
key_border_bottom_color,
|
||||
key_border_left_width,
|
||||
key_border_left_style,
|
||||
key_border_left_color,
|
||||
key_border_top_left_radius,
|
||||
key_border_top_right_radius,
|
||||
key_border_bottom_left_radius,
|
||||
key_border_bottom_right_radius,
|
||||
key_border_end,
|
||||
key_background_start,
|
||||
key_background_color,
|
||||
key_background_image,
|
||||
key_background_size,
|
||||
key_background_size_width,
|
||||
key_background_size_height,
|
||||
key_background_repeat,
|
||||
key_background_repeat_x,
|
||||
key_background_repeat_y,
|
||||
key_background_position,
|
||||
key_background_position_x,
|
||||
key_background_position_y,
|
||||
key_background_origin,
|
||||
key_background_end,
|
||||
key_box_shadow_start,
|
||||
key_box_shadow_x,
|
||||
key_box_shadow_y,
|
||||
key_box_shadow_spread,
|
||||
key_box_shadow_blur,
|
||||
key_box_shadow_color,
|
||||
key_box_shadow_end,
|
||||
key_pointer_events,
|
||||
STYLE_KEY_TOTAL
|
||||
};
|
||||
|
||||
typedef struct LCUI_StyleSheetRec_ {
|
||||
LCUI_Style sheet;
|
||||
int length;
|
||||
} LCUI_StyleSheetRec, *LCUI_StyleSheet;
|
||||
|
||||
typedef struct LCUI_SelectorNodeRec_ {
|
||||
char *id;
|
||||
char *type;
|
||||
char *class_name;
|
||||
char *pseudo_class_name;
|
||||
} LCUI_SelectorNodeRec, *LCUI_SelectorNode;
|
||||
|
||||
typedef struct LCUI_SelectorRec_ {
|
||||
LCUI_SelectorNode *list; /**< 选择器结点列表 */
|
||||
int length; /**< 选择器结点长度 */
|
||||
int rank; /**< 权值,决定优先级 */
|
||||
int batch_num; /**< 批次号 */
|
||||
} LCUI_SelectorRec, *LCUI_Selector;
|
||||
|
||||
#define SetStyle(S, NAME, VAL, TYPE) S->sheet[NAME].is_valid = TRUE, \
|
||||
S->sheet[NAME].is_changed = TRUE, \
|
||||
S->sheet[NAME].type = SVT_##TYPE, \
|
||||
S->sheet[NAME].val_##TYPE = VAL
|
||||
|
||||
/** 部件任务类型,按照任务的依赖顺序排列 */
|
||||
enum WidgetTaskType {
|
||||
WTT_REFRESH_STYLE, /**< 刷新部件全部样式 */
|
||||
@@ -188,17 +85,10 @@ enum WidgetTaskType {
|
||||
WTT_OPACITY,
|
||||
WTT_BODY,
|
||||
WTT_REFRESH,
|
||||
WTT_CACHE_STYLE, /**< 缓存当前样式 */
|
||||
WTT_USER,
|
||||
WTT_TOTAL_NUM
|
||||
};
|
||||
|
||||
#ifndef __IN_WIDGET_TASK_SOURCE_FILE__
|
||||
typedef void* LCUI_WidgetTaskBox;
|
||||
#else
|
||||
typedef struct LCUI_WidgetTaskBoxRec_* LCUI_WidgetTaskBox;
|
||||
#endif
|
||||
|
||||
typedef struct LCUI_WidgetBoxRect {
|
||||
LCUI_Rect content; /**< 内容框的区域 */
|
||||
LCUI_Rect padding; /**< 内边距框的区域 */
|
||||
@@ -215,8 +105,19 @@ typedef struct LCUI_WidgetTaskBoxRec_ {
|
||||
|
||||
typedef struct LCUI_WidgetRec_* LCUI_Widget;
|
||||
|
||||
/** 部件状态 */
|
||||
enum LCUI_WidgetState {
|
||||
WSTATE_CREATED = 0,
|
||||
WSTATE_UPDATED,
|
||||
WSTATE_LAYOUTED,
|
||||
WSTATE_READY,
|
||||
WSTATE_NORMAL,
|
||||
WSTATE_DELETED,
|
||||
};
|
||||
|
||||
/** 部件结构 */
|
||||
typedef struct LCUI_WidgetRec_ {
|
||||
int state; /**< 状态 */
|
||||
int x, y; /**< 当前坐标(由 origin 计算而来) */
|
||||
int origin_x, origin_y; /**< 当前布局下计算出的坐标 */
|
||||
int width, height; /**< 部件区域大小,包括边框和内边距占用区域 */
|
||||
@@ -230,14 +131,12 @@ typedef struct LCUI_WidgetRec_ {
|
||||
LCUI_Rect2 margin; /**< 外边距框 */
|
||||
LCUI_WidgetBoxRect box; /**< 部件的各个区域信息 */
|
||||
LCUI_StyleSheet style; /**< 当前完整样式表 */
|
||||
LCUI_StyleSheet cached_style; /**< 已缓存的完整样式表 */
|
||||
LCUI_StyleSheet inherited_style; /**< 通过继承得到的样式表 */
|
||||
LCUI_StyleSheet custom_style; /**< 自定义样式表 */
|
||||
LCUI_StyleSheet inherited_style; /**< 通过继承得到的样式表 */
|
||||
LCUI_WidgetStyle computed_style; /**< 已经计算的样式数据 */
|
||||
LCUI_Widget parent; /**< 父部件 */
|
||||
LinkedList children; /**< 子部件 */
|
||||
LinkedList children_show; /**< 子部件的堆叠顺序记录,由顶到底 */
|
||||
LinkedList children_trash; /**< 需被删除的子部件 */
|
||||
void *private_data; /**< 私有数据 */
|
||||
void *extend_data; /**< 扩展数据 */
|
||||
LCUI_BOOL enable_graph; /**< 是否启用位图缓存 */
|
||||
@@ -247,11 +146,11 @@ typedef struct LCUI_WidgetRec_ {
|
||||
LCUI_WidgetTaskBoxRec task; /**< 任务记录 */
|
||||
LinkedList dirty_rects; /**< 记录无效区域(脏矩形) */
|
||||
LCUI_BOOL has_dirty_child; /**< 子级部件是否有无效区域 */
|
||||
LCUI_BOOL deleted; /**< 是否已经删除 */
|
||||
LCUI_BOOL layout_locked; /**< 子级部件布局是否已锁定 */
|
||||
LCUI_BOOL event_blocked; /**< 是否阻止自己和子级部件的事件处理 */
|
||||
LCUI_BOOL disabled; /**< 是否禁用 */
|
||||
} LCUI_WidgetRec;
|
||||
|
||||
|
||||
#define Widget_GetNode(w) (LinkedListNode*)(((char*)w) + sizeof(LCUI_WidgetRec))
|
||||
#define Widget_GetShowNode(w) (LinkedListNode*)(((char*)w) + sizeof(LCUI_WidgetRec) + sizeof(LinkedListNode))
|
||||
#define Widget_NewPrivateData(w, type) (type*)(w->private_data = malloc(sizeof(type)))
|
||||
@@ -308,6 +207,9 @@ LCUI_API void Widget_ExecUpdateZIndex( LCUI_Widget w );
|
||||
/** 刷新位置 */
|
||||
LCUI_API void Widget_UpdatePosition( LCUI_Widget w );
|
||||
|
||||
/** 刷新外间距 */
|
||||
LCUI_API void Widget_UpdateMargin( LCUI_Widget w );
|
||||
|
||||
/** 刷新尺寸 */
|
||||
LCUI_API void Widget_UpdateSize( LCUI_Widget w );
|
||||
|
||||
@@ -317,12 +219,6 @@ LCUI_API void Widget_UpdateProps( LCUI_Widget w );
|
||||
/** 更新透明度 */
|
||||
LCUI_API void Widget_UpdateOpacity( LCUI_Widget w );
|
||||
|
||||
/** 处理部件中当前积累的任务 */
|
||||
LCUI_API int Widget_Update( LCUI_Widget w );
|
||||
|
||||
/** 计算部件通过继承得到的样式表 */
|
||||
LCUI_API int Widget_ComputeInheritStyle( LCUI_Widget w, LCUI_StyleSheet out_ss );
|
||||
|
||||
/** 设置部件标题 */
|
||||
LCUI_API void Widget_SetTitleW( LCUI_Widget w, const wchar_t *title );
|
||||
|
||||
@@ -364,6 +260,9 @@ LCUI_API int Widget_AddStatus( LCUI_Widget w, const char *status_name );
|
||||
/** 判断部件是否包含指定的状态 */
|
||||
LCUI_API LCUI_BOOL Widget_HasStatus( LCUI_Widget w, const char *status_name );
|
||||
|
||||
/** 设置部件是否禁用 */
|
||||
LCUI_API void Widget_SetDisabled( LCUI_Widget w, LCUI_BOOL disabled );
|
||||
|
||||
/** 计算部件的最大宽度 */
|
||||
LCUI_API int Widget_ComputeMaxWidth( LCUI_Widget w );
|
||||
|
||||
|
||||
@@ -37,14 +37,15 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ***************************************************************************/
|
||||
|
||||
#ifndef __LCUI_WIDGET_EVENT_H__
|
||||
#define __LCUI_WIDGET_EVENT_H__
|
||||
#ifndef LCUI_WIDGET_EVENT_H
|
||||
#define LCUI_WIDGET_EVENT_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
enum WidgetEventType {
|
||||
WET_NONE,
|
||||
WET_ADD,
|
||||
WET_READY,
|
||||
WET_REMOVE,
|
||||
WET_DESTROY,
|
||||
WET_MOVE,
|
||||
@@ -57,7 +58,7 @@ enum WidgetEventType {
|
||||
WET_KEYDOWN,
|
||||
WET_KEYUP,
|
||||
WET_KEYPRESS,
|
||||
WET_INPUT,
|
||||
WET_TEXTINPUT,
|
||||
|
||||
WET_MOUSEOVER,
|
||||
WET_MOUSEMOVE,
|
||||
@@ -66,26 +67,45 @@ enum WidgetEventType {
|
||||
WET_MOUSEUP,
|
||||
WET_MOUSEWHEEL,
|
||||
WET_CLICK,
|
||||
WET_TOUCH,
|
||||
WET_TOUCHDOWN,
|
||||
WET_TOUCHUP,
|
||||
WET_TOUCHMOVE,
|
||||
|
||||
WET_TITLE,
|
||||
WET_SURFACE,
|
||||
WET_USER
|
||||
};
|
||||
|
||||
/* 部件的事件数据结构和系统事件一样 */
|
||||
typedef LCUI_MouseMotionEvent LCUI_WidgetMouseMotionEvent;
|
||||
typedef LCUI_MouseButtonEvent LCUI_WidgetMouseButtonEvent;
|
||||
typedef LCUI_MouseWheelEvent LCUI_WidgetMouseWheelEvent;
|
||||
typedef LCUI_TextInputEvent LCUI_WidgetTextInputEvent;
|
||||
typedef LCUI_KeyboardEvent LCUI_WidgetKeyboardEvent;
|
||||
typedef LCUI_TouchEvent LCUI_WidgetTouchEvent;
|
||||
|
||||
/** 面向部件级的事件内容结构 */
|
||||
typedef struct LCUI_WidgetEventRec_ {
|
||||
int type; /**< 事件类型标识号 */
|
||||
int which; /**< 指示按了哪个键或按钮 */
|
||||
int x, y; /**< 事件触发时鼠标的坐标(相对于当前部件的边框盒) */
|
||||
int z_delta; /**< 鼠标滚轮滚动的距离差值 */
|
||||
int screen_x, screen_y; /**< 事件触发时鼠标的屏幕坐标 */
|
||||
uint32_t type; /**< 事件类型标识号 */
|
||||
void *data; /**< 附加数据 */
|
||||
LCUI_Widget target; /**< 触发事件的部件 */
|
||||
LCUI_BOOL cancel_bubble; /**< 是否取消事件冒泡 */
|
||||
union {
|
||||
LCUI_WidgetMouseMotionEvent motion;
|
||||
LCUI_WidgetMouseButtonEvent button;
|
||||
LCUI_WidgetMouseWheelEvent wheel;
|
||||
LCUI_WidgetKeyboardEvent key;
|
||||
LCUI_WidgetTouchEvent touch;
|
||||
LCUI_WidgetTextInputEvent text;
|
||||
};
|
||||
} LCUI_WidgetEventRec, *LCUI_WidgetEvent;
|
||||
|
||||
typedef void(*LCUI_WidgetEventFunc)(LCUI_Widget, LCUI_WidgetEvent, void*);
|
||||
|
||||
/** 设置阻止部件及其子级部件的事件 */
|
||||
#define Widget_BlockEvent(WIDGET, FLAG) (WIDGET)->event_blocked = FLAG
|
||||
|
||||
/** 触发事件,让事件处理器在主循环中调用 */
|
||||
LCUI_API int Widget_PostEvent( LCUI_Widget widget, LCUI_WidgetEvent e,
|
||||
void *data, void( *destroy_data )(void*) );
|
||||
@@ -156,6 +176,32 @@ LCUI_API int Widget_PostSurfaceEvent( LCUI_Widget w, int event_type );
|
||||
/** 清除事件对象,通常在部件销毁时调用该函数,以避免部件销毁后还有事件发送给它 */
|
||||
LCUI_API void LCUIWidget_ClearEventTarget( LCUI_Widget widget );
|
||||
|
||||
/** 将一个部件设置为焦点 */
|
||||
LCUI_API int LCUIWidget_SetFocus( LCUI_Widget widget );
|
||||
|
||||
/** 停止部件的事件传播 */
|
||||
LCUI_API int Widget_StopEventPropagation( LCUI_Widget widget );
|
||||
|
||||
/** 为部件设置鼠标捕获,设置后将捕获全局范围内的鼠标事件 */
|
||||
LCUI_API void Widget_SetMouseCapture( LCUI_Widget w );
|
||||
|
||||
/** 为部件解除鼠标捕获 */
|
||||
LCUI_API void Widget_ReleaseMouseCapture( LCUI_Widget w );
|
||||
|
||||
/**
|
||||
* 为部件设置触点捕获,设置后将捕获全局范围内的触点事件
|
||||
* @param[in] w 部件
|
||||
* @param[in] point_id 触点ID,当值为 -1 时则捕获全部触点
|
||||
*/
|
||||
LCUI_API void Widget_SetTouchCapture( LCUI_Widget w, int point_id );
|
||||
|
||||
/**
|
||||
* 为部件解除触点捕获
|
||||
* @param[in] w 部件
|
||||
* @param[in] point_id 触点ID,当值为 -1 时则解除全部触点的捕获
|
||||
*/
|
||||
LCUI_API int Widget_ReleaseTouchCapture( LCUI_Widget w, int point_id );
|
||||
|
||||
/** 初始化 LCUI 部件的事件系统 */
|
||||
void LCUIWidget_InitEvent(void);
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ***************************************************************************/
|
||||
|
||||
#ifndef __LCUI_WIDGET_LIBRARY_H__
|
||||
#define __LCUI_WIDGET_LIBRARY_H__
|
||||
#ifndef LCUI_WIDGET_LIBRARY_H
|
||||
#define LCUI_WIDGET_LIBRARY_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
|
||||
@@ -38,8 +38,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ***************************************************************************/
|
||||
|
||||
#ifndef __WIDGET_PAINT_H__
|
||||
#define __WIDGET_PAINT_H__
|
||||
#ifndef __WIDGET_PAINT_H
|
||||
#define __WIDGET_PAINT_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
@@ -51,6 +51,15 @@ LCUI_BEGIN_HEADER
|
||||
*/
|
||||
LCUI_API void Widget_InvalidateArea( LCUI_Widget w, LCUI_Rect *r, int box_type );
|
||||
|
||||
/**
|
||||
* 将部件一个无效区域推送到根级部件中
|
||||
* @param[in] w 目标部件
|
||||
* @param[in] r 矩形区域
|
||||
* @param[in] box_type 区域相对于何种框进行定位
|
||||
* @returns 推送成功返回 TRUE,如果在推送过程中区域处于部件不可见区域内,则推送失败,返回FALSE
|
||||
*/
|
||||
LCUI_API LCUI_BOOL Widget_PushInvalidArea( LCUI_Widget widget,
|
||||
LCUI_Rect *r, int box_type );
|
||||
/**
|
||||
* 获取部件中的无效区域
|
||||
* @param[in] widget 目标部件
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* ***************************************************************************
|
||||
* widget_style.h -- widget style library module for LCUI.
|
||||
*
|
||||
* Copyright (C) 2015 by Liu Chao <lc-soft@live.cn>
|
||||
* Copyright (C) 2015-2016 by Liu Chao <lc-soft@live.cn>
|
||||
*
|
||||
* This file is part of the LCUI project, and may only be used, modified, and
|
||||
* distributed under the terms of the GPLv2.
|
||||
@@ -22,7 +22,7 @@
|
||||
/* ****************************************************************************
|
||||
* widget_style.h -- LCUI 的部件样式库模块。
|
||||
*
|
||||
* 版权所有 (C) 2015 归属于 刘超 <lc-soft@live.cn>
|
||||
* 版权所有 (C) 2015-2016 归属于 刘超 <lc-soft@live.cn>
|
||||
*
|
||||
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
|
||||
*
|
||||
@@ -38,8 +38,8 @@
|
||||
* ****************************************************************************/
|
||||
|
||||
|
||||
#ifndef __LCUI_WIDGET_STYLE_LIBRARY_H__
|
||||
#define __LCUI_WIDGET_STYLE_LIBRARY_H__
|
||||
#ifndef LCUI_WIDGET_STYLE_LIBRARY_H
|
||||
#define LCUI_WIDGET_STYLE_LIBRARY_H
|
||||
|
||||
/** 初始化 */
|
||||
void LCUIWidget_InitStyle( void );
|
||||
@@ -60,13 +60,16 @@ LCUI_API int StyleSheet_Merge( LCUI_StyleSheet dest, LCUI_StyleSheet src );
|
||||
LCUI_API int StyleSheet_Replace( LCUI_StyleSheet dest, LCUI_StyleSheet src );
|
||||
|
||||
/** 删除样式表 */
|
||||
LCUI_API void StyleSheet_Delete( LCUI_StyleSheet *ss );
|
||||
LCUI_API void StyleSheet_Delete( LCUI_StyleSheet ss );
|
||||
|
||||
/** 根据字符串内容生成相应的选择器 */
|
||||
LCUI_API LCUI_Selector Selector( const char *selector );
|
||||
|
||||
/** 更新选择器内的数据 */
|
||||
LCUI_API void Selector_Update( LCUI_Selector s );
|
||||
|
||||
/** 删除选择器 */
|
||||
LCUI_API void Selector_Delete( LCUI_Selector *selector );
|
||||
LCUI_API void Selector_Delete( LCUI_Selector s );
|
||||
|
||||
/** 判断两个选择器是否相等 */
|
||||
LCUI_API LCUI_BOOL Selector_Compare( LCUI_Selector s1, LCUI_Selector s2 );
|
||||
@@ -75,7 +78,8 @@ LCUI_API LCUI_BOOL Selector_Compare( LCUI_Selector s1, LCUI_Selector s2 );
|
||||
LCUI_API LCUI_BOOL Selector_MatchPath( LCUI_Selector selector, LCUI_Widget *wlist );
|
||||
|
||||
/** 向样式库添加样式表 */
|
||||
LCUI_API int LCUI_PutStyle( LCUI_Selector selector, LCUI_StyleSheet in_ss );
|
||||
LCUI_API int LCUI_PutStyleSheet( LCUI_Selector selector,
|
||||
LCUI_StyleSheet in_ss, const char *space );
|
||||
|
||||
/** 打印样式表的内容 */
|
||||
LCUI_API void LCUI_PrintStyleSheet( LCUI_StyleSheet ss );
|
||||
@@ -84,10 +88,10 @@ LCUI_API void LCUI_PrintStyleSheet( LCUI_StyleSheet ss );
|
||||
LCUI_API void LCUI_PrintSelector( LCUI_Selector selector );
|
||||
|
||||
/** 打印样式库中的内容 */
|
||||
LCUI_API void LCUI_PrintStyleLibrary(void);
|
||||
LCUI_API void LCUI_PrintCSSLibrary(void);
|
||||
|
||||
/** 计算部件继承得到的样式表 */
|
||||
LCUI_API int Widget_ComputeInheritStyle( LCUI_Widget w, LCUI_StyleSheet out_ss );
|
||||
LCUI_API void Widget_GetInheritStyle( LCUI_Widget w, LCUI_StyleSheet out_ss );
|
||||
|
||||
/** 更新当前部件的样式 */
|
||||
LCUI_API void Widget_UpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all );
|
||||
@@ -95,6 +99,13 @@ LCUI_API void Widget_UpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all );
|
||||
/** 直接更新当前部件的样式 */
|
||||
LCUI_API void Widget_ExecUpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all );
|
||||
|
||||
#include <LCUI/gui/css_parser.h>
|
||||
/** 查找作用于当前部件的样式表 */
|
||||
LCUI_API int Widget_FindStyles( LCUI_Widget w, LinkedList *list );
|
||||
|
||||
/** 获取选择器 */
|
||||
LCUI_API LCUI_Selector Widget_GetSelector( LCUI_Widget w );
|
||||
|
||||
/** 处理子级部件样式变化 */
|
||||
LCUI_API int Widget_HandleChildrenStyleChange( LCUI_Widget w, int type, const char *name );
|
||||
|
||||
#endif
|
||||
|
||||
@@ -37,8 +37,10 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ***************************************************************************/
|
||||
|
||||
#ifndef __LCUI_WIDGET_TASK_H__
|
||||
#define __LCUI_WIDGET_TASK_H__
|
||||
#ifndef LCUI_WIDGET_TASK_H
|
||||
#define LCUI_WIDGET_TASK_H
|
||||
|
||||
#define Widget_Update(W) Widget_UpdateEx(W, FALSE)
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
@@ -48,17 +50,23 @@ LCUI_API void Widget_UpdateTaskStatus( LCUI_Widget widget );
|
||||
/** 添加任务 */
|
||||
LCUI_API void Widget_AddTask( LCUI_Widget widget, int task_type );
|
||||
|
||||
/** 处理部件中当前积累的任务 */
|
||||
LCUI_API int Widget_UpdateEx( LCUI_Widget w, LCUI_BOOL has_timeout );
|
||||
|
||||
/** 将部件标记为垃圾,等待销毁 */
|
||||
LCUI_API void Widget_AddToTrash( LCUI_Widget w );
|
||||
|
||||
/** 为子级部件添加任务 */
|
||||
LCUI_API void Widget_AddTaskForChildren( LCUI_Widget widget, int task );
|
||||
|
||||
/** 初始化 LCUI 部件任务处理功能 */
|
||||
void LCUIWidget_InitTask(void);
|
||||
void LCUIWidget_InitTask( void );
|
||||
|
||||
/** 销毁(释放) LCUI 部件任务处理功能的相关资源 */
|
||||
void LCUIWidget_ExitTask(void);
|
||||
void LCUIWidget_ExitTask( void );
|
||||
|
||||
/** 处理一次当前积累的部件任务 */
|
||||
void LCUIWidget_StepTask(void);
|
||||
void LCUIWidget_StepTask( void );
|
||||
|
||||
LCUI_END_HEADER
|
||||
|
||||
|
||||
+66
-29
@@ -1,51 +1,88 @@
|
||||
#ifndef __LCUI_IME_H__
|
||||
#define __LCUI_IME_H__
|
||||
/* ***************************************************************************
|
||||
* ime.h -- Input Method Editor/Engine
|
||||
*
|
||||
* Copyright (C) 2016 by Liu Chao <lc-soft@live.cn>
|
||||
*
|
||||
* This file is part of the LCUI project, and may only be used, modified, and
|
||||
* distributed under the terms of the GPLv2.
|
||||
*
|
||||
* (GPLv2 is abbreviation of GNU General Public License Version 2)
|
||||
*
|
||||
* By continuing to use, modify, or distribute this file you indicate that you
|
||||
* have read the license and understand and accept it fully.
|
||||
*
|
||||
* The LCUI project is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for more details.
|
||||
*
|
||||
* You should have received a copy of the GPLv2 along with this file. It is
|
||||
* usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* ime.h -- 输入法管理器
|
||||
*
|
||||
* 版权所有 (C) 2016 归属于 刘超 <lc-soft@live.cn>
|
||||
*
|
||||
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
|
||||
*
|
||||
* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
|
||||
*
|
||||
* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。
|
||||
*
|
||||
* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特
|
||||
* 定用途的隐含担保,详情请参照GPLv2许可协议。
|
||||
*
|
||||
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef LCUI_IME_H
|
||||
#define LCUI_IME_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
typedef struct LCUIIME_Func_ {
|
||||
typedef struct LCUI_IMEHandlerRec_ {
|
||||
LCUI_BOOL (*prockey)(int,int);
|
||||
void (*settarget)(LCUI_Widget*);
|
||||
void (*settarget)(LCUI_Widget);
|
||||
void (*cleartarget)(void);
|
||||
LCUI_Widget (*gettarget)(void);
|
||||
void (*totext)(char);
|
||||
LCUI_BOOL (*open)(void);
|
||||
LCUI_BOOL (*close)(void);
|
||||
} LCUIIME_Func;
|
||||
} LCUI_IMEHandlerRec, *LCUI_IMEHandler;
|
||||
|
||||
/* 注册一个输入法 */
|
||||
LCUI_API int
|
||||
LCUIIME_Register( const char *ime_name, LCUIIME_Func *ime_func );
|
||||
/** 注册一个输入法 */
|
||||
LCUI_API int LCUIIME_Register( const char *ime_name, LCUI_IMEHandler handler );
|
||||
|
||||
/* 选定输入法 */
|
||||
LCUI_API LCUI_BOOL
|
||||
LCUIIME_Select( int ime_id );
|
||||
/** 选定输入法 */
|
||||
LCUI_API LCUI_BOOL LCUIIME_Select( int ime_id );
|
||||
|
||||
LCUI_API LCUI_BOOL
|
||||
LCUIIME_SelectByName( const char *name );
|
||||
LCUI_API LCUI_BOOL LCUIIME_SelectByName( const char *name );
|
||||
|
||||
/* 切换至下一个输入法 */
|
||||
LCUI_API void
|
||||
LCUIIME_Switch(void);
|
||||
/** 切换至下一个输入法 */
|
||||
LCUI_API void LCUIIME_Switch( void );
|
||||
|
||||
/* 检测输入法是否要处理按键事件 */
|
||||
LCUI_API LCUI_BOOL
|
||||
LCUIIME_ProcessKey( const LCUI_KeyboardEvent *event );
|
||||
/** 检测输入法是否要处理按键事件 */
|
||||
LCUI_API LCUI_BOOL LCUIIME_ProcessKey( LCUI_SysEvent e );
|
||||
|
||||
/* 提交输入法输入的内容至目标 */
|
||||
LCUI_API int
|
||||
LCUIIME_Commit( const wchar_t *str );
|
||||
/** 提交输入法输入的内容至目标 */
|
||||
LCUI_API int LCUIIME_Commit( const wchar_t *str, int length );
|
||||
|
||||
/* 设置输入法的目标 */
|
||||
LCUI_API int
|
||||
LCUIIME_SetTarget( LCUI_Widget widget );
|
||||
/** 设置输入法的目标 */
|
||||
LCUI_API int LCUIIME_SetTarget( LCUI_Widget widget );
|
||||
|
||||
/** 获取输入法的目标 */
|
||||
LCUI_API LCUI_Widget LCUIIME_GetTarget( void );
|
||||
|
||||
/** 清除输入法的目标 */
|
||||
LCUI_API int LCUIIME_ClearTarget( void );
|
||||
|
||||
/* 初始化LCUI输入法模块 */
|
||||
LCUI_API void
|
||||
LCUI_InitIME(void);
|
||||
void LCUI_InitIME( void );
|
||||
|
||||
/* 停用LCUI输入法模块 */
|
||||
LCUI_API void
|
||||
LCUIModule_IME_End(void);
|
||||
void LCUI_ExitIME( void );
|
||||
|
||||
LCUI_END_HEADER
|
||||
|
||||
|
||||
+14
-26
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ***************************************************************************/
|
||||
|
||||
#ifndef __LCUI_INPUT_H__
|
||||
#define __LCUI_INPUT_H__
|
||||
#ifndef LCUI_INPUT_H
|
||||
#define LCUI_INPUT_H
|
||||
|
||||
#define LCUIKEY_SPACE ' '
|
||||
#define LCUIKEY_0 '0'
|
||||
@@ -136,38 +136,26 @@
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
/** 初始化鼠标输入模块 */
|
||||
LCUI_API int LCUI_InitMouse( void );
|
||||
|
||||
void LCUIMouse_SetPos( int x, int y );
|
||||
/** 检测指定键值的按键是否处于按下状态 */
|
||||
LCUI_API LCUI_BOOL LCUIKeyboard_IsHit( int key_code );
|
||||
|
||||
/**
|
||||
* 检测指定键值的按键是否按了两次
|
||||
* @param key_code
|
||||
* 要检测的按键的键值
|
||||
* @param interval_time
|
||||
* 该按键倒数第二次按下时的时间与当前时间的最大间隔
|
||||
*/
|
||||
LCUI_API LCUI_BOOL LCUIKey_IsDoubleHit( int key_code, int interval_time );
|
||||
* 检测指定键值的按键是否按了两次
|
||||
* @param key_code 要检测的按键的键值
|
||||
* @param interval_time 该按键倒数第二次按下时的时间与当前时间的最大间隔
|
||||
*/
|
||||
LCUI_API LCUI_BOOL LCUIKeyboard_IsDoubleHit( int key_code, int interval_time );
|
||||
|
||||
/** 添加已被按下的按键 */
|
||||
LCUI_API void LCUIKeyBoard_HitKey( int key_code );
|
||||
LCUI_API void LCUIKeyboard_HitKey( int key_code );
|
||||
|
||||
/** 标记指定键值的按键已释放 */
|
||||
LCUI_API void LCUIKeyBoard_ReleaseKey( int key_code );
|
||||
LCUI_API void LCUIKeyboard_ReleaseKey( int key_code );
|
||||
|
||||
/** 检测键盘是否有按键按下(类似于kbhit函数) */
|
||||
LCUI_API LCUI_BOOL LCUIKeyboard_IsHit( void );
|
||||
void LCUI_InitKeyboard( void );
|
||||
|
||||
/** 获取被按下的按键的键值(类似于getch函数) */
|
||||
LCUI_API int LCUIKeyboard_GetKey( void );
|
||||
|
||||
/** 初始化键盘输入模块 */
|
||||
LCUI_API int LCUI_InitKeyboard( void );
|
||||
|
||||
/** 停用键盘输入模块 */
|
||||
LCUI_API int LCUI_ExitKeyboard( void );
|
||||
void LCUI_ExitKeyboard( void );
|
||||
|
||||
LCUI_END_HEADER
|
||||
|
||||
#endif /* __LCUI_INPUT_H__ */
|
||||
#endif /* LCUI_INPUT_H */
|
||||
|
||||
+59
-11
@@ -36,8 +36,8 @@
|
||||
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ***************************************************************************/
|
||||
#ifndef __LCUI_LIB_MAIN_H__
|
||||
#define __LCUI_LIB_MAIN_H__
|
||||
#ifndef LCUI_MAIN_H
|
||||
#define LCUI_MAIN_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
@@ -59,25 +59,71 @@ enum LCUI_SysEventType {
|
||||
LCUI_MOUSEDOWN, /**< 鼠标触发的按钮按下事件 */
|
||||
LCUI_MOUSEUP, /**< 鼠标触发的按钮释放事件 */
|
||||
LCUI_MOUSEWHEEL, /**< 鼠标触发的滚轮滚动事件 */
|
||||
LCUI_INPUT, /**< 输入法触发的文本输入事件 */
|
||||
LCUI_TEXTINPUT, /**< 输入法触发的文本输入事件 */
|
||||
LCUI_TOUCH,
|
||||
LCUI_TOUCHMOVE,
|
||||
LCUI_TOUCHDOWN,
|
||||
LCUI_TOUCHUP,
|
||||
LCUI_WIDGET,
|
||||
LCUI_QUIT, /**< 在 LCUI 退出前触发的事件 */
|
||||
LCUI_USER = 100 /**< 用户事件,可以把这个当成系统事件与用户事件的分界 */
|
||||
};
|
||||
|
||||
typedef struct LCUI_TouchPointRec_ {
|
||||
int x;
|
||||
int y;
|
||||
int id;
|
||||
int state;
|
||||
LCUI_BOOL is_primary;
|
||||
} LCUI_TouchPointRec, *LCUI_TouchPoint;
|
||||
|
||||
typedef struct LCUI_KeyboardEvent_ {
|
||||
int code;
|
||||
} LCUI_KeyboardEvent;
|
||||
|
||||
typedef struct LCUI_MouseMotionEvent_ {
|
||||
int x, y;
|
||||
int xrel, yrel;
|
||||
} LCUI_MouseMotionEvent;
|
||||
|
||||
typedef struct LCUI_MouseButtonEvent_ {
|
||||
int x, y;
|
||||
int button;
|
||||
} LCUI_MouseButtonEvent;
|
||||
|
||||
typedef struct LCUI_MouseWheelEvent_ {
|
||||
int x, y;
|
||||
int delta;
|
||||
} LCUI_MouseWheelEvent;
|
||||
|
||||
typedef struct LCUI_TouchEvent_ {
|
||||
int n_points;
|
||||
LCUI_TouchPoint points;
|
||||
} LCUI_TouchEvent;
|
||||
|
||||
typedef struct LCUI_TextInputEvent_ {
|
||||
wchar_t *text;
|
||||
size_t length;
|
||||
} LCUI_TextInputEvent;
|
||||
|
||||
typedef struct LCUI_SysEventRec_ {
|
||||
int type; /**< 事件类型标识号 */
|
||||
int key_code; /**< 按键的键值 */
|
||||
int rel_x, rel_y; /**< 鼠标的坐标与上次坐标的差值 */
|
||||
int z_delta; /**< 鼠标滚轮滚动速度 */
|
||||
void *data; /**< 附加数据 */
|
||||
uint32_t type;
|
||||
void *data;
|
||||
union {
|
||||
LCUI_MouseMotionEvent motion;
|
||||
LCUI_MouseButtonEvent button;
|
||||
LCUI_MouseWheelEvent wheel;
|
||||
LCUI_TextInputEvent text;
|
||||
LCUI_KeyboardEvent key;
|
||||
LCUI_TouchEvent touch;
|
||||
};
|
||||
} LCUI_SysEventRec, *LCUI_SysEvent;
|
||||
|
||||
typedef void(*LCUI_SysEventFunc)(LCUI_SysEvent, void*);
|
||||
|
||||
/** LCUI 应用程序驱动接口,封装了各个平台下的应用程序相关功能支持接口 */
|
||||
typedef struct LCUI_AppDriverRec_ {
|
||||
void( *PumbEvents )(void);
|
||||
void( *DispatchEvent )(void);
|
||||
LCUI_BOOL( *WaitEvent )(void);
|
||||
LCUI_BOOL( *PostTask )(LCUI_AppTask);
|
||||
int( *BindSysEvent )(int, LCUI_EventFunc, void*, void( *)(void*));
|
||||
@@ -99,6 +145,8 @@ LCUI_API int LCUI_UnbindEvent( int handler_id );
|
||||
|
||||
LCUI_API int LCUI_TriggerEvent( LCUI_SysEvent e, void *arg );
|
||||
|
||||
LCUI_API void LCUI_DestroyEvent( LCUI_SysEvent e );
|
||||
|
||||
LCUI_API LCUI_BOOL LCUI_WaitEvent( void );
|
||||
|
||||
LCUI_API int LCUI_BindSysEvent( int event_id, LCUI_EventFunc func,
|
||||
@@ -106,10 +154,10 @@ LCUI_API int LCUI_BindSysEvent( int event_id, LCUI_EventFunc func,
|
||||
|
||||
LCUI_API int LCUI_UnbindSysEvent( int event_id, LCUI_EventFunc func );
|
||||
|
||||
LCUI_API void LCUI_PumbEvents( void );
|
||||
|
||||
LCUI_API void *LCUI_GetAppData( void );
|
||||
|
||||
LCUI_API void LCUI_SetTaskAgent( LCUI_BOOL enabled );
|
||||
|
||||
/** 添加任务 */
|
||||
LCUI_API LCUI_BOOL LCUI_PostTask( LCUI_AppTask task );
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __LCUI_PLATFORM_H__
|
||||
#define __LCUI_PLATFORM_H__
|
||||
#ifndef LCUI_PLATFORM_H
|
||||
#define LCUI_PLATFORM_H
|
||||
|
||||
#ifdef LCUI_BUILD_IN_WIN32
|
||||
#define LCUI_InitApp LCUI_InitWinApp
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#ifndef __LCUI_LINUX_DISPLAY_H__
|
||||
#define __LCUI_LINUX_DISPLAY_H__
|
||||
#ifndef LCUI_LINUX_DISPLAY_H
|
||||
#define LCUI_LINUX_DISPLAY_H
|
||||
|
||||
#include <LCUI/platform/linux/linux_fbdisplay.h>
|
||||
#include <LCUI/platform/linux/linux_x11display.h>
|
||||
|
||||
int LCUI_InitLinuxDisplay( LCUI_DisplayDriver driver );
|
||||
|
||||
|
||||
@@ -1,6 +1,46 @@
|
||||
#ifndef __LCUI_LINUX_EVENTS_H__
|
||||
#define __LCUI_LINUX_EVENTS_H__
|
||||
/* ***************************************************************************
|
||||
* linux_events.c -- event loop support for linux.
|
||||
*
|
||||
* Copyright (C) 2016 by Liu Chao <lc-soft@live.cn>
|
||||
*
|
||||
* This file is part of the LCUI project, and may only be used, modified, and
|
||||
* distributed under the terms of the GPLv2.
|
||||
*
|
||||
* (GPLv2 is abbreviation of GNU General Public License Version 2)
|
||||
*
|
||||
* By continuing to use, modify, or distribute this file you indicate that you
|
||||
* have read the license and understand and accept it fully.
|
||||
*
|
||||
* The LCUI project is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for more details.
|
||||
*
|
||||
* You should have received a copy of the GPLv2 along with this file. It is
|
||||
* usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* linux_events.c -- linux 平台的事件驱动支持。
|
||||
*
|
||||
* 版权所有 (C) 2016 归属于 刘超 <lc-soft@live.cn>
|
||||
*
|
||||
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
|
||||
*
|
||||
* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
|
||||
*
|
||||
* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。
|
||||
*
|
||||
* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特
|
||||
* 定用途的隐含担保,详情请参照GPLv2许可协议。
|
||||
*
|
||||
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef LCUI_LINUX_EVENTS_H
|
||||
#define LCUI_LINUX_EVENTS_H
|
||||
|
||||
#include <LCUI/platform/linux/linux_x11events.h>
|
||||
|
||||
int LCUI_InitLinuxApp( LCUI_AppDriver app );
|
||||
|
||||
|
||||
@@ -1 +1,39 @@
|
||||
/* ***************************************************************************
|
||||
* linux_fbdisplay.h -- surface support for linux framebuffer.
|
||||
*
|
||||
* Copyright (C) 2016 by Liu Chao <lc-soft@live.cn>
|
||||
*
|
||||
* This file is part of the LCUI project, and may only be used, modified, and
|
||||
* distributed under the terms of the GPLv2.
|
||||
*
|
||||
* (GPLv2 is abbreviation of GNU General Public License Version 2)
|
||||
*
|
||||
* By continuing to use, modify, or distribute this file you indicate that you
|
||||
* have read the license and understand and accept it fully.
|
||||
*
|
||||
* The LCUI project is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for more details.
|
||||
*
|
||||
* You should have received a copy of the GPLv2 along with this file. It is
|
||||
* usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* linux_fbdisplay.h -- linux 平台的图形显示功能支持,基于帧缓存(FrameBuffer)。
|
||||
*
|
||||
* 版权所有 (C) 2016 归属于 刘超 <lc-soft@live.cn>
|
||||
*
|
||||
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
|
||||
*
|
||||
* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
|
||||
*
|
||||
* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。
|
||||
*
|
||||
* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特
|
||||
* 定用途的隐含担保,详情请参照GPLv2许可协议。
|
||||
*
|
||||
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __LCUI_LINUX_KEYBOARD_H__
|
||||
#define __LCUI_LINUX_KEYBOARD_H__
|
||||
#ifndef LCUI_LINUX_KEYBOARD_H
|
||||
#define LCUI_LINUX_KEYBOARD_H
|
||||
|
||||
void LCUI_InitLinuxKeyboard( void );
|
||||
|
||||
|
||||
@@ -1,5 +1,46 @@
|
||||
#ifndef __LCUI_LINUX_MOUSE_H__
|
||||
#define __LCUI_LINUX_MOUSE_H__
|
||||
/* ***************************************************************************
|
||||
* linux_mouse.h -- mouse support for linux.
|
||||
*
|
||||
* Copyright (C) 2016 by Liu Chao <lc-soft@live.cn>
|
||||
*
|
||||
* This file is part of the LCUI project, and may only be used, modified, and
|
||||
* distributed under the terms of the GPLv2.
|
||||
*
|
||||
* (GPLv2 is abbreviation of GNU General Public License Version 2)
|
||||
*
|
||||
* By continuing to use, modify, or distribute this file you indicate that you
|
||||
* have read the license and understand and accept it fully.
|
||||
*
|
||||
* The LCUI project is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for more details.
|
||||
*
|
||||
* You should have received a copy of the GPLv2 along with this file. It is
|
||||
* usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* linux_mouse.h -- linux 平台的鼠标支持
|
||||
*
|
||||
* 版权所有 (C) 2016 归属于 刘超 <lc-soft@live.cn>
|
||||
*
|
||||
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
|
||||
*
|
||||
* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
|
||||
*
|
||||
* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。
|
||||
*
|
||||
* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特
|
||||
* 定用途的隐含担保,详情请参照GPLv2许可协议。
|
||||
*
|
||||
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef LCUI_LINUX_MOUSE_H
|
||||
#define LCUI_LINUX_MOUSE_H
|
||||
|
||||
#include <LCUI/platform/linux/linux_x11mouse.h>
|
||||
|
||||
void LCUI_InitLinuxMouse( void );
|
||||
|
||||
|
||||
@@ -1 +1,47 @@
|
||||
/* ***************************************************************************
|
||||
* linux_x11display.h -- surface support for linux xwindow.
|
||||
*
|
||||
* Copyright (C) 2016 by Liu Chao <lc-soft@live.cn>
|
||||
*
|
||||
* This file is part of the LCUI project, and may only be used, modified, and
|
||||
* distributed under the terms of the GPLv2.
|
||||
*
|
||||
* (GPLv2 is abbreviation of GNU General Public License Version 2)
|
||||
*
|
||||
* By continuing to use, modify, or distribute this file you indicate that you
|
||||
* have read the license and understand and accept it fully.
|
||||
*
|
||||
* The LCUI project is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for more details.
|
||||
*
|
||||
* You should have received a copy of the GPLv2 along with this file. It is
|
||||
* usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* linux_x11display.h -- linux 平台的图形显示功能支持,基于 xwindow。
|
||||
*
|
||||
* 版权所有 (C) 2016 归属于 刘超 <lc-soft@live.cn>
|
||||
*
|
||||
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
|
||||
*
|
||||
* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
|
||||
*
|
||||
* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。
|
||||
*
|
||||
* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特
|
||||
* 定用途的隐含担保,详情请参照GPLv2许可协议。
|
||||
*
|
||||
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef LCUI_LINUX_X11_DISPLAY_H
|
||||
#define LCUI_LINUX_X11_DISPLAY_H
|
||||
|
||||
int LCUI_InitLinuxX11Display( LCUI_DisplayDriver driver );
|
||||
|
||||
int LCUI_ExitLinuxX11Display( void );
|
||||
|
||||
#endif
|
||||
@@ -1 +1,64 @@
|
||||
/* ***************************************************************************
|
||||
* linux_x11events.c -- event loop support for linux xwindow.
|
||||
*
|
||||
* Copyright (C) 2016 by Liu Chao <lc-soft@live.cn>
|
||||
*
|
||||
* This file is part of the LCUI project, and may only be used, modified, and
|
||||
* distributed under the terms of the GPLv2.
|
||||
*
|
||||
* (GPLv2 is abbreviation of GNU General Public License Version 2)
|
||||
*
|
||||
* By continuing to use, modify, or distribute this file you indicate that you
|
||||
* have read the license and understand and accept it fully.
|
||||
*
|
||||
* The LCUI project is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for more details.
|
||||
*
|
||||
* You should have received a copy of the GPLv2 along with this file. It is
|
||||
* usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* linux_x11events.c -- linux 平台的事件驱动支持,基于 xwindow。
|
||||
*
|
||||
* 版权所有 (C) 2016 归属于 刘超 <lc-soft@live.cn>
|
||||
*
|
||||
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
|
||||
*
|
||||
* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
|
||||
*
|
||||
* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。
|
||||
*
|
||||
* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特
|
||||
* 定用途的隐含担保,详情请参照GPLv2许可协议。
|
||||
*
|
||||
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef LCUI_LINUX_X11_EVENTS_H
|
||||
#define LCUI_LINUX_X11_EVENTS_H
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/Xos.h>
|
||||
#include <X11/Xatom.h>
|
||||
|
||||
typedef struct LCUI_X11AppDriverRec_ {
|
||||
int screen;
|
||||
Display *display;
|
||||
Window win_root;
|
||||
Window win_main;
|
||||
Colormap cmap;
|
||||
Atom wm_lcui;
|
||||
LCUI_EventTrigger trigger;
|
||||
} LCUI_X11AppDriverRec, *LCUI_X11AppDriver;
|
||||
|
||||
void LCUI_SetLinuxX11MainWindow( Window win );
|
||||
|
||||
void LCUI_PreInitLinuxX11App( void *data );
|
||||
|
||||
int LCUI_InitLinuxX11App( LCUI_AppDriver app );
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* ***************************************************************************
|
||||
* delay.h -- time delay function.
|
||||
/* ***************************************************************************
|
||||
* linux_x11mouse.h -- mouse support for linux xwindow.
|
||||
*
|
||||
* Copyright (C) 2013-2016 by Liu Chao <lc-soft@live.cn>
|
||||
* Copyright (C) 2016 by Liu Chao <lc-soft@live.cn>
|
||||
*
|
||||
* This file is part of the LCUI project, and may only be used, modified, and
|
||||
* distributed under the terms of the GPLv2.
|
||||
@@ -20,9 +20,9 @@
|
||||
* ****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* delay.h -- 一些提供延时功能的函数
|
||||
* linux_x11mouse.h -- linux 平台的鼠标支持,基于 xwindow。
|
||||
*
|
||||
* 版权所有 (C) 2013-2016 归属于 刘超 <lc-soft@live.cn>
|
||||
* 版权所有 (C) 2016 归属于 刘超 <lc-soft@live.cn>
|
||||
*
|
||||
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
|
||||
*
|
||||
@@ -36,18 +36,12 @@
|
||||
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
#ifndef __LCUI_UTIL_DELAY_H__
|
||||
#define __LCUI_UTIL_DELAY_H__
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
#ifndef LCUI_LINUX_X11_MOUSE_H
|
||||
#define LCUI_LINUX_X11_MOUSE_H
|
||||
|
||||
/* 秒级延时 */
|
||||
LCUI_API void LCUI_Sleep( unsigned int s );
|
||||
void LCUI_InitLinuxX11Mouse( void );
|
||||
|
||||
/* 毫秒级延时 */
|
||||
LCUI_API void LCUI_MSleep( unsigned int ms );
|
||||
|
||||
LCUI_END_HEADER
|
||||
void LCUI_ExitLinuxX11Mouse( void );
|
||||
|
||||
#endif
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef __LCUI_WINDOWS_DISPLAY_H__
|
||||
#define __LCUI_WINDOWS_DISPLAY_H__
|
||||
#ifndef LCUI_WINDOWS_DISPLAY_H
|
||||
#define LCUI_WINDOWS_DISPLAY_H
|
||||
|
||||
int LCUI_InitWinDisplay( LCUI_DisplayDriver driver );
|
||||
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
#ifndef __WINDOWS_EVENTS_H__
|
||||
#define __WINDOWS_EVENTS_H__
|
||||
|
||||
typedef struct WIN_SysEvent_ {
|
||||
HWND hwnd;
|
||||
WPARAM wparam;
|
||||
LPARAM lparam;
|
||||
UINT msg;
|
||||
void *data;
|
||||
} WIN_SysEventRec, *WIN_SysEvent;
|
||||
#ifndef LCUI_WINDOWS_EVENTS_H
|
||||
#define LCUI_WINDOWS_EVENTS_H
|
||||
|
||||
LCUI_API void LCUI_PreInitWinApp( void *data );
|
||||
|
||||
void LCUI_SetMainWindow( HWND hwnd );
|
||||
|
||||
int LCUI_InitWinApp( LCUI_AppDriver app );
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __LCUI_WINDOWS_KEYBOARD__
|
||||
#define __LCUI_WINDOWS_KEYBOARD__
|
||||
#ifndef LCUI_WINDOWS_KEYBOARD_H
|
||||
#define LCUI_WINDOWS_KEYBOARD_H
|
||||
|
||||
void LCUI_InitWinKeyboard( void );
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __LCUI_WINDOWS_MOUSE_H__
|
||||
#define __LCUI_WINDOWS_MOUSE_H__
|
||||
#ifndef LCUI_WINDOWS_MOUSE_H
|
||||
#define LCUI_WINDOWS_MOUSE_H
|
||||
|
||||
void LCUI_InitWinMouse( void );
|
||||
|
||||
|
||||
@@ -37,13 +37,13 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ***************************************************************************/
|
||||
|
||||
#ifndef __LCUI_SURFACE_H__
|
||||
#define __LCUI_SURFACE_H__
|
||||
#ifndef LCUI_SURFACE_H
|
||||
#define LCUI_SURFACE_H
|
||||
|
||||
#define RENDER_MODE_BIT_BLT 0
|
||||
#define RENDER_MODE_STRETCH_BLT 1
|
||||
|
||||
#ifdef __IN_SURFACE_SOURCE_FILE__
|
||||
#ifdef LCUI_SURFACE_C
|
||||
typedef struct LCUI_SurfaceRec_ * LCUI_Surface;
|
||||
#else
|
||||
typedef void* LCUI_Surface;
|
||||
|
||||
@@ -39,8 +39,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef __LCUI_THREAD_H__
|
||||
#define __LCUI_THREAD_H__
|
||||
#ifndef LCUI_THREAD_H
|
||||
#define LCUI_THREAD_H
|
||||
|
||||
#ifdef LCUI_THREAD_PTHREAD
|
||||
#include <pthread.h>
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ***************************************************************************/
|
||||
|
||||
#ifndef __LCUI_TIMER_H__
|
||||
#define __LCUI_TIMER_H__
|
||||
#ifndef LCUI_TIMER_H
|
||||
#define LCUI_TIMER_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
|
||||
+3
-3
@@ -37,10 +37,9 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef __LCUI_MISC_H__
|
||||
#define __LCUI_MISC_H__
|
||||
#ifndef LCUI_UTIL_H
|
||||
#define LCUI_UTIL_H
|
||||
#include <LCUI/util/time.h>
|
||||
#include <LCUI/util/delay.h>
|
||||
#include <LCUI/util/dirent.h>
|
||||
#include <LCUI/util/rbtree.h>
|
||||
#include <LCUI/util/linkedlist.h>
|
||||
@@ -50,4 +49,5 @@
|
||||
#include <LCUI/util/string.h>
|
||||
#include <LCUI/util/parse.h>
|
||||
#include <LCUI/util/event.h>
|
||||
#include <LCUI/util/memdebug.h>
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
AUTOMAKE_OPTIONS=foreign
|
||||
|
||||
# Headers to install
|
||||
pkginclude_HEADERS = dict.h rbtree.h linkedlist.h framectrl.h parse.h string.h rect.h delay.h dirent.h
|
||||
pkginclude_HEADERS = dict.h rbtree.h linkedlist.h framectrl.h parse.h string.h rect.h dirent.h
|
||||
pkgincludedir=$(prefix)/include/LCUI/util
|
||||
|
||||
@@ -34,8 +34,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef __DICT_H__
|
||||
#define __DICT_H__
|
||||
#ifndef LCUI_UTIL_DICT_H
|
||||
#define LCUI_UTIL_DICT_H
|
||||
|
||||
/** 哈希表节点结构 */
|
||||
typedef struct DictEntry {
|
||||
@@ -203,6 +203,10 @@ LCUI_API void Dict_PrintStats( Dict *d );
|
||||
|
||||
LCUI_API unsigned int Dict_GenHashFunction( const unsigned char *buf, int len );
|
||||
LCUI_API unsigned int Dict_GenCaseHashFunction( const unsigned char *buf, int len );
|
||||
LCUI_API unsigned int Dict_IntHashFunction( unsigned int key );
|
||||
|
||||
/* Identity hash function for integer keys */
|
||||
LCUI_API unsigned int Dict_IdentityHashFunction( unsigned int key );
|
||||
|
||||
/** 清空字典 */
|
||||
LCUI_API void Dict_Empty( Dict *d );
|
||||
@@ -227,8 +231,7 @@ LCUI_API void Dict_SetHashFunctionSeed( unsigned int initval );
|
||||
LCUI_API unsigned int Dict_GetHashFunctionSeed( void );
|
||||
|
||||
/* Hash table types */
|
||||
extern DictType dictTypeHeapStringCopyKey;
|
||||
extern DictType dictTypeHeapStrings;
|
||||
extern DictType dictTypeHeapStringCopyKeyValue;
|
||||
DictType DictType_StringKey;
|
||||
DictType DictType_StringCopyKey;
|
||||
|
||||
#endif /* __DICT_H__ */
|
||||
#endif /* LCUI_UTIL_DICT_H */
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// dirent.h -- Directory Entry pperation set.
|
||||
#ifndef __LCUI_DIRECTORY_ENTRY_H__
|
||||
#define __LCUI_DIRECTORY_ENTRY_H__
|
||||
#ifndef LCUI_UTIL_DIRENT_H
|
||||
#define LCUI_UTIL_DIRENT_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
|
||||
@@ -36,8 +36,8 @@
|
||||
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
#ifndef __LCUI_LIB_EVENT_H__
|
||||
#define __LCUI_LIB_EVENT_H__
|
||||
#ifndef LCUI_UTIL_EVENT_H
|
||||
#define LCUI_UTIL_EVENT_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
|
||||
@@ -38,35 +38,35 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef __LC_FRAME_CONTROL_H__
|
||||
#define __LC_FRAME_CONTROL_H__
|
||||
#ifndef LCUI_UTIL_FRAMECTRL_H
|
||||
#define LCUI_UTIL_FRAMECTRL_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
#ifdef __IN_FRAME_CONTROL_SOURCE_FILE__
|
||||
typedef struct FrameControlContext* FrameCtrlCtx;
|
||||
#ifdef LCUI_UTIL_FRAMECTRL_C
|
||||
typedef struct FrameControlRec_* FrameControl;
|
||||
#else
|
||||
typedef void* FrameCtrlCtx;
|
||||
typedef void* FrameControl;
|
||||
#endif
|
||||
|
||||
/** 新建帧数控制实例 */
|
||||
LCUI_API FrameCtrlCtx FrameControl_Create( void );
|
||||
LCUI_API FrameControl FrameControl_Create( void );
|
||||
|
||||
/** 销毁帧数控制相关资源 */
|
||||
LCUI_API void FrameControl_Destroy( FrameCtrlCtx ctx );
|
||||
LCUI_API void FrameControl_Destroy( FrameControl ctx );
|
||||
|
||||
|
||||
/** 设置最大FPS(帧数/秒) */
|
||||
LCUI_API void FrameControl_SetMaxFPS( FrameCtrlCtx ctx, unsigned int fps );
|
||||
LCUI_API void FrameControl_SetMaxFPS( FrameControl ctx, unsigned int fps );
|
||||
|
||||
/** 获取当前FPS */
|
||||
LCUI_API int FrameControl_GetFPS( FrameCtrlCtx ctx );
|
||||
LCUI_API int FrameControl_GetFPS( FrameControl ctx );
|
||||
|
||||
/** 让当前帧停留一定时间 */
|
||||
LCUI_API void FrameControl_Remain( FrameCtrlCtx ctx );
|
||||
LCUI_API void FrameControl_Remain( FrameControl ctx );
|
||||
|
||||
/** 暂停数据帧的更新 */
|
||||
LCUI_API void FrameControl_Pause( FrameCtrlCtx ctx, LCUI_BOOL need_pause );
|
||||
LCUI_API void FrameControl_Pause( FrameControl ctx, LCUI_BOOL need_pause );
|
||||
|
||||
LCUI_END_HEADER
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef __LCUI_UTIL_LINKEDLIST_H__
|
||||
#define __LCUI_UTIL_LINKEDLIST_H__
|
||||
#ifndef LCUI_UTIL_LINKEDLIST_H
|
||||
#define LCUI_UTIL_LINKEDLIST_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
@@ -55,14 +55,14 @@ struct LinkedListRec_ {
|
||||
LinkedListNode head, tail;
|
||||
};
|
||||
|
||||
#define LinkedList_ForEach(node, list) \
|
||||
for( node = (list)->head.next; node; node = node->next )
|
||||
#define LinkedList_Each(node, list) \
|
||||
node = (list)->head.next; node; node = node->next
|
||||
|
||||
#define LinkedList_ForEachReverse(node, list) \
|
||||
for( node = (list)->tail.prev; node && node != &(list)->head; node = node->prev )
|
||||
#define LinkedList_EachReverse(node, list) \
|
||||
node = (list)->tail.prev; node && node != &(list)->head; node = node->prev
|
||||
|
||||
#define LinkedList_Clear(list, func) LinkedList_ClearEx( list, func, 1 )
|
||||
#define LinkedList_ClearData(list, func) LinkedList_ClearEx( list, func, 0 )
|
||||
#define LinkedList_ForEach(node, list) for( LinkedList_Each(node, list) )
|
||||
#define LinkedList_ForEachReverse(node, list) for( LinkedList_EachReverse(node, list) )
|
||||
|
||||
LCUI_API LinkedListNode *LinkedList_Append( LinkedList *list, void *data );
|
||||
LCUI_API LinkedListNode *LinkedList_Insert( LinkedList *list, int pos, void *data );
|
||||
@@ -74,10 +74,16 @@ LCUI_API void LinkedList_Link( LinkedList *list, LinkedListNode *cur, LinkedList
|
||||
LCUI_API void LinkedList_Delete( LinkedList *list, int pos );
|
||||
LCUI_API void LinkedList_DeleteNode( LinkedList *list, LinkedListNode *node );
|
||||
LCUI_API void LinkedList_AppendNode( LinkedList *list, LinkedListNode *node );
|
||||
LCUI_API void LinkedList_Sort( LinkedList *list, void(*on_sort)(void*, void*) );
|
||||
LCUI_API void LinkedList_ClearEx( LinkedList *list, void(*on_destroy)(void*), int free_node );
|
||||
LCUI_API void LinkedList_Concat( LinkedList *list1, LinkedList *list2 );
|
||||
|
||||
#define LinkedList_Clear(list, func) LinkedList_ClearEx( list, func, 1 )
|
||||
#define LinkedList_ClearData(list, func) LinkedList_ClearEx( list, func, 0 )
|
||||
|
||||
LCUI_API void LinkedList_SwapNode( LinkedList *list, LinkedListNode *a, LinkedListNode *b );
|
||||
LCUI_API void LinkedList_QuickSort( LinkedList *list, int( *cmp )(void*, void*) );
|
||||
LCUI_API void LinkedList_BubbleSort( LinkedList *list, int( *cmp )(void*, void*) );
|
||||
|
||||
LCUI_END_HEADER
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/* ***************************************************************************
|
||||
* memdebug.h -- memory debug module, used for memory usage statistics.
|
||||
*
|
||||
* Copyright (C) 2016 by Liu Chao <lc-soft@live.cn>
|
||||
*
|
||||
* This file is part of the LCUI project, and may only be used, modified, and
|
||||
* distributed under the terms of the GPLv2.
|
||||
*
|
||||
* (GPLv2 is abbreviation of GNU General Public License Version 2)
|
||||
*
|
||||
* By continuing to use, modify, or distribute this file you indicate that you
|
||||
* have read the license and understand and accept it fully.
|
||||
*
|
||||
* The LCUI project is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for more details.
|
||||
*
|
||||
* You should have received a copy of the GPLv2 along with this file. It is
|
||||
* usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* memdebug.h -- 内存调试模块,用于统计各个内存块的使用情况,方便调试。
|
||||
*
|
||||
* 版权所有 (C) 2016 归属于 刘超 <lc-soft@live.cn>
|
||||
*
|
||||
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
|
||||
*
|
||||
* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
|
||||
*
|
||||
* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。
|
||||
*
|
||||
* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特
|
||||
* 定用途的隐含担保,详情请参照GPLv2许可协议。
|
||||
*
|
||||
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef LCUI_UTIL_MEMDEBUG_H
|
||||
#define LCUI_UTIL_MEMDEBUG_H
|
||||
|
||||
LCUI_API void LCUI_InitMemDebug( void );
|
||||
|
||||
LCUI_API void LCUI_ExitMemDebug( void );
|
||||
|
||||
LCUI_API void LCUI_PrintMemStats( void );
|
||||
|
||||
#ifdef ENABLE_MEMDEBUG
|
||||
|
||||
LCUI_API void *LCUI_Malloc( size_t size, const char *name );
|
||||
|
||||
LCUI_API void *LCUI_Calloc( size_t count, size_t size, const char *name );
|
||||
|
||||
LCUI_API void *LCUI_Realloc( void *ptr, size_t size );
|
||||
|
||||
LCUI_API void LCUI_Free( void *ptr );
|
||||
|
||||
LCUI_API void LCUI_SetMemBlockName( void *ptr, const char *name );
|
||||
|
||||
#undef NEW
|
||||
#define NEW(TYPE, COUNT) (TYPE*)LCUI_Calloc(COUNT, sizeof(TYPE), __FUNCTION__)
|
||||
|
||||
#else
|
||||
|
||||
#define LCUI_Malloc(SIZE, NAME) malloc(SIZE)
|
||||
#define LCUI_Calloc(COUNT, SIZE, NAME) calloc(COUNT, SIZE)
|
||||
#define LCUI_Realloc(PTR, SIZE) realloc(PTR, SIZE)
|
||||
#define LCUI_Free free
|
||||
#define LCUI_SetMemBlockName(PTR, NAME)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ***************************************************************************/
|
||||
|
||||
#ifndef __LCUI_UTIL_PARSE_H__
|
||||
#define __LCUI_UTIL_PARSE_H__
|
||||
#ifndef LCUI_UTIL_PARSE_H
|
||||
#define LCUI_UTIL_PARSE_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ***************************************************************************/
|
||||
|
||||
#ifndef __LCUI_UTIL_RBTREE_H__
|
||||
#define __LCUI_UTIL_RBTREE_H__
|
||||
#ifndef LCUI_UTIL_RBTREE_H
|
||||
#define LCUI_UTIL_RBTREE_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
@@ -56,37 +56,24 @@ struct LCUI_RBTreeNodeRec_ {
|
||||
|
||||
typedef struct LCUI_RBTreeRec_ {
|
||||
int total_node;
|
||||
int need_free_data;
|
||||
int (*judge)(void*, const void*);
|
||||
int (*compare)(void*, const void*);
|
||||
void (*destroy)(void*);
|
||||
LCUI_RBTreeNode *root;
|
||||
} LCUI_RBTree;
|
||||
|
||||
#define RBTree_GetTotal(rbt) (rbt)->total_node;
|
||||
|
||||
#define RBTree_OnJudge(rbt, func) (rbt)->judge = func
|
||||
|
||||
#define RBTree_OnCompare(rbt, func) (rbt)->compare = func
|
||||
#define RBTree_OnDestroy(rbt, func) (rbt)->destroy = func
|
||||
|
||||
#define RBTree_SetDataNeedFree(rbt, flag) (rbt)->need_free_data = flag
|
||||
|
||||
/** 初始化红黑树 */
|
||||
LCUI_API void RBTree_Init( LCUI_RBTree *rbt );
|
||||
|
||||
/** 销毁红黑树 */
|
||||
LCUI_API void RBTree_Destroy( LCUI_RBTree *rbt );
|
||||
|
||||
/** 获取第一个结点 */
|
||||
LCUI_API LCUI_RBTreeNode *RBTree_First( const LCUI_RBTree *rbt );
|
||||
|
||||
/** 获取下一个结点 */
|
||||
LCUI_API LCUI_RBTreeNode *RBTree_Next( const LCUI_RBTreeNode *node );
|
||||
|
||||
LCUI_API LCUI_RBTreeNode* RBTree_Search( LCUI_RBTree* rbt, int key );
|
||||
LCUI_API void* RBTree_GetData( LCUI_RBTree* rbt, int key );
|
||||
LCUI_API LCUI_RBTreeNode* RBTree_Insert( LCUI_RBTree *rbt, int key, void *data );
|
||||
LCUI_API int RBTree_Erase( LCUI_RBTree *rbt, int key );
|
||||
|
||||
LCUI_API void RBTree_EraseNode( LCUI_RBTree *rbt, LCUI_RBTreeNode *node );
|
||||
LCUI_API int RBTree_CustomErase( LCUI_RBTree *rbt, const void *keydata );
|
||||
LCUI_API LCUI_RBTreeNode* RBTree_CustomSearch( LCUI_RBTree* rbt, const void *keydata );
|
||||
LCUI_API void* RBTree_CustomGetData( LCUI_RBTree* rbt, const void *keydata );
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
/* ***************************************************************************
|
||||
* rect.h -- Rectangle area handling
|
||||
*
|
||||
* Copyright (C) 2012-2015 by
|
||||
* Liu Chao
|
||||
* Copyright (C) 2012-2016 by Liu Chao <lc-soft@live.cn>
|
||||
*
|
||||
* This file is part of the LCUI project, and may only be used, modified, and
|
||||
* distributed under the terms of the GPLv2.
|
||||
@@ -23,8 +22,7 @@
|
||||
/* ****************************************************************************
|
||||
* rect.h -- 矩形区域处理
|
||||
*
|
||||
* 版权所有 (C) 2012-2015 归属于
|
||||
* 刘超
|
||||
* 版权所有 (C) 2012-2016 归属于 刘超 <lc-soft@live.cn>
|
||||
*
|
||||
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
|
||||
*
|
||||
@@ -38,8 +36,9 @@
|
||||
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
#ifndef __LCUI_MISC_RECT_H__
|
||||
#define __LCUI_MISC_RECT_H__
|
||||
|
||||
#ifndef LCUI_UTIL_RECT_H
|
||||
#define LCUI_UTIL_RECT_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
|
||||
+52
-10
@@ -1,7 +1,7 @@
|
||||
/* ***************************************************************************
|
||||
* string.h -- The string operation set.
|
||||
*
|
||||
* Copyright (C) 2015 by Liu Chao <lc-soft@live.cn>
|
||||
* Copyright (C) 2015-2016 by Liu Chao <lc-soft@live.cn>
|
||||
*
|
||||
* This file is part of the LCUI project, and may only be used, modified, and
|
||||
* distributed under the terms of the GPLv2.
|
||||
@@ -22,7 +22,7 @@
|
||||
/* ****************************************************************************
|
||||
* string.h -- 字符串相关操作函数。
|
||||
*
|
||||
* 版权所有 (C) 2015 归属于 刘超 <lc-soft@live.cn>
|
||||
* 版权所有 (C) 2015-2016 归属于 刘超 <lc-soft@live.cn>
|
||||
*
|
||||
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
|
||||
*
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef __LCUI_MISC_STRING_H__
|
||||
#define __LCUI_MISC_STRING_H__
|
||||
#ifndef LCUI_UTIL_STRING_H
|
||||
#define LCUI_UTIL_STRING_H
|
||||
|
||||
#ifdef LCUI_BUILD_IN_WIN32
|
||||
#include <tchar.h>
|
||||
@@ -63,14 +63,56 @@ typedef char TCHAR;
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
/**
|
||||
* 清除字符串首尾的字符
|
||||
* @param[out] outstr 处理后的字符串
|
||||
* @param[in] instr 需要处理的字符串
|
||||
* @param[in] charlist 需要清除的字符列表,当为NULL时,默认清除空白符
|
||||
* @return 处理后的字符串的长度
|
||||
*/
|
||||
* 清除字符串首尾的字符
|
||||
* @param[out] outstr 处理后的字符串
|
||||
* @param[in] instr 需要处理的字符串
|
||||
* @param[in] charlist 需要清除的字符列表,当为NULL时,默认清除空白符
|
||||
* @return 处理后的字符串的长度
|
||||
*/
|
||||
LCUI_API int strtrim( char *outstr, const char *instr, const char *charlist );
|
||||
|
||||
/**
|
||||
* 分割字符串
|
||||
* @param[in] instr 需分割的字符串
|
||||
* @param[in] sep 分割标记字符串
|
||||
* @param[out] outstrs 分割后的字符串列表
|
||||
*/
|
||||
LCUI_API int strsplit( const char *instr, const char *sep, char ***outstrs );
|
||||
|
||||
|
||||
/**
|
||||
* 向字符串组添加字符串
|
||||
* @param[in][out] strlist 字符串组
|
||||
* @param[in] str 字符串
|
||||
*/
|
||||
LCUI_API int strsadd( char ***strlist, const char *str );
|
||||
|
||||
/**
|
||||
* 判断字符串组中是否包含指定字符串
|
||||
* @param[in][out] strlist 字符串组
|
||||
* @param[in] str 字符串
|
||||
* @returns 如果包含则返回 1, 否则返回 0
|
||||
*/
|
||||
LCUI_API int strshas( char **strlist, const char *str );
|
||||
|
||||
/**
|
||||
* 从字符串组中删除指定字符串
|
||||
* @param[in][out] strlist 字符串组
|
||||
* @param[in] str 字符串
|
||||
* @returns 如果删除成功则返回 1, 否则返回 0
|
||||
*/
|
||||
LCUI_API int strsdel( char ***strlist, const char *str );
|
||||
|
||||
/**
|
||||
* 向已排序的字符串组添加字符串
|
||||
* @param[in][out] strlist 字符串组
|
||||
* @param[in] str 字符串
|
||||
*/
|
||||
LCUI_API int sortedstrsadd( char ***strlist, const char *str );
|
||||
|
||||
/** 释放字符串组 */
|
||||
LCUI_API void freestrs( char **strs );
|
||||
|
||||
LCUI_END_HEADER
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,14 +1,57 @@
|
||||
|
||||
#ifndef __LCUI_LIB_TIME_H__
|
||||
#define __LCUI_LIB_TIME_H__
|
||||
/* ***************************************************************************
|
||||
* time.c -- The time operation set.
|
||||
*
|
||||
* Copyright (C) 2015-2016 by Liu Chao <lc-soft@live.cn>
|
||||
*
|
||||
* This file is part of the LCUI project, and may only be used, modified, and
|
||||
* distributed under the terms of the GPLv2.
|
||||
*
|
||||
* (GPLv2 is abbreviation of GNU General Public License Version 2)
|
||||
*
|
||||
* By continuing to use, modify, or distribute this file you indicate that you
|
||||
* have read the license and understand and accept it fully.
|
||||
*
|
||||
* The LCUI project is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for more details.
|
||||
*
|
||||
* You should have received a copy of the GPLv2 along with this file. It is
|
||||
* usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* time.c -- 时间相关函数集
|
||||
*
|
||||
* 版权所有 (C) 2015-2016 归属于 刘超 <lc-soft@live.cn>
|
||||
*
|
||||
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
|
||||
*
|
||||
* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
|
||||
*
|
||||
* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。
|
||||
*
|
||||
* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特
|
||||
* 定用途的隐含担保,详情请参照GPLv2许可协议。
|
||||
*
|
||||
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef LCUI_UTIL_TIME_H
|
||||
#define LCUI_UTIL_TIME_H
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
LCUI_API void LCUI_StartTicks( void );
|
||||
LCUI_API void LCUITime_Init( void );
|
||||
|
||||
LCUI_API int64_t LCUI_GetTickCount( void );
|
||||
LCUI_API int64_t LCUI_GetTime( void );
|
||||
|
||||
LCUI_API int64_t LCUI_GetTimeDelta( int64_t start );
|
||||
|
||||
LCUI_API void LCUI_Sleep( unsigned int s );
|
||||
|
||||
LCUI_API void LCUI_MSleep( unsigned int ms );
|
||||
|
||||
LCUI_API int64_t LCUI_GetTicks( int64_t start_ticks );
|
||||
|
||||
LCUI_END_HEADER
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef __LCUI_BUILD_H__
|
||||
#define __LCUI_BUILD_H__
|
||||
#ifndef LCUI_BUILD_H
|
||||
#define LCUI_BUILD_H
|
||||
|
||||
#if defined(__GNUC__)
|
||||
# define LCUI_API
|
||||
|
||||
@@ -0,0 +1,485 @@
|
||||
# ===========================================================================
|
||||
# http://www.gnu.org/software/autoconf-archive/ax_pthread.html
|
||||
# ===========================================================================
|
||||
#
|
||||
# SYNOPSIS
|
||||
#
|
||||
# AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This macro figures out how to build C programs using POSIX threads. It
|
||||
# sets the PTHREAD_LIBS output variable to the threads library and linker
|
||||
# flags, and the PTHREAD_CFLAGS output variable to any special C compiler
|
||||
# flags that are needed. (The user can also force certain compiler
|
||||
# flags/libs to be tested by setting these environment variables.)
|
||||
#
|
||||
# Also sets PTHREAD_CC to any special C compiler that is needed for
|
||||
# multi-threaded programs (defaults to the value of CC otherwise). (This
|
||||
# is necessary on AIX to use the special cc_r compiler alias.)
|
||||
#
|
||||
# NOTE: You are assumed to not only compile your program with these flags,
|
||||
# but also to link with them as well. For example, you might link with
|
||||
# $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
|
||||
#
|
||||
# If you are only building threaded programs, you may wish to use these
|
||||
# variables in your default LIBS, CFLAGS, and CC:
|
||||
#
|
||||
# LIBS="$PTHREAD_LIBS $LIBS"
|
||||
# CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
|
||||
# CC="$PTHREAD_CC"
|
||||
#
|
||||
# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant
|
||||
# has a nonstandard name, this macro defines PTHREAD_CREATE_JOINABLE to
|
||||
# that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
|
||||
#
|
||||
# Also HAVE_PTHREAD_PRIO_INHERIT is defined if pthread is found and the
|
||||
# PTHREAD_PRIO_INHERIT symbol is defined when compiling with
|
||||
# PTHREAD_CFLAGS.
|
||||
#
|
||||
# ACTION-IF-FOUND is a list of shell commands to run if a threads library
|
||||
# is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it
|
||||
# is not found. If ACTION-IF-FOUND is not specified, the default action
|
||||
# will define HAVE_PTHREAD.
|
||||
#
|
||||
# Please let the authors know if this macro fails on any platform, or if
|
||||
# you have any other suggestions or comments. This macro was based on work
|
||||
# by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help
|
||||
# from M. Frigo), as well as ac_pthread and hb_pthread macros posted by
|
||||
# Alejandro Forero Cuervo to the autoconf macro repository. We are also
|
||||
# grateful for the helpful feedback of numerous users.
|
||||
#
|
||||
# Updated for Autoconf 2.68 by Daniel Richard G.
|
||||
#
|
||||
# LICENSE
|
||||
#
|
||||
# Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
|
||||
# Copyright (c) 2011 Daniel Richard G. <skunk@iSKUNK.ORG>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the
|
||||
# Free Software Foundation, either version 3 of the License, or (at your
|
||||
# option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
# Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# As a special exception, the respective Autoconf Macro's copyright owner
|
||||
# gives unlimited permission to copy, distribute and modify the configure
|
||||
# scripts that are the output of Autoconf when processing the Macro. You
|
||||
# need not follow the terms of the GNU General Public License when using
|
||||
# or distributing such scripts, even though portions of the text of the
|
||||
# Macro appear in them. The GNU General Public License (GPL) does govern
|
||||
# all other use of the material that constitutes the Autoconf Macro.
|
||||
#
|
||||
# This special exception to the GPL applies to versions of the Autoconf
|
||||
# Macro released by the Autoconf Archive. When you make and distribute a
|
||||
# modified version of the Autoconf Macro, you may extend this special
|
||||
# exception to the GPL to apply to your modified version as well.
|
||||
|
||||
#serial 23
|
||||
|
||||
AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD])
|
||||
AC_DEFUN([AX_PTHREAD], [
|
||||
AC_REQUIRE([AC_CANONICAL_HOST])
|
||||
AC_REQUIRE([AC_PROG_CC])
|
||||
AC_REQUIRE([AC_PROG_SED])
|
||||
AC_LANG_PUSH([C])
|
||||
ax_pthread_ok=no
|
||||
|
||||
# We used to check for pthread.h first, but this fails if pthread.h
|
||||
# requires special compiler flags (e.g. on Tru64 or Sequent).
|
||||
# It gets checked for in the link test anyway.
|
||||
|
||||
# First of all, check if the user has set any of the PTHREAD_LIBS,
|
||||
# etcetera environment variables, and if threads linking works using
|
||||
# them:
|
||||
if test "x$PTHREAD_CFLAGS$PTHREAD_LIBS" != "x"; then
|
||||
ax_pthread_save_CC="$CC"
|
||||
ax_pthread_save_CFLAGS="$CFLAGS"
|
||||
ax_pthread_save_LIBS="$LIBS"
|
||||
AS_IF([test "x$PTHREAD_CC" != "x"], [CC="$PTHREAD_CC"])
|
||||
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
|
||||
LIBS="$PTHREAD_LIBS $LIBS"
|
||||
AC_MSG_CHECKING([for pthread_join using $CC $PTHREAD_CFLAGS $PTHREAD_LIBS])
|
||||
AC_LINK_IFELSE([AC_LANG_CALL([], [pthread_join])], [ax_pthread_ok=yes])
|
||||
AC_MSG_RESULT([$ax_pthread_ok])
|
||||
if test "x$ax_pthread_ok" = "xno"; then
|
||||
PTHREAD_LIBS=""
|
||||
PTHREAD_CFLAGS=""
|
||||
fi
|
||||
CC="$ax_pthread_save_CC"
|
||||
CFLAGS="$ax_pthread_save_CFLAGS"
|
||||
LIBS="$ax_pthread_save_LIBS"
|
||||
fi
|
||||
|
||||
# We must check for the threads library under a number of different
|
||||
# names; the ordering is very important because some systems
|
||||
# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
|
||||
# libraries is broken (non-POSIX).
|
||||
|
||||
# Create a list of thread flags to try. Items starting with a "-" are
|
||||
# C compiler flags, and other items are library names, except for "none"
|
||||
# which indicates that we try without any flags at all, and "pthread-config"
|
||||
# which is a program returning the flags for the Pth emulation library.
|
||||
|
||||
ax_pthread_flags="pthreads none -Kthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
|
||||
|
||||
# The ordering *is* (sometimes) important. Some notes on the
|
||||
# individual items follow:
|
||||
|
||||
# pthreads: AIX (must check this before -lpthread)
|
||||
# none: in case threads are in libc; should be tried before -Kthread and
|
||||
# other compiler flags to prevent continual compiler warnings
|
||||
# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
|
||||
# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads), Tru64
|
||||
# (Note: HP C rejects this with "bad form for `-t' option")
|
||||
# -pthreads: Solaris/gcc (Note: HP C also rejects)
|
||||
# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
|
||||
# doesn't hurt to check since this sometimes defines pthreads and
|
||||
# -D_REENTRANT too), HP C (must be checked before -lpthread, which
|
||||
# is present but should not be used directly; and before -mthreads,
|
||||
# because the compiler interprets this as "-mt" + "-hreads")
|
||||
# -mthreads: Mingw32/gcc, Lynx/gcc
|
||||
# pthread: Linux, etcetera
|
||||
# --thread-safe: KAI C++
|
||||
# pthread-config: use pthread-config program (for GNU Pth library)
|
||||
|
||||
case $host_os in
|
||||
|
||||
freebsd*)
|
||||
|
||||
# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
|
||||
# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
|
||||
|
||||
ax_pthread_flags="-kthread lthread $ax_pthread_flags"
|
||||
;;
|
||||
|
||||
hpux*)
|
||||
|
||||
# From the cc(1) man page: "[-mt] Sets various -D flags to enable
|
||||
# multi-threading and also sets -lpthread."
|
||||
|
||||
ax_pthread_flags="-mt -pthread pthread $ax_pthread_flags"
|
||||
;;
|
||||
|
||||
openedition*)
|
||||
|
||||
# IBM z/OS requires a feature-test macro to be defined in order to
|
||||
# enable POSIX threads at all, so give the user a hint if this is
|
||||
# not set. (We don't define these ourselves, as they can affect
|
||||
# other portions of the system API in unpredictable ways.)
|
||||
|
||||
AC_EGREP_CPP([AX_PTHREAD_ZOS_MISSING],
|
||||
[
|
||||
# if !defined(_OPEN_THREADS) && !defined(_UNIX03_THREADS)
|
||||
AX_PTHREAD_ZOS_MISSING
|
||||
# endif
|
||||
],
|
||||
[AC_MSG_WARN([IBM z/OS requires -D_OPEN_THREADS or -D_UNIX03_THREADS to enable pthreads support.])])
|
||||
;;
|
||||
|
||||
solaris*)
|
||||
|
||||
# On Solaris (at least, for some versions), libc contains stubbed
|
||||
# (non-functional) versions of the pthreads routines, so link-based
|
||||
# tests will erroneously succeed. (N.B.: The stubs are missing
|
||||
# pthread_cleanup_push, or rather a function called by this macro,
|
||||
# so we could check for that, but who knows whether they'll stub
|
||||
# that too in a future libc.) So we'll check first for the
|
||||
# standard Solaris way of linking pthreads (-mt -lpthread).
|
||||
|
||||
ax_pthread_flags="-mt,pthread pthread $ax_pthread_flags"
|
||||
;;
|
||||
esac
|
||||
|
||||
# GCC generally uses -pthread, or -pthreads on some platforms (e.g. SPARC)
|
||||
|
||||
AS_IF([test "x$GCC" = "xyes"],
|
||||
[ax_pthread_flags="-pthread -pthreads $ax_pthread_flags"])
|
||||
|
||||
# The presence of a feature test macro requesting re-entrant function
|
||||
# definitions is, on some systems, a strong hint that pthreads support is
|
||||
# correctly enabled
|
||||
|
||||
case $host_os in
|
||||
darwin* | hpux* | linux* | osf* | solaris*)
|
||||
ax_pthread_check_macro="_REENTRANT"
|
||||
;;
|
||||
|
||||
aix*)
|
||||
ax_pthread_check_macro="_THREAD_SAFE"
|
||||
;;
|
||||
|
||||
*)
|
||||
ax_pthread_check_macro="--"
|
||||
;;
|
||||
esac
|
||||
AS_IF([test "x$ax_pthread_check_macro" = "x--"],
|
||||
[ax_pthread_check_cond=0],
|
||||
[ax_pthread_check_cond="!defined($ax_pthread_check_macro)"])
|
||||
|
||||
# Are we compiling with Clang?
|
||||
|
||||
AC_CACHE_CHECK([whether $CC is Clang],
|
||||
[ax_cv_PTHREAD_CLANG],
|
||||
[ax_cv_PTHREAD_CLANG=no
|
||||
# Note that Autoconf sets GCC=yes for Clang as well as GCC
|
||||
if test "x$GCC" = "xyes"; then
|
||||
AC_EGREP_CPP([AX_PTHREAD_CC_IS_CLANG],
|
||||
[/* Note: Clang 2.7 lacks __clang_[a-z]+__ */
|
||||
# if defined(__clang__) && defined(__llvm__)
|
||||
AX_PTHREAD_CC_IS_CLANG
|
||||
# endif
|
||||
],
|
||||
[ax_cv_PTHREAD_CLANG=yes])
|
||||
fi
|
||||
])
|
||||
ax_pthread_clang="$ax_cv_PTHREAD_CLANG"
|
||||
|
||||
ax_pthread_clang_warning=no
|
||||
|
||||
# Clang needs special handling, because older versions handle the -pthread
|
||||
# option in a rather... idiosyncratic way
|
||||
|
||||
if test "x$ax_pthread_clang" = "xyes"; then
|
||||
|
||||
# Clang takes -pthread; it has never supported any other flag
|
||||
|
||||
# (Note 1: This will need to be revisited if a system that Clang
|
||||
# supports has POSIX threads in a separate library. This tends not
|
||||
# to be the way of modern systems, but it's conceivable.)
|
||||
|
||||
# (Note 2: On some systems, notably Darwin, -pthread is not needed
|
||||
# to get POSIX threads support; the API is always present and
|
||||
# active. We could reasonably leave PTHREAD_CFLAGS empty. But
|
||||
# -pthread does define _REENTRANT, and while the Darwin headers
|
||||
# ignore this macro, third-party headers might not.)
|
||||
|
||||
PTHREAD_CFLAGS="-pthread"
|
||||
PTHREAD_LIBS=
|
||||
|
||||
ax_pthread_ok=yes
|
||||
|
||||
# However, older versions of Clang make a point of warning the user
|
||||
# that, in an invocation where only linking and no compilation is
|
||||
# taking place, the -pthread option has no effect ("argument unused
|
||||
# during compilation"). They expect -pthread to be passed in only
|
||||
# when source code is being compiled.
|
||||
#
|
||||
# Problem is, this is at odds with the way Automake and most other
|
||||
# C build frameworks function, which is that the same flags used in
|
||||
# compilation (CFLAGS) are also used in linking. Many systems
|
||||
# supported by AX_PTHREAD require exactly this for POSIX threads
|
||||
# support, and in fact it is often not straightforward to specify a
|
||||
# flag that is used only in the compilation phase and not in
|
||||
# linking. Such a scenario is extremely rare in practice.
|
||||
#
|
||||
# Even though use of the -pthread flag in linking would only print
|
||||
# a warning, this can be a nuisance for well-run software projects
|
||||
# that build with -Werror. So if the active version of Clang has
|
||||
# this misfeature, we search for an option to squash it.
|
||||
|
||||
AC_CACHE_CHECK([whether Clang needs flag to prevent "argument unused" warning when linking with -pthread],
|
||||
[ax_cv_PTHREAD_CLANG_NO_WARN_FLAG],
|
||||
[ax_cv_PTHREAD_CLANG_NO_WARN_FLAG=unknown
|
||||
# Create an alternate version of $ac_link that compiles and
|
||||
# links in two steps (.c -> .o, .o -> exe) instead of one
|
||||
# (.c -> exe), because the warning occurs only in the second
|
||||
# step
|
||||
ax_pthread_save_ac_link="$ac_link"
|
||||
ax_pthread_sed='s/conftest\.\$ac_ext/conftest.$ac_objext/g'
|
||||
ax_pthread_link_step=`$as_echo "$ac_link" | sed "$ax_pthread_sed"`
|
||||
ax_pthread_2step_ac_link="($ac_compile) && (echo ==== >&5) && ($ax_pthread_link_step)"
|
||||
ax_pthread_save_CFLAGS="$CFLAGS"
|
||||
for ax_pthread_try in '' -Qunused-arguments -Wno-unused-command-line-argument unknown; do
|
||||
AS_IF([test "x$ax_pthread_try" = "xunknown"], [break])
|
||||
CFLAGS="-Werror -Wunknown-warning-option $ax_pthread_try -pthread $ax_pthread_save_CFLAGS"
|
||||
ac_link="$ax_pthread_save_ac_link"
|
||||
AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])],
|
||||
[ac_link="$ax_pthread_2step_ac_link"
|
||||
AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])],
|
||||
[break])
|
||||
])
|
||||
done
|
||||
ac_link="$ax_pthread_save_ac_link"
|
||||
CFLAGS="$ax_pthread_save_CFLAGS"
|
||||
AS_IF([test "x$ax_pthread_try" = "x"], [ax_pthread_try=no])
|
||||
ax_cv_PTHREAD_CLANG_NO_WARN_FLAG="$ax_pthread_try"
|
||||
])
|
||||
|
||||
case "$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG" in
|
||||
no | unknown) ;;
|
||||
*) PTHREAD_CFLAGS="$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG $PTHREAD_CFLAGS" ;;
|
||||
esac
|
||||
|
||||
fi # $ax_pthread_clang = yes
|
||||
|
||||
if test "x$ax_pthread_ok" = "xno"; then
|
||||
for ax_pthread_try_flag in $ax_pthread_flags; do
|
||||
|
||||
case $ax_pthread_try_flag in
|
||||
none)
|
||||
AC_MSG_CHECKING([whether pthreads work without any flags])
|
||||
;;
|
||||
|
||||
-mt,pthread)
|
||||
AC_MSG_CHECKING([whether pthreads work with -mt -lpthread])
|
||||
PTHREAD_CFLAGS="-mt"
|
||||
PTHREAD_LIBS="-lpthread"
|
||||
;;
|
||||
|
||||
-*)
|
||||
AC_MSG_CHECKING([whether pthreads work with $ax_pthread_try_flag])
|
||||
PTHREAD_CFLAGS="$ax_pthread_try_flag"
|
||||
;;
|
||||
|
||||
pthread-config)
|
||||
AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no])
|
||||
AS_IF([test "x$ax_pthread_config" = "xno"], [continue])
|
||||
PTHREAD_CFLAGS="`pthread-config --cflags`"
|
||||
PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
|
||||
;;
|
||||
|
||||
*)
|
||||
AC_MSG_CHECKING([for the pthreads library -l$ax_pthread_try_flag])
|
||||
PTHREAD_LIBS="-l$ax_pthread_try_flag"
|
||||
;;
|
||||
esac
|
||||
|
||||
ax_pthread_save_CFLAGS="$CFLAGS"
|
||||
ax_pthread_save_LIBS="$LIBS"
|
||||
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
|
||||
LIBS="$PTHREAD_LIBS $LIBS"
|
||||
|
||||
# Check for various functions. We must include pthread.h,
|
||||
# since some functions may be macros. (On the Sequent, we
|
||||
# need a special flag -Kthread to make this header compile.)
|
||||
# We check for pthread_join because it is in -lpthread on IRIX
|
||||
# while pthread_create is in libc. We check for pthread_attr_init
|
||||
# due to DEC craziness with -lpthreads. We check for
|
||||
# pthread_cleanup_push because it is one of the few pthread
|
||||
# functions on Solaris that doesn't have a non-functional libc stub.
|
||||
# We try pthread_create on general principles.
|
||||
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>
|
||||
# if $ax_pthread_check_cond
|
||||
# error "$ax_pthread_check_macro must be defined"
|
||||
# endif
|
||||
static void routine(void *a) { a = 0; }
|
||||
static void *start_routine(void *a) { return a; }],
|
||||
[pthread_t th; pthread_attr_t attr;
|
||||
pthread_create(&th, 0, start_routine, 0);
|
||||
pthread_join(th, 0);
|
||||
pthread_attr_init(&attr);
|
||||
pthread_cleanup_push(routine, 0);
|
||||
pthread_cleanup_pop(0) /* ; */])],
|
||||
[ax_pthread_ok=yes],
|
||||
[])
|
||||
|
||||
CFLAGS="$ax_pthread_save_CFLAGS"
|
||||
LIBS="$ax_pthread_save_LIBS"
|
||||
|
||||
AC_MSG_RESULT([$ax_pthread_ok])
|
||||
AS_IF([test "x$ax_pthread_ok" = "xyes"], [break])
|
||||
|
||||
PTHREAD_LIBS=""
|
||||
PTHREAD_CFLAGS=""
|
||||
done
|
||||
fi
|
||||
|
||||
# Various other checks:
|
||||
if test "x$ax_pthread_ok" = "xyes"; then
|
||||
ax_pthread_save_CFLAGS="$CFLAGS"
|
||||
ax_pthread_save_LIBS="$LIBS"
|
||||
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
|
||||
LIBS="$PTHREAD_LIBS $LIBS"
|
||||
|
||||
# Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
|
||||
AC_CACHE_CHECK([for joinable pthread attribute],
|
||||
[ax_cv_PTHREAD_JOINABLE_ATTR],
|
||||
[ax_cv_PTHREAD_JOINABLE_ATTR=unknown
|
||||
for ax_pthread_attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>],
|
||||
[int attr = $ax_pthread_attr; return attr /* ; */])],
|
||||
[ax_cv_PTHREAD_JOINABLE_ATTR=$ax_pthread_attr; break],
|
||||
[])
|
||||
done
|
||||
])
|
||||
AS_IF([test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xunknown" && \
|
||||
test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xPTHREAD_CREATE_JOINABLE" && \
|
||||
test "x$ax_pthread_joinable_attr_defined" != "xyes"],
|
||||
[AC_DEFINE_UNQUOTED([PTHREAD_CREATE_JOINABLE],
|
||||
[$ax_cv_PTHREAD_JOINABLE_ATTR],
|
||||
[Define to necessary symbol if this constant
|
||||
uses a non-standard name on your system.])
|
||||
ax_pthread_joinable_attr_defined=yes
|
||||
])
|
||||
|
||||
AC_CACHE_CHECK([whether more special flags are required for pthreads],
|
||||
[ax_cv_PTHREAD_SPECIAL_FLAGS],
|
||||
[ax_cv_PTHREAD_SPECIAL_FLAGS=no
|
||||
case $host_os in
|
||||
solaris*)
|
||||
ax_cv_PTHREAD_SPECIAL_FLAGS="-D_POSIX_PTHREAD_SEMANTICS"
|
||||
;;
|
||||
esac
|
||||
])
|
||||
AS_IF([test "x$ax_cv_PTHREAD_SPECIAL_FLAGS" != "xno" && \
|
||||
test "x$ax_pthread_special_flags_added" != "xyes"],
|
||||
[PTHREAD_CFLAGS="$ax_cv_PTHREAD_SPECIAL_FLAGS $PTHREAD_CFLAGS"
|
||||
ax_pthread_special_flags_added=yes])
|
||||
|
||||
AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT],
|
||||
[ax_cv_PTHREAD_PRIO_INHERIT],
|
||||
[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>]],
|
||||
[[int i = PTHREAD_PRIO_INHERIT;]])],
|
||||
[ax_cv_PTHREAD_PRIO_INHERIT=yes],
|
||||
[ax_cv_PTHREAD_PRIO_INHERIT=no])
|
||||
])
|
||||
AS_IF([test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes" && \
|
||||
test "x$ax_pthread_prio_inherit_defined" != "xyes"],
|
||||
[AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], [1], [Have PTHREAD_PRIO_INHERIT.])
|
||||
ax_pthread_prio_inherit_defined=yes
|
||||
])
|
||||
|
||||
CFLAGS="$ax_pthread_save_CFLAGS"
|
||||
LIBS="$ax_pthread_save_LIBS"
|
||||
|
||||
# More AIX lossage: compile with *_r variant
|
||||
if test "x$GCC" != "xyes"; then
|
||||
case $host_os in
|
||||
aix*)
|
||||
AS_CASE(["x/$CC"],
|
||||
[x*/c89|x*/c89_128|x*/c99|x*/c99_128|x*/cc|x*/cc128|x*/xlc|x*/xlc_v6|x*/xlc128|x*/xlc128_v6],
|
||||
[#handle absolute path differently from PATH based program lookup
|
||||
AS_CASE(["x$CC"],
|
||||
[x/*],
|
||||
[AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"])],
|
||||
[AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC])])])
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
|
||||
test -n "$PTHREAD_CC" || PTHREAD_CC="$CC"
|
||||
|
||||
AC_SUBST([PTHREAD_LIBS])
|
||||
AC_SUBST([PTHREAD_CFLAGS])
|
||||
AC_SUBST([PTHREAD_CC])
|
||||
|
||||
# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
|
||||
if test "x$ax_pthread_ok" = "xyes"; then
|
||||
ifelse([$1],,[AC_DEFINE([HAVE_PTHREAD],[1],[Define if you have POSIX threads libraries and header files.])],[$1])
|
||||
:
|
||||
else
|
||||
ax_pthread_ok=no
|
||||
$2
|
||||
fi
|
||||
AC_LANG_POP
|
||||
])dnl AX_PTHREAD
|
||||
+1
-1
@@ -3,7 +3,7 @@ AUTOMAKE_OPTIONS=foreign
|
||||
AM_CFLAGS = -I$(abs_top_srcdir)/include
|
||||
##以下是给Libtool的参数
|
||||
LCUI_LDFLAGS = -version-info 3:0:0
|
||||
LCUI_SOURCES = graph.c ime.c cursor.c main.c timer.c display.c
|
||||
LCUI_SOURCES = graph.c ime.c cursor.c main.c timer.c display.c keyboard.c
|
||||
LCUI_LIBADD = thread/libthread.la util/libutil.la platform/libplatform.la \
|
||||
bmp/libbmp.la draw/libdraw.la gui/libgui.la font/libfont.la \
|
||||
font/in-core/libfont_incore.la $(LCUI_LIBS)
|
||||
|
||||
+6
-5
@@ -38,6 +38,7 @@
|
||||
* ***************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <LCUI_Build.h>
|
||||
#include <LCUI/LCUI.h>
|
||||
#include <LCUI/graph.h>
|
||||
@@ -62,17 +63,17 @@ int Graph_LoadBMP( const char *filepath, LCUI_Graph *out )
|
||||
int x, y, tempi, pocz, omin;
|
||||
FILE *fp = fopen( filepath, "rb" );
|
||||
if( !fp ) {
|
||||
return FILE_ERROR_OPEN_ERROR;
|
||||
return ENOENT;
|
||||
}
|
||||
/* 检测是否为bmp图片 */
|
||||
tempi = fread( &bmp, 1, sizeof( bmp_head ), fp );
|
||||
if( tempi < sizeof( bmp_head ) || bmp.BMPsyg != 19778 ) {
|
||||
return FILE_ERROR_UNKNOWN_FORMAT;
|
||||
return -1;
|
||||
}
|
||||
pocz = bmp.nic[4];
|
||||
if( (bmp.depth != 32) && (bmp.depth != 24) ) {
|
||||
_DEBUG_MSG( "can not support %i bit-depth !\n", bmp.depth );
|
||||
return FILE_ERROR_UNKNOWN_FORMAT;
|
||||
return -1;
|
||||
}
|
||||
out->color_type = COLOR_TYPE_RGB;
|
||||
tempi = Graph_Create( out, bmp.ix, bmp.iy );
|
||||
@@ -131,12 +132,12 @@ int Graph_GetBMPSize( const char *filepath, int *width, int *height )
|
||||
bmp_head bmp;
|
||||
FILE *fp = fopen( filepath, "rb" );
|
||||
if( !fp ) {
|
||||
return FILE_ERROR_OPEN_ERROR;
|
||||
return ENOENT;
|
||||
}
|
||||
/* 检测是否为bmp图片 */
|
||||
n = fread( &bmp, 1, sizeof( bmp_head ), fp );
|
||||
if( n < sizeof( bmp_head ) || bmp.BMPsyg != 19778 ) {
|
||||
return FILE_ERROR_UNKNOWN_FORMAT;
|
||||
return -1;
|
||||
}
|
||||
*width = bmp.ix;
|
||||
*height = bmp.iy;
|
||||
|
||||
+5
-4
@@ -39,6 +39,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <LCUI_Build.h>
|
||||
#include <LCUI/LCUI.h>
|
||||
#include <LCUI/graph.h>
|
||||
@@ -85,11 +86,11 @@ int Graph_LoadJPEG( const char *filepath, LCUI_Graph *buf )
|
||||
|
||||
fp = fopen( filepath, "rb" );
|
||||
if( !fp ) {
|
||||
return FILE_ERROR_OPEN_ERROR;
|
||||
return ENOENT;
|
||||
}
|
||||
if( fread( &JPsyg, sizeof( short int ), 1, fp ) ) {
|
||||
if( JPsyg != -9985 ) { /* 如果不是jpg图片 */
|
||||
return FILE_ERROR_UNKNOWN_FORMAT;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
rewind( fp );
|
||||
@@ -148,11 +149,11 @@ int Graph_GetJPEGSize( const char *filepath, int *width, int *height )
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
FILE *fp = fopen( filepath, "rb" );
|
||||
if( !fp ) {
|
||||
return FILE_ERROR_OPEN_ERROR;
|
||||
return ENOENT;
|
||||
}
|
||||
if( fread( &JPsyg, sizeof( short int ), 1, fp ) ) {
|
||||
if( JPsyg != -9985 ) {
|
||||
return FILE_ERROR_UNKNOWN_FORMAT;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
rewind( fp );
|
||||
|
||||
+23
-47
@@ -1,22 +1,22 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <LCUI_Build.h>
|
||||
#include <LCUI/LCUI.h>
|
||||
#include <LCUI/graph.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/** 检测图片格式,并解码图片 */
|
||||
static int Graph_DetectImage(const char *filepath, LCUI_Graph *out)
|
||||
{
|
||||
int ret = FILE_ERROR_UNKNOWN_FORMAT;
|
||||
if (ret == FILE_ERROR_UNKNOWN_FORMAT) {
|
||||
int ret = -1;
|
||||
if (ret == -1) {
|
||||
ret = Graph_LoadPNG(filepath, out);
|
||||
}
|
||||
if (ret == FILE_ERROR_UNKNOWN_FORMAT) {
|
||||
if (ret == -1) {
|
||||
ret = Graph_LoadJPEG(filepath, out);
|
||||
}
|
||||
if (ret == FILE_ERROR_UNKNOWN_FORMAT) {
|
||||
if (ret == -1) {
|
||||
ret = Graph_LoadBMP(filepath, out);
|
||||
}
|
||||
return ret;
|
||||
@@ -26,35 +26,22 @@ int Graph_LoadImage( const char *filepath, LCUI_Graph *out )
|
||||
{
|
||||
FILE *fp;
|
||||
int ret = 0;
|
||||
|
||||
Graph_Init(out);
|
||||
Graph_Init( out );
|
||||
out->color_type = COLOR_TYPE_RGB;
|
||||
fp = fopen(filepath,"rb");
|
||||
if ( fp == NULL ) {
|
||||
ret = FILE_ERROR_OPEN_ERROR;
|
||||
} else {
|
||||
fgetc(fp);
|
||||
if (!ferror (fp)) { /* 如果没出错 */
|
||||
fseek(fp,0,SEEK_END);
|
||||
if (ftell(fp)>4) {
|
||||
fclose(fp);
|
||||
ret = Graph_DetectImage(filepath, out);
|
||||
} else {
|
||||
ret = FILE_ERROR_SHORT_FILE; /* 文件过小 */
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
fp = fopen( filepath, "rb" );
|
||||
if( fp == NULL ) {
|
||||
return ENOENT;
|
||||
}
|
||||
switch(ret) {
|
||||
case FILE_ERROR_SHORT_FILE:
|
||||
printf("error: file is too short!\n");
|
||||
break;
|
||||
case FILE_ERROR_OPEN_ERROR:
|
||||
perror(filepath);
|
||||
break;
|
||||
case FILE_ERROR_UNKNOWN_FORMAT:
|
||||
printf("error: unknown format!\n");
|
||||
break;
|
||||
fgetc( fp );
|
||||
if( !ferror( fp ) ) {
|
||||
fseek( fp, 0, SEEK_END );
|
||||
if( ftell( fp ) > 4 ) {
|
||||
fclose( fp );
|
||||
ret = Graph_DetectImage( filepath, out );
|
||||
} else {
|
||||
ret = -1;
|
||||
fclose( fp );
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -62,22 +49,11 @@ int Graph_LoadImage( const char *filepath, LCUI_Graph *out )
|
||||
int Graph_GetImageSize( const char *filepath, int *width, int *height )
|
||||
{
|
||||
int ret = Graph_GetPNGSize( filepath, width, height );
|
||||
if( ret == FILE_ERROR_UNKNOWN_FORMAT ) {
|
||||
if( ret != 0 ) {
|
||||
ret = Graph_GetJPEGSize( filepath, width, height );
|
||||
}
|
||||
if( ret == FILE_ERROR_UNKNOWN_FORMAT ) {
|
||||
if( ret != 0 ) {
|
||||
ret = Graph_GetBMPSize( filepath, width, height );
|
||||
}
|
||||
switch( ret ) {
|
||||
case FILE_ERROR_SHORT_FILE:
|
||||
printf( "error: file is too short!\n" );
|
||||
break;
|
||||
case FILE_ERROR_OPEN_ERROR:
|
||||
perror( filepath );
|
||||
break;
|
||||
case FILE_ERROR_UNKNOWN_FORMAT:
|
||||
printf( "error: unknown format!\n" );
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
+14
-11
@@ -39,6 +39,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <LCUI_Build.h>
|
||||
#include <LCUI/LCUI.h>
|
||||
#include <LCUI/graph.h>
|
||||
@@ -62,7 +63,7 @@ int Graph_LoadPNG( const char *filepath, LCUI_Graph *graph )
|
||||
|
||||
fp = fopen( filepath, "rb" );
|
||||
if( fp == NULL ) {
|
||||
return FILE_ERROR_OPEN_ERROR;
|
||||
return ENOENT;
|
||||
}
|
||||
|
||||
png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING, 0, 0, 0 );
|
||||
@@ -75,7 +76,7 @@ int Graph_LoadPNG( const char *filepath, LCUI_Graph *graph )
|
||||
if( temp < PNG_BYTES_TO_CHECK ) {
|
||||
fclose( fp );
|
||||
png_destroy_read_struct( &png_ptr, &info_ptr, 0 );
|
||||
return FILE_ERROR_UNKNOWN_FORMAT;
|
||||
return -1;
|
||||
}
|
||||
/* 检测数据是否为PNG的签名 */
|
||||
temp = png_sig_cmp( (png_bytep)buf, (png_size_t)0, PNG_BYTES_TO_CHECK );
|
||||
@@ -83,7 +84,7 @@ int Graph_LoadPNG( const char *filepath, LCUI_Graph *graph )
|
||||
if( temp != 0 ) {
|
||||
fclose( fp );
|
||||
png_destroy_read_struct( &png_ptr, &info_ptr, 0 );
|
||||
return FILE_ERROR_UNKNOWN_FORMAT;
|
||||
return -1;
|
||||
}
|
||||
/* 复位文件指针 */
|
||||
rewind( fp );
|
||||
@@ -104,7 +105,7 @@ int Graph_LoadPNG( const char *filepath, LCUI_Graph *graph )
|
||||
graph->color_type = COLOR_TYPE_ARGB;
|
||||
temp = Graph_Create( graph, w, h );
|
||||
if( temp != 0 ) {
|
||||
ret = FILE_ERROR_MALLOC_ERROR;
|
||||
ret = -ENOMEM;
|
||||
break;
|
||||
}
|
||||
pixel_ptr = graph->bytes;
|
||||
@@ -126,7 +127,7 @@ int Graph_LoadPNG( const char *filepath, LCUI_Graph *graph )
|
||||
graph->color_type = COLOR_TYPE_RGB;
|
||||
temp = Graph_Create( graph, w, h );
|
||||
if( temp != 0 ) {
|
||||
ret = FILE_ERROR_MALLOC_ERROR;
|
||||
ret = -ENOMEM;
|
||||
break;
|
||||
}
|
||||
pixel_ptr = graph->bytes;
|
||||
@@ -139,14 +140,15 @@ int Graph_LoadPNG( const char *filepath, LCUI_Graph *graph )
|
||||
}
|
||||
break;
|
||||
/* 其它色彩类型的图像就读了 */
|
||||
default: ret = FILE_ERROR_UNKNOWN_FORMAT; break;
|
||||
default: ret = -1; break;
|
||||
}
|
||||
fclose( fp );
|
||||
png_destroy_read_struct( &png_ptr, &info_ptr, 0 );
|
||||
return ret;
|
||||
#else
|
||||
_DEBUG_MSG( "warning: not PNG support!" );
|
||||
return -1;
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
int Graph_GetPNGSize( const char *filepath, int *width, int *height )
|
||||
@@ -158,7 +160,7 @@ int Graph_GetPNGSize( const char *filepath, int *width, int *height )
|
||||
char buf[PNG_BYTES_TO_CHECK];
|
||||
FILE *fp = fopen( filepath, "rb" );
|
||||
if( !fp ) {
|
||||
return FILE_ERROR_OPEN_ERROR;
|
||||
return ENOENT;
|
||||
}
|
||||
png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING, 0, 0, 0 );
|
||||
info_ptr = png_create_info_struct( png_ptr );
|
||||
@@ -167,13 +169,13 @@ int Graph_GetPNGSize( const char *filepath, int *width, int *height )
|
||||
if( ret < PNG_BYTES_TO_CHECK ) {
|
||||
fclose( fp );
|
||||
png_destroy_read_struct( &png_ptr, &info_ptr, 0 );
|
||||
return FILE_ERROR_UNKNOWN_FORMAT;
|
||||
return -1;
|
||||
}
|
||||
ret = png_sig_cmp( (png_bytep)buf, (png_size_t)0, PNG_BYTES_TO_CHECK );
|
||||
if( ret != 0 ) {
|
||||
fclose( fp );
|
||||
png_destroy_read_struct( &png_ptr, &info_ptr, 0 );
|
||||
return FILE_ERROR_UNKNOWN_FORMAT;
|
||||
return -1;
|
||||
}
|
||||
rewind( fp );
|
||||
png_init_io( png_ptr, fp );
|
||||
@@ -182,10 +184,11 @@ int Graph_GetPNGSize( const char *filepath, int *width, int *height )
|
||||
*height = png_get_image_height( png_ptr, info_ptr );
|
||||
fclose( fp );
|
||||
png_destroy_read_struct( &png_ptr, &info_ptr, 0 );
|
||||
return 0;
|
||||
#else
|
||||
_DEBUG_MSG( "warning: not PNG support!" );
|
||||
return -1;
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
int Graph_WritePNG( const char *file_name, const LCUI_Graph *graph )
|
||||
|
||||
+2
-3
@@ -40,7 +40,6 @@
|
||||
//#define DEBUG
|
||||
#include <LCUI_Build.h>
|
||||
#include <LCUI/LCUI.h>
|
||||
#include <LCUI/graph.h>
|
||||
#include <LCUI/cursor.h>
|
||||
#include <LCUI/display.h>
|
||||
|
||||
@@ -106,8 +105,8 @@ static int LCUICursor_LoadDefualtGraph(LCUI_Graph *buff )
|
||||
|
||||
static void OnMouseMoveEvent( LCUI_SysEvent e, void *arg )
|
||||
{
|
||||
global_cursor.pos.x += e->rel_x;
|
||||
global_cursor.pos.y += e->rel_y;
|
||||
global_cursor.pos.x += e->motion.xrel;
|
||||
global_cursor.pos.y += e->motion.yrel;
|
||||
global_cursor.new_pos = global_cursor.pos;
|
||||
DEBUG_MSG("x: %d, y: %d\n", global_cursor.pos.x, global_cursor.pos.y);
|
||||
}
|
||||
|
||||
+20
-15
@@ -43,7 +43,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <LCUI_Build.h>
|
||||
#include <LCUI/LCUI.h>
|
||||
#include <LCUI/graph.h>
|
||||
#include <LCUI/input.h>
|
||||
#include <LCUI/timer.h>
|
||||
#include <LCUI/cursor.h>
|
||||
@@ -52,6 +51,9 @@
|
||||
#include <LCUI/platform.h>
|
||||
#include LCUI_DISPLAY_H
|
||||
|
||||
#define DEFAULT_WIDTH 800
|
||||
#define DEFAULT_HEIGHT 600
|
||||
|
||||
/** surface 记录 */
|
||||
typedef struct SurfaceRecord {
|
||||
LCUI_Surface surface; /**< surface */
|
||||
@@ -63,7 +65,7 @@ static struct DisplayContext {
|
||||
int mode; /**< 显示模式 */
|
||||
LCUI_BOOL show_rect_border; /**< 是否为重绘的区域显示边框 */
|
||||
LCUI_BOOL is_working; /**< 标志,指示当前模块是否处于工作状态 */
|
||||
FrameCtrlCtx fc_ctx; /**< 上下文句柄,用于画面更新时的帧数控制 */
|
||||
FrameControl fc_ctx; /**< 上下文句柄,用于画面更新时的帧数控制 */
|
||||
LCUI_Thread thread; /**< 线程,负责画面更新工作 */
|
||||
LinkedList surfaces; /**< surface 列表 */
|
||||
LCUI_Mutex mutex;
|
||||
@@ -102,7 +104,7 @@ static void LCUIDisplay_Update(void)
|
||||
LCUI_PaintContext paint;
|
||||
LinkedList_Init( &rlist );
|
||||
/* 遍历当前的 surface 记录列表 */
|
||||
LinkedList_ForEach( sn, &display.surfaces ) {
|
||||
for( LinkedList_Each( sn, &display.surfaces ) ) {
|
||||
p_sr = sn->data;
|
||||
if( !p_sr->widget || !p_sr->surface
|
||||
|| !Surface_IsReady(p_sr->surface) ) {
|
||||
@@ -112,8 +114,11 @@ static void LCUIDisplay_Update(void)
|
||||
/* 收集无效区域记录 */
|
||||
Widget_ProcInvalidArea( p_sr->widget, &rlist );
|
||||
/* 在 surface 上逐个重绘无效区域 */
|
||||
LinkedList_ForEach( rn, &rlist ) {
|
||||
for( LinkedList_Each( rn, &rlist ) ) {
|
||||
paint = Surface_BeginPaint( p_sr->surface, rn->data );
|
||||
if( !paint ) {
|
||||
continue;
|
||||
}
|
||||
DEBUG_MSG( "[%s]: render rect: (%d,%d,%d,%d)\n",
|
||||
p_sr->widget->type, paint->rect.left,
|
||||
paint->rect.top, paint->rect.w, paint->rect.h );
|
||||
@@ -131,7 +136,7 @@ static void LCUIDisplay_Update(void)
|
||||
LinkedList_Clear( &rlist, free );
|
||||
}
|
||||
|
||||
void LCUIDisplay_InvalidateArea(LCUI_Rect *rect )
|
||||
void LCUIDisplay_InvalidateArea( LCUI_Rect *rect )
|
||||
{
|
||||
|
||||
}
|
||||
@@ -140,7 +145,7 @@ static LCUI_Widget LCUIDisplay_GetBindWidget( LCUI_Surface surface )
|
||||
{
|
||||
SurfaceRecord *sr;
|
||||
LinkedListNode *node;
|
||||
LinkedList_ForEach( node, &display.surfaces ) {
|
||||
for( LinkedList_Each( node, &display.surfaces ) ) {
|
||||
sr = node->data;
|
||||
if( sr && sr->surface == surface ) {
|
||||
return sr->widget;
|
||||
@@ -153,7 +158,7 @@ static LCUI_Surface LCUIDisplay_GetBindSurface( LCUI_Widget widget )
|
||||
{
|
||||
SurfaceRecord *sr;
|
||||
LinkedListNode *node;
|
||||
LinkedList_ForEach( node, &display.surfaces ) {
|
||||
for( LinkedList_Each( node, &display.surfaces ) ) {
|
||||
sr = node->data;
|
||||
if( sr && sr->widget == widget ) {
|
||||
return sr->surface;
|
||||
@@ -206,7 +211,7 @@ static void LCUIDisplay_UnbindSurface( LCUI_Widget widget )
|
||||
{
|
||||
SurfaceRecord *sr;
|
||||
LinkedListNode *node;
|
||||
LinkedList_ForEach( node, &display.surfaces ) {
|
||||
for( LinkedList_Each( node, &display.surfaces ) ) {
|
||||
sr = node->data;
|
||||
if( sr && sr->widget == widget ) {
|
||||
Surface_Delete( sr->surface );
|
||||
@@ -220,7 +225,7 @@ static void LCUIDisplay_CleanSurfaces( void )
|
||||
{
|
||||
SurfaceRecord *sr;
|
||||
LinkedListNode *node;
|
||||
LinkedList_ForEach( node, &display.surfaces ) {
|
||||
for( LinkedList_Each( node, &display.surfaces ) ) {
|
||||
sr = node->data;
|
||||
Surface_Delete( sr->surface );
|
||||
LinkedList_DeleteNode( &display.surfaces, node );
|
||||
@@ -231,9 +236,10 @@ static int LCUIDisplay_Windowed( void )
|
||||
{
|
||||
LCUI_Widget root = LCUIWidget_GetRoot();
|
||||
switch( display.mode ) {
|
||||
case LCDM_FULLSCREEN:
|
||||
case LCDM_WINDOWED:
|
||||
return 0;
|
||||
case LCDM_FULLSCREEN:
|
||||
break;
|
||||
case LCDM_SEAMLESS:
|
||||
default:
|
||||
LCUIDisplay_CleanSurfaces();
|
||||
@@ -241,7 +247,7 @@ static int LCUIDisplay_Windowed( void )
|
||||
break;
|
||||
}
|
||||
Widget_Show( root );
|
||||
Widget_Resize( root, LCUIDisplay_GetWidth(), LCUIDisplay_GetHeight() );
|
||||
Widget_Resize( root, DEFAULT_WIDTH, DEFAULT_HEIGHT );
|
||||
display.mode = LCDM_WINDOWED;
|
||||
return 0;
|
||||
}
|
||||
@@ -277,7 +283,7 @@ static int LCUIDisplay_Seamless( void )
|
||||
LCUIDisplay_CleanSurfaces();
|
||||
break;
|
||||
}
|
||||
LinkedList_ForEach( node, &root->children ) {
|
||||
for( LinkedList_Each( node, &root->children ) ) {
|
||||
LCUIDisplay_BindSurface( node->data );
|
||||
}
|
||||
display.mode = LCDM_SEAMLESS;
|
||||
@@ -505,7 +511,6 @@ static void OnSurfaceEvent( LCUI_Widget w, LCUI_WidgetEvent e, void *arg )
|
||||
e_type = *((int*)&arg);
|
||||
root = LCUIWidget_GetRoot();
|
||||
surface = LCUIDisplay_GetBindSurface( e->target );
|
||||
DEBUG_MSG("tip, widget: %s, e_type = %d\n", w->type, e_type);
|
||||
if( display.mode == LCDM_SEAMLESS ) {
|
||||
if( !surface && e_type != WET_ADD ) {
|
||||
return;
|
||||
@@ -562,7 +567,7 @@ static void OnPaint( LCUI_Event e, void *arg )
|
||||
SurfaceRecord *sr;
|
||||
LinkedListNode *node;
|
||||
LCUI_DisplayEvent dpy_ev = arg;
|
||||
LinkedList_ForEach( node, &display.surfaces ) {
|
||||
for( LinkedList_Each( node, &display.surfaces ) ) {
|
||||
sr = node->data;
|
||||
if( sr && sr->surface != dpy_ev->surface ) {
|
||||
continue;
|
||||
@@ -606,7 +611,7 @@ int LCUI_InitDisplay( void )
|
||||
FrameControl_SetMaxFPS( display.fc_ctx, MAX_FRAMES_PER_SEC );
|
||||
Widget_BindEvent( root, "surface", OnSurfaceEvent, NULL, NULL );
|
||||
LCUIDisplay_SetMode( LCDM_DEFAULT );
|
||||
printf("[display] init ok.\n");
|
||||
printf("[display] init ok, driver name: %s\n", display.driver.name);
|
||||
return LCUIThread_Create( &display.thread, LCUIDisplay_Thread, NULL );
|
||||
}
|
||||
|
||||
|
||||
+35
-4
@@ -1,7 +1,7 @@
|
||||
/* ***************************************************************************
|
||||
* charset.c -- The charset opreation set.
|
||||
*
|
||||
* Copyright (C) 2012-2016 by Liu Chao <lc-soft@live.cn>
|
||||
* Copyright (C) 2015-2016 by Liu Chao <lc-soft@live.cn>
|
||||
*
|
||||
* This file is part of the LCUI project, and may only be used, modified, and
|
||||
* distributed under the terms of the GPLv2.
|
||||
@@ -22,7 +22,7 @@
|
||||
/* ****************************************************************************
|
||||
* charset.c -- 字符集的相关操作函数
|
||||
*
|
||||
* 版权所有 (C) 2013-2016 归属于 刘超 <lc-soft@live.cn>
|
||||
* 版权所有 (C) 2015-2016 归属于 刘超 <lc-soft@live.cn>
|
||||
*
|
||||
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
|
||||
*
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
#include <LCUI_Build.h>
|
||||
#include <LCUI/LCUI.h>
|
||||
#include <LCUI/font.h>
|
||||
#include <LCUI/font/charset.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -48,6 +48,25 @@
|
||||
|
||||
#define MAX_SAVE_NUM 20
|
||||
|
||||
#ifdef LCUI_BUILD_IN_LINUX
|
||||
static int SetLocaleByEncoding( int encoding )
|
||||
{
|
||||
const char *locale;
|
||||
switch( encoding ) {
|
||||
case ENCODING_ANSI:
|
||||
locale = NULL;
|
||||
break;
|
||||
case ENCODING_UTF8:
|
||||
locale = "zh_CN.UTF-8";
|
||||
break;
|
||||
default: return -1;
|
||||
}
|
||||
if( !setlocale( LC_CTYPE, locale ) ) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
/** 将UTF-8字符串解码成 Unicode 字符串 */
|
||||
static int DecodeFromUTF8( wchar_t *wstr, int max_len, const char *str )
|
||||
{
|
||||
@@ -107,9 +126,12 @@ static int DecodeFromUTF8( wchar_t *wstr, int max_len, const char *str )
|
||||
return len;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int LCUI_DecodeString( wchar_t *wstr, const char *str,
|
||||
int max_len, int encoding )
|
||||
{
|
||||
#ifdef LCUI_BUILD_IN_WIN32
|
||||
// 暂时不处理其它编码方式
|
||||
switch( encoding ) {
|
||||
case ENCODING_ANSI:
|
||||
@@ -117,6 +139,12 @@ int LCUI_DecodeString( wchar_t *wstr, const char *str,
|
||||
default: break;
|
||||
}
|
||||
return DecodeFromUTF8( wstr, max_len, str );
|
||||
#else
|
||||
if( SetLocaleByEncoding( encoding ) != 0 ) {
|
||||
return -1;
|
||||
}
|
||||
return mbstowcs( wstr, str, max_len );
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef LCUI_BUILD_IN_WIN32
|
||||
@@ -137,6 +165,9 @@ int LCUI_EncodeString( char *str, const wchar_t *wstr,
|
||||
}
|
||||
return encode( cp, wstr, str, max_len );
|
||||
#else
|
||||
return -1;
|
||||
if( SetLocaleByEncoding( encoding ) != 0 ) {
|
||||
return -1;
|
||||
}
|
||||
return wcstombs( str, wstr, max_len );
|
||||
#endif
|
||||
}
|
||||
|
||||
+27
-27
@@ -75,8 +75,8 @@ static struct LCUI_FontLibraryContext {
|
||||
LCUI_RBTree family_tree; /**< 字族信息树,按字族名称记录着各个字体的信息 */
|
||||
LCUI_RBTree bitmap_cache; /**< 字体位图缓存区 */
|
||||
LCUI_Font ***font_cache; /**< 字体信息缓存区 */
|
||||
LCUI_Font *default_font; /**< 指针,引用的是默认字体信息 */
|
||||
LCUI_Font *incore_font; /**< 指针,引用的是内置字体的信息 */
|
||||
LCUI_Font *default_font; /**< 默认字体的信息 */
|
||||
LCUI_Font *incore_font; /**< 内置字体的信息 */
|
||||
LCUI_FontEngine engines[2]; /**< 当前可用字体引擎列表 */
|
||||
LCUI_FontEngine *engine; /**< 当前选择的字体引擎 */
|
||||
} fontlib = {0, FALSE};
|
||||
@@ -113,7 +113,7 @@ static void DestroyFontPathNode( void *arg )
|
||||
|
||||
static void DestroyFontFamilyNode( void *arg )
|
||||
{
|
||||
LCUI_FontFamilyNode *node = (LCUI_FontFamilyNode*)arg;
|
||||
LCUI_FontFamilyNode *node = arg;
|
||||
if( node->family_name ) {
|
||||
free( node->family_name );
|
||||
}
|
||||
@@ -123,12 +123,14 @@ static void DestroyFontFamilyNode( void *arg )
|
||||
|
||||
static void DestroyFontBitmap( void *arg )
|
||||
{
|
||||
FontBitmap_Free( (LCUI_FontBitmap*)arg );
|
||||
FontBitmap_Free( arg );
|
||||
free( arg );
|
||||
}
|
||||
|
||||
static void DestroyTreeNode( void *arg )
|
||||
{
|
||||
RBTree_Destroy( (LCUI_RBTree*)arg );
|
||||
RBTree_Destroy( arg );
|
||||
free( arg );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,7 +170,7 @@ int LCUIFont_Add( LCUI_Font *font, const char *filepath )
|
||||
RBTree_CustomInsert( &fontlib.family_tree,
|
||||
font->family_name, fn );
|
||||
}
|
||||
LinkedList_ForEach( node, &fn->styles ) {
|
||||
for( LinkedList_Each( node, &fn->styles ) ) {
|
||||
f = (LCUI_Font*)node->data;
|
||||
if( strcmp( f->style_name, font->style_name ) == 0 ) {
|
||||
return -3;
|
||||
@@ -234,7 +236,7 @@ int LCUIFont_GetId( const char *family_name, const char *style_name )
|
||||
if( !fnode ) {
|
||||
return -2;
|
||||
}
|
||||
LinkedList_ForEach( node, &fnode->styles ) {
|
||||
for( LinkedList_Each( node, &fnode->styles ) ) {
|
||||
font = (LCUI_Font*)node->data;
|
||||
if( style_name ) {
|
||||
if( strcasecmp( font->style_name, style_name ) ) {
|
||||
@@ -299,7 +301,6 @@ LCUI_FontBitmap* LCUIFont_AddBitmap( wchar_t ch, int font_id,
|
||||
return NULL;
|
||||
}
|
||||
RBTree_Init( tree_font );
|
||||
RBTree_SetDataNeedFree( tree_font, TRUE );
|
||||
RBTree_OnDestroy( tree_font, DestroyTreeNode );
|
||||
RBTree_Insert( &fontlib.bitmap_cache, ch, tree_font );
|
||||
}
|
||||
@@ -316,7 +317,6 @@ LCUI_FontBitmap* LCUIFont_AddBitmap( wchar_t ch, int font_id,
|
||||
}
|
||||
RBTree_Init( tree_bmp );
|
||||
RBTree_OnDestroy( tree_bmp, DestroyFontBitmap );
|
||||
RBTree_SetDataNeedFree( tree_bmp, TRUE );
|
||||
RBTree_Insert( tree_font, font_id, tree_bmp );
|
||||
}
|
||||
/* 在字体位图库中获取指定像素大小的字体位图 */
|
||||
@@ -349,21 +349,22 @@ int LCUIFont_GetBitmap( wchar_t ch, int font_id, int size,
|
||||
LCUI_RBTree *ctx;
|
||||
LCUI_FontBitmap bmp_cache;
|
||||
|
||||
*bmp = NULL;
|
||||
if( !fontlib.is_inited ) {
|
||||
return -2;
|
||||
}
|
||||
if( font_id <= 0 ) {
|
||||
if( fontlib.default_font ) {
|
||||
font_id = fontlib.default_font->id;
|
||||
} else {
|
||||
font_id = fontlib.incore_font->id;
|
||||
}
|
||||
}
|
||||
/* 这里的 while 只是为了减少缩进 */
|
||||
while( TRUE ) {
|
||||
if( !fontlib.is_inited ) {
|
||||
*bmp = NULL;
|
||||
return -2;
|
||||
}
|
||||
if( !(ctx = SelectChar(ch)) ) {
|
||||
break;
|
||||
}
|
||||
if( font_id <= 0 ) {
|
||||
if( !fontlib.default_font ) {
|
||||
return -3;
|
||||
}
|
||||
font_id = fontlib.default_font->id;
|
||||
}
|
||||
ctx = SelectFont( ctx, font_id );
|
||||
if( !ctx ) {
|
||||
break;
|
||||
@@ -377,10 +378,7 @@ int LCUIFont_GetBitmap( wchar_t ch, int font_id, int size,
|
||||
FontBitmap_Init( &bmp_cache );
|
||||
ret = FontBitmap_Load( &bmp_cache, ch, font_id, size );
|
||||
*bmp = LCUIFont_AddBitmap( ch, font_id, size, &bmp_cache );
|
||||
if( *bmp && ret == 0 ) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** 载入字体值数据库中 */
|
||||
@@ -400,6 +398,7 @@ int LCUIFont_LoadFile( const char *filepath )
|
||||
}
|
||||
ret = fontlib.engine->open( filepath, &font );
|
||||
if( ret != 0 ) {
|
||||
printf( "[font] failed to load file: %s\n", filepath );
|
||||
return -2;
|
||||
}
|
||||
font->engine = fontlib.engine;
|
||||
@@ -594,6 +593,7 @@ int FontBitmap_Load( LCUI_FontBitmap *buff, wchar_t ch,
|
||||
} else {
|
||||
info = fontlib.incore_font;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if( !info ) {
|
||||
return -1;
|
||||
@@ -619,7 +619,7 @@ void LCUI_InitFont( void )
|
||||
"C:/Windows/Fonts/simsun.ttc",
|
||||
"C:/Windows/Fonts/consola.ttf"
|
||||
#else
|
||||
"../fonts/msyh.ttf"
|
||||
"/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-R.ttf"
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -629,18 +629,18 @@ void LCUI_InitFont( void )
|
||||
RBTree_Init( &fontlib.bitmap_cache );
|
||||
RBTree_Init( &fontlib.path_map );
|
||||
RBTree_Init( &fontlib.family_tree );
|
||||
RBTree_OnJudge( &fontlib.path_map, OnComparePath );
|
||||
RBTree_OnJudge( &fontlib.family_tree, OnCompareFamily );
|
||||
RBTree_OnCompare( &fontlib.path_map, OnComparePath );
|
||||
RBTree_OnCompare( &fontlib.family_tree, OnCompareFamily );
|
||||
RBTree_OnDestroy( &fontlib.path_map, DestroyFontPathNode );
|
||||
RBTree_OnDestroy( &fontlib.family_tree, DestroyFontFamilyNode );
|
||||
RBTree_OnDestroy( &fontlib.bitmap_cache, DestroyTreeNode );
|
||||
RBTree_SetDataNeedFree( &fontlib.bitmap_cache, TRUE );
|
||||
fontlib.is_inited = TRUE;
|
||||
|
||||
/* 先初始化内置的字体引擎 */
|
||||
LCUIFont_InitInCoreFont( &fontlib.engines[0] );
|
||||
font_id = LCUIFont_GetId( "inconsolata", NULL );
|
||||
fontlib.incore_font = LCUIFont_GetById( font_id );
|
||||
fontlib.default_font = fontlib.incore_font;
|
||||
fontlib.engine = &fontlib.engines[0];
|
||||
/* 然后看情况启用其它字体引擎 */
|
||||
#ifdef LCUI_FONT_ENGINE_FREETYPE
|
||||
|
||||
+10
-6
@@ -165,11 +165,12 @@ static size_t Convert_FTGlyph( LCUI_FontBitmap *bmp, FT_GlyphSlot slot, int mode
|
||||
return size;
|
||||
}
|
||||
|
||||
static int FreeType_Render( LCUI_FontBitmap *bmp, wchar_t ch,
|
||||
static int FreeType_Render( LCUI_FontBitmap *bmp, wchar_t ch,
|
||||
int pixel_size, LCUI_Font *font )
|
||||
{
|
||||
int error;
|
||||
int ret = 0;
|
||||
size_t size;
|
||||
FT_UInt index;
|
||||
LCUI_BOOL has_space = FALSE;
|
||||
FT_Face ft_face = (FT_Face)font->data;
|
||||
|
||||
@@ -180,17 +181,20 @@ static int FreeType_Render( LCUI_FontBitmap *bmp, wchar_t ch,
|
||||
ch = 'a';
|
||||
has_space = TRUE;
|
||||
}
|
||||
index = FT_Get_Char_Index( ft_face, ch );
|
||||
if( index == 0 ) {
|
||||
ret = -1;
|
||||
}
|
||||
/* 载入该字的字形数据 */
|
||||
error = FT_Load_Char( ft_face, ch, LCUI_FONT_LOAD_FALGS );
|
||||
if(error) {
|
||||
return error;
|
||||
if( FT_Load_Glyph( ft_face, index, LCUI_FONT_LOAD_FALGS ) != 0 ) {
|
||||
return -2;
|
||||
}
|
||||
size = Convert_FTGlyph( bmp, ft_face->glyph, LCUI_FONT_RENDER_MODE );
|
||||
/* 如果是空格则将位图内容清空 */
|
||||
if( has_space ) {
|
||||
memset( bmp->buffer, 0, size );
|
||||
}
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LCUIFont_InitFreeType( LCUI_FontEngine *engine )
|
||||
|
||||
@@ -7615,7 +7615,7 @@ static const unsigned char *font_bitmap[SIZE_TOTAL] = {
|
||||
|
||||
int FontInconsolata_GetBitmap( LCUI_FontBitmap *bmp, wchar_t ch, int size )
|
||||
{
|
||||
int i, j;
|
||||
int i, j, *ptr;
|
||||
const uchar_t *byte_ptr;
|
||||
|
||||
if( size < 12 || size > 18 ) {
|
||||
@@ -7664,7 +7664,7 @@ int FontInconsolata_GetBitmap( LCUI_FontBitmap *bmp, wchar_t ch, int size )
|
||||
i = size - 12;
|
||||
j = ch - ' ';
|
||||
*bmp = font_info_index[i][j];
|
||||
j = *((int*)&bmp->buffer);
|
||||
j = *(ptr = (int*)&bmp->buffer);
|
||||
byte_ptr = &font_bitmap[i][j];
|
||||
size = sizeof(unsigned char)*bmp->width*bmp->rows;
|
||||
bmp->buffer = (uchar_t*)malloc(size);
|
||||
|
||||
+171
-121
@@ -43,15 +43,29 @@
|
||||
#include <LCUI/graph.h>
|
||||
#include <LCUI/font.h>
|
||||
|
||||
/** 文本添加类型 */
|
||||
enum TextAddType {
|
||||
TAT_INSERT, /**< 插入至插入点处 */
|
||||
TAT_APPEND /**< 追加至文本末尾 */
|
||||
};
|
||||
|
||||
#undef max
|
||||
#define max(a, b) ((a) > (b) ? (a):(b))
|
||||
#define TextRowList_AddNewRow(ROWLIST) TextRowList_InsertNewRow(ROWLIST, (ROWLIST)->length)
|
||||
#define TextLayer_GetRow(layer, n) (n >= layer->rowlist.length) ? NULL:layer->rowlist.rows[n]
|
||||
|
||||
/* 根据对齐方式,计算文本行的起始X轴位置 */
|
||||
static int TextLayer_GetRowStartX( LCUI_TextLayer layer, TextRow txtrow )
|
||||
{
|
||||
int width;
|
||||
if( layer->fixed_width > 0 ) {
|
||||
width = layer->fixed_width;
|
||||
} else {
|
||||
width = layer->width;
|
||||
}
|
||||
switch( layer->text_align ) {
|
||||
case SV_CENTER: return (layer->max_width - txtrow->width)/2;
|
||||
case SV_RIGHT: return layer->max_width - txtrow->width;
|
||||
case SV_CENTER: return (width - txtrow->width) / 2;
|
||||
case SV_RIGHT: return width - txtrow->width;
|
||||
case SV_LEFT:
|
||||
default: break;
|
||||
}
|
||||
@@ -272,17 +286,15 @@ static void TextChar_UpdateBitmap( TextChar ch, LCUI_TextStyle *style )
|
||||
size = ch->style->pixel_size;
|
||||
}
|
||||
}
|
||||
if( !font_ids ) {
|
||||
LCUIFont_GetBitmap( ch->char_code, -1, size, &ch->bitmap );
|
||||
return;
|
||||
}
|
||||
while( font_ids[i] >= 0 ) {
|
||||
if( 0 == LCUIFont_GetBitmap(ch->char_code,
|
||||
style->font_ids[i], size, &ch->bitmap) ) {
|
||||
break;
|
||||
while( font_ids && font_ids[i] >= 0 ) {
|
||||
int ret = LCUIFont_GetBitmap( ch->char_code, font_ids[i],
|
||||
size, &ch->bitmap );
|
||||
if( ret == 0 ) {
|
||||
return;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
LCUIFont_GetBitmap( ch->char_code, -1, size, &ch->bitmap );
|
||||
}
|
||||
|
||||
/** 新建文本图层 */
|
||||
@@ -290,12 +302,16 @@ LCUI_TextLayer TextLayer_New(void)
|
||||
{
|
||||
LCUI_TextLayer layer;
|
||||
layer = malloc( sizeof( LCUI_TextLayerRec ) );
|
||||
layer->width = 0;
|
||||
layer->length = 0;
|
||||
layer->offset_x = 0;
|
||||
layer->offset_y = 0;
|
||||
layer->insert_x = 0;
|
||||
layer->insert_y = 0;
|
||||
layer->max_width = 0;
|
||||
layer->max_height = 0;
|
||||
layer->fixed_width = 0;
|
||||
layer->fixed_height = 0;
|
||||
layer->new_offset_x = 0;
|
||||
layer->new_offset_y = 0;
|
||||
layer->rowlist.length = 0;
|
||||
@@ -335,14 +351,12 @@ static void TextRowList_Destroy( TextRowList list )
|
||||
}
|
||||
|
||||
/** 销毁TextLayer */
|
||||
void TextLayer_Destroy( LCUI_TextLayer *layer_ptr )
|
||||
void TextLayer_Destroy( LCUI_TextLayer layer )
|
||||
{
|
||||
LCUI_TextLayer layer = *layer_ptr;
|
||||
LinkedList_Clear( &layer->dirty_rect, free );
|
||||
Graph_Free( &layer->graph );
|
||||
TextRowList_Destroy( &layer->rowlist );
|
||||
free( layer );
|
||||
*layer_ptr = NULL;
|
||||
}
|
||||
|
||||
/** 获取指定文本行中的文本段的矩形区域 */
|
||||
@@ -383,7 +397,6 @@ static int TextLayer_GetRowRect( LCUI_TextLayer layer, int i_row,
|
||||
rect->width += txtrow->string[i]->bitmap->advance.x;
|
||||
}
|
||||
}
|
||||
LCUIRect_ValidateArea( rect, layer->max_width, layer->max_height );
|
||||
if( rect->width <= 0 || rect->height <= 0 ) {
|
||||
return 1;
|
||||
}
|
||||
@@ -408,18 +421,18 @@ void TextLayer_InvalidateRowsRect( LCUI_TextLayer layer,
|
||||
LCUI_Rect rect;
|
||||
|
||||
if( end_row < 0 || end_row >= layer->rowlist.length ) {
|
||||
end_row = layer->rowlist.length-1;
|
||||
end_row = layer->rowlist.length - 1;
|
||||
}
|
||||
|
||||
y = layer->offset_y;
|
||||
for( i=0; i<layer->rowlist.length; ++i ) {
|
||||
for( i = 0; i < layer->rowlist.length; ++i ) {
|
||||
y += layer->rowlist.rows[i]->height;
|
||||
if( i >= start_row && y >= 0 ) {
|
||||
y -= layer->rowlist.rows[i]->height;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for( ; i<=end_row; ++i ) {
|
||||
for( ; i <= end_row; ++i ) {
|
||||
TextLayer_GetRowRect( layer, i, 0, -1, &rect );
|
||||
RectList_Add( &layer->dirty_rect, &rect );
|
||||
y += layer->rowlist.rows[i]->height;
|
||||
@@ -542,11 +555,14 @@ int TextLayer_GetCaretPixelPos( LCUI_TextLayer layer, LCUI_Pos *pixel_pos )
|
||||
/** 清空文本 */
|
||||
void TextLayer_ClearText( LCUI_TextLayer layer )
|
||||
{
|
||||
layer->length = 0;
|
||||
layer->insert_x = 0;
|
||||
layer->insert_y = 0;
|
||||
layer->width = 0;
|
||||
TextLayer_InvalidateRowsRect( layer, 0, -1 );
|
||||
TextRowList_Destroy( &layer->rowlist );
|
||||
LinkedList_Clear( &layer->style_cache, (FuncPtr)TextStyle_Destroy );
|
||||
TextRowList_InsertNewRow( &layer->rowlist, 0 );
|
||||
layer->task.redraw_all = TRUE;
|
||||
}
|
||||
|
||||
@@ -577,7 +593,13 @@ static void TextLayer_TextRowTypeset( LCUI_TextLayer layer, int row )
|
||||
TextChar txtchar;
|
||||
LCUI_BOOL not_autowrap;
|
||||
int col, row_width = 0;
|
||||
if( layer->max_width <= 0 || !layer->is_autowrap_mode ||
|
||||
int max_width;
|
||||
if( layer->fixed_width > 0 ) {
|
||||
max_width = layer->fixed_width;
|
||||
} else {
|
||||
max_width = layer->max_width;
|
||||
}
|
||||
if( max_width <= 0 || !layer->is_autowrap_mode ||
|
||||
(layer->is_autowrap_mode && !layer->is_mulitiline_mode) ) {
|
||||
not_autowrap = TRUE;
|
||||
} else {
|
||||
@@ -592,8 +614,7 @@ static void TextLayer_TextRowTypeset( LCUI_TextLayer layer, int row )
|
||||
/* 累加行宽度 */
|
||||
row_width += txtchar->bitmap->advance.x;
|
||||
/* 如果是当前行的第一个字符,或者行宽度没有超过宽度限制 */
|
||||
if( not_autowrap || col < 1 ||
|
||||
row_width <= layer->max_width ) {
|
||||
if( not_autowrap || col < 1 || row_width <= max_width ) {
|
||||
continue;
|
||||
}
|
||||
TextLayer_BreakTextRow( layer, row, col, EOL_NONE );
|
||||
@@ -622,7 +643,7 @@ static void TextLayer_TextRowTypeset( LCUI_TextLayer layer, int row )
|
||||
}
|
||||
row_width += txtchar->bitmap->advance.x;
|
||||
/* 如果没有超过宽度限制 */
|
||||
if( not_autowrap || row_width <= layer->max_width ) {
|
||||
if( not_autowrap || row_width <= max_width ) {
|
||||
TextRow_Insert( txtrow, -1, txtchar );
|
||||
next_txtrow->string[col] = NULL;
|
||||
continue;
|
||||
@@ -662,7 +683,7 @@ static void TextLayer_TextTypeset( LCUI_TextLayer layer, int start_row )
|
||||
int row;
|
||||
/* 记录排版前各个文本行的矩形区域 */
|
||||
TextLayer_InvalidateRowsRect( layer, start_row, -1 );
|
||||
for( row=start_row; row<layer->rowlist.length; ++row ) {
|
||||
for( row = start_row; row < layer->rowlist.length; ++row ) {
|
||||
TextLayer_TextRowTypeset( layer, row );
|
||||
}
|
||||
/* 记录排版后各个文本行的矩形区域 */
|
||||
@@ -670,10 +691,8 @@ static void TextLayer_TextTypeset( LCUI_TextLayer layer, int start_row )
|
||||
}
|
||||
|
||||
/** 对文本进行预处理 */
|
||||
static int TextLayer_ProcessText( LCUI_TextLayer layer,
|
||||
const wchar_t *wstr,
|
||||
int add_type,
|
||||
LinkedList *tags )
|
||||
static int TextLayer_ProcessText( LCUI_TextLayer layer, const wchar_t *wstr,
|
||||
int add_type, LinkedList *tags )
|
||||
{
|
||||
EOLChar eol;
|
||||
TextRow txtrow;
|
||||
@@ -691,13 +710,13 @@ static int TextLayer_ProcessText( LCUI_TextLayer layer,
|
||||
rect_has_added = FALSE;
|
||||
is_tmp_tag_stack = FALSE;
|
||||
/* 如果是将文本追加至文本末尾 */
|
||||
if( add_type == TEXT_ADD_TYPE_APPEND ) {
|
||||
if( add_type == TAT_APPEND ) {
|
||||
if( layer->rowlist.length > 0 ) {
|
||||
cur_row = layer->rowlist.length - 1;
|
||||
} else {
|
||||
cur_row = 0;
|
||||
}
|
||||
txtrow = TextLayer_GetRow( layer, cur_row );
|
||||
txtrow = TextLayer_GetRow( layer, cur_row );
|
||||
if( !txtrow ) {
|
||||
txtrow = TextRowList_AddNewRow( &layer->rowlist );
|
||||
}
|
||||
@@ -716,11 +735,11 @@ static int TextLayer_ProcessText( LCUI_TextLayer layer,
|
||||
/* 如果没有可用的标签栈,则使用临时的标签栈 */
|
||||
if( !tags ) {
|
||||
is_tmp_tag_stack = TRUE;
|
||||
TagList_Init( &tmp_tags );
|
||||
StyleTags_Init( &tmp_tags );
|
||||
tags = &tmp_tags;
|
||||
}
|
||||
p_end = wstr + wcslen(wstr);
|
||||
for( p=wstr; p<p_end; ++p ) {
|
||||
p_end = wstr + wcslen( wstr );
|
||||
for( p = wstr; p < p_end; ++p ) {
|
||||
/* 如果启用的样式标签支持,则处理样式的结束标签 */
|
||||
if( layer->is_using_style_tags ) {
|
||||
pp = StyleTags_ScanEndingTag( tags, p );
|
||||
@@ -743,7 +762,7 @@ static int TextLayer_ProcessText( LCUI_TextLayer layer,
|
||||
if( *p == '\r' || *p == '\n' ) {
|
||||
/* 判断是哪一种换行模式 */
|
||||
if( *p == '\r' ) {
|
||||
if( p+1 < p_end && *(p+1) == '\n' ) {
|
||||
if( p + 1 < p_end && *(p + 1) == '\n' ) {
|
||||
eol = EOL_CR_LF;
|
||||
} else {
|
||||
eol = EOL_CR;
|
||||
@@ -759,7 +778,9 @@ static int TextLayer_ProcessText( LCUI_TextLayer layer,
|
||||
}
|
||||
/* 将当前行中的插入点为截点,进行断行 */
|
||||
TextLayer_BreakTextRow( layer, ins_y, ins_x, eol );
|
||||
layer->width = max( layer->width, txtrow->width );
|
||||
need_typeset = TRUE;
|
||||
++layer->length;
|
||||
ins_x = 0;
|
||||
++ins_y;
|
||||
txtrow = TextLayer_GetRow( layer, ins_y );
|
||||
@@ -769,11 +790,13 @@ static int TextLayer_ProcessText( LCUI_TextLayer layer,
|
||||
txtchar.char_code = *p;
|
||||
TextChar_UpdateBitmap( &txtchar, &layer->text_style );
|
||||
TextRow_InsertCopy( txtrow, ins_x, &txtchar );
|
||||
++layer->length;
|
||||
++ins_x;
|
||||
}
|
||||
/* 更新当前行的尺寸 */
|
||||
TextLayer_UpdateRowSize( layer, txtrow );
|
||||
if( add_type == TEXT_ADD_TYPE_INSERT ) {
|
||||
layer->width = max( layer->width, txtrow->width );
|
||||
if( add_type == TAT_INSERT ) {
|
||||
layer->insert_x = ins_x;
|
||||
layer->insert_y = ins_y;
|
||||
}
|
||||
@@ -790,7 +813,7 @@ static int TextLayer_ProcessText( LCUI_TextLayer layer,
|
||||
}
|
||||
/* 如果使用的是临时标签栈,则销毁它 */
|
||||
if( is_tmp_tag_stack ) {
|
||||
TagList_Clear( tags );
|
||||
StyleTags_Clear( tags );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -799,7 +822,7 @@ static int TextLayer_ProcessText( LCUI_TextLayer layer,
|
||||
int TextLayer_InsertTextW( LCUI_TextLayer layer, const wchar_t *wstr,
|
||||
LinkedList *tag_stack )
|
||||
{
|
||||
return TextLayer_ProcessText( layer, wstr, TEXT_ADD_TYPE_INSERT,
|
||||
return TextLayer_ProcessText( layer, wstr, TAT_INSERT,
|
||||
tag_stack );
|
||||
}
|
||||
|
||||
@@ -819,7 +842,7 @@ int TextLayer_InsertText( LCUI_TextLayer layer, const char *utf8_str )
|
||||
int TextLayer_AppendTextW( LCUI_TextLayer layer, const wchar_t *wstr,
|
||||
LinkedList *tag_stack )
|
||||
{
|
||||
return TextLayer_ProcessText( layer, wstr, TEXT_ADD_TYPE_APPEND,
|
||||
return TextLayer_ProcessText( layer, wstr, TAT_APPEND,
|
||||
tag_stack );
|
||||
}
|
||||
|
||||
@@ -886,7 +909,6 @@ int TextLayer_GetTextW( LCUI_TextLayer layer, int start_pos,
|
||||
return i;
|
||||
}
|
||||
|
||||
/** 获取文本位图缓存 */
|
||||
LCUI_Graph* TextLayer_GetGraphBuffer( LCUI_TextLayer layer )
|
||||
{
|
||||
if( layer->is_using_buffer ) {
|
||||
@@ -895,16 +917,57 @@ LCUI_Graph* TextLayer_GetGraphBuffer( LCUI_TextLayer layer )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** 设置最大尺寸 */
|
||||
int TextLayer_SetMaxSize( LCUI_TextLayer layer, LCUI_Size new_size )
|
||||
int TextLayer_GetWidth( LCUI_TextLayer layer )
|
||||
{
|
||||
if( new_size.w <= 0 || new_size.h <= 0 ) {
|
||||
return -1;
|
||||
int i, row, w, max_w;
|
||||
TextRow txtrow;
|
||||
|
||||
for( row = 0, max_w = 0; row < layer->rowlist.length; ++row ) {
|
||||
txtrow = layer->rowlist.rows[row];
|
||||
for( i = 0, w = 0; i < txtrow->length; ++i ) {
|
||||
if( !txtrow->string[i]->bitmap ||
|
||||
!txtrow->string[i]->bitmap->buffer ) {
|
||||
continue;
|
||||
}
|
||||
w += txtrow->string[i]->bitmap->advance.x;
|
||||
}
|
||||
if( w > max_w ) {
|
||||
max_w = w;
|
||||
}
|
||||
}
|
||||
layer->max_width = new_size.w;
|
||||
layer->max_height = new_size.h;
|
||||
return max_w;
|
||||
}
|
||||
|
||||
int TextLayer_GetHeight( LCUI_TextLayer layer )
|
||||
{
|
||||
int i, h;
|
||||
for( i = 0, h = 0; i < layer->rowlist.length; ++i ) {
|
||||
h += layer->rowlist.rows[i]->height;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
int TextLayer_SetFixedSize( LCUI_TextLayer layer, int width, int height )
|
||||
{
|
||||
layer->fixed_width = width;
|
||||
layer->fixed_height = height;
|
||||
if( layer->is_using_buffer ) {
|
||||
Graph_Create( &layer->graph, new_size.w, new_size.h );
|
||||
Graph_Create( &layer->graph, width, height );
|
||||
}
|
||||
layer->task.redraw_all = TRUE;
|
||||
if( layer->is_autowrap_mode ) {
|
||||
layer->task.typeset_start_row = 0;
|
||||
layer->task.update_typeset = TRUE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TextLayer_SetMaxSize( LCUI_TextLayer layer, int width, int height )
|
||||
{
|
||||
layer->max_width = width;
|
||||
layer->max_height = height;
|
||||
if( layer->is_using_buffer ) {
|
||||
Graph_Create( &layer->graph, width, height );
|
||||
}
|
||||
layer->task.redraw_all = TRUE;
|
||||
if( layer->is_autowrap_mode ) {
|
||||
@@ -925,8 +988,8 @@ void TextLayer_SetMultiline( LCUI_TextLayer layer, int is_true )
|
||||
}
|
||||
|
||||
/** 删除指定行列的文字及其右边的文本 */
|
||||
static int TextLayer_DeleteText( LCUI_TextLayer layer, int char_y,
|
||||
int char_x, int n_char )
|
||||
static int TextLayer_TextDeleteEx( LCUI_TextLayer layer, int char_y,
|
||||
int char_x, int n_char )
|
||||
{
|
||||
int end_x, end_y, i, j, len;
|
||||
TextRow txtrow, end_txtrow, prev_txtrow;
|
||||
@@ -947,53 +1010,61 @@ static int TextLayer_DeleteText( LCUI_TextLayer layer, int char_y,
|
||||
if( char_x > txtrow->length ) {
|
||||
char_x = txtrow->length;
|
||||
}
|
||||
--n_char;
|
||||
i = n_char;
|
||||
end_x = char_x;
|
||||
end_y = char_y;
|
||||
/* 计算结束点的位置 */
|
||||
for( ; end_y < layer->rowlist.length && n_char > 0; ++end_y ) {
|
||||
txtrow = layer->rowlist.rows[end_y];
|
||||
if( txtrow->eol == EOL_NONE ) {
|
||||
if( end_x + n_char < txtrow->length ) {
|
||||
end_x += n_char;
|
||||
n_char = 0;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if( end_x + n_char <= txtrow->length ) {
|
||||
end_x += n_char;
|
||||
n_char = 0;
|
||||
break;
|
||||
}
|
||||
if( end_x + n_char <= txtrow->length ) {
|
||||
end_x += n_char;
|
||||
n_char = 0;
|
||||
break;
|
||||
}
|
||||
n_char -= (txtrow->length - end_x);
|
||||
end_x = 0;
|
||||
if( txtrow->eol == EOL_NONE ) {
|
||||
end_x = 0;
|
||||
} else {
|
||||
n_char -= 1;
|
||||
end_x = 0;
|
||||
}
|
||||
}
|
||||
if( n_char >= 0 ) {
|
||||
layer->length -= i - n_char;
|
||||
} else {
|
||||
layer->length -= n_char;
|
||||
}
|
||||
if( end_y >= layer->rowlist.length ) {
|
||||
end_y = layer->rowlist.length - 1;
|
||||
end_txtrow = layer->rowlist.rows[end_y];
|
||||
end_x = end_txtrow->length;
|
||||
} else {
|
||||
end_txtrow = layer->rowlist.rows[end_y];
|
||||
}
|
||||
end_txtrow = layer->rowlist.rows[end_y];
|
||||
if( end_x > end_txtrow->length ) {
|
||||
end_x = end_txtrow->length;
|
||||
}
|
||||
if( end_x == char_x && end_y == char_y ) {
|
||||
return 0;
|
||||
}
|
||||
/* 获取上一行文本 */
|
||||
prev_txtrow = layer->rowlist.rows[char_y - 1];
|
||||
// 计算起始行与结束行拼接后的长度
|
||||
// 起始行:0 1 2 3 4 5,起点位置:2
|
||||
// 结束行:0 1 2 3 4 5,终点位置:4
|
||||
// 拼接后的长度:2 + 6 - 4 - 1 = 3
|
||||
len = char_x + end_txtrow->length - end_x - 1;
|
||||
// 拼接后的长度:2 + 6 - 4 = 4
|
||||
len = char_x + end_txtrow->length - end_x;
|
||||
if( len < 0 ) {
|
||||
return -3;
|
||||
}
|
||||
/* 如果是同一行 */
|
||||
if( txtrow == end_txtrow ) {
|
||||
if( end_x >= end_txtrow->length ) {
|
||||
if( end_x > end_txtrow->length ) {
|
||||
return -4;
|
||||
}
|
||||
TextLayer_InvalidateRowRect( layer, char_y, char_x, -1 );
|
||||
TextLayer_AddUpdateTypeset( layer, char_y );
|
||||
for( i = char_x, j = end_x + 1; j < txtrow->length; ++i, ++j ) {
|
||||
for( i = char_x, j = end_x; j < txtrow->length; ++i, ++j ) {
|
||||
txtrow->string[i] = txtrow->string[j];
|
||||
}
|
||||
/* 如果当前行为空,也不是第一行,并且上一行没有结束符 */
|
||||
@@ -1043,14 +1114,14 @@ static int TextLayer_DeleteText( LCUI_TextLayer layer, int char_y,
|
||||
}
|
||||
|
||||
/** 删除文本光标的当前坐标右边的文本 */
|
||||
int TextLayer_Delete( LCUI_TextLayer layer, int n_char )
|
||||
int TextLayer_TextDelete( LCUI_TextLayer layer, int n_char )
|
||||
{
|
||||
return TextLayer_DeleteText( layer, layer->insert_y,
|
||||
return TextLayer_TextDeleteEx( layer, layer->insert_y,
|
||||
layer->insert_x, n_char );
|
||||
}
|
||||
|
||||
/** 退格删除文本,即删除文本光标的当前坐标左边的文本 */
|
||||
int TextLayer_Backspace( LCUI_TextLayer layer, int n_char )
|
||||
int TextLayer_TextBackspace( LCUI_TextLayer layer, int n_char )
|
||||
{
|
||||
int n_del;
|
||||
int char_x, char_y;
|
||||
@@ -1060,7 +1131,7 @@ int TextLayer_Backspace( LCUI_TextLayer layer, int n_char )
|
||||
char_x = layer->insert_x;
|
||||
char_y = layer->insert_y;
|
||||
/* 再计算删除 n_char 个字后的位置 */
|
||||
for( n_del=n_char; char_y>=0; --char_y ) {
|
||||
for( n_del = n_char; char_y >= 0; --char_y ) {
|
||||
txtrow = layer->rowlist.rows[char_y];
|
||||
/* 如果不是当前行,则重定位至行尾 */
|
||||
if( char_y < layer->insert_y ) {
|
||||
@@ -1076,7 +1147,7 @@ int TextLayer_Backspace( LCUI_TextLayer layer, int n_char )
|
||||
}
|
||||
n_del = n_del - char_x - 1;
|
||||
}
|
||||
if( char_y < 0 && n_del == n_char ) {
|
||||
if( char_y < 0 || n_del == n_char ) {
|
||||
return -1;
|
||||
}
|
||||
/* 若能够被删除的字不够 n_char 个,则调整需删除的字数 */
|
||||
@@ -1084,11 +1155,11 @@ int TextLayer_Backspace( LCUI_TextLayer layer, int n_char )
|
||||
n_char -= n_del;
|
||||
}
|
||||
/* 开始删除文本 */
|
||||
TextLayer_DeleteText( layer, char_y, char_x, n_char );
|
||||
TextLayer_TextDeleteEx( layer, char_y, char_x, n_char );
|
||||
/* 若最后一行被完全移除,则移动输入点至上一行的行尾处 */
|
||||
if( char_x == 0 && layer->rowlist.length > 0
|
||||
&& char_y >= layer->rowlist.length ) {
|
||||
char_y = layer->rowlist.length-1;
|
||||
&& char_y >= layer->rowlist.length ) {
|
||||
char_y = layer->rowlist.length - 1;
|
||||
char_x = layer->rowlist.rows[char_y]->length;
|
||||
}
|
||||
/* 更新文本光标的位置 */
|
||||
@@ -1112,45 +1183,13 @@ void TextLayer_SetUsingStyleTags( LCUI_TextLayer layer, LCUI_BOOL is_true )
|
||||
layer->is_using_style_tags = is_true;
|
||||
}
|
||||
|
||||
/** 计算并获取文本的宽度 */
|
||||
int TextLayer_GetWidth( LCUI_TextLayer layer )
|
||||
{
|
||||
int i, row, w, max_w;
|
||||
TextRow txtrow;
|
||||
|
||||
for( row=0,max_w=0; row<layer->rowlist.length; ++row ) {
|
||||
txtrow = layer->rowlist.rows[row];
|
||||
for( i=0, w=0; i<txtrow->length; ++i ) {
|
||||
if( !txtrow->string[i]->bitmap ||
|
||||
!txtrow->string[i]->bitmap->buffer ) {
|
||||
continue;
|
||||
}
|
||||
w += txtrow->string[i]->bitmap->advance.x;
|
||||
}
|
||||
if( w > max_w ) {
|
||||
max_w = w;
|
||||
}
|
||||
}
|
||||
return max_w;
|
||||
}
|
||||
|
||||
/** 计算并获取文本的高度 */
|
||||
int TextLayer_GetHeight( LCUI_TextLayer layer )
|
||||
{
|
||||
int i, h;
|
||||
for( i=0,h=0; i<layer->rowlist.length; ++i ) {
|
||||
h += layer->rowlist.rows[i]->height;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
/** 重新载入各个文字的字体位图 */
|
||||
void TextLayer_ReloadCharBitmap( LCUI_TextLayer layer )
|
||||
{
|
||||
int row, col;
|
||||
for( row=0; row<layer->rowlist.length; ++row ) {
|
||||
for( row = 0; row < layer->rowlist.length; ++row ) {
|
||||
TextRow txtrow = layer->rowlist.rows[row];
|
||||
for( col=0; col<txtrow->length; ++col ) {
|
||||
for( col = 0; col < txtrow->length; ++col ) {
|
||||
TextChar txtchar = txtrow->string[col];
|
||||
TextChar_UpdateBitmap( txtchar, &layer->text_style );
|
||||
}
|
||||
@@ -1173,6 +1212,7 @@ void TextLayer_Update( LCUI_TextLayer layer, LinkedList *rect_list )
|
||||
layer->task.update_typeset = FALSE;
|
||||
layer->task.typeset_start_row = 0;
|
||||
}
|
||||
layer->width = TextLayer_GetWidth( layer );
|
||||
/* 如果坐标偏移量有变化,记录各个文本行区域 */
|
||||
if( layer->new_offset_x != layer->offset_x
|
||||
|| layer->new_offset_y != layer->offset_y ) {
|
||||
@@ -1187,23 +1227,26 @@ void TextLayer_Update( LCUI_TextLayer layer, LinkedList *rect_list )
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将文本图层中的指定区域的内容绘制至目标图像中
|
||||
* @param layer 要使用的文本图层
|
||||
* @param area 文本图层中需要绘制的区域
|
||||
* @param layer_pos 文本图层在目标图像中的位置
|
||||
* @param graph 目标图像
|
||||
*/
|
||||
int TextLayer_DrawToGraph( LCUI_TextLayer layer, LCUI_Rect area,
|
||||
LCUI_Pos layer_pos, LCUI_Graph *graph )
|
||||
{
|
||||
TextRow txtrow;
|
||||
TextChar txtchar;
|
||||
LCUI_Pos char_pos;
|
||||
int x, y, row, col;
|
||||
int x, y, row, col, width, height;
|
||||
y = layer->offset_y;
|
||||
LCUIRect_ValidateArea( &area, layer->max_width, layer->max_height );
|
||||
for( row=0; row<layer->rowlist.length; ++row ) {
|
||||
if( layer->fixed_width > 0 ) {
|
||||
width = layer->fixed_width;
|
||||
} else {
|
||||
width = layer->width;
|
||||
}
|
||||
if( layer->fixed_width > 0 ) {
|
||||
height = layer->fixed_width;
|
||||
} else {
|
||||
height = TextLayer_GetHeight( layer );
|
||||
}
|
||||
LCUIRect_ValidateArea( &area, width, height );
|
||||
for( row = 0; row < layer->rowlist.length; ++row ) {
|
||||
txtrow = TextLayer_GetRow( layer, row );
|
||||
y += txtrow->height;
|
||||
if( y > area.y ) {
|
||||
@@ -1220,7 +1263,7 @@ int TextLayer_DrawToGraph( LCUI_TextLayer layer, LCUI_Rect area,
|
||||
x = TextLayer_GetRowStartX( layer, txtrow );
|
||||
x += layer->offset_x;
|
||||
/* 确定从哪个文字开始绘制 */
|
||||
for( col=0; col<txtrow->length; ++col ) {
|
||||
for( col = 0; col < txtrow->length; ++col ) {
|
||||
txtchar = txtrow->string[col];
|
||||
/* 忽略无字体位图的文字 */
|
||||
if( !txtchar->bitmap ) {
|
||||
@@ -1238,7 +1281,7 @@ int TextLayer_DrawToGraph( LCUI_TextLayer layer, LCUI_Rect area,
|
||||
continue;
|
||||
}
|
||||
/* 遍历该行的文字 */
|
||||
for( ; col<txtrow->length; ++col ) {
|
||||
for( ; col < txtrow->length; ++col ) {
|
||||
txtchar = txtrow->string[col];
|
||||
if( !txtchar->bitmap ) {
|
||||
continue;
|
||||
@@ -1300,7 +1343,7 @@ void TextLayer_ClearInvalidRect( LCUI_TextLayer layer )
|
||||
LinkedList_Clear( &layer->dirty_rect, free );
|
||||
return;
|
||||
}
|
||||
LinkedList_ForEach( node, &layer->dirty_rect ) {
|
||||
for( LinkedList_Each( node, &layer->dirty_rect ) ) {
|
||||
Graph_Quote( &invalid_graph, &layer->graph, node->data );
|
||||
Graph_FillAlpha( &invalid_graph, 0 );
|
||||
}
|
||||
@@ -1310,7 +1353,8 @@ void TextLayer_ClearInvalidRect( LCUI_TextLayer layer )
|
||||
/** 设置全局文本样式 */
|
||||
void TextLayer_SetTextStyle( LCUI_TextLayer layer, LCUI_TextStyle *style )
|
||||
{
|
||||
layer->text_style = *style;
|
||||
TextStyle_Destroy( &layer->text_style );
|
||||
TextStyle_Copy( &layer->text_style, style );
|
||||
layer->task.update_bitmap = TRUE;
|
||||
}
|
||||
|
||||
@@ -1329,3 +1373,9 @@ void TextLayer_SetLineHeight( LCUI_TextLayer layer, LCUI_Style val )
|
||||
layer->task.update_typeset = TRUE;
|
||||
layer->task.typeset_start_row = 0;
|
||||
}
|
||||
|
||||
void TextLayer_SetOffset( LCUI_TextLayer layer, int offset_x, int offset_y )
|
||||
{
|
||||
layer->new_offset_x = offset_x;
|
||||
layer->new_offset_y = offset_y;
|
||||
}
|
||||
|
||||
+25
-14
@@ -39,6 +39,7 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <LCUI_Build.h>
|
||||
#include <LCUI/LCUI.h>
|
||||
#include <LCUI/font.h>
|
||||
@@ -57,7 +58,6 @@ typedef struct LCUI_StyleTag {
|
||||
LCUI_StyleRec style;
|
||||
} LCUI_StyleTag;
|
||||
|
||||
/** 初始化字体样式数据 */
|
||||
void TextStyle_Init( LCUI_TextStyle *data )
|
||||
{
|
||||
data->has_style = FALSE;
|
||||
@@ -75,6 +75,23 @@ void TextStyle_Init( LCUI_TextStyle *data )
|
||||
data->pixel_size = 13;
|
||||
}
|
||||
|
||||
int TextStyle_Copy( LCUI_TextStyle *dst, LCUI_TextStyle *src )
|
||||
{
|
||||
int len;
|
||||
*dst = *src;
|
||||
if( !dst->has_family ) {
|
||||
return 0;
|
||||
}
|
||||
for( len = 0; dst->font_ids[len] != -1; ++len );
|
||||
len += 1;
|
||||
dst->font_ids = malloc( len * sizeof( int ) );
|
||||
if( !dst->font_ids ) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
memcpy( dst->font_ids, src->font_ids, len * sizeof( int ) );
|
||||
return 0;
|
||||
}
|
||||
|
||||
void TextStyle_Destroy( LCUI_TextStyle *data )
|
||||
{
|
||||
if( data->font_ids ) {
|
||||
@@ -91,8 +108,8 @@ void TextStyle_Destroy( LCUI_TextStyle *data )
|
||||
int TextStyle_SetFont( LCUI_TextStyle *ts, const char *str )
|
||||
{
|
||||
char name[256];
|
||||
const char *p, *style_name;
|
||||
int count, i, *ids;
|
||||
const char *p, *style_name;
|
||||
|
||||
if( ts->has_family && ts->font_ids ) {
|
||||
free( ts->font_ids );
|
||||
@@ -110,7 +127,7 @@ int TextStyle_SetFont( LCUI_TextStyle *ts, const char *str )
|
||||
if( p - str == 0 ) {
|
||||
return -1;
|
||||
}
|
||||
ids = (int*)malloc(sizeof(int)*(count+1));
|
||||
ids = NEW( int, count + 1 );
|
||||
if( !ids ) {
|
||||
return -2;
|
||||
}
|
||||
@@ -127,7 +144,7 @@ int TextStyle_SetFont( LCUI_TextStyle *ts, const char *str )
|
||||
continue;
|
||||
}
|
||||
name[i] = 0;
|
||||
strtrim( name, name, NULL );
|
||||
strtrim( name, name, "'\"\n\r\t " );
|
||||
ids[count] = LCUIFont_GetId( name, style_name );
|
||||
if( ids[count] > 0 ) {
|
||||
++count;
|
||||
@@ -143,7 +160,7 @@ int TextStyle_SetFont( LCUI_TextStyle *ts, const char *str )
|
||||
} else {
|
||||
ts->has_family = FALSE;
|
||||
ts->font_ids = NULL;
|
||||
free(ids);
|
||||
free( ids );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -151,15 +168,9 @@ int TextStyle_SetFont( LCUI_TextStyle *ts, const char *str )
|
||||
/*-------------------------- StyleTag --------------------------------*/
|
||||
#define MAX_TAG_NUM 2
|
||||
|
||||
static void DestroyTag( LCUI_StyleTag *tag )
|
||||
void StyleTags_Clear( LinkedList *tags )
|
||||
{
|
||||
free( tag );
|
||||
// XXX
|
||||
}
|
||||
|
||||
void TagList_Clear( LinkedList *tags )
|
||||
{
|
||||
LinkedList_Clear( tags, (FuncPtr)DestroyTag );
|
||||
LinkedList_Clear( tags, free );
|
||||
}
|
||||
|
||||
/** 获取当前的文本样式 */
|
||||
@@ -221,7 +232,7 @@ static void StyleTags_Delete( LinkedList *tags, int id )
|
||||
if( tags->length <= 0 ) {
|
||||
return;
|
||||
}
|
||||
LinkedList_ForEach( node, tags ) {
|
||||
for( LinkedList_Each( node, tags ) ) {
|
||||
p = (LCUI_StyleTag*)node->data;
|
||||
if( p->id == id ) {
|
||||
LinkedList_DeleteNode( tags, node );
|
||||
|
||||
@@ -10,8 +10,10 @@ widget_task.c \
|
||||
widget_paint.c \
|
||||
widget_background.c \
|
||||
css_parser.c \
|
||||
css_library.c \
|
||||
builder.c \
|
||||
widget/textview.c \
|
||||
widget/textedit.c \
|
||||
widget/sidebar.c \
|
||||
widget/scrollbar.c \
|
||||
widget/button.c
|
||||
|
||||
+13
-9
@@ -37,6 +37,7 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <LCUI_Build.h>
|
||||
#include <LCUI/LCUI.h>
|
||||
@@ -44,7 +45,7 @@
|
||||
#include <LCUI/gui/widget.h>
|
||||
#include <LCUI/gui/builder.h>
|
||||
|
||||
#define WARNING_TEXT "[builder] warning: this module is not enabled before build."
|
||||
#define WARN_TXT "[builder] warning: this module is not enabled before build.\n"
|
||||
|
||||
#ifdef USE_LCUI_BUILDER
|
||||
#include <libxml/xmlmemory.h>
|
||||
@@ -81,6 +82,7 @@ struct XMLParserContextRec_ {
|
||||
LCUI_Widget widget;
|
||||
LCUI_Widget root;
|
||||
ParserPtr parent;
|
||||
const char *space;
|
||||
};
|
||||
|
||||
static struct ModuleContext {
|
||||
@@ -108,20 +110,21 @@ static int ParseResource( XMLParserContext ctx, xmlNodePtr node )
|
||||
}
|
||||
prop = prop->next;
|
||||
}
|
||||
if( !type || !src ) {
|
||||
if( !type && !src ) {
|
||||
return PB_WARNING;
|
||||
}
|
||||
if( strstr(type, "application/font-") ) {
|
||||
LCUIFont_LoadFile( src );
|
||||
}
|
||||
else if( strstr(type, "text/css") ) {
|
||||
LCUICSS_LoadFile( src );
|
||||
if( src ) {
|
||||
LCUI_LoadCSSFile( src );
|
||||
}
|
||||
for( node = node->children; node; node = node->next ) {
|
||||
if( node->type != XML_TEXT_NODE ) {
|
||||
continue;
|
||||
}
|
||||
LCUICSS_LoadString( (char*)node->content );
|
||||
node = node->next;
|
||||
LCUI_LoadCSSString( (char*)node->content, ctx->space );
|
||||
}
|
||||
}
|
||||
return PB_NEXT;
|
||||
@@ -216,8 +219,7 @@ static void LCUIBuilder_Init( void )
|
||||
Parser *p;
|
||||
|
||||
RBTree_Init( &self.parsers );
|
||||
RBTree_OnJudge( &self.parsers, CompareName );
|
||||
RBTree_SetDataNeedFree( &self.parsers, FALSE );
|
||||
RBTree_OnCompare( &self.parsers, CompareName );
|
||||
len = sizeof(parser_list) / sizeof(parser_list[0]);
|
||||
for( i = 0; i < len; ++i ) {
|
||||
p = &parser_list[i];
|
||||
@@ -267,7 +269,7 @@ static void ParseNode( XMLParserContext ctx, xmlNodePtr node )
|
||||
LCUI_Widget LCUIBuilder_LoadString( const char *str, int size )
|
||||
{
|
||||
#ifndef USE_LCUI_BUILDER
|
||||
printf(WARNING_TEXT);
|
||||
printf(WARN_TXT);
|
||||
#else
|
||||
xmlDocPtr doc;
|
||||
xmlNodePtr cur;
|
||||
@@ -285,6 +287,7 @@ LCUI_Widget LCUIBuilder_LoadString( const char *str, int size )
|
||||
ctx.root = NULL;
|
||||
ctx.widget = NULL;
|
||||
ctx.parent = NULL;
|
||||
ctx.space = NULL;
|
||||
if( !self.is_inited ) {
|
||||
LCUIBuilder_Init();
|
||||
}
|
||||
@@ -301,7 +304,7 @@ FAILED:
|
||||
LCUI_Widget LCUIBuilder_LoadFile( const char *filepath )
|
||||
{
|
||||
#ifndef USE_LCUI_BUILDER
|
||||
printf(WARNING_TEXT);
|
||||
printf(WARN_TXT);
|
||||
#else
|
||||
xmlDocPtr doc;
|
||||
xmlNodePtr cur;
|
||||
@@ -319,6 +322,7 @@ LCUI_Widget LCUIBuilder_LoadFile( const char *filepath )
|
||||
ctx.root = NULL;
|
||||
ctx.widget = NULL;
|
||||
ctx.parent = NULL;
|
||||
ctx.space = filepath;
|
||||
if( !self.is_inited ) {
|
||||
LCUIBuilder_Init();
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+88
-194
@@ -36,13 +36,21 @@
|
||||
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
//#define DEBUG
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <LCUI_Build.h>
|
||||
#include <LCUI/LCUI.h>
|
||||
#include <LCUI/gui/widget.h>
|
||||
#include <LCUI/thread.h>
|
||||
#include <LCUI/gui/css_library.h>
|
||||
#include <LCUI/gui/css_parser.h>
|
||||
|
||||
#define SPLIT_NUMBER 1
|
||||
#define SPLIT_COLOR (1<<1)
|
||||
#define SPLIT_STYLE (1<<2)
|
||||
|
||||
#define LEN(A) sizeof( A ) / sizeof( *A )
|
||||
|
||||
/** 解析器的环境参数(上下文数据) */
|
||||
typedef struct CSSParserContextRec_ {
|
||||
@@ -61,40 +69,15 @@ typedef struct CSSParserContextRec_ {
|
||||
LinkedList selectors; /**< 当前匹配到的选择器列表 */
|
||||
LCUI_StyleSheet css; /**< 当前缓存的样式表 */
|
||||
LCUI_StyleParser parser; /**< 当前找到的解析器 */
|
||||
char *space; /**< 样式记录所属的空间 */
|
||||
} CSSParserContextRec, *CSSParserContext;
|
||||
|
||||
/** 样式字符串值与标识码 */
|
||||
typedef struct KeyNameGroup {
|
||||
int key;
|
||||
char *name;
|
||||
} KeyNameGroup;
|
||||
|
||||
static struct {
|
||||
LCUI_RBTree parser_tree;
|
||||
LCUI_RBTree option_tree;
|
||||
LCUI_RBTree name_tree;
|
||||
static struct CSSParserModule {
|
||||
int count;
|
||||
DictType dicttype; /**< 解析器表的字典类型数据 */
|
||||
Dict *parsers; /**< 解析器表,以名称进行索引 */
|
||||
} self;
|
||||
|
||||
#define SPLIT_NUMBER 1
|
||||
#define SPLIT_COLOR (1<<1)
|
||||
#define SPLIT_STYLE (1<<2)
|
||||
|
||||
int ParseStyleOption( const char *str )
|
||||
{
|
||||
LCUI_RBTreeNode *node;
|
||||
node = RBTree_CustomSearch( &self.option_tree, str );
|
||||
if( !node ) {
|
||||
return -1;
|
||||
}
|
||||
return ((KeyNameGroup*)(node->data))->key;
|
||||
}
|
||||
|
||||
const char *GetStyleName( int key )
|
||||
{
|
||||
return RBTree_GetData( &self.name_tree, key );
|
||||
}
|
||||
|
||||
static int SplitValues( const char *str, LCUI_Style slist,
|
||||
int max_len, int mode )
|
||||
{
|
||||
@@ -143,7 +126,7 @@ static int SplitValues( const char *str, LCUI_Style slist,
|
||||
}
|
||||
}
|
||||
if( mode & SPLIT_STYLE ) {
|
||||
val = ParseStyleOption( values[vj] );
|
||||
val = LCUI_GetStyleValue( values[vj] );
|
||||
if( val > 0 ) {
|
||||
slist[vj].style = val;
|
||||
slist[vj].type = SVT_style;
|
||||
@@ -191,6 +174,29 @@ static int OnParseNumber( LCUI_StyleSheet ss, int key, const char *str )
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int OnParseBoolean( LCUI_StyleSheet ss, int key, const char *str )
|
||||
{
|
||||
LCUI_Style s = &ss->sheet[key];
|
||||
if( strcasecmp(str, "true") == 0 ) {
|
||||
s->is_valid = TRUE;
|
||||
s->type = SVT_BOOL;
|
||||
s->value = TRUE;
|
||||
return 0;
|
||||
} else if( strcasecmp(str, "false") == 0 ) {
|
||||
s->is_valid = TRUE;
|
||||
s->type = SVT_BOOL;
|
||||
s->value = FALSE;
|
||||
return 0;
|
||||
}
|
||||
if( strcmp("auto", str) == 0 ) {
|
||||
s->is_valid = TRUE;
|
||||
s->type = SVT_AUTO;
|
||||
s->style = SV_AUTO;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int OnParseColor( LCUI_StyleSheet ss, int key, const char *str )
|
||||
{
|
||||
LCUI_Style s = &ss->sheet[key];
|
||||
@@ -199,7 +205,10 @@ static int OnParseColor( LCUI_StyleSheet ss, int key, const char *str )
|
||||
}
|
||||
if( strcmp("transparent", str) == 0 ) {
|
||||
s->is_valid = TRUE;
|
||||
s->color = ARGB(0,255,255,255);
|
||||
s->color.alpha = 0;
|
||||
s->color.red = 255;
|
||||
s->color.green = 255;
|
||||
s->color.blue = 255;
|
||||
s->type = SVT_COLOR;
|
||||
return 0;
|
||||
}
|
||||
@@ -239,12 +248,12 @@ static int OnParseImage( LCUI_StyleSheet ss, int key, const char *str )
|
||||
static int OnParseStyleOption( LCUI_StyleSheet ss, int key, const char *str )
|
||||
{
|
||||
LCUI_Style s = &ss->sheet[key];
|
||||
int v = ParseStyleOption( str );
|
||||
int v = LCUI_GetStyleValue( str );
|
||||
if( v < 0 ) {
|
||||
return -1;
|
||||
}
|
||||
s->type = SVT_style;
|
||||
s->style = v;
|
||||
s->type = SVT_STYLE;
|
||||
s->is_valid = TRUE;
|
||||
s->is_changed = TRUE;
|
||||
return 0;
|
||||
@@ -507,92 +516,6 @@ static int OnParseBackgroundSize( LCUI_StyleSheet ss, int key, const char *str )
|
||||
return 0;
|
||||
}
|
||||
|
||||
static KeyNameGroup style_name_map[] = {
|
||||
{ key_visible, "visible"},
|
||||
{ key_width, "width" },
|
||||
{ key_height, "height" },
|
||||
{ key_min_width, "min-width" },
|
||||
{ key_min_height, "min-height" },
|
||||
{ key_max_width, "max-width" },
|
||||
{ key_max_height, "max-height" },
|
||||
{ key_display, "display" },
|
||||
{ key_z_index, "z-index" },
|
||||
{ key_top, "top" },
|
||||
{ key_right, "right" },
|
||||
{ key_left, "left" },
|
||||
{ key_bottom, "bottom" },
|
||||
{ key_position, "position" },
|
||||
{ key_vertical_align, "vertical-align" },
|
||||
{ key_background_color, "background-color" },
|
||||
{ key_background_position, "background-position" },
|
||||
{ key_background_size, "background-size" },
|
||||
{ key_background_image, "background-image" },
|
||||
{ key_border_color, "border-color" },
|
||||
{ key_border_width, "border-width" },
|
||||
{ key_border_style, "border-style" },
|
||||
{ key_padding_left, "padding-left" },
|
||||
{ key_padding_right, "padding-right" },
|
||||
{ key_padding_top, "padding-top" },
|
||||
{ key_padding_bottom, "padding-bottom" },
|
||||
{ key_margin_left, "margin-left" },
|
||||
{ key_margin_right, "margin-right" },
|
||||
{ key_margin_top, "margin-top" },
|
||||
{ key_margin_bottom, "margin-bottom" },
|
||||
{ key_border_top_color, "border-top-color" },
|
||||
{ key_border_right_color, "border-right-color" },
|
||||
{ key_border_bottom_color, "border-bottom-color" },
|
||||
{ key_border_left_color, "border-left-color" },
|
||||
{ key_border_top_width, "border-top-width" },
|
||||
{ key_border_right_width, "border-right-width" },
|
||||
{ key_border_bottom_width, "border-bottom-width" },
|
||||
{ key_border_left_width, "border-left-width" },
|
||||
{ key_border_top_width, "border-top-width" },
|
||||
{ key_border_right_width, "border-right-width" },
|
||||
{ key_border_bottom_width, "border-bottom-width" },
|
||||
{ key_border_left_width, "border-left-width" },
|
||||
{ key_border_top_style, "border-top-style" },
|
||||
{ key_border_right_style, "border-right-style" },
|
||||
{ key_border_bottom_style, "border-bottom-style" },
|
||||
{ key_border_left_style, "border-left-style" },
|
||||
{ key_pointer_events, "pointer-events" },
|
||||
{ key_box_sizing, "box-sizing" }
|
||||
};
|
||||
|
||||
/** 样式字符串与标识码的映射表 */
|
||||
static KeyNameGroup style_option_map[] = {
|
||||
{ SV_NONE, "none" },
|
||||
{ SV_AUTO, "auto" },
|
||||
{ SV_CONTAIN, "contain" },
|
||||
{ SV_COVER, "cover" },
|
||||
{ SV_LEFT, "left" },
|
||||
{ SV_CENTER, "center" },
|
||||
{ SV_RIGHT, "right" },
|
||||
{ SV_TOP, "top" },
|
||||
{ SV_TOP_LEFT, "top left" },
|
||||
{ SV_TOP_CENTER, "top center" },
|
||||
{ SV_TOP_RIGHT, "top right" },
|
||||
{ SV_MIDDLE, "middle" },
|
||||
{ SV_CENTER_LEFT, "center left" },
|
||||
{ SV_CENTER_CENTER, "center center" },
|
||||
{ SV_CENTER_RIGHT, "center right" },
|
||||
{ SV_BOTTOM, "bottom" },
|
||||
{ SV_BOTTOM_LEFT, "bottom left" },
|
||||
{ SV_BOTTOM_CENTER, "bottom center" },
|
||||
{ SV_BOTTOM_RIGHT, "bottom right" },
|
||||
{ SV_SOLID, "solid" },
|
||||
{ SV_DOTTED, "dotted" },
|
||||
{ SV_DOUBLE, "double" },
|
||||
{ SV_DASHED, "dashed" },
|
||||
{ SV_CONTENT_BOX, "content-box" },
|
||||
{ SV_PADDING_BOX, "padding-box" },
|
||||
{ SV_BORDER_BOX, "border-box" },
|
||||
{ SV_GRAPH_BOX, "graph-box" },
|
||||
{ SV_STATIC, "static" },
|
||||
{ SV_RELATIVE, "relative" },
|
||||
{ SV_ABSOLUTE, "absolute" },
|
||||
{ SV_BLOCK, "block" },
|
||||
{ SV_INLINE_BLOCK, "inline-block" }
|
||||
};
|
||||
|
||||
/** 各个样式的解析器映射表 */
|
||||
static LCUI_StyleParserRec style_parser_map[] = {
|
||||
@@ -635,6 +558,7 @@ static LCUI_StyleParserRec style_parser_map[] = {
|
||||
{ key_margin_right, NULL, OnParseNumber },
|
||||
{ key_margin_bottom, NULL, OnParseNumber },
|
||||
{ key_margin_left, NULL, OnParseNumber },
|
||||
{ key_focusable, NULL, OnParseBoolean },
|
||||
{ key_pointer_events, NULL, OnParseStyleOption },
|
||||
{ key_box_sizing, NULL, OnParseStyleOption },
|
||||
{ -1, "border", OnParseBorder },
|
||||
@@ -656,12 +580,8 @@ static int CompareParserName( void *data, const void *keydata )
|
||||
return strcmp(((LCUI_StyleParser)data)->name, (const char*)keydata);
|
||||
}
|
||||
|
||||
static int CompareName( void *data, const void *keydata )
|
||||
{
|
||||
return strcmp(((KeyNameGroup*)data)->name, (const char*)keydata);
|
||||
}
|
||||
|
||||
static CSSParserContext NewCSSParserContext( size_t buffer_size )
|
||||
static CSSParserContext NewCSSParserContext( size_t buffer_size,
|
||||
const char *space )
|
||||
{
|
||||
CSSParserContext ctx = NEW(CSSParserContextRec, 1);
|
||||
LinkedList_Init( &ctx->selectors );
|
||||
@@ -669,6 +589,7 @@ static CSSParserContext NewCSSParserContext( size_t buffer_size )
|
||||
ctx->buffer_size = buffer_size;
|
||||
ctx->target_bak = TARGET_NONE;
|
||||
ctx->target = TARGET_NONE;
|
||||
ctx->space = space ? strdup( space ): NULL;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
@@ -681,14 +602,8 @@ static void DeleteCSSParserContext( CSSParserContext *ctx_ptr )
|
||||
*ctx_ptr = NULL;
|
||||
}
|
||||
|
||||
static void OnDeleteSelector( void *data )
|
||||
{
|
||||
LCUI_Selector s = data;
|
||||
Selector_Delete( &s );
|
||||
}
|
||||
|
||||
/** 载入CSS代码块,用于实现CSS代码的分块载入 */
|
||||
static int LCUICSS_LoadBlock( CSSParserContext ctx, const char *str )
|
||||
static int LCUI_LoadCSSBlock( CSSParserContext ctx, const char *str )
|
||||
{
|
||||
size_t size = 0;
|
||||
LCUI_Selector s;
|
||||
@@ -707,7 +622,7 @@ static int LCUICSS_LoadBlock( CSSParserContext ctx, const char *str )
|
||||
ctx->buffer[ctx->pos] = 0;
|
||||
ctx->pos = 0;
|
||||
DEBUG_MSG("selector: %s\n", ctx->buffer);
|
||||
s = Selector(ctx->buffer);
|
||||
s = Selector( ctx->buffer );
|
||||
if( !s ) {
|
||||
// 解析出错 ...
|
||||
break;
|
||||
@@ -804,18 +719,17 @@ proc_comment:
|
||||
put_css:
|
||||
DEBUG_MSG("put css\n");
|
||||
/* 将记录的样式表添加至匹配到的选择器中 */
|
||||
LinkedList_ForEach( node, &ctx->selectors ) {
|
||||
LCUI_PutStyle( node->data, ctx->css );
|
||||
for( LinkedList_Each( node, &ctx->selectors ) ) {
|
||||
LCUI_PutStyleSheet( node->data, ctx->css, ctx->space );
|
||||
}
|
||||
LinkedList_Clear( &ctx->selectors, OnDeleteSelector );
|
||||
StyleSheet_Delete( &ctx->css );
|
||||
LinkedList_Clear( &ctx->selectors, (FuncPtr)Selector_Delete );
|
||||
StyleSheet_Delete( ctx->css );
|
||||
continue;
|
||||
select_parser:
|
||||
ctx->target = TARGET_VALUE;
|
||||
ctx->buffer[ctx->pos] = 0;
|
||||
ctx->pos = 0;
|
||||
ctx->parser = RBTree_CustomGetData( &self.parser_tree,
|
||||
ctx->buffer );
|
||||
ctx->parser = Dict_FetchValue( self.parsers, ctx->buffer );
|
||||
DEBUG_MSG("select style: %s, parser: %p\n",
|
||||
ctx->buffer, ctx->parser);
|
||||
continue;
|
||||
@@ -839,7 +753,7 @@ parse_value:
|
||||
}
|
||||
|
||||
/** 从文件中载入CSS样式数据,并导入至样式库中 */
|
||||
int LCUICSS_LoadFile( const char *filepath )
|
||||
int LCUI_LoadCSSFile( const char *filepath )
|
||||
{
|
||||
int n;
|
||||
FILE *fp;
|
||||
@@ -850,11 +764,11 @@ int LCUICSS_LoadFile( const char *filepath )
|
||||
if( !fp ) {
|
||||
return -1;
|
||||
}
|
||||
ctx = NewCSSParserContext( 512 );
|
||||
ctx = NewCSSParserContext( 512, filepath );
|
||||
n = fread( buff, 1, 511, fp );
|
||||
while( n > 0 ) {
|
||||
buff[n] = 0;
|
||||
LCUICSS_LoadBlock( ctx, buff );
|
||||
LCUI_LoadCSSBlock( ctx, buff );
|
||||
n = fread( buff, 1, 511, fp );
|
||||
}
|
||||
DeleteCSSParserContext( &ctx );
|
||||
@@ -862,76 +776,62 @@ int LCUICSS_LoadFile( const char *filepath )
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** 从字符串中解析出样式,并导入至样式库中 */
|
||||
int LCUICSS_LoadString( const char *str )
|
||||
int LCUI_LoadCSSString( const char *str, const char *space )
|
||||
{
|
||||
int len = 1;
|
||||
const char *cur;
|
||||
CSSParserContext ctx;
|
||||
DEBUG_MSG("parse begin\n");
|
||||
ctx = NewCSSParserContext( 512 );
|
||||
ctx = NewCSSParserContext( 512, space );
|
||||
for( cur = str; len > 0; cur += len ) {
|
||||
len = LCUICSS_LoadBlock( ctx, cur );
|
||||
len = LCUI_LoadCSSBlock( ctx, cur );
|
||||
}
|
||||
DeleteCSSParserContext( &ctx );
|
||||
DEBUG_MSG("parse end\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** 获取当前记录的样式属性的总数 */
|
||||
int LCUICSS_GetStyleTotal(void)
|
||||
int LCUI_AddCSSParser( LCUI_StyleParser sp )
|
||||
{
|
||||
return self.count;
|
||||
}
|
||||
|
||||
/** 注册新的属性和对应的属性值解析器 */
|
||||
int LCUICSS_AddParser( LCUI_StyleParser sp )
|
||||
{
|
||||
int key;
|
||||
LCUI_StyleParser new_sp;
|
||||
if( !sp->name || strlen(sp->name) < 1 ) {
|
||||
if( !sp->name || strlen( sp->name ) < 1 ) {
|
||||
return -1;
|
||||
}
|
||||
if( RBTree_CustomSearch(&self.name_tree, sp->name) ) {
|
||||
if( Dict_FetchValue( self.parsers, sp->name ) ) {
|
||||
return -2;
|
||||
}
|
||||
key = self.count++;
|
||||
new_sp = NEW(LCUI_StyleParserRec, 1);
|
||||
self.count += 1;
|
||||
new_sp = NEW( LCUI_StyleParserRec, 1 );
|
||||
new_sp->key = sp->key;
|
||||
new_sp->parse = sp->parse;
|
||||
new_sp->name = strdup( sp->name );
|
||||
RBTree_Insert( &self.name_tree, key, new_sp->name );
|
||||
RBTree_CustomInsert( &self.parser_tree, new_sp->name, new_sp );
|
||||
return key;
|
||||
Dict_Add( self.parsers, new_sp->name, new_sp );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void DestroyStyleParser( void *privdata, void *val )
|
||||
{
|
||||
LCUI_StyleParser sp = val;
|
||||
free( sp->name );
|
||||
free( sp );
|
||||
}
|
||||
|
||||
/** 初始化 LCUI 的 CSS 代码解析功能 */
|
||||
void LCUICSS_Init(void)
|
||||
void LCUI_InitCSSParser( void )
|
||||
{
|
||||
KeyNameGroup *skn, *skn_end;
|
||||
LCUI_StyleParser new_sp, sp, sp_end;
|
||||
/* 构建一个红黑树,方便按名称查找解析器 */
|
||||
RBTree_Init( &self.parser_tree );
|
||||
RBTree_Init( &self.option_tree );
|
||||
RBTree_Init( &self.name_tree );
|
||||
RBTree_SetDataNeedFree( &self.parser_tree, TRUE );
|
||||
RBTree_SetDataNeedFree( &self.option_tree, FALSE );
|
||||
RBTree_SetDataNeedFree( &self.name_tree, FALSE );
|
||||
RBTree_OnJudge( &self.parser_tree, CompareParserName );
|
||||
RBTree_OnJudge( &self.option_tree, CompareName );
|
||||
skn = style_name_map;
|
||||
skn_end = skn + sizeof(style_name_map)/sizeof(KeyNameGroup);
|
||||
for( ; skn < skn_end; ++skn ) {
|
||||
RBTree_Insert( &self.name_tree, skn->key, skn->name );
|
||||
}
|
||||
sp = style_parser_map;
|
||||
sp_end = sp + sizeof(style_parser_map)/sizeof(LCUI_StyleParserRec);
|
||||
for( ; sp < sp_end; ++sp ) {
|
||||
new_sp = malloc(sizeof(LCUI_StyleParserRec));
|
||||
|
||||
self.count = 0;
|
||||
self.dicttype = DictType_StringKey;
|
||||
self.dicttype.valDestructor = DestroyStyleParser;
|
||||
self.parsers = Dict_Create( &self.dicttype, NULL );
|
||||
sp_end = style_parser_map + LEN( style_parser_map );
|
||||
for( sp = style_parser_map; sp < sp_end; ++sp ) {
|
||||
new_sp = malloc( sizeof( LCUI_StyleParserRec ) );
|
||||
new_sp->key = sp->key;
|
||||
new_sp->parse = sp->parse;
|
||||
if( !sp->name && sp->key >= 0 ) {
|
||||
const char *name = GetStyleName(sp->key);
|
||||
const char *name = LCUI_GetStyleName( sp->key );
|
||||
if( !name ) {
|
||||
free( new_sp );
|
||||
continue;
|
||||
@@ -940,17 +840,11 @@ void LCUICSS_Init(void)
|
||||
} else {
|
||||
new_sp->name = strdup( sp->name );
|
||||
}
|
||||
RBTree_CustomInsert( &self.parser_tree, new_sp->name, new_sp );
|
||||
Dict_Add( self.parsers, new_sp->name, new_sp );
|
||||
}
|
||||
skn = style_option_map;
|
||||
skn_end = skn + sizeof(style_option_map)/sizeof(KeyNameGroup);
|
||||
for( ; skn < skn_end; ++skn ) {
|
||||
RBTree_CustomInsert( &self.option_tree, skn->name, skn );
|
||||
}
|
||||
self.count = STYLE_KEY_TOTAL;
|
||||
}
|
||||
|
||||
void LCUICSS_Destroy(void)
|
||||
void LCUI_ExitCSSParser( void )
|
||||
{
|
||||
|
||||
Dict_Release( self.parsers );
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -105,6 +105,10 @@ button:active {
|
||||
background-color:rgb(215,215,215);
|
||||
}
|
||||
|
||||
button:disabled textview {
|
||||
color: #aaa;
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
/** 添加按钮部件类型 */
|
||||
@@ -113,7 +117,8 @@ void LCUIWidget_AddButton( void )
|
||||
LCUI_WidgetClass *wc = LCUIWidget_AddClass( "button" );
|
||||
wc->methods.init = Button_OnInit;
|
||||
wc->methods.paint = Button_OnPaint;
|
||||
wc->methods.set_text = Button_SetText;
|
||||
wc->methods.destroy = Button_OnDestroy;
|
||||
wc->task_handler = Button_OnTask;
|
||||
LCUICSS_LoadString( button_css );
|
||||
LCUI_LoadCSSString( button_css, NULL );
|
||||
}
|
||||
|
||||
+213
-32
@@ -37,26 +37,46 @@
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <LCUI_Build.h>
|
||||
#include <LCUI/LCUI.h>
|
||||
#include <LCUI/font.h>
|
||||
#include <LCUI/cursor.h>
|
||||
#include <LCUI/timer.h>
|
||||
#include <LCUI/gui/widget.h>
|
||||
#include <LCUI/gui/widget/scrollbar.h>
|
||||
|
||||
#define EFFECT_FRAMES 50
|
||||
|
||||
/** 惯性滚动效果的相关数据 */
|
||||
typedef struct InertialScrollingRec_ {
|
||||
int start_pos; /**< 起始位置 */
|
||||
int end_pos; /**< 结束位置 */
|
||||
int timer; /**< 定时器 */
|
||||
int interval; /**< 定时器的间隔时间 */
|
||||
int speed; /**< 滚动速度 */
|
||||
int speed_delta; /**< 速度差(加速度) */
|
||||
int64_t timestamp; /**< 开始时间 */
|
||||
LCUI_BOOL is_running; /**< 当前效果是否正在运行 */
|
||||
} InertialScrollingRec, *InertialScrolling;
|
||||
|
||||
/** 滚动条的相关数据 */
|
||||
typedef struct LCUI_ScrollBarRec_ {
|
||||
LCUI_Widget box; /**< 容器 */
|
||||
LCUI_Widget layer; /**< 滚动层 */
|
||||
LCUI_Widget slider; /**< 滑块 */
|
||||
LCUI_BOOL is_dragging; /**< 是否处于拖拽状态 */
|
||||
int slider_x, slider_y; /**< 拖拽开始时的滑块位置 */
|
||||
int mouse_x, mouse_y; /**< 拖拽开始时的鼠标坐标 */
|
||||
int direction; /**< 滚动条的方向(垂直或水平) */
|
||||
int eids[2]; /**< 鼠标事件的绑定ID */
|
||||
int scroll_step; /**< 每次滚动的距离,主要针对使用鼠标滚轮触发的滚动 */
|
||||
int pos; /**< 当前的位置 */
|
||||
LCUI_Widget box; /**< 容器 */
|
||||
LCUI_Widget layer; /**< 滚动层 */
|
||||
LCUI_Widget slider; /**< 滑块 */
|
||||
LCUI_BOOL is_dragging; /**< 是否处于拖拽状态 */
|
||||
int slider_x, slider_y; /**< 拖拽开始时的滑块位置 */
|
||||
int mouse_x, mouse_y; /**< 拖拽开始时的鼠标坐标 */
|
||||
int touch_point_id; /**< 触点的ID */
|
||||
int direction; /**< 滚动条的方向(垂直或水平) */
|
||||
int scroll_step; /**< 每次滚动的距离,主要针对使用鼠标滚轮触发的滚动 */
|
||||
int pos; /**< 当前的位置 */
|
||||
int old_pos; /**< 拖拽开始时的位置 */
|
||||
int distance; /**< 滚动距离 */
|
||||
InertialScrollingRec effect; /**< 用于实现惯性滚动效果的相关数据 */
|
||||
} LCUI_ScrollBarRec, *LCUI_ScrollBar;
|
||||
|
||||
static int scroll_event_id = -1;
|
||||
@@ -77,6 +97,8 @@ top: 0;
|
||||
left: 0;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
min-width: 14px;
|
||||
min-height: 14px;
|
||||
position: absolute;
|
||||
background-color: #888;
|
||||
}
|
||||
@@ -96,24 +118,78 @@ top: auto;
|
||||
|
||||
);
|
||||
|
||||
static void OnMouseUp( LCUI_SysEvent e, void *arg )
|
||||
static void OnInertialScrolling( void *arg )
|
||||
{
|
||||
LCUI_Widget w = e->data;
|
||||
LCUI_ScrollBar scrollbar = w->private_data;
|
||||
LCUI_UnbindEvent( scrollbar->eids[0] );
|
||||
LCUI_UnbindEvent( scrollbar->eids[1] );
|
||||
scrollbar->eids[0] = -1;
|
||||
scrollbar->eids[1] = -1;
|
||||
scrollbar->is_dragging = FALSE;
|
||||
int pos;
|
||||
LCUI_Widget w = arg;
|
||||
LCUI_ScrollBar scrollbar;
|
||||
InertialScrolling effect;
|
||||
scrollbar = w->private_data;
|
||||
effect = &scrollbar->effect;
|
||||
pos = scrollbar->pos + effect->speed;
|
||||
effect->speed += effect->speed_delta;
|
||||
ScrollBar_SetPosition( w, pos );
|
||||
if( effect->speed == 0 || !effect->is_running ||
|
||||
(effect->speed_delta > 0) == (effect->speed > 0) ) {
|
||||
effect->speed = 0;
|
||||
effect->timer = -1;
|
||||
effect->is_running = FALSE;
|
||||
return;
|
||||
}
|
||||
effect->timer = LCUITimer_Set( effect->interval,
|
||||
OnInertialScrolling, w, FALSE );
|
||||
}
|
||||
|
||||
static void OnMouseMove( LCUI_SysEvent e, void *arg )
|
||||
static void ScrollBar_UpdateInertialScrolling( LCUI_Widget w )
|
||||
{
|
||||
LCUI_ScrollBar scrollbar;
|
||||
scrollbar = w->private_data;
|
||||
scrollbar->effect.speed = 0;
|
||||
scrollbar->effect.is_running = FALSE;
|
||||
scrollbar->effect.start_pos = scrollbar->pos;
|
||||
scrollbar->effect.timestamp = LCUI_GetTime();
|
||||
}
|
||||
|
||||
static void ScrollBar_StartInertialScrolling( LCUI_Widget w )
|
||||
{
|
||||
int distance;
|
||||
int64_t time_delta;
|
||||
LCUI_ScrollBar scrollbar;
|
||||
InertialScrolling effect;
|
||||
scrollbar = w->private_data;
|
||||
effect = &scrollbar->effect;
|
||||
effect->end_pos = scrollbar->pos;
|
||||
distance = effect->end_pos - effect->start_pos;
|
||||
time_delta = LCUI_GetTimeDelta( effect->timestamp );
|
||||
/* 计算每一帧的滚动距离(速度) */
|
||||
if( time_delta > 0 ) {
|
||||
effect->speed = distance * effect->interval / (int)time_delta;
|
||||
} else {
|
||||
effect->speed = 0;
|
||||
}
|
||||
/* 计算加速度,该值的正负符号始终与速度值的相反 */
|
||||
if( (effect->speed > 0) == (effect->speed_delta > 0) ) {
|
||||
effect->speed_delta = -effect->speed_delta;
|
||||
}
|
||||
effect->timestamp = LCUI_GetTime();
|
||||
if( effect->is_running ) {
|
||||
return;
|
||||
}
|
||||
effect->is_running = TRUE;
|
||||
effect->timer = LCUITimer_Set( effect->interval,
|
||||
OnInertialScrolling, w, FALSE );
|
||||
DEBUG_MSG("start_pos: %d, end_pos: %d\n", effect->start_pos, effect->end_pos);
|
||||
DEBUG_MSG("effect->speed: %d, distance: %d, time: %d\n",
|
||||
effect->speed, distance, (int)time_delta);
|
||||
}
|
||||
|
||||
static void Slider_OnMouseMove( LCUI_Widget slider,
|
||||
LCUI_WidgetEvent e, void *arg )
|
||||
{
|
||||
float n;
|
||||
LCUI_Pos pos;
|
||||
LCUI_Widget w = e->data;
|
||||
LCUI_ScrollBar scrollbar = w->private_data;
|
||||
LCUI_Widget slider = scrollbar->slider;
|
||||
LCUI_Widget layer = scrollbar->layer;
|
||||
int x, y, box_size, size, layer_pos;
|
||||
|
||||
@@ -179,23 +255,36 @@ static void OnMouseMove( LCUI_SysEvent e, void *arg )
|
||||
}
|
||||
scrollbar->pos = layer_pos;
|
||||
Widget_UpdateStyle( layer, FALSE );
|
||||
Widget_Move( scrollbar->slider, x, y );
|
||||
Widget_Move( slider, x, y );
|
||||
}
|
||||
|
||||
static void OnMouseDown( LCUI_Widget slider, LCUI_WidgetEvent e, void *arg )
|
||||
static void Slider_OnMouseUp( LCUI_Widget slider,
|
||||
LCUI_WidgetEvent e, void *arg )
|
||||
{
|
||||
LCUI_Widget w = slider->parent;
|
||||
LCUI_Widget w = e->data;
|
||||
LCUI_ScrollBar scrollbar = w->private_data;
|
||||
Widget_UnbindEvent( slider, "mousemove", Slider_OnMouseMove );
|
||||
Widget_UnbindEvent( slider, "mouseup", Slider_OnMouseUp );
|
||||
Widget_ReleaseMouseCapture( slider );
|
||||
scrollbar->is_dragging = FALSE;
|
||||
}
|
||||
|
||||
static void Slider_OnMouseDown( LCUI_Widget slider,
|
||||
LCUI_WidgetEvent e, void *arg )
|
||||
{
|
||||
LCUI_Widget w = e->data;
|
||||
LCUI_ScrollBar scrollbar = w->private_data;
|
||||
if( scrollbar->is_dragging ) {
|
||||
return;
|
||||
}
|
||||
scrollbar->slider_x = slider->x;
|
||||
scrollbar->slider_y = slider->y;
|
||||
scrollbar->mouse_x = e->screen_x;
|
||||
scrollbar->mouse_y = e->screen_y;
|
||||
scrollbar->mouse_x = e->motion.x;
|
||||
scrollbar->mouse_y = e->motion.y;
|
||||
scrollbar->is_dragging = TRUE;
|
||||
scrollbar->eids[0] = LCUI_BindEvent( LCUI_MOUSEMOVE, OnMouseMove, w, NULL );
|
||||
scrollbar->eids[1] = LCUI_BindEvent( LCUI_MOUSEUP, OnMouseUp, w, NULL );
|
||||
Widget_SetMouseCapture( slider );
|
||||
Widget_BindEvent( slider, "mousemove", Slider_OnMouseMove, w, NULL );
|
||||
Widget_BindEvent( slider, "mouseup", Slider_OnMouseUp, w, NULL );
|
||||
}
|
||||
|
||||
static void ScrollBar_OnInit( LCUI_Widget w )
|
||||
@@ -204,16 +293,27 @@ static void ScrollBar_OnInit( LCUI_Widget w )
|
||||
LCUI_ScrollBar self;
|
||||
slider = LCUIWidget_New( NULL );
|
||||
self = Widget_NewPrivateData( w, LCUI_ScrollBarRec );
|
||||
Widget_BindEvent( slider, "mousedown", OnMouseDown, NULL, NULL );
|
||||
Widget_AddClass( slider, "slider" );
|
||||
Widget_Append( w, slider );
|
||||
self->direction = SBD_VERTICAL;
|
||||
self->is_dragging = FALSE;
|
||||
self->scroll_step = 40;
|
||||
self->slider = slider;
|
||||
self->layer = NULL;
|
||||
self->box = NULL;
|
||||
self->old_pos = 0;
|
||||
self->pos = 0;
|
||||
self->touch_point_id = -1;
|
||||
self->effect.timer = -1;
|
||||
self->effect.end_pos = 0;
|
||||
self->effect.start_pos = 0;
|
||||
self->effect.timestamp = 0;
|
||||
self->effect.speed = 0;
|
||||
self->effect.speed_delta = 1;
|
||||
self->effect.is_running = FALSE;
|
||||
self->effect.interval = 1000 / EFFECT_FRAMES;
|
||||
Widget_BindEvent( slider, "mousedown",
|
||||
Slider_OnMouseDown, w, NULL );
|
||||
Widget_AddClass( slider, "slider" );
|
||||
Widget_Append( w, slider );
|
||||
}
|
||||
|
||||
static void ScrollBar_UpdateSize( LCUI_Widget w )
|
||||
@@ -222,6 +322,9 @@ static void ScrollBar_UpdateSize( LCUI_Widget w )
|
||||
int size, box_size;
|
||||
LCUI_ScrollBar scrollbar = w->private_data;
|
||||
LCUI_Widget slider = scrollbar->slider;
|
||||
if( !scrollbar->box ) {
|
||||
return;
|
||||
}
|
||||
if( scrollbar->direction == SBD_HORIZONTAL ) {
|
||||
if( scrollbar->layer ) {
|
||||
size = scrollbar->layer->box.outer.width;
|
||||
@@ -259,7 +362,7 @@ static void ScrollLayer_OnWheel( LCUI_Widget layer, LCUI_WidgetEvent e, void *ar
|
||||
LCUI_Widget w = e->data;
|
||||
LCUI_ScrollBar scrollbar = w->private_data;
|
||||
int pos = ScrollBar_GetPosition( w );
|
||||
if( e->z_delta > 0 ) {
|
||||
if( e->wheel.delta > 0 ) {
|
||||
pos -= scrollbar->scroll_step;
|
||||
} else {
|
||||
pos += scrollbar->scroll_step;
|
||||
@@ -267,6 +370,83 @@ static void ScrollLayer_OnWheel( LCUI_Widget layer, LCUI_WidgetEvent e, void *ar
|
||||
ScrollBar_SetPosition( w, pos );
|
||||
}
|
||||
|
||||
/** 滚动层的触屏事件响应 */
|
||||
static void ScrollLayer_OnTouch( LCUI_Widget layer, LCUI_WidgetEvent e, void *arg )
|
||||
{
|
||||
int i, pos, distance;
|
||||
LCUI_TouchPoint point;
|
||||
LCUI_Widget w = e->data;
|
||||
LCUI_ScrollBar scrollbar;
|
||||
if( e->touch.n_points < 1 ) {
|
||||
return;
|
||||
}
|
||||
scrollbar = w->private_data;
|
||||
if( scrollbar->touch_point_id == -1 ) {
|
||||
point = &e->touch.points[0];
|
||||
/* 如果这个触点的状态不是 TOUCHDOWN,则说明是上次触控拖拽操
|
||||
* 作时的多余触点,直接忽略这次触控事件 */
|
||||
if( point->state != WET_TOUCHDOWN ) {
|
||||
return;
|
||||
}
|
||||
scrollbar->touch_point_id = point->id;
|
||||
} else {
|
||||
for( point = NULL, i = 0; i < e->touch.n_points; ++i ) {
|
||||
point = &e->touch.points[i];
|
||||
if( point->id == scrollbar->touch_point_id ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( !point ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
switch( point->state ) {
|
||||
case WET_TOUCHDOWN:
|
||||
scrollbar->distance = 0;
|
||||
scrollbar->effect.speed = 0;
|
||||
scrollbar->effect.is_running = FALSE;
|
||||
scrollbar->old_pos = scrollbar->pos;
|
||||
if( scrollbar->is_dragging ) {
|
||||
return;
|
||||
}
|
||||
Widget_SetTouchCapture( layer, point->id );
|
||||
scrollbar->mouse_x = point->x;
|
||||
scrollbar->mouse_y = point->y;
|
||||
break;
|
||||
case WET_TOUCHUP:
|
||||
Widget_ReleaseTouchCapture( layer, -1 );
|
||||
if( scrollbar->is_dragging ) {
|
||||
ScrollBar_StartInertialScrolling( w );
|
||||
}
|
||||
scrollbar->touch_point_id = -1;
|
||||
scrollbar->is_dragging = FALSE;
|
||||
Widget_BlockEvent( layer, FALSE );
|
||||
break;
|
||||
case WET_TOUCHMOVE:
|
||||
pos = scrollbar->old_pos;
|
||||
if( scrollbar->direction == SBD_HORIZONTAL ) {
|
||||
pos -= point->x - scrollbar->mouse_x;
|
||||
} else {
|
||||
pos -= point->y - scrollbar->mouse_y;
|
||||
}
|
||||
if( pos != scrollbar->pos ) {
|
||||
if( !scrollbar->is_dragging ) {
|
||||
scrollbar->is_dragging = TRUE;
|
||||
LCUIWidget_ClearEventTarget( NULL );
|
||||
Widget_BlockEvent( layer, TRUE );
|
||||
}
|
||||
distance = pos - scrollbar->pos;
|
||||
if( (scrollbar->distance > 0) != (distance > 0) ||
|
||||
scrollbar->distance == 0 ) {
|
||||
ScrollBar_UpdateInertialScrolling( w );
|
||||
}
|
||||
scrollbar->distance = distance;
|
||||
}
|
||||
ScrollBar_SetPosition( w, pos );
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
static void ScrollBar_OnUpdateSize( LCUI_Widget box, LCUI_WidgetEvent e, void *arg )
|
||||
{
|
||||
ScrollBar_UpdateSize( e->data );
|
||||
@@ -294,6 +474,7 @@ void ScrollBar_BindLayer( LCUI_Widget w, LCUI_Widget layer )
|
||||
scrollbar->layer = layer;
|
||||
Widget_BindEvent( layer, "resize", ScrollBar_OnUpdateSize, w, NULL );
|
||||
Widget_BindEvent( layer, "mousewheel", ScrollLayer_OnWheel, w, NULL );
|
||||
Widget_BindEvent( layer, "touch", ScrollLayer_OnTouch, w, NULL );
|
||||
ScrollBar_UpdateSize( w );
|
||||
}
|
||||
|
||||
@@ -398,5 +579,5 @@ void LCUIWidget_AddTScrollBar( void )
|
||||
wc->methods.set_attr = ScrollBar_OnSetAttr;
|
||||
scroll_event_id = LCUIWidget_AllocEventId();
|
||||
LCUIWidget_SetEventName( scroll_event_id, "scroll" );
|
||||
LCUICSS_LoadString( scrollbar_css );
|
||||
LCUI_LoadCSSString( scrollbar_css, NULL );
|
||||
}
|
||||
|
||||
@@ -181,5 +181,5 @@ void LCUIWidget_AddSideBar(void)
|
||||
wc->methods.destroy = SideBarItem_OnDestroy;
|
||||
wc = LCUIWidget_AddClass("sidebar-toggle");
|
||||
wc->methods.init = SideBarToggle_OnInit;
|
||||
LCUICSS_LoadString( sidebar_css );
|
||||
LCUI_LoadCSSString( sidebar_css, NULL );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,929 @@
|
||||
/* ***************************************************************************
|
||||
* textedit.c -- textedit widget, used to allow user edit text.
|
||||
*
|
||||
* Copyright (C) 2016 by Liu Chao <lc-soft@live.cn>
|
||||
*
|
||||
* This file is part of the LCUI project, and may only be used, modified, and
|
||||
* distributed under the terms of the GPLv2.
|
||||
*
|
||||
* (GPLv2 is abbreviation of GNU General Public License Version 2)
|
||||
*
|
||||
* By continuing to use, modify, or distribute this file you indicate that you
|
||||
* have read the license and understand and accept it fully.
|
||||
*
|
||||
* The LCUI project is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for more details.
|
||||
*
|
||||
* You should have received a copy of the GPLv2 along with this file. It is
|
||||
* usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* textedit.c -- 文本编辑部件,用于让用户编辑文本。
|
||||
*
|
||||
* 版权所有 (C) 2016 归属于 刘超 <lc-soft@live.cn>
|
||||
*
|
||||
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
|
||||
*
|
||||
* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
|
||||
*
|
||||
* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。
|
||||
*
|
||||
* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特
|
||||
* 定用途的隐含担保,详情请参照GPLv2许可协议。
|
||||
*
|
||||
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
//#define DEBUG
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <LCUI_Build.h>
|
||||
#include <LCUI/LCUI.h>
|
||||
#include <LCUI/graph.h>
|
||||
#include <LCUI/font.h>
|
||||
#include <LCUI/input.h>
|
||||
#include <LCUI/timer.h>
|
||||
#include <LCUI/gui/widget.h>
|
||||
#include <LCUI/gui/widget/textedit.h>
|
||||
#include <LCUI/ime.h>
|
||||
|
||||
#define CARET_HIDE 0
|
||||
#define CARET_SHOW 1
|
||||
#define TBT_SIZE 512
|
||||
|
||||
enum TaskType {
|
||||
TASK_SET_TEXT,
|
||||
TASK_UPDATE,
|
||||
TASK_UPDATE_CARET,
|
||||
TASK_TOTAL
|
||||
};
|
||||
|
||||
/** 文本插入符相关数据 */
|
||||
typedef struct LCUI_TextCaretRec_ {
|
||||
int type;
|
||||
int state; /**< 当前状态 */
|
||||
int blink_time; /**< 闪烁间隔 */
|
||||
int timer_id; /**< 定时器 */
|
||||
LCUI_BOOL need_show;
|
||||
} LCUI_TextCaretRec, *LCUI_TextCaret;
|
||||
|
||||
typedef struct LCUI_TextEditRec_ {
|
||||
LCUI_TextLayer layer_source; /**< 实际文本层 */
|
||||
LCUI_TextLayer layer_mask; /**< 屏蔽后的文本层 */
|
||||
LCUI_TextLayer layer_placeholder; /**< 占位符的文本层 */
|
||||
LCUI_TextLayer layer; /**< 当前使用的文本层 */
|
||||
LCUI_Widget scrollbars[2]; /**< 两个滚动条 */
|
||||
LCUI_Widget caret; /**< 文本插入符 */
|
||||
LCUI_BOOL is_read_only; /**< 是否只读 */
|
||||
LCUI_BOOL is_multiline_mode; /**< 是否为多行模式 */
|
||||
LCUI_BOOL is_placeholder_shown; /**< 是否已经显示占位符 */
|
||||
wchar_t *allow_input_char; /**< 允许输入的字符 */
|
||||
wchar_t password_char; /**< 屏蔽符的副本 */
|
||||
int text_block_size; /**< 块大小 */
|
||||
LinkedList text_blocks; /**< 文本块缓冲区 */
|
||||
LinkedList text_tags; /**< 当前处理的标签列表 */
|
||||
LCUI_BOOL tasks[TASK_TOTAL]; /**< 待处理的任务 */
|
||||
LCUI_Mutex mutex; /**< 互斥锁 */
|
||||
} LCUI_TextEditRec, *LCUI_TextEdit;
|
||||
|
||||
enum TextBlockType {
|
||||
TBT_BEGIN,
|
||||
TBT_BODY,
|
||||
TBT_END
|
||||
};
|
||||
|
||||
enum TextBlockAddType {
|
||||
TBAT_INSERT,
|
||||
TBAT_APPEND
|
||||
};
|
||||
|
||||
enum TextBlockOwnerType {
|
||||
TBOT_SOURCE,
|
||||
TBOT_PLACEHOLDER
|
||||
};
|
||||
|
||||
/** 文本块数据结构 */
|
||||
typedef struct LCUI_TextBlockRec_ {
|
||||
int type; /**< 文本块类型 */
|
||||
int owner; /**< 所属的文本层 */
|
||||
int add_type; /**< 指定该文本块的添加方式 */
|
||||
wchar_t *text; /**< 文本块(段) */
|
||||
} LCUI_TextBlockRec, *LCUI_TextBlock;
|
||||
|
||||
static int textedit_event_id = -1;
|
||||
|
||||
/*---------------------------------- Caret ----------------------------------*/
|
||||
|
||||
static const char *textcaret_css = ToString(
|
||||
textcaret {
|
||||
pointer-events: none;
|
||||
focusable: false;
|
||||
width: 1px;
|
||||
height:14px;
|
||||
position: absolute;
|
||||
background-color: #000;
|
||||
}
|
||||
);
|
||||
|
||||
static const char *textedit_css = ToString(
|
||||
|
||||
textedit {
|
||||
min-width: 124px;
|
||||
min-height: 14px;
|
||||
background-color: #fff;
|
||||
border: 1px solid #eee;
|
||||
padding: 5px 10px;
|
||||
}
|
||||
textedit:focus {
|
||||
border: 1px solid #2196F3;
|
||||
box-shadow: 0 0 6px rgba(33,150,243,0.4);
|
||||
}
|
||||
|
||||
textedit:disabled {
|
||||
background-color: #eaeaea;
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
static void TextCaret_BlinkShow( LCUI_Widget widget )
|
||||
{
|
||||
LCUI_TextCaret caret = widget->private_data;
|
||||
if( !caret->need_show ) {
|
||||
return;
|
||||
}
|
||||
caret->state = CARET_SHOW;
|
||||
LCUITimer_Reset( caret->timer_id, caret->blink_time );
|
||||
Widget_Show( widget );
|
||||
}
|
||||
|
||||
static void TextCaret_BlinkHide( LCUI_Widget widget )
|
||||
{
|
||||
LCUI_TextCaret caret = widget->private_data;
|
||||
caret->state = CARET_HIDE;
|
||||
LCUITimer_Reset( caret->timer_id, caret->blink_time );
|
||||
Widget_Hide( widget );
|
||||
}
|
||||
|
||||
static void TextCaret_OnBlink( void *arg )
|
||||
{
|
||||
LCUI_Widget widget = arg;
|
||||
LCUI_TextCaret caret = widget->private_data;
|
||||
if( caret->need_show ) {
|
||||
if( caret->state == CARET_HIDE ) {
|
||||
caret->state = CARET_SHOW;
|
||||
Widget_Show( widget );
|
||||
} else {
|
||||
caret->state = CARET_HIDE;
|
||||
Widget_Hide( widget );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void TextCaret_SetVisible( LCUI_Widget widget, LCUI_BOOL visible )
|
||||
{
|
||||
LCUI_TextCaret caret = widget->private_data;
|
||||
caret->need_show = visible;
|
||||
if( caret->need_show ) {
|
||||
TextCaret_BlinkShow( widget );
|
||||
} else {
|
||||
TextCaret_BlinkHide( widget );
|
||||
}
|
||||
}
|
||||
|
||||
static void TextCaret_OnInit( LCUI_Widget widget )
|
||||
{
|
||||
LCUI_TextCaret caret;
|
||||
caret = Widget_NewPrivateData( widget, LCUI_TextCaretRec );
|
||||
caret->type = 0;
|
||||
caret->need_show = FALSE;
|
||||
caret->state = CARET_HIDE;
|
||||
caret->blink_time = 500;
|
||||
caret->timer_id = LCUITimer_Set( caret->blink_time,
|
||||
TextCaret_OnBlink, widget, TRUE );
|
||||
}
|
||||
|
||||
/** 设置闪烁的时间间隔 */
|
||||
static void TextCaret_SetBlinkTime( LCUI_Widget widget, unsigned int n_ms )
|
||||
{
|
||||
LCUI_TextCaret caret = widget->private_data;
|
||||
caret->blink_time = n_ms;
|
||||
LCUITimer_Reset( caret->timer_id, caret->blink_time );
|
||||
}
|
||||
|
||||
/** 销毁插入符 */
|
||||
static void TextCaret_OnDestroy( LCUI_Widget widget )
|
||||
{
|
||||
LCUI_TextCaret caret = widget->private_data;
|
||||
LCUITimer_Free( caret->timer_id );
|
||||
caret->timer_id = -1;
|
||||
}
|
||||
|
||||
static void LCUIWidget_AddTextCaret( void )
|
||||
{
|
||||
LCUI_WidgetClass *wc = LCUIWidget_AddClass( "textcaret" );
|
||||
wc->methods.init = TextCaret_OnInit;
|
||||
wc->methods.destroy = TextCaret_OnDestroy;
|
||||
LCUI_LoadCSSString( textcaret_css, NULL );
|
||||
}
|
||||
|
||||
/*-------------------------------- End Caret --------------------------------*/
|
||||
|
||||
static void TextEdit_UpdateCaret( LCUI_Widget widget )
|
||||
{
|
||||
LCUI_Pos pos;
|
||||
LCUI_StyleSheet sheet;
|
||||
LCUI_TextEdit edit = widget->private_data;
|
||||
int offset_x = 0, offset_y = 0, height, row;
|
||||
|
||||
if( edit->is_placeholder_shown ) {
|
||||
pos.x = pos.y = 0;
|
||||
} else {
|
||||
if( TextLayer_GetCaretPixelPos( edit->layer, &pos ) != 0 ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
row = edit->layer->insert_y;
|
||||
sheet = edit->caret->custom_style;
|
||||
height = TextLayer_GetRowHeight( edit->layer, row );
|
||||
SetStyle( sheet, key_height, height, px );
|
||||
pos.x += widget->padding.left;
|
||||
pos.y += widget->padding.top;
|
||||
if( pos.x > widget->box.content.width ) {
|
||||
offset_x = widget->box.content.width - pos.x;
|
||||
offset_x -= edit->caret->width;
|
||||
pos.x += offset_x;
|
||||
}
|
||||
if( pos.y > widget->box.content.height ) {
|
||||
offset_y = widget->box.content.height - pos.y;
|
||||
offset_y -= edit->caret->height;
|
||||
pos.y += offset_y;
|
||||
}
|
||||
TextLayer_SetOffset( edit->layer, offset_x, offset_y );
|
||||
Widget_Move( edit->caret, pos.x, pos.y );
|
||||
edit->tasks[TASK_UPDATE] = TRUE;
|
||||
Widget_AddTask( widget, WTT_USER );
|
||||
TextCaret_BlinkShow( edit->caret );
|
||||
}
|
||||
|
||||
/** 移动文本框内的文本插入符的行列坐标 */
|
||||
static void TextEdit_MoveCaret( LCUI_Widget widget, int row, int col )
|
||||
{
|
||||
LCUI_TextEdit edit = widget->private_data;
|
||||
if( edit->is_placeholder_shown ) {
|
||||
row = col = 0;
|
||||
}
|
||||
TextLayer_SetCaretPos( edit->layer, row, col );
|
||||
TextEdit_UpdateCaret( widget );
|
||||
}
|
||||
|
||||
/*------------------------------- TextBlock ---------------------------------*/
|
||||
static void TextBlock_OnDestroy( void *arg )
|
||||
{
|
||||
LCUI_TextBlock blk = arg;
|
||||
free( blk->text );
|
||||
blk->text = NULL;
|
||||
free( blk );
|
||||
}
|
||||
|
||||
static int TextEdit_AddTextToBuffer( LCUI_Widget widget, const wchar_t *wtext,
|
||||
int add_type, int owner )
|
||||
{
|
||||
const wchar_t *p;
|
||||
LCUI_TextEdit edit;
|
||||
LCUI_TextBlock txtblk;
|
||||
int i, j, len, tag_len, size;
|
||||
|
||||
if( !wtext ) {
|
||||
return -1;
|
||||
}
|
||||
edit = widget->private_data;
|
||||
len = wcslen( wtext );
|
||||
for( i = 0; i < len; ++i ) {
|
||||
txtblk = NEW( LCUI_TextBlockRec, 1 );
|
||||
if( !txtblk ) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
txtblk->owner = owner;
|
||||
txtblk->add_type = add_type;
|
||||
size = edit->text_block_size;
|
||||
if( i == 0 ) {
|
||||
txtblk->type = TBT_BEGIN;
|
||||
} else if( len - i > edit->text_block_size ) {
|
||||
txtblk->type = TBT_BODY;
|
||||
} else {
|
||||
size = len - i;
|
||||
txtblk->type = TBT_END;
|
||||
}
|
||||
txtblk->text = NEW( wchar_t, size );
|
||||
if( !txtblk->text ) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
/* 如果未启用样式标签功能 */
|
||||
if( !edit->layer->is_using_style_tags ) {
|
||||
for( j = 0; i < len && j < size - 1; ++j, ++i ) {
|
||||
txtblk->text[j] = wtext[i];
|
||||
}
|
||||
--i;
|
||||
txtblk->text[j] = 0;
|
||||
LinkedList_Append( &edit->text_blocks, txtblk );
|
||||
continue;
|
||||
}
|
||||
for( j = 0; i < len && j < size - 1; ++j, ++i ) {
|
||||
wchar_t *text;
|
||||
txtblk->text[j] = wtext[i];
|
||||
/* 检测是否有样式标签 */
|
||||
p = scan_style_tag( wtext + i, NULL, 0, NULL );
|
||||
if( !p ) {
|
||||
p = scan_style_ending_tag( wtext + i, NULL );
|
||||
if( !p ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/* 计算标签的长度 */
|
||||
tag_len = p - wtext - i;
|
||||
/* 若当前块大小能够容纳这个标签 */
|
||||
if( j + tag_len <= size - 1 ) {
|
||||
continue;
|
||||
}
|
||||
/* 重新计算该文本块的大小,并重新分配内存空间 */
|
||||
size = j + tag_len + 1;
|
||||
text = realloc( txtblk->text, sizeof( wchar_t ) * size );
|
||||
if( !text ) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
txtblk->text = text;
|
||||
}
|
||||
--i;
|
||||
txtblk->text[j] = 0;
|
||||
/* 添加文本块至缓冲区 */
|
||||
LinkedList_Append( &edit->text_blocks, txtblk );
|
||||
}
|
||||
edit->tasks[TASK_SET_TEXT] = TRUE;
|
||||
Widget_AddTask( widget, WTT_USER );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** 更新文本框内的字体位图 */
|
||||
static void TextEdit_ProcTextBlock( LCUI_Widget widget, LCUI_TextBlock txtblk )
|
||||
{
|
||||
LinkedList *tags;
|
||||
LCUI_TextEdit edit;
|
||||
LCUI_TextLayer layer;
|
||||
edit = widget->private_data;
|
||||
switch( txtblk->owner ) {
|
||||
case TBOT_SOURCE:
|
||||
layer = edit->layer_source;
|
||||
tags = &edit->text_tags;
|
||||
break;
|
||||
case TBOT_PLACEHOLDER:
|
||||
layer = edit->layer_placeholder;
|
||||
tags = NULL;
|
||||
break;
|
||||
default:return;
|
||||
}
|
||||
switch( txtblk->add_type ) {
|
||||
case TBAT_APPEND:
|
||||
/* 将此文本块追加至文本末尾 */
|
||||
TextLayer_AppendTextW( layer, txtblk->text, tags );
|
||||
break;
|
||||
case TBAT_INSERT:
|
||||
/* 将此文本块插入至文本插入符所在处 */
|
||||
TextLayer_InsertTextW( layer, txtblk->text, tags );
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** 更新文本框的文本图层 */
|
||||
static void TextEdit_UpdateTextLayer( LCUI_Widget widget )
|
||||
{
|
||||
LinkedList rects;
|
||||
LCUI_TextEdit edit;
|
||||
LCUI_TextStyle style;
|
||||
LinkedListNode *node;
|
||||
LinkedList_Init( &rects );
|
||||
edit = widget->private_data;
|
||||
TextLayer_Update( edit->layer, &rects );
|
||||
for( LinkedList_Each( node, &rects ) ) {
|
||||
Widget_InvalidateArea( widget, node->data, SV_CONTENT_BOX );
|
||||
}
|
||||
LinkedList_Clear( &rects, free );
|
||||
TextLayer_ClearInvalidRect( edit->layer );
|
||||
TextStyle_Copy( &style, &edit->layer_source->text_style );
|
||||
style.has_fore_color = TRUE;
|
||||
style.fore_color.value = 0xC8C8C8;
|
||||
TextLayer_SetTextStyle( edit->layer_placeholder, &style );
|
||||
TextStyle_Destroy( &style );
|
||||
}
|
||||
|
||||
static void TextEdit_OnTask( LCUI_Widget widget )
|
||||
{
|
||||
LCUI_TextEdit edit = widget->private_data;
|
||||
if( edit->tasks[TASK_SET_TEXT] ) {
|
||||
LinkedList blocks;
|
||||
LinkedListNode *node;
|
||||
LCUI_WidgetEventRec ev;
|
||||
LinkedList_Init( &blocks );
|
||||
LCUIMutex_Lock( &edit->mutex );
|
||||
LinkedList_Concat( &blocks, &edit->text_blocks );
|
||||
LCUIMutex_Unlock( &edit->mutex );
|
||||
for( LinkedList_Each( node, &blocks ) ) {
|
||||
TextEdit_ProcTextBlock( widget, node->data );
|
||||
}
|
||||
LinkedList_Clear( &blocks, TextBlock_OnDestroy );
|
||||
ev.type = textedit_event_id;
|
||||
Widget_TriggerEvent( widget, &ev, NULL );
|
||||
edit->tasks[TASK_UPDATE_CARET] = TRUE;
|
||||
edit->tasks[TASK_SET_TEXT] = FALSE;
|
||||
edit->tasks[TASK_UPDATE] = TRUE;
|
||||
}
|
||||
if( edit->tasks[TASK_UPDATE] ) {
|
||||
LCUI_BOOL is_shown;
|
||||
TextEdit_UpdateTextLayer( widget );
|
||||
is_shown = edit->layer_source->length == 0;
|
||||
if( is_shown ) {
|
||||
edit->layer = edit->layer_placeholder;
|
||||
} else {
|
||||
edit->layer = edit->layer_source;
|
||||
}
|
||||
if( edit->is_placeholder_shown != is_shown ) {
|
||||
Widget_InvalidateArea( widget, NULL, SV_PADDING_BOX );
|
||||
}
|
||||
edit->is_placeholder_shown = is_shown;
|
||||
edit->tasks[TASK_UPDATE] = FALSE;
|
||||
}
|
||||
if( edit->tasks[TASK_UPDATE_CARET] ) {
|
||||
TextEdit_UpdateCaret( widget );
|
||||
edit->tasks[TASK_UPDATE_CARET] = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void TextEdit_AutoSize( LCUI_Widget widget, int *width, int *height )
|
||||
{
|
||||
LCUI_TextEdit edit;
|
||||
edit = widget->private_data;
|
||||
if( edit->is_multiline_mode ) {
|
||||
int i, n;
|
||||
*height = 0;
|
||||
n = TextLayer_GetRowTotal( edit->layer );
|
||||
n = n > 3 ? 3 : n;
|
||||
for( i = 0; i < n; ++i ) {
|
||||
*height += TextLayer_GetRowHeight( edit->layer, i );
|
||||
}
|
||||
} else {
|
||||
*height = TextLayer_GetHeight( edit->layer );
|
||||
}
|
||||
*width = 176;
|
||||
if( widget->computed_style.box_sizing != SV_CONTENT_BOX ) {
|
||||
*height += widget->padding.top + widget->padding.bottom;
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------- End TextBlock ---------------------------------*/
|
||||
|
||||
/** 指定文本框是否处理控制符 */
|
||||
void TextEdit_SetUsingStyleTags( LCUI_Widget widget, LCUI_BOOL is_true )
|
||||
{
|
||||
LCUI_TextEdit edit = widget->private_data;
|
||||
TextLayer_SetUsingStyleTags( edit->layer, is_true );
|
||||
}
|
||||
|
||||
/** 指定文本框是否启用多行文本显示 */
|
||||
void TextEdit_SetMultiline( LCUI_Widget widget, LCUI_BOOL is_true )
|
||||
{
|
||||
LCUI_TextEdit edit = widget->private_data;
|
||||
TextLayer_SetMultiline( edit->layer_source, is_true );
|
||||
TextLayer_SetMultiline( edit->layer_mask, is_true );
|
||||
edit->is_multiline_mode = is_true;
|
||||
}
|
||||
|
||||
void TextEdit_ClearText( LCUI_Widget widget )
|
||||
{
|
||||
LCUI_TextEdit edit;
|
||||
Widget_Lock( widget );
|
||||
edit = widget->private_data;
|
||||
LCUIMutex_Lock( &edit->mutex );
|
||||
TextLayer_ClearText( edit->layer );
|
||||
StyleTags_Clear( &edit->text_tags );
|
||||
edit->tasks[TASK_UPDATE] = TRUE;
|
||||
Widget_AddTask( widget, WTT_USER );
|
||||
LCUIMutex_Unlock( &edit->mutex );
|
||||
Widget_InvalidateArea( widget, NULL, SV_PADDING_BOX );
|
||||
Widget_Unlock( widget );
|
||||
}
|
||||
|
||||
int TextEdit_GetTextW( LCUI_Widget w, int start, int max_len, wchar_t *buf )
|
||||
{
|
||||
LCUI_TextEdit edit = w->private_data;
|
||||
return TextLayer_GetTextW( edit->layer_source, start, max_len, buf );
|
||||
}
|
||||
|
||||
int TextEdit_GetTextLength( LCUI_Widget w )
|
||||
{
|
||||
LCUI_TextEdit edit = w->private_data;
|
||||
return edit->layer_source->length;
|
||||
}
|
||||
|
||||
int TextEdit_SetTextW( LCUI_Widget w, const wchar_t *wstr )
|
||||
{
|
||||
TextEdit_ClearText( w );
|
||||
return TextEdit_AddTextToBuffer( w, wstr, TBAT_APPEND, TBOT_SOURCE );
|
||||
}
|
||||
|
||||
int TextEdit_SetText( LCUI_Widget widget, const char *utf8_str )
|
||||
{
|
||||
int ret;
|
||||
size_t len = strlen( utf8_str ) + 1;
|
||||
wchar_t *wstr = malloc( len * sizeof( wchar_t ) );
|
||||
if( !wstr ) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
LCUI_DecodeString( wstr, utf8_str, len, ENCODING_UTF8 );
|
||||
ret = TextEdit_SetTextW( widget, wstr );
|
||||
free( wstr );
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** 为文本框追加文本(宽字符版) */
|
||||
int TextEdit_AppendTextW( LCUI_Widget w, const wchar_t *wstr )
|
||||
{
|
||||
return TextEdit_AddTextToBuffer( w, wstr, TBAT_APPEND, TBOT_SOURCE );
|
||||
}
|
||||
|
||||
/** 为文本框插入文本(宽字符版) */
|
||||
int TextEdit_InsertTextW( LCUI_Widget w, const wchar_t *wstr )
|
||||
{
|
||||
return TextEdit_AddTextToBuffer( w, wstr, TBAT_INSERT, TBOT_SOURCE );
|
||||
}
|
||||
|
||||
int TextEdit_SetPlaceHolderW( LCUI_Widget w, const wchar_t *wstr )
|
||||
{
|
||||
LCUI_TextEdit edit = w->private_data;
|
||||
Widget_Lock( w );
|
||||
LCUIMutex_Lock( &edit->mutex );
|
||||
TextLayer_ClearText( edit->layer_placeholder );
|
||||
LCUIMutex_Unlock( &edit->mutex );
|
||||
if( edit->is_placeholder_shown ) {
|
||||
Widget_InvalidateArea( w, NULL, SV_PADDING_BOX );
|
||||
}
|
||||
Widget_Unlock( w );
|
||||
return TextEdit_AddTextToBuffer( w, wstr, TBAT_INSERT,
|
||||
TBOT_PLACEHOLDER );
|
||||
}
|
||||
|
||||
int TextEdit_SetPlaceHolder( LCUI_Widget w, const char *str )
|
||||
{
|
||||
int ret;
|
||||
size_t len = strlen( str ) + 1;
|
||||
wchar_t *wstr = malloc( len * sizeof( wchar_t ) );
|
||||
if( !wstr ) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
LCUI_DecodeString( wstr, str, len, ENCODING_UTF8 );
|
||||
ret = TextEdit_SetPlaceHolderW( w, wstr );
|
||||
free( wstr );
|
||||
return ret;
|
||||
}
|
||||
|
||||
void TextEdit_SetCaretBlink( LCUI_Widget w, LCUI_BOOL enabled, int time )
|
||||
{
|
||||
LCUI_TextEdit edit;
|
||||
edit = w->private_data;
|
||||
TextCaret_SetVisible( edit->caret, enabled );
|
||||
TextCaret_SetBlinkTime( edit->caret, time );
|
||||
}
|
||||
|
||||
static void TextEdit_OnParseText( LCUI_Widget w, const char *text )
|
||||
{
|
||||
TextEdit_SetText( w, text );
|
||||
}
|
||||
|
||||
static void TextEdit_OnFocus( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg )
|
||||
{
|
||||
LCUI_TextEdit edit;
|
||||
edit = widget->private_data;
|
||||
/* 设定输入法的目标 */
|
||||
LCUIIME_SetTarget( widget );
|
||||
TextCaret_SetVisible( edit->caret, TRUE );
|
||||
TextCaret_BlinkHide( edit->caret );
|
||||
edit->tasks[TASK_UPDATE_CARET] = TRUE;
|
||||
Widget_AddTask( widget, WTT_USER );
|
||||
}
|
||||
|
||||
static void TextEdit_OnBlur( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg )
|
||||
{
|
||||
LCUI_TextEdit edit;
|
||||
edit = widget->private_data;
|
||||
LCUIIME_ClearTarget();
|
||||
TextCaret_SetVisible( edit->caret, FALSE );
|
||||
}
|
||||
|
||||
static void TextEdit_TextBackspace( LCUI_Widget widget, int n_ch )
|
||||
{
|
||||
LCUI_TextEdit edit;
|
||||
LCUI_WidgetEventRec ev;
|
||||
Widget_Lock( widget );
|
||||
edit = widget->private_data;
|
||||
LCUIMutex_Lock( &edit->mutex );
|
||||
TextLayer_TextBackspace( edit->layer_source, n_ch );
|
||||
if( edit->password_char ) {
|
||||
TextLayer_TextBackspace( edit->layer_mask, n_ch );
|
||||
}
|
||||
TextCaret_BlinkShow( edit->caret );
|
||||
edit->tasks[TASK_UPDATE] = TRUE;
|
||||
Widget_AddTask( widget, WTT_USER );
|
||||
LCUIMutex_Unlock( &edit->mutex );
|
||||
Widget_Unlock( widget );
|
||||
ev.type = textedit_event_id;
|
||||
Widget_TriggerEvent( widget, &ev, NULL );
|
||||
}
|
||||
|
||||
static void TextEdit_TextDelete(LCUI_Widget widget, int n_ch )
|
||||
{
|
||||
LCUI_TextEdit edit;
|
||||
LCUI_WidgetEventRec ev;
|
||||
Widget_Lock( widget );
|
||||
edit = widget->private_data;
|
||||
LCUIMutex_Lock( &edit->mutex );
|
||||
TextLayer_TextDelete( edit->layer_source, n_ch );
|
||||
if( edit->password_char ) {
|
||||
TextLayer_TextDelete( edit->layer_mask, n_ch );
|
||||
}
|
||||
TextCaret_BlinkShow( edit->caret );
|
||||
edit->tasks[TASK_UPDATE] = TRUE;
|
||||
Widget_AddTask( widget, WTT_USER );
|
||||
LCUIMutex_Unlock( &edit->mutex );
|
||||
Widget_Unlock( widget );
|
||||
ev.type = textedit_event_id;
|
||||
Widget_TriggerEvent( widget, &ev, NULL );
|
||||
}
|
||||
|
||||
/** 处理按键事件 */
|
||||
static void TextEdit_OnKeyDown( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg )
|
||||
{
|
||||
LCUI_TextEdit edit;
|
||||
int cols, rows, cur_col, cur_row;
|
||||
edit = widget->private_data;
|
||||
cur_row = edit->layer->insert_y;
|
||||
cur_col = edit->layer->insert_x;
|
||||
rows = TextLayer_GetRowTotal( edit->layer );
|
||||
cols = TextLayer_GetRowTextLength( edit->layer, cur_row );
|
||||
switch( e->key.code ) {
|
||||
case LCUIKEY_HOMEPAGE: // home键移动光标至行首
|
||||
cur_col = 0;
|
||||
break;
|
||||
case LCUIKEY_END: // end键移动光标至行尾
|
||||
cur_col = cols;
|
||||
break;
|
||||
case LCUIKEY_LEFT:
|
||||
if( cur_col > 0 ) {
|
||||
--cur_col;
|
||||
} else if( cur_row > 0 ) {
|
||||
--cur_row;
|
||||
cur_col = TextLayer_GetRowTextLength( edit->layer,
|
||||
cur_row );
|
||||
}
|
||||
break;
|
||||
case LCUIKEY_RIGHT:
|
||||
if( cur_col < cols ) {
|
||||
++cur_col;
|
||||
} else if( cur_row < rows - 1 ) {
|
||||
++cur_row;
|
||||
cur_col = 0;
|
||||
}
|
||||
break;
|
||||
case LCUIKEY_UP:
|
||||
if( cur_row > 0 ) {
|
||||
--cur_row;
|
||||
}
|
||||
break;
|
||||
case LCUIKEY_DOWN:
|
||||
if( cur_row < rows - 1 ) {
|
||||
++cur_row;
|
||||
}
|
||||
break;
|
||||
case LCUIKEY_BACKSPACE: // 删除光标左边的字符
|
||||
TextEdit_TextBackspace( widget, 1 );
|
||||
return;
|
||||
case LCUIKEY_DELETE: // 删除光标右边的字符
|
||||
TextEdit_TextDelete( widget, 1 );
|
||||
return;
|
||||
default:break;
|
||||
}
|
||||
TextEdit_MoveCaret( widget, cur_row, cur_col );
|
||||
}
|
||||
|
||||
/** 处理输入法对文本框输入的内容 */
|
||||
static void TextEdit_OnTextInput( LCUI_Widget widget,
|
||||
LCUI_WidgetEvent e, void *arg )
|
||||
{
|
||||
uint_t i, j, k;
|
||||
wchar_t ch, *text, excludes[8] = L"\b\r\t\x1b";
|
||||
LCUI_TextEdit edit = widget->private_data;
|
||||
/* 如果不是多行文本编辑模式则删除换行符 */
|
||||
if( !edit->is_multiline_mode ) {
|
||||
wcscat( excludes, L"\n" );
|
||||
}
|
||||
/* 如果文本框是只读的 */
|
||||
if( edit->is_read_only ) {
|
||||
return;
|
||||
}
|
||||
text = malloc( sizeof( wchar_t ) * (e->text.length + 1) );
|
||||
if( !text ) {
|
||||
return;
|
||||
}
|
||||
for( i = 0, j = 0; i < e->text.length; ++i ) {
|
||||
ch = e->text.text[i];
|
||||
for( k = 0; excludes[k]; ++k ) {
|
||||
if( ch == excludes[k] ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( excludes[k] ) {
|
||||
continue;
|
||||
}
|
||||
if( !edit->allow_input_char ) {
|
||||
text[j++] = ch;
|
||||
continue;
|
||||
}
|
||||
/* 判断当前字符是否为限制范围内的字符 */
|
||||
for( j = 0; edit->allow_input_char[j]; ++j ) {
|
||||
if( edit->allow_input_char[j] == ch ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* 如果已提前结束循环,则表明当前字符是允许的 */
|
||||
if( edit->allow_input_char[j] ) {
|
||||
text[j++] = e->text.text[i];
|
||||
continue;
|
||||
}
|
||||
text[j] = 0;
|
||||
}
|
||||
text[j] = 0;
|
||||
TextEdit_InsertTextW( widget, text );
|
||||
free( text );
|
||||
}
|
||||
|
||||
static void TextEdit_OnResize( LCUI_Widget w, LCUI_WidgetEvent e, void *arg )
|
||||
{
|
||||
LinkedList rects;
|
||||
LinkedListNode *node;
|
||||
LCUI_TextEdit edit;
|
||||
int width = 0, height = 0;
|
||||
int max_width = 0, max_height = 0;
|
||||
|
||||
edit = w->private_data;
|
||||
if( !w->style->sheet[key_width].is_valid ||
|
||||
w->style->sheet[key_width].type == SVT_AUTO ) {
|
||||
max_width = Widget_ComputeMaxWidth( w );
|
||||
max_width -= w->computed_style.border.left.width;
|
||||
max_width -= w->computed_style.border.right.width;
|
||||
max_width -= w->padding.left + w->padding.right;
|
||||
} else {
|
||||
max_width = width = w->box.content.width;
|
||||
}
|
||||
if( w->style->sheet[key_height].is_valid &&
|
||||
!w->style->sheet[key_height].type == SVT_AUTO ) {
|
||||
max_height = height = w->box.content.width;
|
||||
}
|
||||
LinkedList_Init( &rects );
|
||||
TextLayer_SetFixedSize( edit->layer_mask, width, height );
|
||||
TextLayer_SetFixedSize( edit->layer_source, width, height );
|
||||
TextLayer_SetFixedSize( edit->layer_placeholder, width, height );
|
||||
TextLayer_SetMaxSize( edit->layer_mask, max_width, max_height );
|
||||
TextLayer_SetMaxSize( edit->layer_source, max_width, max_height );
|
||||
TextLayer_SetMaxSize( edit->layer_placeholder, max_width, max_height );
|
||||
TextLayer_Update( edit->layer, &rects );
|
||||
for( LinkedList_Each( node, &rects ) ) {
|
||||
Widget_InvalidateArea( w, node->data, SV_CONTENT_BOX );
|
||||
}
|
||||
LinkedList_Clear( &rects, free );
|
||||
TextLayer_ClearInvalidRect( edit->layer );
|
||||
}
|
||||
|
||||
static void TextEdit_OnMouseMove( LCUI_Widget w, LCUI_WidgetEvent e, void *arg )
|
||||
{
|
||||
int abs_x, abs_y, x, y;
|
||||
LCUI_TextEdit edit = w->private_data;
|
||||
if( !edit->is_placeholder_shown ) {
|
||||
Widget_GetAbsXY( w, NULL, &abs_x, &abs_y );
|
||||
x = e->motion.x - abs_x - w->padding.left;
|
||||
y = e->motion.y - abs_y - w->padding.top;
|
||||
TextLayer_SetCaretPosByPixelPos( edit->layer, x, y );
|
||||
}
|
||||
TextEdit_UpdateCaret( w );
|
||||
}
|
||||
|
||||
static void TextEdit_OnMouseUp( LCUI_Widget w, LCUI_WidgetEvent e, void *arg )
|
||||
{
|
||||
Widget_ReleaseMouseCapture( w );
|
||||
Widget_UnbindEvent( w, "mousemove", TextEdit_OnMouseMove );
|
||||
}
|
||||
|
||||
static void TextEdit_OnMouseDown( LCUI_Widget w, LCUI_WidgetEvent e, void *arg )
|
||||
{
|
||||
int abs_x, abs_y, x, y;
|
||||
LCUI_TextEdit edit = w->private_data;
|
||||
Widget_GetAbsXY( w, NULL, &abs_x, &abs_y );
|
||||
x = e->motion.x - abs_x - w->padding.left;
|
||||
y = e->motion.y - abs_y - w->padding.top;
|
||||
TextLayer_SetCaretPosByPixelPos( edit->layer, x, y );
|
||||
TextEdit_UpdateCaret( w );
|
||||
Widget_SetMouseCapture( w );
|
||||
Widget_BindEvent( w, "mousemove", TextEdit_OnMouseMove, NULL, NULL );
|
||||
}
|
||||
|
||||
static void TextEdit_OnReady( LCUI_Widget w, LCUI_WidgetEvent e, void *arg )
|
||||
{
|
||||
TextEdit_UpdateCaret( w );
|
||||
}
|
||||
|
||||
static void TextEdit_SetAttr( LCUI_Widget w, const char *name,
|
||||
const char *val )
|
||||
{
|
||||
if( strcasecmp( name, "data-placeholder" ) == 0 ) {
|
||||
TextEdit_SetPlaceHolder( w, val );
|
||||
}
|
||||
}
|
||||
|
||||
static void TextEdit_OnInit( LCUI_Widget w )
|
||||
{
|
||||
LCUI_TextEdit edit;
|
||||
edit = Widget_NewPrivateData( w, LCUI_TextEditRec );
|
||||
edit->is_read_only = FALSE;
|
||||
edit->password_char = 0;
|
||||
edit->allow_input_char = NULL;
|
||||
edit->is_placeholder_shown = FALSE;
|
||||
edit->layer_mask = TextLayer_New();
|
||||
edit->layer_source = TextLayer_New();
|
||||
edit->layer_placeholder = TextLayer_New();
|
||||
edit->layer = edit->layer_source;
|
||||
edit->text_block_size = TBT_SIZE;
|
||||
memset( edit->tasks, 0, sizeof(edit->tasks) );
|
||||
edit->caret = LCUIWidget_New( "textcaret" );
|
||||
LinkedList_Init( &edit->text_blocks );
|
||||
StyleTags_Init( &edit->text_tags );
|
||||
TextEdit_SetMultiline( w, FALSE );
|
||||
TextLayer_SetAutoWrap( edit->layer, TRUE );
|
||||
TextLayer_SetAutoWrap( edit->layer_mask, TRUE );
|
||||
TextLayer_SetUsingStyleTags( edit->layer, FALSE );
|
||||
Widget_BindEvent( w, "textinput", TextEdit_OnTextInput, NULL, NULL );
|
||||
Widget_BindEvent( w, "mousedown", TextEdit_OnMouseDown, NULL, NULL );
|
||||
Widget_BindEvent( w, "mouseup", TextEdit_OnMouseUp, NULL, NULL );
|
||||
Widget_BindEvent( w, "keydown", TextEdit_OnKeyDown, NULL, NULL );
|
||||
Widget_BindEvent( w, "resize", TextEdit_OnResize, NULL, NULL );
|
||||
Widget_BindEvent( w, "focus", TextEdit_OnFocus, NULL, NULL );
|
||||
Widget_BindEvent( w, "blur", TextEdit_OnBlur, NULL, NULL );
|
||||
Widget_BindEvent( w, "ready", TextEdit_OnReady, NULL, NULL );
|
||||
Widget_Append( w, edit->caret );
|
||||
Widget_Hide( edit->caret );
|
||||
LCUIMutex_Init( &edit->mutex );
|
||||
}
|
||||
|
||||
static void TextEdit_OnDestroy( LCUI_Widget widget )
|
||||
{
|
||||
LCUI_TextEdit edit = widget->private_data;
|
||||
TextLayer_Destroy( edit->layer );
|
||||
TextLayer_Destroy( edit->layer_mask );
|
||||
LinkedList_Clear( &edit->text_blocks, TextBlock_OnDestroy );
|
||||
}
|
||||
|
||||
static void TextEdit_OnPaint( LCUI_Widget w, LCUI_PaintContext paint )
|
||||
{
|
||||
LCUI_TextEdit edit;
|
||||
LCUI_Pos layer_pos;
|
||||
LCUI_Rect content_rect, rect;
|
||||
|
||||
edit = w->private_data;
|
||||
content_rect.width = w->box.content.width;
|
||||
content_rect.height = w->box.content.height;
|
||||
content_rect.y = w->box.content.top - w->box.graph.top;
|
||||
content_rect.x = w->box.content.left - w->box.graph.left;
|
||||
LCUIRect_GetOverlayRect( &content_rect, &paint->rect, &rect );
|
||||
layer_pos.x = content_rect.x - paint->rect.x;
|
||||
layer_pos.y = content_rect.y - paint->rect.y;
|
||||
rect.x -= content_rect.x;
|
||||
rect.y -= content_rect.y;
|
||||
TextLayer_DrawToGraph( edit->layer, rect, layer_pos, &paint->canvas );
|
||||
}
|
||||
|
||||
/** 添加 TextEdit 部件类型 */
|
||||
void LCUIWidget_AddTextEdit( void )
|
||||
{
|
||||
LCUI_WidgetClass *wc = LCUIWidget_AddClass( "textedit" );
|
||||
wc->methods.init = TextEdit_OnInit;
|
||||
wc->methods.paint = TextEdit_OnPaint;
|
||||
wc->methods.destroy = TextEdit_OnDestroy;
|
||||
wc->methods.set_text = TextEdit_OnParseText;
|
||||
wc->methods.set_attr = TextEdit_SetAttr;
|
||||
wc->methods.autosize = TextEdit_AutoSize;
|
||||
wc->task_handler = TextEdit_OnTask;
|
||||
LCUI_LoadCSSString( textedit_css, NULL );
|
||||
LCUIWidget_AddTextCaret();
|
||||
textedit_event_id = LCUIWidget_AllocEventId();
|
||||
LCUIWidget_SetEventName( textedit_event_id, "change" );
|
||||
}
|
||||
+118
-51
@@ -56,7 +56,8 @@ enum TaskType {
|
||||
|
||||
typedef struct LCUI_TextView_ {
|
||||
LCUI_TextStyle style;
|
||||
LCUI_TextLayer layer; /**< 文本图层 */
|
||||
LCUI_BOOL has_content; /**< 是否有设置 content 属性 */
|
||||
LCUI_TextLayer layer; /**< 文本图层 */
|
||||
struct {
|
||||
LCUI_BOOL is_valid;
|
||||
union {
|
||||
@@ -67,15 +68,6 @@ typedef struct LCUI_TextView_ {
|
||||
} tasks[TASK_TOTAL];
|
||||
} LCUI_TextView;
|
||||
|
||||
|
||||
static const char *textview_css = ToString(
|
||||
|
||||
textview {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
/*---------------------------- Private -------------------------------*/
|
||||
|
||||
enum FontStyleKey {
|
||||
@@ -87,6 +79,7 @@ enum FontStyleKey {
|
||||
key_line_height,
|
||||
key_text_align,
|
||||
key_content,
|
||||
key_white_space,
|
||||
TOTAL_FONT_STYLE_KEY
|
||||
};
|
||||
|
||||
@@ -101,7 +94,7 @@ static int style_key_map[TOTAL_FONT_STYLE_KEY];
|
||||
static int unescape( const wchar_t *instr, wchar_t *outstr )
|
||||
{
|
||||
int i = -1;
|
||||
char buff[6];
|
||||
wchar_t buff[6];
|
||||
wchar_t *pout = outstr;
|
||||
const wchar_t *pin = instr;
|
||||
|
||||
@@ -109,20 +102,20 @@ static int unescape( const wchar_t *instr, wchar_t *outstr )
|
||||
if( i >= 0 ) {
|
||||
buff[i++] = *pin;
|
||||
if( i >= 4 ) {
|
||||
sscanf( buff, "%x", pout );
|
||||
swscanf( buff, L"%x", pout );
|
||||
++pout;
|
||||
i = -1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if( *pin == '\\' ) {
|
||||
if( *pin == L'\\' ) {
|
||||
i = 0;
|
||||
continue;
|
||||
}
|
||||
*pout++ = *pin;
|
||||
}
|
||||
if( i >= 4 ) {
|
||||
sscanf( buff, "%x", pout );
|
||||
swscanf( buff, L"%x", pout );
|
||||
++pout;
|
||||
}
|
||||
*pout = 0;
|
||||
@@ -176,7 +169,6 @@ static int OnParseFontFamily( LCUI_StyleSheet ss, int key, const char *str )
|
||||
&& ss->sheet[style_key_map[key]].string) {
|
||||
free( ss->sheet[style_key_map[key]].string );
|
||||
}
|
||||
strtrim( name, str, "'\"\n\r\t " );
|
||||
SetStyle( ss, style_key_map[key], name, string );
|
||||
return 0;
|
||||
}
|
||||
@@ -197,7 +189,7 @@ static int OnParseFontWeight( LCUI_StyleSheet ss, int key, const char *str )
|
||||
|
||||
static int OnParseTextAlign( LCUI_StyleSheet ss, int key, const char *str )
|
||||
{
|
||||
int val = ParseStyleOption( str );
|
||||
int val = LCUI_GetStyleValue( str );
|
||||
if( val < 0 ) {
|
||||
return -1;
|
||||
}
|
||||
@@ -218,6 +210,20 @@ static int OnParseLineHeight( LCUI_StyleSheet ss, int key, const char *str )
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int OnParseStyleOption( LCUI_StyleSheet ss, int key, const char *str )
|
||||
{
|
||||
LCUI_Style s = &ss->sheet[style_key_map[key]];
|
||||
int v = LCUI_GetStyleValue( str );
|
||||
if( v < 0 ) {
|
||||
return -1;
|
||||
}
|
||||
s->style = v;
|
||||
s->type = SVT_STYLE;
|
||||
s->is_valid = TRUE;
|
||||
s->is_changed = TRUE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static LCUI_StyleParserRec style_parsers[] = {
|
||||
{ key_color, "color", OnParseColor },
|
||||
{ key_font_family, "font-family", OnParseFontFamily },
|
||||
@@ -227,6 +233,7 @@ static LCUI_StyleParserRec style_parsers[] = {
|
||||
{ key_text_align, "text-align", OnParseTextAlign },
|
||||
{ key_line_height, "line-height", OnParseLineHeight },
|
||||
{ key_content, "content", OnParseContent },
|
||||
{ key_white_space, "white-space", OnParseStyleOption }
|
||||
};
|
||||
|
||||
static void TextView_UpdateStyle( LCUI_Widget w )
|
||||
@@ -240,39 +247,79 @@ static void TextView_UpdateStyle( LCUI_Widget w )
|
||||
continue;
|
||||
}
|
||||
s = &w->style->sheet[style_key_map[i]];
|
||||
if( !s->is_valid ) {
|
||||
continue;
|
||||
}
|
||||
switch( i ) {
|
||||
case key_color:
|
||||
txt->style.fore_color = s->color;
|
||||
txt->style.has_fore_color = TRUE;
|
||||
if( s->is_valid ) {
|
||||
txt->style.fore_color = s->color;
|
||||
txt->style.has_fore_color = TRUE;
|
||||
} else {
|
||||
txt->style.has_fore_color = FALSE;
|
||||
}
|
||||
break;
|
||||
case key_font_family:
|
||||
TextStyle_SetFont( &txt->style, s->string );
|
||||
if( s->is_valid ) {
|
||||
TextStyle_SetFont( &txt->style, s->string );
|
||||
} else {
|
||||
TextStyle_SetFont( &txt->style, NULL );
|
||||
}
|
||||
break;
|
||||
case key_font_size:
|
||||
if( s->type == SVT_PX ) {
|
||||
txt->style.pixel_size = s->px;
|
||||
} else if( s->type == SVT_PT ) {
|
||||
// ...
|
||||
txt->style.pixel_size = 14;
|
||||
if( s->is_valid ) {
|
||||
if( s->type == SVT_PX ) {
|
||||
txt->style.pixel_size = s->px;
|
||||
}
|
||||
}
|
||||
txt->style.has_pixel_size = TRUE;
|
||||
break;
|
||||
case key_font_style:
|
||||
txt->style.style = s->value;
|
||||
txt->style.has_style = TRUE;
|
||||
txt->style.has_style = FALSE;
|
||||
if( s->is_valid ) {
|
||||
txt->style.style = s->value;
|
||||
txt->style.has_style = TRUE;
|
||||
}
|
||||
break;
|
||||
case key_font_weight:
|
||||
break;
|
||||
case key_text_align:
|
||||
TextLayer_SetTextAlign( txt->layer, s->style );
|
||||
if( s->is_valid ) {
|
||||
TextLayer_SetTextAlign( txt->layer, s->style );
|
||||
} else {
|
||||
TextLayer_SetTextAlign( txt->layer, SV_LEFT );
|
||||
}
|
||||
break;
|
||||
case key_line_height:
|
||||
TextLayer_SetLineHeight( txt->layer, s );
|
||||
if( s->is_valid ) {
|
||||
TextLayer_SetLineHeight( txt->layer, s );
|
||||
} else {
|
||||
LCUI_StyleRec style;
|
||||
style.val_scale = 1.5;
|
||||
style.type = SVT_SCALE;
|
||||
style.is_valid = TRUE;
|
||||
TextLayer_SetLineHeight( txt->layer, &style );
|
||||
}
|
||||
break;
|
||||
case key_content:
|
||||
TextView_SetTextW( w, s->wstring );
|
||||
if( s->is_valid ) {
|
||||
txt->has_content = TRUE;
|
||||
TextView_SetTextW( w, s->wstring );
|
||||
} else {
|
||||
if( txt->has_content ) {
|
||||
txt->has_content = FALSE;
|
||||
TextView_SetTextW( w, NULL );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case key_white_space:
|
||||
if( !s->is_valid || s->type != SVT_STYLE ) {
|
||||
TextLayer_SetAutoWrap( txt->layer, TRUE );
|
||||
break;
|
||||
}
|
||||
if( s->style == SV_NOWRAP ) {
|
||||
TextLayer_SetAutoWrap( txt->layer, FALSE );
|
||||
} else {
|
||||
TextLayer_SetAutoWrap( txt->layer, TRUE );
|
||||
}
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
@@ -285,24 +332,29 @@ static void TextView_OnResize( LCUI_Widget w, LCUI_WidgetEvent e, void *arg )
|
||||
{
|
||||
LinkedList rects;
|
||||
LinkedListNode *node;
|
||||
LCUI_Size new_size = {16, 16};
|
||||
LCUI_TextView *txt = w->private_data;
|
||||
if( w->width > new_size.w ) {
|
||||
new_size.w = w->width;
|
||||
}
|
||||
if( w->height > new_size.h ) {
|
||||
new_size.h = w->height;
|
||||
}
|
||||
LCUI_TextView *txt;
|
||||
int width = 0, height = 0;
|
||||
int max_width = 0, max_height = 0;
|
||||
|
||||
txt = w->private_data;
|
||||
LinkedList_Init( &rects );
|
||||
if( w->style->sheet[key_width].is_valid &&
|
||||
w->style->sheet[key_width].type != SVT_AUTO ) {
|
||||
TextLayer_SetAutoWrap( txt->layer, TRUE );
|
||||
if( !w->style->sheet[key_width].is_valid ||
|
||||
w->style->sheet[key_width].type == SVT_AUTO ) {
|
||||
max_width = Widget_ComputeMaxWidth( w );
|
||||
max_width -= w->computed_style.border.left.width;
|
||||
max_width -= w->computed_style.border.right.width;
|
||||
max_width -= w->padding.left + w->padding.right;
|
||||
} else {
|
||||
TextLayer_SetAutoWrap( txt->layer, FALSE );
|
||||
max_width = width = w->box.content.width;
|
||||
}
|
||||
TextLayer_SetMaxSize( txt->layer, new_size );
|
||||
if( w->style->sheet[key_height].is_valid &&
|
||||
!w->style->sheet[key_height].type == SVT_AUTO ) {
|
||||
max_height = height = w->box.content.width;
|
||||
}
|
||||
TextLayer_SetMaxSize( txt->layer, max_width, max_height );
|
||||
TextLayer_SetFixedSize( txt->layer, width, height );
|
||||
TextLayer_Update( txt->layer, &rects );
|
||||
LinkedList_ForEach( node, &rects ) {
|
||||
for( LinkedList_Each( node, &rects ) ) {
|
||||
Widget_InvalidateArea( w, node->data, SV_CONTENT_BOX );
|
||||
}
|
||||
LinkedList_Clear( &rects, free );
|
||||
@@ -319,9 +371,11 @@ static void TextView_OnInit( LCUI_Widget w )
|
||||
for( i = 0; i < TASK_TOTAL; ++i ) {
|
||||
txt->tasks[i].is_valid = FALSE;
|
||||
}
|
||||
txt->has_content = FALSE;
|
||||
/* 初始化文本图层 */
|
||||
txt->layer = TextLayer_New();
|
||||
/* 启用多行文本显示 */
|
||||
TextLayer_SetAutoWrap( txt->layer, TRUE );
|
||||
TextLayer_SetMultiline( txt->layer, TRUE );
|
||||
/* 启用样式标签的支持 */
|
||||
TextLayer_SetUsingStyleTags( txt->layer, TRUE );
|
||||
@@ -333,7 +387,7 @@ static void TextView_OnDestroy( LCUI_Widget w )
|
||||
{
|
||||
LCUI_TextView *txt;
|
||||
txt = w->private_data;
|
||||
TextLayer_Destroy( &txt->layer );
|
||||
TextLayer_Destroy( txt->layer );
|
||||
}
|
||||
|
||||
static void TextView_AutoSize( LCUI_Widget w, int *width, int *height )
|
||||
@@ -341,7 +395,6 @@ static void TextView_AutoSize( LCUI_Widget w, int *width, int *height )
|
||||
LCUI_TextView *txt = w->private_data;
|
||||
*width = TextLayer_GetWidth( txt->layer );
|
||||
*height = TextLayer_GetHeight( txt->layer );
|
||||
DEBUG_MSG("width: %d, height: %d\n", *width, *height);
|
||||
}
|
||||
|
||||
/** 私有的任务处理接口 */
|
||||
@@ -365,6 +418,12 @@ static void TextView_OnTask( LCUI_Widget w )
|
||||
TextLayer_SetAutoWrap( txt->layer, txt->tasks[i].autowrap );
|
||||
txt->tasks[TASK_UPDATE].is_valid = TRUE;
|
||||
}
|
||||
i = TASK_SET_TEXT_ALIGN;
|
||||
if( txt->tasks[i].is_valid ) {
|
||||
txt->tasks[i].is_valid = FALSE;
|
||||
TextLayer_SetTextAlign( txt->layer, txt->tasks[i].align );
|
||||
txt->tasks[TASK_UPDATE].is_valid = TRUE;
|
||||
}
|
||||
i = TASK_UPDATE;
|
||||
if( !txt->tasks[i].is_valid ) {
|
||||
return;
|
||||
@@ -373,7 +432,7 @@ static void TextView_OnTask( LCUI_Widget w )
|
||||
txt = w->private_data;
|
||||
LinkedList_Init( &rects );
|
||||
TextLayer_Update( txt->layer, &rects );
|
||||
LinkedList_ForEach( node, &rects ) {
|
||||
for( LinkedList_Each( node, &rects ) ) {
|
||||
Widget_InvalidateArea( w, node->data, SV_CONTENT_BOX );
|
||||
}
|
||||
LinkedList_Clear( &rects, free );
|
||||
@@ -486,6 +545,14 @@ void TextView_SetTextAlign( LCUI_Widget w, int align )
|
||||
Widget_AddTask( w, WTT_USER );
|
||||
}
|
||||
|
||||
void TextView_SetAutoWrap( LCUI_Widget w, LCUI_BOOL autowrap )
|
||||
{
|
||||
LCUI_TextView *txt = w->private_data;
|
||||
txt->tasks[TASK_SET_AUTOWRAP].autowrap = autowrap;
|
||||
txt->tasks[TASK_SET_AUTOWRAP].is_valid = TRUE;
|
||||
Widget_AddTask( w, WTT_USER );
|
||||
}
|
||||
|
||||
/*-------------------------- End Public ------------------------------*/
|
||||
|
||||
/** 添加 TextView 部件类型 */
|
||||
@@ -501,8 +568,8 @@ void LCUIWidget_AddTextView( void )
|
||||
wc->methods.set_text = TextView_OnParseText;
|
||||
wc->task_handler = TextView_OnTask;
|
||||
for( i = 0; i < TOTAL_FONT_STYLE_KEY; ++i ) {
|
||||
style_key_map[style_parsers[i].key] =
|
||||
LCUICSS_AddParser( &style_parsers[i] );
|
||||
LCUI_StyleParser parser = &style_parsers[i];
|
||||
style_key_map[parser->key] = LCUI_AddStyleName( parser->name );
|
||||
LCUI_AddCSSParser( parser );
|
||||
}
|
||||
LCUICSS_LoadString( textview_css );
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user