diff --git a/README.md b/README.md index c1d4a677..0e8ac36d 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,84 @@ # The LCUI Project -[![Join the chat at https://gitter.im/lc-soft/LCUI](https://badges.gitter.im/lc-soft/LCUI.svg)](https://gitter.im/lc-soft/LCUI?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -[![Build Status](https://travis-ci.org/lc-soft/LCUI.png?branch=master)](https://travis-ci.org/lc-soft/LCUI) - ![LCUI Logo](http://lcui.org/static/images/lcui-project-logo.png) +[![Join the chat at https://gitter.im/lc-soft/LCUI](https://badges.gitter.im/lc-soft/LCUI.svg)](https://gitter.im/lc-soft/LCUI?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Build Status](https://travis-ci.org/lc-soft/LCUI.png?branch=master)](https://travis-ci.org/lc-soft/LCUI) +[![Downloads](https://img.shields.io/sourceforge/dt/lc-ui.svg)](https://sourceforge.net/projects/lc-ui) +[![License](https://img.shields.io/badge/license-GPLv2-blue.svg)](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. +![example screenshot](https://lcui.lc-soft.io/static/images/feature-screenshot-02.png) - 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 + +Liu Chao Special thanks to Liu Chao for his great work on the LCUI's development. diff --git a/README.zh-cn.md b/README.zh-cn.md index f7efe018..8d2eaf2f 100644 --- a/README.zh-cn.md +++ b/README.zh-cn.md @@ -1,17 +1,24 @@ # The LCUI Project -[![Gitter](https://badges.gitter.im/lc-soft/LCUI.svg)](https://gitter.im/lc-soft/LCUI?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) -[![Build Status](https://travis-ci.org/lc-soft/LCUI.png?branch=master)](https://travis-ci.org/lc-soft/LCUI) - ![LCUI Logo](http://lcui.org/static/images/lcui-project-logo.png) +[![Join the chat at https://gitter.im/lc-soft/LCUI](https://badges.gitter.im/lc-soft/LCUI.svg)](https://gitter.im/lc-soft/LCUI?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Build Status](https://travis-ci.org/lc-soft/LCUI.png?branch=master)](https://travis-ci.org/lc-soft/LCUI) +[![Downloads](https://img.shields.io/sourceforge/dt/lc-ui.svg)](https://sourceforge.net/projects/lc-ui) +[![License](https://img.shields.io/badge/license-GPLv2-blue.svg)](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + ## 说明 -LCUI 是一个简单的跨平台图形界面库,适用于开发一些简单的小程序,其诞生目的主要是方便作者开发图形界面程序。 +LCUI 是一个简单的跨平台图形界面库,其诞生目的主要是方便作者开发图形界面程序, +源代码主要由 C 语言编写,支持使用 XML 和 CSS 代码来描述图像界面,适用于开发一 +些简单的小程序,可以实现一些简单的效果,类似于这样: -LCUI 是一个自由软件项目,基于 GNU通用公共许可协议 发布,该许可协议要求 LCUI 及 LCUI 衍生软件无论以何种形式发布,都必须确保收受者能收到或得到源码。 +![example screenshot](https://lcui.lc-soft.io/static/images/feature-screenshot-02.png) -此项目主要由作者利用闲余时间进行开发和维护,项目的活跃度通常会受到各种因素的影响,大多数时间内都处于低活跃度状态。 +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 diff --git a/build/VS2012/LCUI-Demo.sln b/build/VS2012/LCUI-Demo.sln index ab665613..a2a5306b 100644 --- a/build/VS2012/LCUI-Demo.sln +++ b/build/VS2012/LCUI-Demo.sln @@ -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 diff --git a/build/VS2012/LCUI/LCUI.rc b/build/VS2012/LCUI/LCUI.rc index 124e1528..11245c94 100644 Binary files a/build/VS2012/LCUI/LCUI.rc and b/build/VS2012/LCUI/LCUI.rc differ diff --git a/build/VS2012/LCUI/LCUI.vcxproj b/build/VS2012/LCUI/LCUI.vcxproj index 76199db3..5ffa731c 100644 --- a/build/VS2012/LCUI/LCUI.vcxproj +++ b/build/VS2012/LCUI/LCUI.vcxproj @@ -113,7 +113,7 @@ Windows - false + true true true libxml2.lib;libpng16.lib;libjpeg.lib;freetype253.lib;zlib.lib;kernel32.lib;user32.lib;gdi32.lib; @@ -148,12 +148,13 @@ + - + @@ -170,7 +171,6 @@ - @@ -180,12 +180,14 @@ + + @@ -214,10 +216,12 @@ + + @@ -231,6 +235,7 @@ MaxSpeed + @@ -243,13 +248,12 @@ $(SolutionDir)include;$(SolutionDir)include\..\..\..\include;%(AdditionalIncludeDirectories) - - + diff --git a/build/VS2012/LCUI/LCUI.vcxproj.filters b/build/VS2012/LCUI/LCUI.vcxproj.filters index 529db24b..284f7823 100644 --- a/build/VS2012/LCUI/LCUI.vcxproj.filters +++ b/build/VS2012/LCUI/LCUI.vcxproj.filters @@ -96,9 +96,6 @@ 头文件\LCUI\draw - - 头文件\LCUI\gui - 头文件\LCUI\draw @@ -195,9 +192,6 @@ 头文件\LCUI\platform\windows - - 头文件\LCUI - 头文件\LCUI @@ -237,6 +231,18 @@ 头文件\LCUI\util + + 头文件\LCUI\gui\widget + + + 头文件\LCUI\util + + + 头文件\LCUI + + + 头文件\LCUI\gui + @@ -272,9 +278,6 @@ 源文件\bmp - - 源文件\bmp - 源文件\bmp @@ -368,9 +371,6 @@ 源文件 - - 源文件\util - 源文件\util @@ -386,9 +386,6 @@ 源文件\util - - 源文件\util - 源文件\util @@ -404,6 +401,21 @@ 源文件\util + + 源文件\bmp + + + 源文件\gui\widget + + + 源文件 + + + 源文件\util + + + 源文件\gui + diff --git a/build/VS2012/testtouch/testtouch.vcxproj b/build/VS2012/testtouch/testtouch.vcxproj new file mode 100644 index 00000000..806fd875 --- /dev/null +++ b/build/VS2012/testtouch/testtouch.vcxproj @@ -0,0 +1,107 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {E5E79245-9412-49C8-8FE7-3AF7A7111E2F} + Win32Proj + testtouch + 8.1 + + + + Application + true + v110 + Unicode + + + Application + false + v140_xp + true + MultiByte + + + + + + + + + + + + + true + AllRules.ruleset + + + $(SolutionDir)..\..\bin\ + $(SolutionDir)..\..\bin\$(Configuration)\ + + + false + AllRules.ruleset + + + $(SolutionDir)..\..\bin\ + $(SolutionDir)..\..\bin\$(Configuration)\ + + + + + + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + $(SolutionDir)\include;$(SolutionDir)\include\..\..\..\include;%(AdditionalIncludeDirectories) + CompileAsC + + + Windows + true + $(OutDir) + LCUI_D.lib;LCUIMain.lib; + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + $(SolutionDir)\include;$(SolutionDir)\include\..\..\..\include;%(AdditionalIncludeDirectories) + 4819 + true + + + Windows + true + true + true + $(OutDir) + LCUI.lib + + + true + + + + + + + + + \ No newline at end of file diff --git a/build/VS2012/testtouch/testtouch.vcxproj.filters b/build/VS2012/testtouch/testtouch.vcxproj.filters new file mode 100644 index 00000000..f7629373 --- /dev/null +++ b/build/VS2012/testtouch/testtouch.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + \ No newline at end of file diff --git a/configure.ac b/configure.ac index 207cd7ab..d9ef9a60 100755 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/fonts/README.zh-cn b/fonts/README.zh-cn deleted file mode 100755 index 35b86277..00000000 --- a/fonts/README.zh-cn +++ /dev/null @@ -1,2 +0,0 @@ -测试程序默认打开本文件目录中的msyh.ttf文件,也就是微软雅黑字体,你可以将其它字体放在本文件目录下,在程序调用LCUI_Init()函数前用Set_Default_Font()函数自定义字体文件所在位置,或者设置环境变量LCUI_FONTFILE,这样LCUI初始化后就会使用该字体文件。 - diff --git a/fonts/glyphicons-halflings-regular.ttf b/fonts/glyphicons-halflings-regular.ttf deleted file mode 100644 index 1413fc60..00000000 Binary files a/fonts/glyphicons-halflings-regular.ttf and /dev/null differ diff --git a/include/LCUI/LCUI.h b/include/LCUI/LCUI.h index 1096e956..e9975e7f 100755 --- a/include/LCUI/LCUI.h +++ b/include/LCUI/LCUI.h @@ -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 #include -#endif /* __LCUI_H__ */ +#endif /* LCUI_H */ diff --git a/include/LCUI/Makefile.am b/include/LCUI/Makefile.am index 76da7dfd..163fa0bc 100755 --- a/include/LCUI/Makefile.am +++ b/include/LCUI/Makefile.am @@ -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) diff --git a/include/LCUI/cursor.h b/include/LCUI/cursor.h index 739b985f..cf31d65b 100644 --- a/include/LCUI/cursor.h +++ b/include/LCUI/cursor.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_CURSOR_H__ -#define __LCUI_CURSOR_H__ +#ifndef LCUI_CURSOR_H +#define LCUI_CURSOR_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/display.h b/include/LCUI/display.h index 69b72e4b..f87f9df2 100644 --- a/include/LCUI/display.h +++ b/include/LCUI/display.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_DISPLAY_H__ -#define __LCUI_DISPLAY_H__ +#ifndef LCUI_DISPLAY_CONTROL_H +#define LCUI_DISPLAY_CONTROL_H #include #include diff --git a/include/LCUI/draw.h b/include/LCUI/draw.h index 84fdd855..dcbf91ba 100644 --- a/include/LCUI/draw.h +++ b/include/LCUI/draw.h @@ -39,17 +39,10 @@ * 没有,请查看:. * ****************************************************************************/ -#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 #include diff --git a/include/LCUI/draw/background.h b/include/LCUI/draw/background.h index eeb22350..7a62b289 100644 --- a/include/LCUI/draw/background.h +++ b/include/LCUI/draw/background.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ***************************************************************************/ -#ifndef __LCUI_DRAW_BACKGROUND_H__ -#define __LCUI_DRAW_BACKGROUND_H__ +#ifndef LCUI_DRAW_BACKGROUND_H +#define LCUI_DRAW_BACKGROUND_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/draw/border.h b/include/LCUI/draw/border.h index b81e887e..ce27e717 100755 --- a/include/LCUI/draw/border.h +++ b/include/LCUI/draw/border.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ***************************************************************************/ -#ifndef __LCUI_DRAW_BORDER_H__ -#define __LCUI_DRAW_BORDER_H__ +#ifndef LCUI_DRAW_BORDER_H +#define LCUI_DRAW_BORDER_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/draw/boxshadow.h b/include/LCUI/draw/boxshadow.h index 593c8ba3..3de55c32 100644 --- a/include/LCUI/draw/boxshadow.h +++ b/include/LCUI/draw/boxshadow.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ***************************************************************************/ -#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 ); diff --git a/include/LCUI/draw/line.h b/include/LCUI/draw/line.h index dccded48..183d4cae 100644 --- a/include/LCUI/draw/line.h +++ b/include/LCUI/draw/line.h @@ -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 ); diff --git a/include/LCUI/font.h b/include/LCUI/font.h index 43293e06..a2254fda 100644 --- a/include/LCUI/font.h +++ b/include/LCUI/font.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ***************************************************************************/ -#ifndef __LCUI_FONT_H__ -#define __LCUI_FONT_H__ +#ifndef LCUI_FONT_H +#define LCUI_FONT_H #include #include diff --git a/include/LCUI/font/charset.h b/include/LCUI/font/charset.h index 312e391e..d3ef1844 100755 --- a/include/LCUI/font/charset.h +++ b/include/LCUI/font/charset.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_CHARSET_H__ -#define __LCUI_CHARSET_H__ +#ifndef LCUI_CHARSET_H +#define LCUI_CHARSET_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/font/fontlibrary.h b/include/LCUI/font/fontlibrary.h index 0d18d69c..007862b7 100755 --- a/include/LCUI/font/fontlibrary.h +++ b/include/LCUI/font/fontlibrary.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_FONT_LIBRARY_H__ -#define __LCUI_FONT_LIBRARY_H__ +#ifndef LCUI_FONT_LIBRARY_H +#define LCUI_FONT_LIBRARY_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/font/textlayer.h b/include/LCUI/font/textlayer.h index f88e76b2..a29d0fb6 100755 --- a/include/LCUI/font/textlayer.h +++ b/include/LCUI/font/textlayer.h @@ -37,17 +37,11 @@ * 没有,请查看:. * ****************************************************************************/ -#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 ); diff --git a/include/LCUI/font/textstyle.h b/include/LCUI/font/textstyle.h index c1f2eea3..a4ffbeaa 100755 --- a/include/LCUI/font/textstyle.h +++ b/include/LCUI/font/textstyle.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#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 ); /** 在字符串中获取样式的结束标签,输出的是标签名 */ diff --git a/include/LCUI/graph.h b/include/LCUI/graph.h index c398aa00..6b63ff39 100644 --- a/include/LCUI/graph.h +++ b/include/LCUI/graph.h @@ -36,8 +36,8 @@ * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果s * 没有,请查看:. * ***************************************************************************/ -#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 -#endif /* __LCUI_GRAPH_H__ */ +#endif /* LCUI_GRAPH_H */ diff --git a/include/LCUI/gui/Makefile.am b/include/LCUI/gui/Makefile.am index 704128ee..6389a95b 100755 --- a/include/LCUI/gui/Makefile.am +++ b/include/LCUI/gui/Makefile.am @@ -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 diff --git a/include/LCUI/gui/builder.h b/include/LCUI/gui/builder.h index e0baf668..ca51a331 100644 --- a/include/LCUI/gui/builder.h +++ b/include/LCUI/gui/builder.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_BUILDER_H__ -#define __LCUI_BUILDER_H__ +#ifndef LCUI_BUILDER_H +#define LCUI_BUILDER_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/gui/css_library.h b/include/LCUI/gui/css_library.h new file mode 100644 index 00000000..be88ebc2 --- /dev/null +++ b/include/LCUI/gui/css_library.h @@ -0,0 +1,249 @@ +/* *************************************************************************** + * css_library.h -- css library operation module. + * + * Copyright (C) 2015-2016 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * css_library.h -- CSS 样式库操作模块 + * + * 版权所有 (C) 2015-2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +#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 \ No newline at end of file diff --git a/include/LCUI/gui/css_parser.h b/include/LCUI/gui/css_parser.h index 4f63d2d8..bb81d22f 100644 --- a/include/LCUI/gui/css_parser.h +++ b/include/LCUI/gui/css_parser.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#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 diff --git a/include/LCUI/gui/messagebox.h b/include/LCUI/gui/messagebox.h deleted file mode 100755 index 047dfe80..00000000 --- a/include/LCUI/gui/messagebox.h +++ /dev/null @@ -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 . - * ****************************************************************************/ - -/* **************************************************************************** - * messagebox.h -- LCUI 的消息框 - * - * 版权所有 (C) 2012-2013 归属于 - * 刘超 - * - * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 - * - * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) - * - * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 - * - * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 - * 定用途的隐含担保,详情请参照GPLv2许可协议。 - * - * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 - * 没有,请查看:. - * ****************************************************************************/ -#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 diff --git a/include/LCUI/gui/widget.h b/include/LCUI/gui/widget.h index 7a22e70e..924aeb1a 100644 --- a/include/LCUI/gui/widget.h +++ b/include/LCUI/gui/widget.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_WIDGET_BUILD_H__ -#define __LCUI_WIDGET_BUILD_H__ +#ifndef LCUI_WIDGET_BUILD_H +#define LCUI_WIDGET_BUILD_H #include #include diff --git a/include/LCUI/gui/widget/button.h b/include/LCUI/gui/widget/button.h index 32a6c85d..7ff7b06a 100644 --- a/include/LCUI/gui/widget/button.h +++ b/include/LCUI/gui/widget/button.h @@ -36,8 +36,8 @@ * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_BUTTON_H__ -#define __LCUI_BUTTON_H__ +#ifndef LCUI_BUTTON_H +#define LCUI_BUTTON_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/gui/widget/scrollbar.h b/include/LCUI/gui/widget/scrollbar.h index 7d1ffc39..8ed0f7ba 100644 --- a/include/LCUI/gui/widget/scrollbar.h +++ b/include/LCUI/gui/widget/scrollbar.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_SCROLLBAR_H__ -#define __LCUI_SCROLLBAR_H__ +#ifndef LCUI_SCROLLBAR_H +#define LCUI_SCROLLBAR_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/gui/widget/sidebar.h b/include/LCUI/gui/widget/sidebar.h index ba461e8c..cc584bae 100644 --- a/include/LCUI/gui/widget/sidebar.h +++ b/include/LCUI/gui/widget/sidebar.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_SIDEBAR_WIDGET_H__ -#define __LCUI_SIDEBAR_WIDGET_H__ +#ifndef LCUI_SIDEBAR_WIDGET_H +#define LCUI_SIDEBAR_WIDGET_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/gui/widget/textedit.h b/include/LCUI/gui/widget/textedit.h new file mode 100644 index 00000000..7611e91b --- /dev/null +++ b/include/LCUI/gui/widget/textedit.h @@ -0,0 +1,82 @@ +/* *************************************************************************** + * textedit.c -- textedit widget, used to allow user edit text. + * + * Copyright (C) 2016 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * textedit.c -- 文本编辑部件,用于让用户编辑文本。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ +#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 diff --git a/include/LCUI/gui/widget/textview.h b/include/LCUI/gui/widget/textview.h index 6bbbb094..6cb27d3d 100644 --- a/include/LCUI/gui/widget/textview.h +++ b/include/LCUI/gui/widget/textview.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_TEXTVIEW_H__ -#define __LCUI_TEXTVIEW_H__ +#ifndef LCUI_TEXTVIEW_H +#define LCUI_TEXTVIEW_H #include @@ -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 diff --git a/include/LCUI/gui/widget_base.h b/include/LCUI/gui/widget_base.h index ab3475ea..05aa8152 100755 --- a/include/LCUI/gui/widget_base.h +++ b/include/LCUI/gui/widget_base.h @@ -37,25 +37,23 @@ * 没有,请查看:. * ****************************************************************************/ -#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 +#include /** 部件样式 */ 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 ); diff --git a/include/LCUI/gui/widget_event.h b/include/LCUI/gui/widget_event.h index ad3377bf..da0bec6e 100644 --- a/include/LCUI/gui/widget_event.h +++ b/include/LCUI/gui/widget_event.h @@ -37,14 +37,15 @@ * 没有,请查看:. * ***************************************************************************/ -#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); diff --git a/include/LCUI/gui/widget_library.h b/include/LCUI/gui/widget_library.h index 46143262..d8c48bc8 100644 --- a/include/LCUI/gui/widget_library.h +++ b/include/LCUI/gui/widget_library.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ***************************************************************************/ -#ifndef __LCUI_WIDGET_LIBRARY_H__ -#define __LCUI_WIDGET_LIBRARY_H__ +#ifndef LCUI_WIDGET_LIBRARY_H +#define LCUI_WIDGET_LIBRARY_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/gui/widget_paint.h b/include/LCUI/gui/widget_paint.h index a164a347..e8712216 100644 --- a/include/LCUI/gui/widget_paint.h +++ b/include/LCUI/gui/widget_paint.h @@ -38,8 +38,8 @@ * 没有,请查看:. * ***************************************************************************/ -#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 目标部件 diff --git a/include/LCUI/gui/widget_style.h b/include/LCUI/gui/widget_style.h index b12d6940..e026fb4d 100644 --- a/include/LCUI/gui/widget_style.h +++ b/include/LCUI/gui/widget_style.h @@ -1,7 +1,7 @@ /* *************************************************************************** * widget_style.h -- widget style library module for LCUI. * - * Copyright (C) 2015 by Liu Chao + * Copyright (C) 2015-2016 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. @@ -22,7 +22,7 @@ /* **************************************************************************** * widget_style.h -- LCUI 的部件样式库模块。 * - * 版权所有 (C) 2015 归属于 刘超 + * 版权所有 (C) 2015-2016 归属于 刘超 * * 这个文件是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_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 diff --git a/include/LCUI/gui/widget_task.h b/include/LCUI/gui/widget_task.h index c2f2304d..2619d46a 100644 --- a/include/LCUI/gui/widget_task.h +++ b/include/LCUI/gui/widget_task.h @@ -37,8 +37,10 @@ * 没有,请查看:. * ***************************************************************************/ -#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 diff --git a/include/LCUI/ime.h b/include/LCUI/ime.h index f992652d..5373c6a8 100644 --- a/include/LCUI/ime.h +++ b/include/LCUI/ime.h @@ -1,51 +1,88 @@ -#ifndef __LCUI_IME_H__ -#define __LCUI_IME_H__ +/* *************************************************************************** + * ime.h -- Input Method Editor/Engine + * + * Copyright (C) 2016 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * ime.h -- 输入法管理器 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +#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 diff --git a/include/LCUI/input.h b/include/LCUI/input.h index 475a2541..6b9728fb 100644 --- a/include/LCUI/input.h +++ b/include/LCUI/input.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ***************************************************************************/ -#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 */ diff --git a/include/LCUI/main.h b/include/LCUI/main.h index dae68257..419360c6 100644 --- a/include/LCUI/main.h +++ b/include/LCUI/main.h @@ -36,8 +36,8 @@ * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 * 没有,请查看:. * ***************************************************************************/ -#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 ); diff --git a/include/LCUI/platform.h b/include/LCUI/platform.h index 02064936..443ab294 100644 --- a/include/LCUI/platform.h +++ b/include/LCUI/platform.h @@ -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 diff --git a/include/LCUI/platform/linux/linux_display.h b/include/LCUI/platform/linux/linux_display.h index 23194955..83c2f19e 100644 --- a/include/LCUI/platform/linux/linux_display.h +++ b/include/LCUI/platform/linux/linux_display.h @@ -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 +#include int LCUI_InitLinuxDisplay( LCUI_DisplayDriver driver ); diff --git a/include/LCUI/platform/linux/linux_events.h b/include/LCUI/platform/linux/linux_events.h index f8c1949c..585a917e 100644 --- a/include/LCUI/platform/linux/linux_events.h +++ b/include/LCUI/platform/linux/linux_events.h @@ -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 + * + * 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 . + * ****************************************************************************/ +/* **************************************************************************** + * linux_events.c -- linux 平台的事件驱动支持。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +#ifndef LCUI_LINUX_EVENTS_H +#define LCUI_LINUX_EVENTS_H + +#include int LCUI_InitLinuxApp( LCUI_AppDriver app ); diff --git a/include/LCUI/platform/linux/linux_fbdisplay.h b/include/LCUI/platform/linux/linux_fbdisplay.h index 8b137891..5323d41e 100644 --- a/include/LCUI/platform/linux/linux_fbdisplay.h +++ b/include/LCUI/platform/linux/linux_fbdisplay.h @@ -1 +1,39 @@ +/* *************************************************************************** + * linux_fbdisplay.h -- surface support for linux framebuffer. + * + * Copyright (C) 2016 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * linux_fbdisplay.h -- linux 平台的图形显示功能支持,基于帧缓存(FrameBuffer)。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ diff --git a/include/LCUI/platform/linux/linux_keyboard.h b/include/LCUI/platform/linux/linux_keyboard.h index a2107494..9eece3c1 100644 --- a/include/LCUI/platform/linux/linux_keyboard.h +++ b/include/LCUI/platform/linux/linux_keyboard.h @@ -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 ); diff --git a/include/LCUI/platform/linux/linux_mouse.h b/include/LCUI/platform/linux/linux_mouse.h index db72fdc8..31ae4901 100644 --- a/include/LCUI/platform/linux/linux_mouse.h +++ b/include/LCUI/platform/linux/linux_mouse.h @@ -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 + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * linux_mouse.h -- linux 平台的鼠标支持 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +#ifndef LCUI_LINUX_MOUSE_H +#define LCUI_LINUX_MOUSE_H + +#include void LCUI_InitLinuxMouse( void ); diff --git a/include/LCUI/platform/linux/linux_x11display.h b/include/LCUI/platform/linux/linux_x11display.h index 8b137891..646e6198 100644 --- a/include/LCUI/platform/linux/linux_x11display.h +++ b/include/LCUI/platform/linux/linux_x11display.h @@ -1 +1,47 @@ +/* *************************************************************************** + * linux_x11display.h -- surface support for linux xwindow. + * + * Copyright (C) 2016 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 . + * ****************************************************************************/ +/* **************************************************************************** + * linux_x11display.h -- linux 平台的图形显示功能支持,基于 xwindow。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +#ifndef LCUI_LINUX_X11_DISPLAY_H +#define LCUI_LINUX_X11_DISPLAY_H + +int LCUI_InitLinuxX11Display( LCUI_DisplayDriver driver ); + +int LCUI_ExitLinuxX11Display( void ); + +#endif \ No newline at end of file diff --git a/include/LCUI/platform/linux/linux_x11events.h b/include/LCUI/platform/linux/linux_x11events.h index 8b137891..0d5637c4 100644 --- a/include/LCUI/platform/linux/linux_x11events.h +++ b/include/LCUI/platform/linux/linux_x11events.h @@ -1 +1,64 @@ +/* *************************************************************************** + * linux_x11events.c -- event loop support for linux xwindow. + * + * Copyright (C) 2016 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 . + * ****************************************************************************/ +/* **************************************************************************** + * linux_x11events.c -- linux 平台的事件驱动支持,基于 xwindow。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +#ifndef LCUI_LINUX_X11_EVENTS_H +#define LCUI_LINUX_X11_EVENTS_H + +#include +#include +#include +#include + +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 diff --git a/include/LCUI/util/delay.h b/include/LCUI/platform/linux/linux_x11mouse.h similarity index 76% rename from include/LCUI/util/delay.h rename to include/LCUI/platform/linux/linux_x11mouse.h index 1d31b662..aabd4ae3 100644 --- a/include/LCUI/util/delay.h +++ b/include/LCUI/platform/linux/linux_x11mouse.h @@ -1,7 +1,7 @@ -/* *************************************************************************** - * delay.h -- time delay function. +/* *************************************************************************** + * linux_x11mouse.h -- mouse support for linux xwindow. * - * Copyright (C) 2013-2016 by Liu Chao + * Copyright (C) 2016 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. @@ -20,9 +20,9 @@ * ****************************************************************************/ /* **************************************************************************** - * delay.h -- 一些提供延时功能的函数 + * linux_x11mouse.h -- linux 平台的鼠标支持,基于 xwindow。 * - * 版权所有 (C) 2013-2016 归属于 刘超 + * 版权所有 (C) 2016 归属于 刘超 * * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 * @@ -36,18 +36,12 @@ * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 * 没有,请查看:. * ****************************************************************************/ -#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 - diff --git a/include/LCUI/platform/windows/windows_display.h b/include/LCUI/platform/windows/windows_display.h index 2f3dc2ae..edba8f33 100644 --- a/include/LCUI/platform/windows/windows_display.h +++ b/include/LCUI/platform/windows/windows_display.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#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 ); diff --git a/include/LCUI/platform/windows/windows_events.h b/include/LCUI/platform/windows/windows_events.h index 0db46767..7983281c 100644 --- a/include/LCUI/platform/windows/windows_events.h +++ b/include/LCUI/platform/windows/windows_events.h @@ -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 diff --git a/include/LCUI/platform/windows/windows_keyboard.h b/include/LCUI/platform/windows/windows_keyboard.h index 6ce540b2..066ca047 100644 --- a/include/LCUI/platform/windows/windows_keyboard.h +++ b/include/LCUI/platform/windows/windows_keyboard.h @@ -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 ); diff --git a/include/LCUI/platform/windows/windows_mouse.h b/include/LCUI/platform/windows/windows_mouse.h index b6342c4d..8c488556 100644 --- a/include/LCUI/platform/windows/windows_mouse.h +++ b/include/LCUI/platform/windows/windows_mouse.h @@ -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 ); diff --git a/include/LCUI/surface.h b/include/LCUI/surface.h index 5805325b..18dc9645 100644 --- a/include/LCUI/surface.h +++ b/include/LCUI/surface.h @@ -37,13 +37,13 @@ * 没有,请查看:. * ***************************************************************************/ -#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; diff --git a/include/LCUI/thread.h b/include/LCUI/thread.h index 9a7687ca..242c8b0b 100644 --- a/include/LCUI/thread.h +++ b/include/LCUI/thread.h @@ -39,8 +39,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_THREAD_H__ -#define __LCUI_THREAD_H__ +#ifndef LCUI_THREAD_H +#define LCUI_THREAD_H #ifdef LCUI_THREAD_PTHREAD #include diff --git a/include/LCUI/timer.h b/include/LCUI/timer.h index 86d9d2fd..c4266626 100644 --- a/include/LCUI/timer.h +++ b/include/LCUI/timer.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ***************************************************************************/ -#ifndef __LCUI_TIMER_H__ -#define __LCUI_TIMER_H__ +#ifndef LCUI_TIMER_H +#define LCUI_TIMER_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/util.h b/include/LCUI/util.h index 3aa48a71..538050ac 100644 --- a/include/LCUI/util.h +++ b/include/LCUI/util.h @@ -37,10 +37,9 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_MISC_H__ -#define __LCUI_MISC_H__ +#ifndef LCUI_UTIL_H +#define LCUI_UTIL_H #include -#include #include #include #include @@ -50,4 +49,5 @@ #include #include #include +#include #endif diff --git a/include/LCUI/util/Makefile.am b/include/LCUI/util/Makefile.am index af4e1773..f6754e4d 100644 --- a/include/LCUI/util/Makefile.am +++ b/include/LCUI/util/Makefile.am @@ -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 diff --git a/include/LCUI/util/dict.h b/include/LCUI/util/dict.h index 379f02f4..7762b0f3 100644 --- a/include/LCUI/util/dict.h +++ b/include/LCUI/util/dict.h @@ -34,8 +34,8 @@ #include -#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 */ diff --git a/include/LCUI/util/dirent.h b/include/LCUI/util/dirent.h index e4072180..f6975b55 100644 --- a/include/LCUI/util/dirent.h +++ b/include/LCUI/util/dirent.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 diff --git a/include/LCUI/util/event.h b/include/LCUI/util/event.h index 8fdd1643..8b683643 100644 --- a/include/LCUI/util/event.h +++ b/include/LCUI/util/event.h @@ -36,8 +36,8 @@ * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_LIB_EVENT_H__ -#define __LCUI_LIB_EVENT_H__ +#ifndef LCUI_UTIL_EVENT_H +#define LCUI_UTIL_EVENT_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/util/framectrl.h b/include/LCUI/util/framectrl.h index 7f576457..0a648622 100644 --- a/include/LCUI/util/framectrl.h +++ b/include/LCUI/util/framectrl.h @@ -38,35 +38,35 @@ * 没有,请查看:. * ****************************************************************************/ -#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 diff --git a/include/LCUI/util/linkedlist.h b/include/LCUI/util/linkedlist.h index b7975b36..fb9d9c7e 100644 --- a/include/LCUI/util/linkedlist.h +++ b/include/LCUI/util/linkedlist.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#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 diff --git a/include/LCUI/util/memdebug.h b/include/LCUI/util/memdebug.h new file mode 100644 index 00000000..2835b7d4 --- /dev/null +++ b/include/LCUI/util/memdebug.h @@ -0,0 +1,74 @@ +/* *************************************************************************** + * memdebug.h -- memory debug module, used for memory usage statistics. + * + * Copyright (C) 2016 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * memdebug.h -- Äڴæµ÷ÊÔģ¿飬ÓÃÓÚͳ¼Ƹ÷¸öÄڴæ¿éµÄʹÓÃÇé¿ö£¬·½±ãµ÷Êԡ£ + * + * °æȨËùÓÐ (C) 2016 ¹éÊôÓÚ Áõ³¬ + * + * Õâ¸öÎļþÊÇLCUIÏîĿµÄһ²¿·֣¬²¢ÇÒֻ¿ÉÒԸù¾ÝGPLv2Ðí¿ÉЭÒéÀ´ʹÓᢸü¸ĺͷ¢²¼¡£ + * + * (GPLv2 ÊÇ GNUͨÓù«¹²Ðí¿É֤µڶþ°æ µÄӢÎÄËõд) + * + * ¼ÌÐøʹÓá¢Ð޸Ļ򷢲¼±¾Îļþ£¬±íÃ÷ÄúÒѾ­ÔĶÁ²¢ÍêȫÀí½âºͽÓÊÜÕâ¸öÐí¿ÉЭÒ顣 + * + * LCUI ÏîĿÊǻùÓÚʹÓÃĿµĶø¼ÓÒÔɢ²¼µģ¬µ«²»¸ºÈκε£±£ÔðÈΣ¬ÉõÖÁûÓÐÊÊÏúÐԻòÌØ + * ¶¨ÓÃ;µÄÒþº¬µ£±££¬ÏêÇéÇë²ÎÕÕGPLv2Ðí¿ÉЭÒ顣 + * + * ÄúӦÒÑÊյ½¸½ËæÓڱ¾ÎļþµÄGPLv2Ðí¿ÉЭÒéµĸ±±¾£¬Ëüͨ³£ÔÚLICENSE.TXTÎļþÖУ¬Èç¹û + * ûÓУ¬Çë²鿴£º. + * ****************************************************************************/ + +#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 diff --git a/include/LCUI/util/parse.h b/include/LCUI/util/parse.h index 5cab33ce..02372bbe 100644 --- a/include/LCUI/util/parse.h +++ b/include/LCUI/util/parse.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ***************************************************************************/ -#ifndef __LCUI_UTIL_PARSE_H__ -#define __LCUI_UTIL_PARSE_H__ +#ifndef LCUI_UTIL_PARSE_H +#define LCUI_UTIL_PARSE_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/util/rbtree.h b/include/LCUI/util/rbtree.h index 75f4174e..440e2b4c 100644 --- a/include/LCUI/util/rbtree.h +++ b/include/LCUI/util/rbtree.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ***************************************************************************/ -#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 ); diff --git a/include/LCUI/util/rect.h b/include/LCUI/util/rect.h index ba321bad..347ac046 100644 --- a/include/LCUI/util/rect.h +++ b/include/LCUI/util/rect.h @@ -1,8 +1,7 @@ /* *************************************************************************** * rect.h -- Rectangle area handling * - * Copyright (C) 2012-2015 by - * Liu Chao + * Copyright (C) 2012-2016 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. @@ -23,8 +22,7 @@ /* **************************************************************************** * rect.h -- 矩形区域处理 * - * 版权所有 (C) 2012-2015 归属于 - * 刘超 + * 版权所有 (C) 2012-2016 归属于 刘超 * * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 * @@ -38,8 +36,9 @@ * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_MISC_RECT_H__ -#define __LCUI_MISC_RECT_H__ + +#ifndef LCUI_UTIL_RECT_H +#define LCUI_UTIL_RECT_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/util/string.h b/include/LCUI/util/string.h index 25962af0..e7ccb35e 100644 --- a/include/LCUI/util/string.h +++ b/include/LCUI/util/string.h @@ -1,7 +1,7 @@ /* *************************************************************************** * string.h -- The string operation set. * - * Copyright (C) 2015 by Liu Chao + * Copyright (C) 2015-2016 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. @@ -22,7 +22,7 @@ /* **************************************************************************** * string.h -- 字符串相关操作函数。 * - * 版权所有 (C) 2015 归属于 刘超 + * 版权所有 (C) 2015-2016 归属于 刘超 * * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 * @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#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 @@ -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 diff --git a/include/LCUI/util/time.h b/include/LCUI/util/time.h index 1dcc3980..e04cbcfa 100644 --- a/include/LCUI/util/time.h +++ b/include/LCUI/util/time.h @@ -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 +* +* 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 . +* ****************************************************************************/ + +/* **************************************************************************** +* time.c -- 时间相关函数集 +* +* 版权所有 (C) 2015-2016 归属于 刘超 +* +* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 +* +* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) +* +* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 +* +* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 +* 定用途的隐含担保,详情请参照GPLv2许可协议。 +* +* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 +* 没有,请查看:. +* ****************************************************************************/ + +#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 diff --git a/include/LCUI_Build.h b/include/LCUI_Build.h index 5da32a83..4493e731 100755 --- a/include/LCUI_Build.h +++ b/include/LCUI_Build.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_BUILD_H__ -#define __LCUI_BUILD_H__ +#ifndef LCUI_BUILD_H +#define LCUI_BUILD_H #if defined(__GNUC__) # define LCUI_API diff --git a/m4/ax_pthread.m4 b/m4/ax_pthread.m4 new file mode 100644 index 00000000..4c4051ea --- /dev/null +++ b/m4/ax_pthread.m4 @@ -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 +# Copyright (c) 2011 Daniel Richard G. +# +# 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 . +# +# 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 +# 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 ], + [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 ]], + [[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 diff --git a/src/Makefile.am b/src/Makefile.am index d586ecc6..7502f699 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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) diff --git a/src/bmp/bmp.c b/src/bmp/bmp.c index 3334d5cb..f0ea2ed9 100755 --- a/src/bmp/bmp.c +++ b/src/bmp/bmp.c @@ -38,6 +38,7 @@ * ***************************************************************************/ #include +#include #include #include #include @@ -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; diff --git a/src/bmp/jpeg.c b/src/bmp/jpeg.c index ec57420e..db01d8bf 100755 --- a/src/bmp/jpeg.c +++ b/src/bmp/jpeg.c @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -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 ); diff --git a/src/bmp/load_image.c b/src/bmp/load_image.c index 0eca5c9a..efacef9f 100755 --- a/src/bmp/load_image.c +++ b/src/bmp/load_image.c @@ -1,22 +1,22 @@ +#include +#include +#include #include #include #include -#include -#include - /** 检测图片格式,并解码图片 */ 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; } diff --git a/src/bmp/png.c b/src/bmp/png.c index c30c33d7..727034aa 100644 --- a/src/bmp/png.c +++ b/src/bmp/png.c @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -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 ) diff --git a/src/cursor.c b/src/cursor.c index d2f0dc2f..54e30d00 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -40,7 +40,6 @@ //#define DEBUG #include #include -#include #include #include @@ -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); } diff --git a/src/display.c b/src/display.c index 17ee3395..6377b7e9 100644 --- a/src/display.c +++ b/src/display.c @@ -43,7 +43,6 @@ #include #include #include -#include #include #include #include @@ -52,6 +51,9 @@ #include #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 ); } diff --git a/src/font/charset.c b/src/font/charset.c index 4ca34d8c..3f51d3f5 100755 --- a/src/font/charset.c +++ b/src/font/charset.c @@ -1,7 +1,7 @@ /* *************************************************************************** * charset.c -- The charset opreation set. * -* Copyright (C) 2012-2016 by Liu Chao +* Copyright (C) 2015-2016 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. @@ -22,7 +22,7 @@ /* **************************************************************************** * charset.c -- 字符集的相关操作函数 * -* 版权所有 (C) 2013-2016 归属于 刘超 +* 版权所有 (C) 2015-2016 归属于 刘超 * * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 * @@ -39,7 +39,7 @@ #include #include -#include +#include #include #include @@ -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 } diff --git a/src/font/fontlibrary.c b/src/font/fontlibrary.c index 3c267bbf..c197eddb 100644 --- a/src/font/fontlibrary.c +++ b/src/font/fontlibrary.c @@ -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 diff --git a/src/font/freetype.c b/src/font/freetype.c index 6548def2..3b25b0c7 100644 --- a/src/font/freetype.c +++ b/src/font/freetype.c @@ -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 ) diff --git a/src/font/in-core/font_inconsolata.c b/src/font/in-core/font_inconsolata.c index 3d5e0104..30677e6d 100644 --- a/src/font/in-core/font_inconsolata.c +++ b/src/font/in-core/font_inconsolata.c @@ -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); diff --git a/src/font/textlayer.c b/src/font/textlayer.c index 875628bb..eaa60580 100644 --- a/src/font/textlayer.c +++ b/src/font/textlayer.c @@ -43,15 +43,29 @@ #include #include + /** 文本添加类型 */ +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; irowlist.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; rowrowlist.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; pis_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; rowrowlist.length; ++row ) { - txtrow = layer->rowlist.rows[row]; - for( i=0, w=0; ilength; ++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; irowlist.length; ++i ) { - h += layer->rowlist.rows[i]->height; - } - return h; -} - /** 重新载入各个文字的字体位图 */ void TextLayer_ReloadCharBitmap( LCUI_TextLayer layer ) { int row, col; - for( row=0; rowrowlist.length; ++row ) { + for( row = 0; row < layer->rowlist.length; ++row ) { TextRow txtrow = layer->rowlist.rows[row]; - for( col=0; collength; ++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; rowrowlist.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; collength; ++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( ; collength; ++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; +} diff --git a/src/font/textstyle.c b/src/font/textstyle.c index 08cd7ef2..3cb73964 100755 --- a/src/font/textstyle.c +++ b/src/font/textstyle.c @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -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 ); diff --git a/src/gui/Makefile.am b/src/gui/Makefile.am index 38102dec..d3c8679c 100755 --- a/src/gui/Makefile.am +++ b/src/gui/Makefile.am @@ -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 diff --git a/src/gui/builder.c b/src/gui/builder.c index f0cf1c0a..7b4eaeb2 100644 --- a/src/gui/builder.c +++ b/src/gui/builder.c @@ -37,6 +37,7 @@ * 没有,请查看:. * ****************************************************************************/ +#include #include #include #include @@ -44,7 +45,7 @@ #include #include -#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 @@ -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(); } diff --git a/src/gui/css_library.c b/src/gui/css_library.c new file mode 100644 index 00000000..1228b886 --- /dev/null +++ b/src/gui/css_library.c @@ -0,0 +1,1464 @@ +/* *************************************************************************** + * css_library.c -- css library operation module. + * + * Copyright (C) 2015-2016 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * css_library.c -- CSS 样式库操作模块 + * + * 版权所有 (C) 2015-2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_NAME_LEN 256 +#define LEN(A) sizeof( A ) / sizeof( *A ) + +enum SelectorRank { + GENERAL_RANK = 0, + TYPE_RANK = 1, + CLASS_RANK = 10, + PCLASS_RANK = 10, + ID_RANK = 100 +}; + +enum SelectorFinderLevel { + LEVEL_NONE, + LEVEL_TYPE, + LEVEL_ID, + LEVEL_CLASS, + LEVEL_CLASS_2, + LEVEL_STATUS, + LEVEL_STATUS_2, + LEVEL_TOTAL_NUM +}; + +/* 样式表查找器的上下文数据结构 */ +typedef struct NamesFinderRec_ { + int level; /**< 当前选择器层级 */ + int class_i; /**< 当前处理到第几个类名 */ + int status_i; /**< 当前处理到第几个状态名(伪类名) */ + int name_i; /**< 选择器名称从第几个字符开始 */ + char name[MAX_NAME_LEN]; /**< 选择器名称缓存 */ + LCUI_SelectorNode node; /**< 针对的选择器结点 */ +} NamesFinderRec, *NamesFinder; + +/** 样式链接记录组 */ +typedef struct StyleLinkGroupRec_ { + Dict *links; /**< 样式链接表 */ + char *name; /**< 选择器名称 */ + LCUI_SelectorNodeRec snode; /**< 选择器结点 */ +} StyleLinkGroupRec, *StyleLinkGroup; + +/** 样式结点记录 */ +typedef struct StyleNodeRec_ { + int rank; /**< 权值,决定优先级 */ + int batch_num; /**< 批次号 */ + char *space; /**< 所属的空间 */ + char *selector; /**< 选择器 */ + LCUI_StyleSheet sheet; /**< 样式表 */ +} StyleNodeRec, *StyleNode; + +/** 样式链接记录 */ +typedef struct StyleLinkRec_ { + char *selector; /**< 选择器 */ + StyleLinkGroup group; /**< 所属组 */ + LinkedList styles; /**< 作用于当前选择器的样式 */ + Dict *parents; /**< 父级节点 */ +} StyleLinkRec, *StyleLink; + +static struct { + LCUI_BOOL is_inited; + LCUI_Mutex mutex; /**< 互斥锁 */ + LinkedList groups; /**< 样式组列表 */ + Dict *cache; /**< 样式表缓存,以选择器的 hash 值索引 */ + Dict *names; /**< 样式属性名称表,以值的名称索引 */ + Dict *value_keys; /**< 样式属性值表,以值的名称索引 */ + Dict *value_names; /**< 样式属性值名称表,以值索引 */ + size_t count; /**< 当前记录的属性数量 */ +} library; + +/** 样式字符串值与标识码 */ +typedef struct KeyNameGroupRec_ { + int key; + char *name; +} KeyNameGroupRec, *KeyNameGroup; + +static KeyNameGroupRec 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_box_shadow_x, "box-shadow-x" }, + { key_box_shadow_y, "box-shadow-y" }, + { key_box_shadow_blur, "box-shadow-blur" }, + { key_box_shadow_spread, "box-shadow-spread" }, + { key_box_shadow_color, "box-shadow-color" }, + { key_pointer_events, "pointer-events" }, + { key_focusable, "focusable" }, + { key_box_sizing, "box-sizing" } +}; + +/** 样式字符串与标识码的映射表 */ +static KeyNameGroupRec style_value_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" }, + { SV_NOWRAP, "nowrap" } +}; + +static int LCUI_DirectAddStyleName( int key, const char *name ) +{ + unsigned int *newkey; + char *newname = strdup( name ); + if( !newname ) { + return -ENOMEM; + } + newkey = malloc( sizeof(unsigned int) ); + if( !newkey ) { + free( newname ); + return -ENOMEM; + } + *newkey = key; + if( Dict_Add( library.names, newkey, newname ) == 0 ) { + return 0; + } + free( newname ); + return -1; +} + +int LCUI_SetStyleName( int key, const char *name ) +{ + char *newname; + DictEntry *entry; + LCUIMutex_Lock( &library.mutex ); + entry = Dict_Find( library.names, &key ); + if( entry ) { + newname = strdup( name ); + free( DictEntry_GetVal( entry ) ); + Dict_SetVal( library.names, entry, newname ); + LCUIMutex_Unlock( &library.mutex ); + return 0; + } + LCUIMutex_Unlock( &library.mutex ); + return -1; +} + +int LCUI_AddStyleName( const char *name ) +{ + int key; + LCUIMutex_Lock( &library.mutex ); + key = library.count++; + if( LCUI_DirectAddStyleName( key, name ) != 0 ) { + --library.count; + LCUIMutex_Unlock( &library.mutex ); + return -1; + } + LCUIMutex_Unlock( &library.mutex ); + return key; +} + +int LCUI_AddStyleValue( int key, const char *name ) +{ + char *newname; + unsigned int *val; + newname = strdup( name ); + if( !newname ) { + return -ENOMEM; + } + val = malloc( sizeof( unsigned int ) ); + if( !val ) { + free( newname ); + return -ENOMEM; + } + *val = key; + if( Dict_Add( library.value_keys, newname, val ) ) { + free( newname ); + free( val ); + return -1; + } + return Dict_Add( library.value_names, val, newname ); +} + +int LCUI_GetStyleValue( const char *str ) +{ + int *val = Dict_FetchValue( library.value_keys, str ); + if( val ) { + return *val; + } + return -1; +} + +const char *LCUI_GetStyleValueName( int val ) +{ + return Dict_FetchValue( library.value_names, &val ); +} + +const char *LCUI_GetStyleName( int key ) +{ + return Dict_FetchValue( library.names, &key ); +} + +int LCUI_GetStyleTotal( void ) +{ + return library.count; +} + +LCUI_BOOL SelectorNode_Match( LCUI_SelectorNode sn1, + LCUI_SelectorNode sn2 ) +{ + int i, j; + if( sn2->id ) { + if( !sn1->id || strcmp( sn1->id, sn2->id ) != 0 ) { + return FALSE; + } + } + if( sn2->type && strcmp(sn2->type, "*") != 0 ) { + if( !sn1->type || strcmp( sn1->type, sn2->type ) != 0 ) { + return FALSE; + } + } + if( sn2->classes ) { + if( !sn1->classes ) { + return FALSE; + } + for( i = 0; sn2->classes[i]; ++i ) { + for( j = 0; sn1->classes[j]; ++j ) { + if( strcmp( sn2->classes[i], + sn1->classes[i] ) == 0 ) { + j = -1; + break; + } + } + if( j != -1 ) { + return FALSE; + } + } + } + if( sn2->status ) { + if( !sn1->status ) { + return FALSE; + } + for( i = 0; sn2->status[i]; ++i ) { + for( j = 0; sn1->status[j]; ++j ) { + if( strcmp( sn2->status[i], + sn1->status[i] ) == 0 ) { + j = -1; + break; + } + } + if( j != -1 ) { + return FALSE; + } + } + } + return TRUE; +} + +static void SelectorNode_Copy( LCUI_SelectorNode dst, LCUI_SelectorNode src ) +{ + int i; + dst->id = src->id ? strdup( src->id ) : NULL; + dst->type = src->type ? strdup( src->type ) : NULL; + dst->fullname = src->fullname ? strdup( src->fullname ) : NULL; + if( src->classes ) { + for( i = 0; src->classes[i]; ++i ) { + sortedstrsadd( &dst->classes, src->classes[i] ); + } + } + if( src->status ) { + for( i = 0; src->status[i]; ++i ) { + sortedstrsadd( &dst->status, src->status[i] ); + } + } +} + +static void SelectorNode_Delete( LCUI_SelectorNode node ) +{ + if( node->type ) { + free( node->type ); + node->type = NULL; + } + if( node->id ) { + free( node->id ); + node->id = NULL; + } + if( node->classes ) { + freestrs( node->classes ); + node->classes = NULL; + } + if( node->status ) { + freestrs( node->status ); + node->status = NULL; + } + if( node->fullname ) { + free( node->fullname ); + node->fullname = NULL; + } + free( node ); +} + +void Selector_Delete( LCUI_Selector s ) +{ + int i; + for( i = 0; i < MAX_SELECTOR_DEPTH; ++i ) { + if( !s->nodes[i] ) { + break; + } + SelectorNode_Delete( s->nodes[i] ); + s->nodes[i] = NULL; + } + s->rank = 0; + s->length = 0; + s->batch_num = 0; + free( s->nodes ); + free( s ); +} + +LCUI_StyleSheet StyleSheet( void ) +{ + LCUI_StyleSheet ss; + ss = NEW( LCUI_StyleSheetRec, 1 ); + if( !ss ) { + return ss; + } + ss->length = LCUI_GetStyleTotal(); + ss->sheet = NEW( LCUI_StyleRec, ss->length + 1 ); + return ss; +} + +void StyleSheet_Clear( LCUI_StyleSheet ss ) +{ + int i; + LCUI_Style s; + for( i = 0; i < ss->length; ++i ) { + s = &ss->sheet[i]; + switch( s->type ) { + case SVT_STRING: + case SVT_WSTRING: + if( s->is_valid && s->string ) { + free( s->string ); + } + s->string = NULL; + default: break; + } + s->is_valid = FALSE; + s->is_changed = TRUE; + } +} + +void StyleSheet_Delete( LCUI_StyleSheet ss ) +{ + StyleSheet_Clear( ss ); + free( ss->sheet ); + free( ss ); +} + +int StyleSheet_Merge( LCUI_StyleSheet dest, LCUI_StyleSheet src ) +{ + LCUI_Style s; + int i, count, size; + if( src->length > dest->length ) { + size = sizeof( LCUI_StyleRec )*src->length; + s = realloc( dest->sheet, size ); + if( !s ) { + return -1; + } + for( i = dest->length; i < src->length; ++i ) { + s[i].is_valid = FALSE; + } + dest->sheet = s; + dest->length = src->length; + } + for( count = 0, i = 0; i < src->length; ++i ) { + s = &dest->sheet[i]; + if( !src->sheet[i].is_valid || s->is_valid ) { + continue; + } + ++count; + switch( src->sheet[i].type ) { + case SVT_STRING: + s->string = strdup( src->sheet[i].string ); + break; + case SVT_WSTRING: + size = wcslen( src->sheet[i].wstring ) + 1; + s->wstring = malloc( size * sizeof( wchar_t ) ); + wcscpy( s->wstring, src->sheet[i].wstring ); + break; + default: + *s = src->sheet[i]; + break; + } + s->is_valid = TRUE; + s->is_changed = TRUE; + s->type = src->sheet[i].type; + } + return 0; +} + +int StyleSheet_Replace( LCUI_StyleSheet dest, LCUI_StyleSheet src ) +{ + LCUI_Style s; + int i, count, size; + if( src->length > dest->length ) { + size = sizeof( LCUI_StyleRec )*src->length; + s = realloc( dest->sheet, size ); + if( !s ) { + return -1; + } + for( i = dest->length; i < src->length; ++i ) { + s[i].is_valid = FALSE; + } + dest->sheet = s; + dest->length = src->length; + } + for( count = 0, i = 0; i < src->length; ++i ) { + if( !src->sheet[i].is_valid ) { + continue; + } + s = &dest->sheet[i]; + switch( src->sheet[i].type ) { + case SVT_STRING: + if( s->is_valid && s->string ) { + free( s->string ); + } + s->string = strdup( src->sheet[i].string ); + break; + case SVT_WSTRING: + if( s->is_valid && s->string ) { + free( s->wstring ); + } + size = wcslen( src->sheet[i].wstring ) + 1; + s->wstring = malloc( size * sizeof( wchar_t ) ); + wcscpy( s->wstring, src->sheet[i].wstring ); + break; + default: + *s = src->sheet[i]; + break; + } + s->is_valid = TRUE; + s->is_changed = TRUE; + s->type = src->sheet[i].type; + ++count; + } + return count; +} + +/** 初始化样式表查找器 */ +static void NamesFinder_Init( NamesFinder sfinder, LCUI_SelectorNode snode ) +{ + sfinder->level = 0; + sfinder->class_i = 0; + sfinder->name_i = 0; + sfinder->status_i = 0; + sfinder->name[0] = 0; + sfinder->node = snode; +} + +/** 销毁样式表查找器 */ +static void NamesFinder_Destroy( NamesFinder sfinder ) +{ + sfinder->name_i = 0; + sfinder->name[0] = 0; + sfinder->class_i = 0; + sfinder->status_i = 0; + sfinder->node = NULL; + sfinder->level = LEVEL_NONE; +} + +/* 生成选择器全名列表 */ +static int NamesFinder_Find( NamesFinder sfinder, LinkedList *list ) +{ + int i, len, old_len, old_level, count = 0; + char *fullname = sfinder->name + sfinder->name_i; + old_len = len = strlen( fullname ); + old_level = sfinder->level; + switch( sfinder->level ) { + case LEVEL_TYPE: + /* 按类型选择器生成选择器全名 */ + if( !sfinder->node->type ) { + return 0; + } + strcpy( fullname, sfinder->node->type ); + LinkedList_Append( list, strdup( fullname ) ); + break; + case LEVEL_ID: + /* 按ID选择器生成选择器全名 */ + if( !sfinder->node->id ) { + return 0; + } + fullname[len++] = '#'; + fullname[len] = 0; + strcpy( fullname + len, sfinder->node->id ); + LinkedList_Append( list, strdup( fullname ) ); + break; + case LEVEL_CLASS: + if( !sfinder->node->classes ) { + return 0; + } + /* 按类选择器生成选择器全名 + * 假设当前选择器全名为:textview#main-btn-text,且有 .a .b .c + * 这三个类,那么下面的处理将会拆分成以下三个选择器: + * textview#test-text.a + * textview#test-text.b + * textview#test-text.a + */ + fullname[len++] = '.'; + for( i = 0; sfinder->node->classes[i]; ++i ) { + sfinder->level += 1; + strcpy( fullname + len, sfinder->node->classes[i] ); + LinkedList_Append( list, strdup( fullname ) ); + /* 将当前选择器名与其它层级的选择器名组合 */ + while( sfinder->level < LEVEL_TOTAL_NUM ) { + count += NamesFinder_Find( sfinder, list ); + sfinder->level += 1; + } + sfinder->level = LEVEL_CLASS; + sfinder->class_i += 1; + } + sfinder->level = LEVEL_CLASS; + fullname[old_len] = 0; + sfinder->class_i = 0; + return count; + case LEVEL_CLASS_2: + if( !sfinder->node->classes ) { + return 0; + } + /* 按类选择器生成选择器全名,结果类似于这样: + * textview#test-text.a.b + * textview#test-text.a.c + * textview#test-text.b.c + * textview#test-text.a.b.c + */ + fullname[len++] = '.'; + for( i = 0; sfinder->node->classes[i]; ++i ) { + if( i <= sfinder->class_i ) { + continue; + } + strcpy( fullname + len, sfinder->node->classes[i] ); + LinkedList_Append( list, strdup( fullname ) ); + sfinder->class_i += 1; + count += NamesFinder_Find( sfinder, list ); + sfinder->class_i -= 1; + sfinder->level = LEVEL_STATUS; + /** + * 递归拼接伪类名,例如: + * textview#main-btn-text:active + */ + count += NamesFinder_Find( sfinder, list ); + sfinder->level = LEVEL_CLASS_2; + } + fullname[old_len] = 0; + sfinder->level = LEVEL_CLASS_2; + return count; + case LEVEL_STATUS: + if( !sfinder->node->status ) { + return 0; + } + fullname[len++] = ':'; + sfinder->level = LEVEL_STATUS_2; + /** + * 按伪类选择器生成选择器全名 + * 假设当前选择器全名为:textview#main-btn-text:hover:focus:active + * 那么下面的循环会将它拆分为以下几个选择器: + * textview#main-btn-text:active + * textview#main-btn-text:active:focus + * textview#main-btn-text:active:focus:hover + * textview#main-btn-text:active:hover + * textview#main-btn-text:focus + * textview#main-btn-text:focus:hover + * textview#main-btn-text:hover + */ + for( i = 0; sfinder->node->status[i]; ++i ) { + strcpy( fullname + len, sfinder->node->status[i] ); + LinkedList_Append( list, strdup( fullname ) ); + /** + * 递归调用,以一层层拼接出像下面这样的选择器: + * textview#main-btn-text:active:focus:hover + */ + count += NamesFinder_Find( sfinder, list ); + sfinder->status_i += 1; + } + sfinder->level = LEVEL_STATUS; + fullname[old_len] = 0; + sfinder->status_i = 0; + return count; + case LEVEL_STATUS_2: + if( !sfinder->node->status ) { + return 0; + } + /** 按伪类选择器生成选择器全名 */ + for( i = 0; sfinder->node->status[i]; ++i ) { + if( i <= sfinder->status_i ) { + continue; + } + fullname[len] = ':'; + strcpy( fullname + len + 1, sfinder->node->status[i] ); + LinkedList_Append( list, strdup( fullname ) ); + sfinder->status_i += 1; + count += NamesFinder_Find( sfinder, list ); + sfinder->status_i -= 1; + } + fullname[old_len] = 0; + return count; + default:break; + } + for( i = sfinder->level + 1; i < LEVEL_TOTAL_NUM; ++i ) { + if( i == LEVEL_STATUS_2 || i == LEVEL_CLASS_2 ) { + continue; + } + sfinder->level = i; + count += NamesFinder_Find( sfinder, list ); + } + fullname[old_len] = 0; + sfinder->level = old_level; + return count; +} + +static int SelectorNode_Save( LCUI_SelectorNode node, + const char *name, int len, char type ) +{ + char *str; + if( len < 1 ) { + return 0; + } + switch( type ) { + case 0: + if( node->type ) { + break; + } + len += 1; + str = malloc( sizeof( char ) * len ); + strncpy( str, name, len ); + node->type = str; + return TYPE_RANK; + case ':': + if( sortedstrsadd( &node->status, name ) == 0 ) { + return PCLASS_RANK; + } + break; + case '.': + if( sortedstrsadd( &node->classes, name ) == 0 ) { + return CLASS_RANK; + } + break; + case '#': + if( node->id ) { + break; + } + len += 1; + str = malloc( sizeof( char ) * len ); + strncpy( str, name, len ); + node->id = str; + return ID_RANK; + default: break; + } + return 0; +} + +int SelectorNode_GetNames( LCUI_SelectorNode sn, LinkedList *names ) +{ + int count; + NamesFinderRec sfinder; + NamesFinder_Init( &sfinder, sn ); + count = NamesFinder_Find( &sfinder, names ); + NamesFinder_Destroy( &sfinder ); + return count; +} + +int SelectorNode_Update( LCUI_SelectorNode node ) +{ + int i, len = 0; + char *fullname; + + node->rank = 0; + if( node->id ) { + len += strlen( node->id ) + 1; + node->rank += ID_RANK; + } + if( node->type ) { + len += strlen( node->type ) + 1; + node->rank += TYPE_RANK; + } + if( node->classes ) { + for( i = 0; node->classes[i]; ++i ) { + len += strlen( node->classes[i] ) + 1; + node->rank += CLASS_RANK; + } + } + if( node->status ) { + for( i = 0; node->status[i]; ++i ) { + len += strlen( node->status[i] ) + 1; + node->rank += PCLASS_RANK; + } + } + if( len > 0 ) { + fullname = malloc( sizeof( char ) * (len + 1) ); + if( !fullname ) { + return -ENOMEM; + } + fullname[0] = 0; + if( node->type ) { + strcat( fullname, node->type ); + } + if( node->id ) { + strcat( fullname, "#" ); + strcat( fullname, node->id ); + } + if( node->classes ) { + for( i = 0; node->classes[i]; ++i ) { + strcat( fullname, "." ); + strcat( fullname, node->classes[i] ); + } + len += 1; + } + if( node->status ) { + for( i = 0; node->status[i]; ++i ) { + strcat( fullname, ":" ); + strcat( fullname, node->status[i] ); + } + len += 1; + } + } else { + fullname = NULL; + } + if( node->fullname ) { + free( node->fullname ); + } + node->fullname = fullname; + return len; +} + +void Selector_Update( LCUI_Selector s ) +{ + int i; + const unsigned char *p; + unsigned int hash = 5381; + for( i = 0; i < s->length; ++i ) { + p = (unsigned char*)s->nodes[i]->fullname; + while( *p ) { + hash = ((hash << 5) + hash) + (*p++); + } + } + s->hash = hash; +} + +LCUI_Selector Selector( const char *selector ) +{ + const char *p; + int ni, si, rank; + static int batch_num = 0; + char type = 0, name[MAX_NAME_LEN]; + LCUI_BOOL is_saving = FALSE; + LCUI_SelectorNode node = NULL; + LCUI_Selector s = NEW( LCUI_SelectorRec, 1 ); + + s->batch_num = ++batch_num; + s->nodes = NEW( LCUI_SelectorNode, MAX_SELECTOR_DEPTH ); + if( !selector ) { + s->length = 0; + s->nodes[0] = NULL; + return s; + } + for( ni = 0, si = 0, p = selector; *p; ++p ) { + if( !node && is_saving ) { + node = NEW( LCUI_SelectorNodeRec, 1 ); + if( si >= MAX_SELECTOR_DEPTH ) { + _DEBUG_MSG( "%s: selector node list is too long.\n", + selector ); + return NULL; + } + s->nodes[si] = node; + } + switch( *p ) { + case ':': + case '.': + case '#': + if( !is_saving ) { + is_saving = TRUE; + type = *p; + continue; + } + /* 保存上个结点 */ + rank = SelectorNode_Save( node, name, ni, type ); + if( rank > 0 ) { + s->rank += rank; + } else { + _DEBUG_MSG( "%s: invalid selector node at %ld.\n", + selector, p - selector - ni ); + SelectorNode_Delete( node ); + node = NULL; + } + ni = 0; + is_saving = TRUE; + type = *p; + continue; + case ' ': + case '\r': + case '\n': + case '\t': + if( !is_saving ) { + ni = 0; + node = NULL; + continue; + } + is_saving = FALSE; + rank = SelectorNode_Save( node, name, ni, type ); + if( rank > 0 ) { + SelectorNode_Update( node ); + s->rank += rank; + node = NULL; + ni = 0; + si++; + continue; + } + _DEBUG_MSG( "%s: invalid selector node at %ld.\n", + selector, p - selector - ni ); + SelectorNode_Delete( node ); + node = NULL; + ni = 0; + continue; + default: break; + } + if( *p == '-' || *p == '_' || *p == '*' + || (*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') + || (*p >= '0' && *p <= '9') ) { + if( !is_saving ) { + type = 0; + is_saving = TRUE; + } + name[ni++] = *p; + name[ni] = 0; + continue; + } + _DEBUG_MSG( "%s: unknown char 0x%02x at %ld.\n", + selector, *p, p - selector ); + return NULL; + } + if( is_saving ) { + rank = SelectorNode_Save( s->nodes[si], name, ni, type ); + if( rank > 0 ) { + SelectorNode_Update( s->nodes[si] ); + s->rank += rank; + si++; + } else { + SelectorNode_Delete( s->nodes[si] ); + } + } + s->nodes[si] = NULL; + s->length = si; + Selector_Update( s ); + return s; +} + +static void DeleteStyleNode( StyleNode node ) +{ + if( node->space ) { + free( node->space ); + node->space = NULL; + } + if( node->selector ) { + free( node->selector ); + node->selector = NULL; + } + StyleSheet_Delete( node->sheet ); + node->sheet = NULL; +} + +static StyleLink CreateStyleLink( void ) +{ + StyleLink link = NEW( StyleLinkRec, 1 ); + link->group = NULL; + LinkedList_Init( &link->styles ); + link->parents = Dict_Create( &DictType_StringCopyKey, NULL ); + return link; +} + +static void DeleteStyleLink( StyleLink link ) +{ + link->group = NULL; + Dict_Release( link->parents ); + link->parents = NULL; + LinkedList_Clear( &link->styles, (FuncPtr)DeleteStyleNode ); +} + +static void OnDeleteStyleLink( void *privdata, void *data ) +{ + DeleteStyleLink( data ); +} + +static StyleLinkGroup CreateStyleLinkGroup( LCUI_SelectorNode snode ) +{ + DictType *dtype = NEW( DictType, 1 ); + StyleLinkGroup group = NEW( StyleLinkGroupRec, 1 ); + SelectorNode_Copy( &group->snode, snode ); + group->name = group->snode.fullname; + *dtype = DictType_StringCopyKey; + dtype->valDestructor = OnDeleteStyleLink; + group->links = Dict_Create( dtype, dtype ); + return group; +} + +static void DeleteStyleLinkGroup( StyleLinkGroup group ) +{ + free( group->name ); + Dict_Release( group->links ); + free( group->links->privdata ); + group->name = NULL; + group->links = NULL; +} + +static void OnDeleteStyleLinkGroup( void *privdata, void *data ) +{ + DeleteStyleLinkGroup( data ); +} + +static Dict *CreateStyleGroup( void ) +{ + Dict *dict; + DictType *dtype = NEW( DictType, 1 ); + *dtype = DictType_StringCopyKey; + dtype->valDestructor = OnDeleteStyleLinkGroup; + dict = Dict_Create( dtype, dtype ); + return dict; +} + +static void DeleteStyleGroup( Dict *dict ) +{ + Dict_Release( dict ); + free( dict->privdata ); + dict->privdata = NULL; +} + +/** 根据选择器,选中匹配的样式表 */ +static LCUI_StyleSheet LCUI_SelectStyleSheet( LCUI_Selector selector, + const char *space ) +{ + int i, right; + StyleLink link; + StyleNode snode; + StyleLinkGroup slg; + LinkedListNode *node; + LCUI_SelectorNode sn; + Dict *group, *parents; + char buf[MAX_SELECTOR_LEN]; + char fullname[MAX_SELECTOR_LEN]; + + link = NULL; + parents = NULL; + for( i = 0, right = selector->length - 1; right >= 0; --right, ++i ) { + group = LinkedList_Get( &library.groups, i ); + if( !group ) { + group = CreateStyleGroup(); + LinkedList_Append( &library.groups, group ); + } + sn = selector->nodes[right]; + slg = Dict_FetchValue( group, sn->fullname ); + if( !slg ) { + slg = CreateStyleLinkGroup( sn ); + Dict_Add( group, sn->fullname, slg ); + } + if( i == 0 ) { + strcpy( fullname, "*" ); + } else { + strcpy( fullname, buf ); + } + link = Dict_FetchValue( slg->links, fullname ); + if( !link ) { + link = CreateStyleLink(); + link->group = slg; + link->selector = strdup( fullname ); + Dict_Add( slg->links, fullname, link ); + } + if( i == 0 ) { + strcpy( buf, sn->fullname ); + strcpy( fullname, buf ); + } else { + strcpy( fullname, buf ); + sprintf( buf, "%s %s", sn->fullname, fullname ); + } + /* 如果有上一级的父链接记录,则将当前链接添加进去 */ + if( parents ) { + if( !Dict_FetchValue( parents, sn->fullname ) ) { + Dict_Add( parents, sn->fullname, link ); + } + } + parents = link->parents; + } + if( !link ) { + return NULL; + } + for( LinkedList_Each( node, &link->styles ) ) { + snode = node->data; + if( snode->space && space ) { + if( strcmp( snode->space, space ) == 0 ) { + return snode->sheet; + } + } else { + if( snode->space == space ) { + return snode->sheet; + } + } + } + snode = NEW( StyleNodeRec, 1 ); + if( space ) { + snode->space = NEW( char, strlen(space) + 1 ); + strcpy( snode->space, space ); + } else { + snode->space = NULL; + } + snode->sheet = StyleSheet(); + snode->rank = selector->rank; + snode->selector = strdup( fullname ); + snode->batch_num = selector->batch_num; + LinkedList_Append( &link->styles, snode ); + return snode->sheet; +} + +int LCUI_PutStyleSheet( LCUI_Selector selector, + LCUI_StyleSheet in_ss, const char *space ) +{ + LCUI_StyleSheet ss; + LCUIMutex_Lock( &library.mutex ); + Dict_Empty( library.cache ); + ss = LCUI_SelectStyleSheet( selector, space ); + if( ss ) { + StyleSheet_Replace( ss, in_ss ); + } + LCUIMutex_Unlock( &library.mutex ); + return 0; +} + +static int StyleLink_GetStyleSheets( StyleLink link, LinkedList *outlist ) +{ + StyleNode snode, out_snode; + LinkedListNode *node, *out_node; + + if( !outlist ) { + return link->styles.length; + } + for( LinkedList_Each( node, &link->styles ) ) { + int pos = -1, i = 0; + snode = node->data; + for( LinkedList_Each( out_node, outlist ) ) { + out_snode = out_node->data; + if( snode->rank > out_snode->rank ) { + pos = i; + break; + } + if( snode->rank != out_snode->rank ) { + i += 1; + continue; + } + if( snode->batch_num > out_snode->batch_num ) { + pos = i; + break; + } + i += 1; + } + if( pos >= 0 ) { + LinkedList_Insert( outlist, pos, snode ); + } else { + LinkedList_Append( outlist, snode ); + } + } + return link->styles.length; +} + +static int LCUI_FindStyleSheetFromLink( StyleLink link, LCUI_Selector s, + int i, LinkedList *list ) +{ + int count = 0; + StyleLink parent; + LinkedList names; + LinkedListNode *node; + LCUI_SelectorNode sn; + + LinkedList_Init( &names ); + count += StyleLink_GetStyleSheets( link, list ); + while( --i >= 0 ) { + sn = s->nodes[i]; + SelectorNode_GetNames( sn, &names ); + for( LinkedList_Each( node, &names ) ) { + parent = Dict_FetchValue( link->parents, node->data ); + if( !parent ) { + continue; + } + count += LCUI_FindStyleSheetFromLink( parent, s, + i, list ); + } + LinkedList_Clear( &names, free ); + } + return count; +} + +int LCUI_FindStyleSheetFromGroup( int group, const char *name, + LCUI_Selector s, LinkedList *list ) +{ + int i, count; + Dict *groups; + StyleLinkGroup slg; + LinkedListNode *node; + LinkedList names; + + groups = LinkedList_Get( &library.groups, group ); + if( !groups || s->length < 1 ) { + return 0; + } + count = 0; + i = s->length - 1; + LinkedList_Init( &names ); + if( name ) { + LinkedList_Append( &names, strdup( name ) ); + } else { + SelectorNode_GetNames( s->nodes[i], &names ); + LinkedList_Append( &names, strdup( "*" ) ); + } + for( LinkedList_Each( node, &names ) ) { + DictEntry *entry; + DictIterator *iter; + char *name = node->data; + slg = Dict_FetchValue( groups, name ); + if( !slg ) { + continue; + } + iter = Dict_GetIterator( slg->links ); + while( (entry = Dict_Next( iter )) ) { + StyleLink link = DictEntry_GetVal( entry ); + count += LCUI_FindStyleSheetFromLink( link, s, + i, list ); + } + } + LinkedList_Clear( &names, free ); + return count; +} + +void LCUI_PrintStyleSheet( LCUI_StyleSheet ss ) +{ + int key; + const char *name; + for( key = 0; key < ss->length; ++key ) { + LCUI_Style s = &ss->sheet[key]; + if( !s->is_valid ) { + continue; + } + name = LCUI_GetStyleName( key ); + if( name ) { + printf( "\t%s", name ); + } else { + printf( "\t", key ); + } + printf( "%s: ", key > STYLE_KEY_TOTAL ? " (+)" : "" ); + switch( s->type ) { + case SVT_AUTO: + printf( "auto" ); + break; + case SVT_BOOL: + printf( "%s", s->val_bool ? "true" : "false" ); + break; + case SVT_COLOR: { + LCUI_Color *clr = &s->val_color; + if( clr->alpha < 255 ) { + printf( "rgba(%d,%d,%d,%0.2f)", clr->r, + clr->g, clr->b, clr->a / 255.0 ); + } else { + printf( "#%02x%02x%02x", clr->r, clr->g, clr->b ); + } + break; + } + case SVT_PX: + printf( "%dpx", s->val_px ); + break; + case SVT_STRING: + printf( "%s", s->val_string ); + break; + case SVT_SCALE: + printf( "%.2lf%%", s->val_scale * 100 ); + break; + case SVT_STYLE: + printf( "%s", LCUI_GetStyleValueName( s->val_style ) ); + break; + default: + printf( "%d", s->value ); + break; + } + printf( ";\n" ); + } +} + +void LCUI_PrintSelector( LCUI_Selector selector ) +{ + char path[MAX_SELECTOR_LEN]; + LCUI_SelectorNode *sn; + + path[0] = 0; + for( sn = selector->nodes; *sn; ++sn ) { + strcat( path, (*sn)->fullname ); + strcat( path, " " ); + } + printf("path: %s (rank = %d, batch_num = %d)\n", path, + selector->rank, selector->batch_num); +} + +static void LCUI_PrintStyleLink( StyleLink link, const char *selector ) +{ + DictEntry *entry; + DictIterator *iter; + LinkedListNode *node; + char fullname[MAX_SELECTOR_LEN]; + if( selector ) { + sprintf( fullname, "%s %s", link->group->name, selector ); + } else { + strcpy( fullname, link->group->name ); + } + for( LinkedList_Each( node, &link->styles ) ) { + StyleNode snode = node->data; + printf("\n[%s]\n", snode->space ? snode->space:""); + printf("%s {\n", fullname); + LCUI_PrintStyleSheet( snode->sheet ); + printf("}\n"); + } + iter = Dict_GetIterator( link->parents ); + while( (entry = Dict_Next( iter )) ) { + StyleLink parent = DictEntry_GetVal( entry ); + LCUI_PrintStyleLink( parent, fullname ); + } + Dict_ReleaseIterator( iter ); +} + +void LCUI_PrintCSSLibrary( void ) +{ + Dict *group; + StyleLink link; + StyleLinkGroup slg; + DictIterator *iter; + DictEntry *entry; + + link = NULL; + printf( "style library begin\n" ); + group = LinkedList_Get( &library.groups, 0 ); + iter = Dict_GetIterator( group ); + while( (entry = Dict_Next(iter)) ) { + DictEntry *entry_slg; + DictIterator *iter_slg; + slg = DictEntry_GetVal( entry ); + iter_slg = Dict_GetIterator( slg->links ); + while( (entry_slg = Dict_Next(iter_slg)) ) { + link = DictEntry_GetVal( entry_slg ); + LCUI_PrintStyleLink( link, NULL ); + } + Dict_ReleaseIterator( iter_slg ); + } + Dict_ReleaseIterator( iter ); + printf( "style library end\n" ); +} + +void LCUI_GetStyleSheet( LCUI_Selector s, LCUI_StyleSheet out_ss ) +{ + LinkedList list; + LinkedListNode *node; + LCUI_StyleSheet ss; + LinkedList_Init( &list ); + StyleSheet_Clear( out_ss ); + LCUIMutex_Lock( &library.mutex ); + ss = Dict_FetchValue( library.cache, &s->hash ); + if( ss ) { + StyleSheet_Replace( out_ss, ss ); + LCUIMutex_Unlock( &library.mutex ); + return; + } + ss = StyleSheet(); + LCUI_FindStyleSheet( s, &list ); + for( LinkedList_Each( node, &list ) ) { + StyleNode sn = node->data; + StyleSheet_Merge( ss, sn->sheet ); + } + LinkedList_Clear( &list, NULL ); + Dict_Add( library.cache, &s->hash, ss ); + StyleSheet_Replace( out_ss, ss ); + LCUIMutex_Unlock( &library.mutex ); +} + +static void DestroyStyleSheetCache( void *privdata, void *val ) +{ + StyleSheet_Delete( val ); +} + +static void DestroyStyleName( void *privdata, void *val ) +{ + free( val ); +} + +static unsigned int IntKeyDict_HashFunction( const void *key ) +{ + return Dict_IdentityHashFunction( *(unsigned int*)key ); +} + +static int IntKeyDict_KeyCompare( void *privdata, + const void *key1, const void *key2 ) +{ + return *(unsigned int*)key1 == *(unsigned int*)key2; +} + +static void IntKeyDict_KeyDestructor( void *privdata, void *key ) +{ + free( key ); +} + +static void *IntKeyDict_KeyDup( void *privdata, const void *key ) +{ + unsigned int *newkey = malloc( sizeof(unsigned int) ); + *newkey = *(unsigned int*)key; + return newkey; +} + +void LCUI_InitCSSLibrary( void ) +{ + KeyNameGroup skn, skn_end; + static DictType cachedict, namedict; + cachedict.keyDup = IntKeyDict_KeyDup; + cachedict.keyCompare = IntKeyDict_KeyCompare; + cachedict.hashFunction = IntKeyDict_HashFunction; + cachedict.keyDestructor = IntKeyDict_KeyDestructor; + cachedict.valDestructor = DestroyStyleSheetCache; + cachedict.valDup = namedict.valDup = NULL; + namedict.keyDup = IntKeyDict_KeyDup; + namedict.keyCompare = IntKeyDict_KeyCompare; + namedict.hashFunction = IntKeyDict_HashFunction; + namedict.keyDestructor = IntKeyDict_KeyDestructor; + namedict.valDestructor = DestroyStyleName; + library.names = Dict_Create( &namedict, NULL ); + library.cache = Dict_Create( &cachedict, NULL ); + library.value_names = Dict_Create( &namedict, NULL ); + library.value_keys = Dict_Create( &DictType_StringKey, NULL ); + LinkedList_Init( &library.groups ); + LCUIMutex_Init( &library.mutex ); + skn_end = style_name_map + LEN( style_name_map ); + for( skn = style_name_map; skn < skn_end; ++skn ) { + LCUI_DirectAddStyleName( skn->key, skn->name ); + } + skn_end = style_value_map + LEN( style_value_map ); + for( skn = style_value_map; skn < skn_end; ++skn ) { + LCUI_AddStyleValue( skn->key, skn->name ); + } + library.count = STYLE_KEY_TOTAL; + library.is_inited = TRUE; +} + +void LCUI_ExitCSSLibrary( void ) +{ + library.is_inited = FALSE; + Dict_Release( library.names ); + Dict_Release( library.cache ); + Dict_Release( library.value_keys ); + Dict_Release( library.value_names ); + LCUIMutex_Destroy( &library.mutex ); + LinkedList_Clear( &library.groups, (FuncPtr)DeleteStyleGroup ); +} diff --git a/src/gui/css_parser.c b/src/gui/css_parser.c index 371254b3..04d5e927 100644 --- a/src/gui/css_parser.c +++ b/src/gui/css_parser.c @@ -36,13 +36,21 @@ * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 * 没有,请查看:. * ****************************************************************************/ -//#define DEBUG + #include #include #include #include #include -#include +#include +#include +#include + +#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 ); } diff --git a/src/gui/messagebox.c b/src/gui/messagebox.c deleted file mode 100755 index 15d00e77..00000000 --- a/src/gui/messagebox.c +++ /dev/null @@ -1,1775 +0,0 @@ -/* *************************************************************************** - * messagebox.c -- 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 . - * ****************************************************************************/ - -/* **************************************************************************** - * messagebox.c -- LCUI 的消息框 - * - * 版权所有 (C) 2012-2013 归属于 - * 刘超 - * - * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 - * - * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) - * - * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 - * - * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 - * 定用途的隐含担保,详情请参照GPLv2许可协议。 - * - * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 - * 没有,请查看:. - * ****************************************************************************/ -#ifdef ENABLE_THIS_MODULE -#include -#include -#include -#include -#include -#include -#include LC_LABEL_H -#include LC_BUTTON_H -#include LC_PICBOX_H -#include LC_WINDOW_H - -#define TEXT_MB_BTN_OK L"确定" -#define TEXT_MB_BTN_CANCEL L"取消" -#define TEXT_MB_BTN_ABORT L"终止" -#define TEXT_MB_BTN_IGNORE L"忽略" -#define TEXT_MB_BTN_RETRY L"重试" -#define TEXT_MB_BTN_YES L"是" -#define TEXT_MB_BTN_NO L"否" - -#define WIDGET_ID_MB_MSG_AREA 30 - -#define MB_BTN_SIZE Size(65, 28) -#define MB_BTN_AREA_BGCOLOR RGB(215,235,240) -#define MB_BTN_AREA_LINECOLOR RGB(180,200,240) -#define MB_ICONBOX_SIZE Size(48,48) -#define WIDGET_ID_MESSAGEBOX 1<<5 -#define MSGBOX_NONE_ICON 1<<6 -#define MB_BTN_AREA_HEIGHT 40 -#define MB_MSG_AREA_HEIGHT 55 -#define MB_BTN_AREA_HEIGHT_TEXT "40px" -#define MB_MSG_AREA_HEIGHT_TEXT "55px" - -enum IMG_ID { - IMG_ID_ERROR, - IMG_ID_HELP, - IMG_ID_INFO, - IMG_ID_WARNING, - IMG_TOTAL_NUM -}; - -typedef struct { - LCUI_MainLoop *mainloop; - LCUI_Widget msgbox; - MB_BTN clicked_button; -} MB_data; - -static unsigned char msgbox_icon[IMG_TOTAL_NUM][4][48*48] = { -{ - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,116,116,120,147, - 182,213,235,249,254,254,254,249,235,213,182,147,120,116,116,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,116,116,119,144,203,250,253,247,238,227,214,204,196,200,210,222,235,246,253,249,202,144,119, - 116,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,119,145,222,255,248,232,209, - 209,212,216,216,215,212,209,204,199,194,190,192,222,245,254,222,145,119,116,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,116,124,204,255,248,224,211,220,227,223,218,214,212,211,209,207,206,204,201,198,194,188,181,205,243, - 255,203,124,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,143,235,253,232,211,224,229,221,217, - 217,219,219,220,220,219,217,215,212,210,205,201,197,191,182,174,214,250,234,143,116,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,116,159,250,247,218,219,232,223,218,219,223,224,225,223,223,221,220,218,218,215,212,210,208,204,200,196,187, - 175,188,240,250,159,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,160,254,244,212,225,226,218,221,224,225,225, - 223,224,222,221,220,219,215,214,213,211,211,208,205,203,199,196,192,176,179,234,254,158,116,0,0,0,0,0,0,0,0,0, - 0,0,0,116,143,250,244,209,226,222,216,222,225,227,224,223,222,221,219,219,217,215,213,211,209,209,207,205,203,202,199,197, - 193,190,175,179,232,249,138,116,0,0,0,0,0,0,0,0,0,0,116,124,234,245,211,225,220,217,223,224,221,217,220,221, - 220,219,217,215,213,211,209,209,206,203,204,201,197,193,196,195,193,189,187,176,180,238,232,122,116,0,0,0,0,0,0,0, - 0,116,119,203,251,216,222,220,215,221,224,219,233,247,230,212,217,215,213,211,211,210,205,205,203,202,198,197,219,220,191,189, - 191,188,185,183,171,189,247,193,118,116,0,0,0,0,0,0,0,116,145,255,230,215,222,213,219,223,215,231,255,255,255,224, - 204,211,210,209,206,204,201,201,200,195,193,221,222,230,228,184,183,185,183,179,177,165,212,253,135,115,0,0,0,0,0,0, - 116,119,220,247,205,225,213,216,221,217,231,255,255,255,255,255,221,201,207,203,203,201,199,199,195,191,219,221,212,208,223,224, - 179,179,180,177,174,171,153,236,206,117,108,0,0,0,0,0,116,144,255,220,215,215,213,219,216,225,255,255,255,255,255,255, - 255,218,196,202,201,199,197,193,192,221,219,212,208,206,199,218,213,173,175,173,172,170,163,207,249,131,110,0,0,0,0,0, - 116,203,247,202,218,209,214,218,211,232,255,255,255,255,255,255,255,255,216,190,197,194,191,190,219,218,211,209,204,201,194,233, - 214,164,170,169,168,167,165,182,232,172,111,0,0,0,0,116,120,250,227,208,211,210,214,213,212,207,242,255,255,255,255,254, - 248,249,250,213,184,189,189,218,218,211,208,204,201,194,232,217,124,143,167,165,163,163,161,163,219,223,116,89,0,0,0,116, - 147,253,198,212,205,209,211,212,210,208,197,235,255,255,253,248,244,238,238,243,207,181,217,218,212,205,201,198,193,231,216,121, - 134,145,160,159,158,159,157,150,195,243,129,102,0,0,0,116,179,246,195,208,203,209,210,208,206,204,202,193,233,255,250,243, - 239,236,229,232,237,220,214,206,202,196,193,187,230,213,119,133,146,160,159,159,158,158,157,154,174,237,154,106,0,0,0,116, - 210,235,196,201,203,206,206,204,202,200,201,198,187,226,246,239,235,229,226,218,216,212,201,198,194,190,187,228,213,119,134,146, - 163,160,160,160,159,158,159,157,159,230,180,107,0,0,0,116,234,218,197,198,201,203,204,202,200,198,197,195,193,185,221,237, - 230,222,216,211,205,201,199,194,192,187,228,214,122,134,146,164,163,163,161,160,160,160,160,160,154,227,207,109,0,0,0,116, - 249,201,197,197,200,201,200,200,197,195,193,192,192,189,177,212,223,213,211,205,202,199,194,190,187,228,214,122,133,146,164,164, - 164,164,163,163,161,161,161,162,147,224,221,112,0,0,0,116,254,185,196,194,199,200,197,195,194,192,191,191,185,179,173,166, - 200,213,206,201,198,194,190,187,228,215,121,134,148,164,164,164,164,164,164,164,164,164,164,164,151,218,230,118,0,0,0,116, - 254,175,194,193,197,196,194,192,191,190,189,181,175,172,169,169,201,207,200,197,194,190,188,184,193,214,154,143,166,167,167,167, - 167,167,167,168,168,167,167,167,154,218,232,115,0,0,0,116,254,181,189,189,192,192,191,190,189,186,177,173,172,169,169,207, - 208,199,197,193,190,187,184,181,178,193,218,184,161,168,169,169,169,171,171,171,171,171,172,170,154,222,231,115,0,0,0,116, - 247,194,183,188,190,190,189,188,183,176,172,172,169,168,206,207,198,196,193,190,185,182,181,180,180,175,192,218,184,166,171,172, - 172,172,173,173,175,175,175,173,153,229,227,114,0,0,0,116,230,211,177,185,188,189,188,182,173,171,171,167,168,203,208,198, - 196,192,189,186,224,187,179,180,178,180,180,196,219,184,169,175,175,176,177,177,178,178,178,177,157,235,213,126,0,0,0,116, - 207,228,169,183,184,184,182,172,171,169,166,166,202,206,198,195,192,189,184,224,213,173,181,178,182,183,187,188,208,225,186,172, - 178,180,180,181,183,183,183,180,172,237,182,113,0,0,0,116,179,242,162,180,181,180,172,169,168,166,164,199,206,197,195,190, - 188,184,225,213,121,133,178,182,183,187,192,198,202,221,231,187,178,184,184,185,186,187,187,176,191,242,153,85,0,0,0,116, - 148,251,166,173,177,171,169,168,166,164,198,205,198,195,192,188,182,225,213,121,134,148,164,178,187,193,199,205,213,221,236,236, - 191,187,190,190,190,191,189,173,215,235,119,61,0,0,0,116,120,247,209,154,166,166,166,164,159,180,208,198,194,190,188,183, - 225,213,120,133,148,166,168,167,183,199,208,213,222,231,236,254,228,183,194,195,196,196,191,182,232,204,108,23,0,0,0,0, - 116,196,239,136,160,162,164,163,159,164,201,195,189,189,183,225,212,117,133,146,166,167,169,172,171,187,213,225,231,237,250,248, - 195,185,199,200,200,200,185,204,242,149,86,0,0,0,0,0,116,140,253,176,147,160,162,160,159,154,164,195,188,183,225,212, - 117,129,145,163,166,169,172,173,177,175,195,227,241,251,251,196,150,177,203,205,205,201,165,233,244,117,57,0,0,0,0,0, - 116,118,216,236,135,154,158,158,158,155,150,158,188,206,209,115,127,142,161,164,167,169,172,176,178,183,178,200,241,248,197,152, - 179,207,208,209,210,190,179,244,178,98,13,0,0,0,0,0,0,116,139,254,189,139,156,155,153,153,152,146,154,174,114,127, - 142,160,161,164,167,169,173,177,180,184,188,186,201,188,156,182,209,209,213,213,209,165,228,246,117,55,0,0,0,0,0,0, - 0,116,118,198,245,158,142,153,152,151,149,149,149,144,133,138,158,159,163,164,169,172,176,178,183,187,190,195,191,191,182,210, - 214,215,216,217,175,207,248,165,91,7,0,0,0,0,0,0,0,0,116,121,230,230,139,143,150,150,147,149,149,152,153,154, - 158,159,163,166,169,172,177,180,185,188,192,197,201,206,209,214,216,218,218,186,186,244,219,111,38,0,0,0,0,0,0,0, - 0,0,0,115,136,249,220,132,141,147,147,147,149,149,153,154,158,160,163,168,171,173,178,183,186,191,195,200,205,209,214,217, - 220,221,191,175,241,248,120,58,0,0,0,0,0,0,0,0,0,0,0,0,113,148,254,221,137,137,147,147,147,150,152,154, - 158,160,164,168,172,176,180,185,188,194,198,203,207,214,215,219,220,184,177,241,254,133,69,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,111,146,248,230,156,132,144,148,151,152,154,158,160,164,168,172,177,181,186,190,195,201,206,210,214,218,210, - 170,195,244,248,137,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,133,227,240,188,128,138,150,154,156, - 157,161,165,169,172,177,183,187,192,199,204,206,211,209,181,159,222,248,228,127,69,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,104,119,187,252,236,201,155,137,153,158,162,166,170,174,179,184,188,194,198,201,199,171,155,201,241, - 253,187,115,61,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,95,112,133,214,249,237,219,186, - 143,136,146,160,171,179,180,175,164,154,146,183,225,244,249,210,137,98,44,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,52,97,113,130,181,246,243,242,229,213,199,189,188,193,200,213,228,243,246,242,188,138,107, - 66,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,91,104,115,132, - 179,212,230,245,254,254,254,247,231,213,190,150,120,96,66,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,65,85,94,102,117,117,116,116,116,117,118,99,86,70,41,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,119,146, - 181,213,235,249,254,254,254,249,235,213,181,146,119,115,115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,115,115,118,144,203,250,250,229,199,160,122,87,69,84,117,155,194,227,249,249,202,144,118, - 115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,118,145,222,253,231,174,96, - 100,113,121,121,117,109,102,91,81,72,66,77,163,228,253,222,145,118,115,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,115,123,203,254,229,149,103,130,149,129,108,92,81,76,72,72,71,71,71,69,68,65,58,129,224, - 254,202,123,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,142,235,245,176,103,141,150,114,89, - 78,77,76,76,77,76,74,73,71,69,69,65,64,62,58,53,157,243,234,142,115,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,115,158,250,231,128,129,161,115,84,79,78,78,76,77,77,76,76,75,73,73,72,70,67,66,63,61,57, - 53,99,222,250,159,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,159,254,218,107,145,135,91,78,78,78,78, - 77,76,75,75,73,73,72,73,71,69,69,68,66,65,61,59,58,50,81,210,254,157,115,0,0,0,0,0,0,0,0,0, - 0,0,0,115,142,250,218,99,150,117,79,77,78,77,77,76,75,75,73,72,72,70,70,69,67,67,67,65,66,64,62,60, - 58,56,49,89,209,249,138,115,0,0,0,0,0,0,0,0,0,0,115,123,234,222,104,149,109,77,77,79,68,58,68,76, - 73,70,71,70,70,67,67,67,65,64,66,61,47,48,59,60,57,56,52,48,98,223,232,121,115,0,0,0,0,0,0,0, - 0,115,118,202,242,126,140,115,76,77,77,62,98,165,101,58,72,70,68,68,67,65,64,63,63,63,57,54,127,127,50,51, - 56,54,51,49,47,125,242,193,117,115,0,0,0,0,0,0,0,115,145,254,173,123,127,76,74,76,56,100,230,255,231,96, - 50,68,66,65,65,62,61,62,62,53,48,147,229,236,157,42,47,51,51,49,46,46,173,253,134,114,0,0,0,0,0,0, - 115,118,220,228,96,148,87,74,76,60,100,233,255,255,255,234,97,47,66,64,63,61,61,59,53,46,149,227,217,213,230,154, - 40,47,48,46,43,42,45,224,206,116,107,0,0,0,0,0,115,144,253,148,126,104,73,73,65,88,231,255,255,255,255,255, - 234,95,46,60,61,59,58,51,47,154,227,215,206,204,204,223,140,37,43,42,42,41,43,169,249,130,109,0,0,0,0,0, - 115,203,230,91,127,76,72,71,54,113,255,255,255,255,255,255,255,238,99,37,58,57,49,45,153,228,215,207,204,201,194,241, - 184,35,40,42,40,38,39,103,226,171,110,0,0,0,0,115,119,250,170,110,97,69,68,67,65,56,157,255,255,255,255,254, - 248,255,238,98,37,48,43,157,228,215,206,204,201,194,237,203,44,27,37,34,34,31,29,58,194,223,115,88,0,0,0,115, - 146,249,88,118,76,67,65,65,66,59,44,156,255,255,252,248,244,238,247,233,92,33,154,228,214,205,201,198,192,236,201,33, - 11,10,11,11,11,11,12,15,129,242,128,101,0,0,0,115,179,228,83,101,65,65,65,62,63,62,56,45,157,255,254,243, - 239,236,229,239,215,164,215,210,201,196,193,187,233,199,33,11,9,11,11,11,11,11,12,13,79,233,153,105,0,0,0,115, - 210,197,90,85,64,62,62,60,60,58,60,52,38,154,253,241,235,229,226,217,221,222,203,198,194,190,186,233,200,30,11,9, - 11,11,11,11,11,11,11,13,49,210,179,106,0,0,0,115,233,156,91,73,62,60,60,59,58,56,57,56,49,40,158,247, - 236,222,216,211,205,201,199,194,192,187,232,202,35,11,9,10,11,11,11,11,11,11,11,13,32,197,205,108,0,0,0,115, - 249,114,90,66,60,58,58,58,57,53,54,52,57,48,23,131,229,218,211,205,202,199,194,190,186,231,201,36,11,9,10,10, - 10,10,11,11,11,11,11,12,17,184,219,111,0,0,0,115,254,78,85,61,58,58,57,55,53,52,53,56,40,17,9,10, - 108,218,207,201,198,194,190,187,231,199,30,11,9,10,10,10,10,10,10,10,10,10,11,12,15,171,229,118,0,0,0,115, - 254,59,80,59,56,55,53,53,52,53,51,27,9,9,10,10,114,212,202,197,194,190,188,184,198,195,43,10,10,10,10,10, - 10,10,10,10,10,10,10,12,14,169,231,114,0,0,0,115,254,79,75,56,54,53,52,51,53,46,14,9,9,10,10,125, - 216,203,196,193,190,187,184,181,178,200,200,53,11,10,10,10,10,10,10,10,10,10,10,12,15,173,230,114,0,0,0,115, - 247,113,69,56,53,52,51,54,37,9,9,9,10,10,127,218,204,194,193,190,186,185,181,180,180,175,202,201,48,10,10,9, - 9,9,9,9,9,9,10,12,17,189,227,113,0,0,0,115,230,152,64,54,52,51,54,35,9,10,10,10,10,124,218,202, - 194,192,189,185,227,195,183,179,178,180,179,207,202,50,10,9,9,9,9,9,9,9,10,12,26,201,212,125,0,0,0,115, - 207,191,57,53,50,52,37,9,10,10,10,10,119,219,203,195,192,189,184,229,192,111,182,183,180,183,187,188,219,207,49,9, - 9,9,8,8,8,8,9,12,54,213,180,112,0,0,0,115,178,223,52,53,48,39,9,10,10,10,10,113,217,202,194,190, - 188,184,228,200,34,11,89,191,186,187,192,198,202,234,213,40,9,8,8,8,8,8,10,13,87,232,152,84,0,0,0,115, - 147,249,68,48,38,9,10,10,10,10,108,213,201,194,192,188,185,228,201,35,11,9,10,94,196,198,198,205,213,219,244,214, - 42,8,7,7,7,8,10,28,133,230,118,60,0,0,0,115,119,247,160,32,18,9,10,10,11,56,213,206,193,190,188,183, - 229,200,36,11,9,10,10,10,94,210,213,213,222,230,236,255,173,8,7,7,7,11,12,63,188,196,107,23,0,0,0,0, - 115,196,224,10,9,9,10,11,11,26,165,207,190,188,183,229,196,31,11,9,10,10,10,9,10,96,219,229,230,237,254,255, - 101,8,8,9,10,13,16,108,223,143,86,0,0,0,0,0,115,140,253,100,8,10,10,11,11,11,30,168,200,186,228,197, - 31,11,10,11,10,10,9,9,9,9,102,236,247,255,255,118,9,7,12,10,12,15,22,173,240,116,57,0,0,0,0,0, - 115,117,215,222,8,10,10,11,11,11,12,32,160,219,193,29,12,10,11,10,10,10,9,9,9,8,9,102,251,255,116,9, - 5,13,11,12,15,18,44,217,165,97,13,0,0,0,0,0,0,115,138,254,128,9,10,11,12,12,12,12,26,105,25,12, - 10,11,11,10,10,10,9,9,8,8,8,8,81,76,8,5,12,12,14,15,17,25,149,242,116,55,0,0,0,0,0,0, - 0,115,117,198,240,60,10,11,12,12,12,12,12,13,11,10,11,11,11,10,10,9,9,9,8,8,7,7,7,7,9,13, - 12,13,15,16,21,83,232,151,90,7,0,0,0,0,0,0,0,0,115,120,230,215,24,11,11,12,12,12,12,12,12,11, - 11,11,11,10,10,9,9,8,8,8,7,8,11,11,12,13,14,15,16,21,45,205,206,110,38,0,0,0,0,0,0,0, - 0,0,0,114,136,249,195,12,11,12,12,12,12,12,12,11,11,11,11,10,10,9,9,8,8,7,8,11,11,11,13,14, - 15,17,21,33,185,244,117,58,0,0,0,0,0,0,0,0,0,0,0,0,112,147,254,192,24,12,13,13,12,12,12,11, - 11,11,10,10,9,9,8,8,8,7,10,12,13,13,14,15,18,23,41,182,253,125,68,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,110,146,248,207,59,14,13,12,12,12,12,11,11,10,10,9,9,8,8,7,8,11,14,13,15,16,19, - 25,69,197,243,124,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,107,132,227,229,120,14,14,13,13,13, - 12,12,11,11,10,10,9,9,8,12,12,15,16,18,23,27,122,221,213,118,69,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,103,118,187,251,218,147,65,17,15,13,13,12,12,11,11,11,11,11,15,15,19,22,24,92,189, - 248,166,112,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,94,111,132,213,245,221,181,122, - 41,15,15,16,15,15,15,16,17,19,21,85,160,210,239,191,120,96,43,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,52,96,112,130,179,243,231,225,201,168,144,127,124,131,143,160,187,211,224,237,164,120,105, - 65,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,90,103,114,130, - 173,211,230,245,254,254,254,247,230,212,188,127,111,94,65,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,84,93,101,116,116,115,115,115,116,117,98,86,69,41,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,119,146, - 181,213,235,249,254,254,254,249,235,213,181,146,119,115,115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,115,115,118,144,203,250,250,229,199,160,122,87,69,84,117,155,194,227,249,249,202,144,118, - 115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,118,145,222,253,231,174,96, - 100,113,121,121,117,109,102,91,81,72,66,77,163,228,253,222,145,118,115,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,115,123,203,254,229,149,103,130,149,129,107,92,82,76,72,71,71,71,71,69,68,65,58,129,224, - 254,202,123,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,142,235,245,176,103,141,150,114,89, - 78,77,76,76,77,76,75,73,71,69,67,65,64,62,58,53,157,243,234,142,115,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,115,158,250,231,128,129,161,114,84,79,78,78,78,76,77,77,74,75,73,73,72,70,69,66,63,61,57, - 53,98,222,250,159,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,159,254,218,107,145,135,91,78,78,77,76, - 77,76,75,75,73,72,71,73,71,69,69,68,66,64,61,59,58,50,81,210,254,157,115,0,0,0,0,0,0,0,0,0, - 0,0,0,115,142,250,218,99,150,117,79,77,78,79,78,76,75,75,73,72,72,70,70,69,67,67,67,65,66,64,62,60, - 58,55,48,89,209,249,138,115,0,0,0,0,0,0,0,0,0,0,115,123,234,222,104,149,109,77,77,79,69,58,68,76, - 73,72,72,70,70,67,67,67,64,64,66,61,49,48,59,60,56,56,53,47,97,223,232,121,115,0,0,0,0,0,0,0, - 0,115,118,202,242,126,140,115,76,77,77,62,98,167,101,58,71,70,68,68,66,65,64,65,63,63,57,54,127,127,50,50, - 56,54,51,49,47,124,242,193,117,115,0,0,0,0,0,0,0,115,145,254,173,123,127,76,76,74,56,100,230,255,231,96, - 50,68,66,67,64,62,61,62,62,55,48,147,229,236,158,42,47,51,51,49,45,45,172,253,134,114,0,0,0,0,0,0, - 115,118,220,228,96,148,87,74,76,60,100,233,255,255,255,234,99,47,66,62,63,61,60,59,53,48,149,227,217,213,230,154, - 40,47,48,46,43,43,45,224,206,116,107,0,0,0,0,0,115,144,253,148,125,105,74,73,65,88,229,255,255,255,255,255, - 234,95,46,60,61,59,58,51,47,154,227,215,206,204,204,223,140,37,43,42,42,41,44,169,250,130,109,0,0,0,0,0, - 115,203,230,91,127,76,72,71,56,113,255,255,255,255,255,255,255,238,101,37,58,57,49,45,153,228,215,207,204,201,194,241, - 184,35,40,43,41,38,39,104,225,171,110,0,0,0,0,115,119,250,170,110,97,69,66,67,65,56,157,255,255,255,255,254, - 248,255,238,100,37,48,43,157,228,215,206,204,201,194,236,204,44,27,38,34,35,31,30,58,195,224,115,88,0,0,0,115, - 146,249,88,118,76,67,65,65,66,59,44,156,255,255,252,248,244,238,247,234,92,33,154,228,214,205,201,198,192,236,201,33, - 11,10,11,11,11,11,12,15,130,242,128,101,0,0,0,115,179,228,83,101,66,65,65,62,63,62,56,45,157,255,254,243, - 239,236,229,239,215,164,215,210,201,196,193,187,233,199,33,11,9,11,11,11,11,11,11,13,81,232,153,105,0,0,0,115, - 210,197,90,85,65,63,61,61,60,58,60,53,38,154,253,241,235,229,226,217,221,222,203,198,194,190,186,233,200,30,11,9, - 11,11,11,11,11,11,11,12,50,209,178,106,0,0,0,115,233,156,91,73,62,61,60,58,58,56,57,56,49,40,159,247, - 236,222,216,211,205,201,199,194,192,187,232,202,35,11,9,10,11,11,11,11,11,11,11,12,33,198,205,108,0,0,0,115, - 249,114,90,66,59,58,58,56,57,53,54,52,57,48,24,131,229,218,211,205,202,199,194,190,186,231,201,36,11,9,10,10, - 10,10,11,11,11,11,11,13,19,185,222,111,0,0,0,115,254,78,85,61,58,58,55,53,53,52,53,56,40,17,9,10, - 109,218,207,201,198,194,190,187,231,199,30,11,9,10,10,10,10,10,10,10,10,10,11,13,16,171,230,118,0,0,0,115, - 254,59,80,59,56,55,53,53,50,53,51,27,9,9,10,10,114,212,202,197,194,190,188,184,198,195,43,10,10,10,10,10, - 10,10,10,10,10,10,10,12,14,169,230,114,0,0,0,115,254,79,75,56,54,53,52,52,53,46,14,9,9,10,10,125, - 216,203,196,193,190,187,184,181,178,200,200,53,11,10,10,10,10,10,10,10,10,10,10,12,15,175,230,114,0,0,0,115, - 247,113,68,56,53,52,51,54,37,9,9,9,10,10,127,218,204,194,193,190,186,185,181,180,180,175,202,201,48,10,10,9, - 9,9,9,9,9,9,10,12,17,188,228,113,0,0,0,115,230,152,63,54,52,51,54,36,9,10,10,10,10,124,218,202, - 194,192,189,185,227,195,183,179,178,180,179,207,202,50,10,9,9,9,9,9,9,9,10,12,26,199,212,125,0,0,0,115, - 207,191,57,53,50,52,36,9,10,10,10,10,119,219,203,195,192,189,184,229,192,111,182,183,180,183,187,188,219,207,49,9, - 9,9,8,8,8,8,9,12,53,212,180,112,0,0,0,115,178,223,52,53,48,39,9,10,10,10,10,113,217,202,194,190, - 188,184,228,200,34,11,89,191,186,187,192,198,202,234,211,40,9,8,8,8,8,9,10,13,86,232,152,84,0,0,0,115, - 147,249,68,48,37,9,10,10,10,10,108,213,201,194,192,188,185,228,201,35,11,9,10,95,196,198,198,205,213,219,244,214, - 42,8,7,7,7,8,10,28,133,230,118,60,0,0,0,115,119,247,160,32,17,9,10,10,11,56,213,206,193,190,188,183, - 229,200,36,11,9,10,10,10,94,211,213,213,222,230,236,255,175,8,7,7,7,10,12,61,188,194,107,23,0,0,0,0, - 115,196,224,9,9,9,10,11,11,26,165,207,190,188,183,229,196,31,11,9,10,10,10,9,10,96,219,229,230,237,254,255, - 101,8,6,8,10,13,16,109,223,143,86,0,0,0,0,0,115,140,253,99,9,10,10,11,11,11,30,166,200,186,228,197, - 31,11,10,11,10,10,9,9,9,9,102,236,247,255,255,118,9,7,10,11,12,15,22,173,240,116,57,0,0,0,0,0, - 115,117,215,222,8,10,10,11,11,11,12,32,160,219,193,30,12,10,11,10,10,10,9,9,9,8,9,102,251,255,116,9, - 5,13,11,13,14,18,44,217,165,97,13,0,0,0,0,0,0,115,138,254,128,9,10,11,12,12,12,12,26,105,25,12, - 10,11,11,10,10,10,9,9,8,8,8,8,81,76,8,5,12,12,14,15,17,25,149,242,116,55,0,0,0,0,0,0, - 0,115,117,198,240,60,10,11,12,12,12,12,12,13,11,10,11,11,11,10,10,9,9,9,8,8,7,7,7,7,9,13, - 13,13,15,16,21,83,232,151,90,7,0,0,0,0,0,0,0,0,115,120,230,215,23,10,11,12,12,12,12,12,12,11, - 11,11,11,10,10,9,9,8,8,8,7,8,11,11,12,13,14,16,16,21,44,205,206,110,38,0,0,0,0,0,0,0, - 0,0,0,114,136,249,195,12,11,12,12,12,12,12,12,11,11,11,11,10,10,9,9,8,8,7,8,11,10,11,13,15, - 15,17,21,33,185,244,117,58,0,0,0,0,0,0,0,0,0,0,0,0,112,147,254,192,24,12,13,13,12,12,12,11, - 11,11,10,10,9,9,8,8,8,7,10,12,13,13,14,15,18,23,41,182,253,125,68,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,110,146,248,207,59,14,13,12,12,12,12,11,11,10,10,9,9,8,8,7,10,12,12,13,15,16,19, - 25,69,197,243,124,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,107,132,227,229,120,13,14,13,13,13, - 12,12,11,11,10,10,9,9,8,12,12,15,16,18,23,27,122,221,213,118,69,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,103,118,187,251,218,147,65,18,15,13,13,12,12,11,11,11,11,11,15,15,19,22,24,91,189, - 248,166,112,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,94,111,132,213,246,221,182,121, - 41,15,15,16,15,15,15,16,18,19,21,86,160,210,239,191,120,96,43,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,52,96,112,130,179,243,231,225,201,167,144,128,124,130,142,161,188,211,224,237,164,119,105, - 65,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,90,103,114,130, - 173,211,230,245,254,254,254,247,231,212,188,127,111,94,65,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,84,93,101,116,116,115,115,115,116,117,98,86,69,41,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,42,93,139,181,216,242,254,254,254,242,216,181,139,93,42,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,21,90,169,220,209, - 218,235,248,253,255,255,255,253,248,235,218,209,220,169,90,21,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,12,93,203,207,225,252,255,255,255,255,255,255,255,255,255,255,255,255,255,252,225,207,203, - 93,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,176,206,234,253,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,252,233,206,176,55,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,91,212,222,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 253,221,212,92,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,114,204,242,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,241,203,115,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,115,204,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,252,204,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,204,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,204,114,0,0,0,0,0,0,0,0,0, - 0,0,0,92,203,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,252,207,83,0,0,0,0,0,0,0,0,0,0,56,211,241,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,242,216,49,0,0,0,0,0,0,0, - 0,12,176,221,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,221,166,8,0,0,0,0,0,0,0,93,206,253,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,212,77,0,0,0,0,0,0, - 20,200,234,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,232,189,14,0,0,0,0,0,91,206,252,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,253,217,73,0,0,0,0,0, - 170,224,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,254,225,141,2,0,0,0,42,220,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,247,222,26,0,0,0,93, - 209,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,254,223,73,1,0,0,136,218,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,225,124,4,0,0,178, - 233,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,254,236,165,8,0,0,215,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,250,191,13,1,0,242, - 253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,252,212,19,3,0,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,229,24,6,0,254, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,227,28,8,0,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,228,32,9,0,238, - 253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,224,33,10,0,210,246,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,221,34,10,0,175, - 233,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,246,190,33,10,0,135,218,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,241,145,32,9,0,94, - 209,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,253,234,103,28,7,0,38,223,251,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,249,222,65,23,5,0,0, - 162,224,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,236,164,46,18,3,0,0,84,209,253,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,233,111,36,12,1,0,0, - 17,197,233,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,243,195,64,27,7,0,0,0,0,81,210,253,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,234,119,46,18,4,0,0,0, - 0,9,173,223,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,239,184,67,32,10,1,0,0,0,0,0,47,218,242,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,249,232,103,48,20,5,0,0,0,0, - 0,0,0,83,208,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,254,232,135,61,31,10,1,0,0,0,0,0,0,0,0,105,209,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,232,155,72,41,17,4,0,0,0,0,0, - 0,0,0,0,1,107,211,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,254,234,158,79,49,24,8,1,0,0,0,0,0,0,0,0,0,0,2,108,213,244,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,252,234,158,81,54,28,10,2,0,0,0,0,0,0, - 0,0,0,0,0,0,3,88,220,228,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,244,235,145,80,54,30,12,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,60,180,217,248,253,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,249,237,205,122,74,51,29,12,3,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,3,20,103,209,220,235,254,255,255,255,255,255,255,255,255,255,255,255,255,255,253,246,238,223, - 150,90,65,44,25,11,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,8,35,107,183,231,225, - 247,255,255,255,255,255,255,255,255,255,255,244,241,203,149,96,70,52,34,19,8,2,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,1,5,13,24,70,124,166,200,233,247,255,255,255,249,237,208,181,151,113,78,66,52, - 37,24,12,5,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,7,13,22, - 32,43,52,60,67,72,76,77,76,72,67,60,52,43,32,22,13,7,2,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,5,10,16,22,27,31,34,37,38,37,35,31,27,22,16,10,5, - 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 1,2,4,7,9,10,12,12,12,10,9,7,4,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} -},{ - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,116,116,120,147, - 182,213,235,249,254,254,254,249,235,213,182,147,120,116,116,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,116,116,119,144,203,250,251,237,213,185,155,135,126,131,151,182,211,236,251,249,202,144,119, - 116,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,119,145,222,254,238,199,161, - 135,112,94,86,82,80,80,80,80,85,100,134,191,236,253,222,145,119,116,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,116,124,204,254,238,186,153,142,116,84,72,71,71,69,68,69,69,67,68,69,67,77,90,161,233, - 254,203,124,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,143,235,249,203,161,149,113,85,69, - 68,70,70,69,68,67,66,65,63,62,64,65,65,68,67,92,183,246,234,143,116,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,116,159,250,239,176,157,122,84,67,68,70,70,69,68,67,66,66,63,62,61,61,60,60,59,61,62,63, - 67,128,231,250,159,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,160,254,232,170,147,109,64,68,70,70,69, - 68,67,65,62,60,59,59,59,59,60,59,58,57,56,55,57,62,60,89,216,254,158,116,0,0,0,0,0,0,0,0,0, - 0,0,0,116,143,250,231,155,148,92,66,70,70,69,68,66,57,57,62,66,75,76,72,61,57,48,50,56,56,53,52,53, - 54,58,60,75,216,249,138,116,0,0,0,0,0,0,0,0,0,0,116,124,234,233,165,147,84,66,70,70,69,68,63,63, - 123,183,216,231,244,245,240,223,206,173,92,47,50,52,52,52,50,51,56,58,89,229,232,122,116,0,0,0,0,0,0,0, - 0,116,119,203,246,167,144,85,67,70,69,69,68,60,99,223,255,255,255,255,255,255,255,255,255,255,246,180,56,46,51,49, - 47,47,48,54,54,111,244,193,118,116,0,0,0,0,0,0,0,116,145,254,198,149,109,63,70,69,68,67,67,51,139,255, - 255,255,255,255,255,255,255,254,252,247,246,255,167,46,47,47,46,45,44,46,53,58,167,253,135,115,0,0,0,0,0,0, - 116,119,220,237,148,122,63,69,68,68,67,65,65,50,136,255,255,255,255,255,255,255,255,254,253,251,249,243,255,142,35,46, - 45,45,43,44,47,56,65,228,206,117,108,0,0,0,0,0,116,144,254,178,142,85,66,68,67,67,65,63,63,49,133,255, - 254,255,255,251,249,252,255,255,252,251,250,246,252,206,41,45,46,43,43,43,44,50,56,143,251,131,110,0,0,0,0,0, - 116,203,237,123,115,61,66,66,65,63,62,62,61,47,131,255,251,179,107,86,76,80,140,253,253,250,250,249,249,238,59,40, - 45,45,43,43,43,46,55,72,228,172,111,0,0,0,0,116,120,250,192,140,91,61,63,63,62,61,61,61,59,49,112,204, - 109,35,38,46,48,45,35,145,252,247,249,247,249,250,82,36,47,47,46,45,43,45,50,53,180,226,116,89,0,0,0,116, - 147,251,140,123,62,63,62,61,61,61,60,59,58,58,55,47,43,52,52,51,51,51,43,56,226,246,245,246,247,251,81,32, - 41,40,39,39,40,41,45,52,105,244,129,102,0,0,0,116,179,236,114,83,61,61,61,61,60,60,59,57,57,56,55,52, - 53,52,51,51,51,49,42,60,218,230,231,234,241,230,40,21,27,27,27,27,27,28,31,41,63,226,154,106,0,0,0,116, - 210,210,90,68,61,61,60,60,59,57,57,56,55,55,52,52,52,51,51,49,41,33,18,110,206,208,218,225,242,196,21,26, - 28,28,28,29,29,29,31,38,50,193,179,107,0,0,0,116,233,174,81,65,61,60,59,58,57,56,56,55,53,52,51,51, - 50,46,38,29,24,12,55,182,193,200,211,221,253,136,16,28,29,29,30,30,30,31,32,38,48,194,206,109,0,0,0,116, - 249,139,83,60,59,58,57,57,56,55,53,52,52,51,51,47,35,25,21,22,14,40,164,184,183,193,204,230,191,22,27,30, - 30,30,30,31,31,32,33,39,48,174,221,112,0,0,0,116,254,113,80,57,57,56,55,53,52,52,52,51,52,48,35,26, - 21,21,22,14,65,159,183,175,180,188,206,225,62,19,32,32,33,33,33,33,33,33,34,40,49,138,231,118,0,0,0,116, - 254,101,76,56,55,55,53,52,52,51,51,50,40,28,22,22,21,21,17,45,165,185,174,175,178,196,219,101,18,37,37,37, - 37,37,38,38,38,37,37,41,49,131,231,115,0,0,0,116,254,113,72,54,53,52,51,51,51,50,46,31,24,22,22,21, - 21,19,35,164,188,179,178,178,195,189,79,24,40,41,41,42,43,43,43,43,43,42,42,46,53,148,231,115,0,0,0,116, - 247,138,71,54,52,50,50,49,50,43,26,21,22,21,20,20,21,10,86,201,188,185,184,195,178,50,27,43,45,46,47,47, - 48,48,48,48,48,47,48,51,57,178,228,114,0,0,0,116,230,172,70,54,51,49,49,49,39,25,21,21,21,20,19,20, - 20,15,139,209,196,195,200,193,56,31,47,47,49,50,51,51,52,52,52,52,52,51,50,55,62,190,214,126,0,0,0,116, - 207,206,71,55,48,47,47,40,24,21,22,20,19,19,20,20,18,28,178,210,202,203,213,110,29,49,49,51,53,55,55,56, - 56,57,56,56,56,55,55,60,70,203,181,113,0,0,0,116,179,232,84,55,47,46,38,22,21,20,20,19,18,18,20,19, - 19,38,193,208,204,209,203,51,45,52,53,56,58,58,59,59,60,60,59,59,59,58,60,64,88,239,153,85,0,0,0,116, - 148,250,107,53,47,39,22,20,20,19,19,17,17,19,19,20,22,37,174,198,195,203,190,49,50,56,57,59,60,61,61,62, - 62,62,62,61,61,60,63,66,126,238,119,61,0,0,0,116,120,247,179,56,45,27,19,20,19,18,17,16,17,18,19,24, - 28,31,52,62,65,69,67,50,57,59,60,61,61,63,63,63,63,63,62,62,61,62,66,70,187,207,108,23,0,0,0,0, - 116,196,231,57,42,22,19,18,17,17,16,16,17,18,21,26,31,36,33,31,35,38,43,57,60,61,61,62,63,63,63,63, - 63,63,62,62,62,65,69,91,229,150,86,0,0,0,0,0,116,140,253,132,36,23,20,17,17,16,15,16,17,19,25,29, - 35,35,60,104,123,126,103,57,59,63,63,63,63,63,63,63,63,62,62,62,63,68,72,162,242,117,57,0,0,0,0,0, - 116,118,215,229,53,28,20,17,16,15,15,16,17,20,27,31,32,58,170,190,189,190,206,162,60,62,63,63,63,63,62,62, - 62,61,61,62,66,71,89,227,174,98,13,0,0,0,0,0,0,116,139,254,153,34,26,19,16,14,15,16,18,22,28,33, - 31,122,193,181,181,182,188,215,107,55,63,63,62,61,61,61,60,59,60,64,70,76,177,244,117,55,0,0,0,0,0,0, - 0,116,118,198,242,93,30,23,15,13,15,16,19,25,30,36,37,157,195,185,184,185,191,208,121,49,62,62,60,59,59,58, - 58,58,61,68,72,128,240,162,91,7,0,0,0,0,0,0,0,0,116,121,230,222,64,30,20,15,15,16,21,27,33,39, - 37,143,208,194,193,194,199,221,110,50,61,60,58,57,56,55,54,59,65,71,98,222,215,111,38,0,0,0,0,0,0,0, - 0,0,0,115,136,249,207,49,30,22,18,18,22,29,36,41,40,87,212,218,209,212,225,204,63,59,59,57,56,55,53,53, - 57,64,69,84,211,247,120,58,0,0,0,0,0,0,0,0,0,0,0,0,113,148,254,205,64,33,27,25,27,32,37,43, - 48,50,94,160,195,191,138,66,55,60,57,55,52,52,53,57,64,69,91,208,253,132,69,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,111,146,248,217,93,39,35,34,36,41,46,50,55,51,49,61,57,45,57,61,58,55,54,53,54,59,65, - 70,117,218,246,136,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,133,227,234,145,48,43,45,47,51, - 53,57,60,61,60,61,63,62,60,58,56,57,59,64,67,72,162,234,223,126,69,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,104,119,187,251,222,124,56,53,57,59,61,63,64,65,64,65,65,63,64,65,67,66,71,132,212, - 251,183,115,61,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,95,112,133,214,248,211,147,72, - 62,64,66,70,73,74,73,71,68,68,69,84,155,213,248,205,136,98,44,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,52,97,113,130,181,245,237,231,229,191,161,137,129,138,159,186,216,224,237,245,184,136,107, - 66,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,91,104,115,132, - 178,211,230,245,254,254,254,247,230,212,190,147,120,96,66,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,65,85,94,102,117,117,116,116,116,117,118,99,86,70,41,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,119,146, - 181,213,235,249,254,254,254,249,235,213,181,146,119,115,115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,115,115,118,144,203,250,251,237,214,188,163,144,136,140,159,186,211,236,251,249,202,144,118, - 115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,118,145,222,254,238,200,167, - 152,140,128,123,119,117,117,115,114,114,122,143,193,236,253,222,145,118,115,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,115,123,203,254,238,188,167,166,149,124,113,111,110,109,110,109,108,108,105,105,101,106,110,165,233, - 254,202,123,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,142,235,249,203,172,172,146,125,111, - 110,111,110,110,110,109,107,106,103,103,103,103,102,101,96,110,184,246,234,142,115,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,115,158,250,239,181,178,153,123,109,110,111,110,110,110,109,108,107,106,103,102,101,101,99,99,99,98,95, - 93,136,231,250,159,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,159,254,232,177,172,144,109,111,112,111,110, - 110,109,107,104,101,101,101,100,99,99,99,98,97,96,94,95,95,89,104,217,254,157,115,0,0,0,0,0,0,0,0,0, - 0,0,0,115,142,250,231,170,174,130,108,112,112,110,110,108,100,99,104,107,113,113,111,101,98,90,91,94,96,93,92,91, - 90,91,89,93,216,249,138,115,0,0,0,0,0,0,0,0,0,0,115,123,234,233,174,173,124,108,112,111,110,110,106,104, - 153,201,225,238,247,249,243,230,216,190,124,87,90,92,90,89,88,88,90,87,101,230,232,121,115,0,0,0,0,0,0,0, - 0,115,118,202,246,174,169,125,108,111,111,110,109,102,133,231,255,255,255,255,255,255,255,255,255,255,247,194,93,86,89,87, - 86,84,84,85,82,120,244,193,117,115,0,0,0,0,0,0,0,115,145,254,199,171,142,106,111,110,109,108,108,96,165,255, - 255,255,255,255,255,255,255,254,252,247,245,255,182,83,84,84,84,83,81,83,85,82,169,253,134,114,0,0,0,0,0,0, - 115,118,220,237,162,152,105,110,110,109,108,107,106,92,161,255,255,255,255,255,255,255,255,254,253,251,249,243,255,162,75,83, - 83,82,80,80,81,84,84,228,206,116,107,0,0,0,0,0,115,144,254,180,166,122,108,110,108,108,107,104,104,91,158,255, - 253,255,255,251,249,251,255,255,252,251,250,247,251,212,78,82,82,81,80,80,80,83,82,146,251,130,109,0,0,0,0,0, - 115,203,237,145,146,103,108,107,106,104,103,103,102,89,157,255,250,185,127,112,106,109,158,252,252,250,250,249,247,238,88,79, - 81,81,80,79,79,81,83,88,229,171,110,0,0,0,0,115,119,250,194,164,125,103,106,104,102,102,102,101,100,91,140,209, - 128,69,78,88,88,84,75,163,251,247,249,247,247,250,107,75,82,82,81,81,81,80,81,76,182,226,115,88,0,0,0,115, - 146,251,148,152,103,104,103,102,102,101,100,99,98,97,94,82,82,93,93,91,90,89,83,91,229,245,245,246,246,249,104,70, - 78,77,76,76,76,76,77,77,113,244,128,101,0,0,0,115,179,236,133,120,101,103,102,101,101,100,98,98,97,94,93,92, - 92,92,90,89,88,87,80,94,220,230,231,234,240,231,69,61,65,65,63,65,65,65,66,70,79,226,153,105,0,0,0,115, - 210,211,120,107,102,101,101,99,99,98,97,94,93,92,92,91,91,90,89,86,79,73,60,130,205,208,216,225,241,202,56,65, - 65,66,66,66,66,66,66,69,71,194,179,106,0,0,0,115,233,178,115,105,101,100,99,98,96,96,94,93,92,91,91,90, - 89,84,78,69,65,57,88,183,192,200,211,220,251,150,52,66,67,67,67,67,67,67,67,70,70,197,206,108,0,0,0,115, - 249,147,117,100,98,98,96,96,94,93,92,91,90,90,89,86,75,66,63,63,56,78,169,182,183,192,203,228,196,53,65,67, - 67,67,67,67,67,67,68,70,71,179,221,111,0,0,0,115,254,122,115,97,96,94,94,93,93,92,91,90,89,86,75,68, - 63,63,63,57,94,164,181,175,180,188,205,224,86,57,69,69,69,68,69,68,68,68,69,71,73,145,231,118,0,0,0,115, - 254,111,112,94,96,94,93,92,91,90,90,88,80,70,63,63,63,63,58,80,169,182,174,175,178,195,219,119,55,72,71,72, - 72,72,72,72,72,72,71,72,74,139,231,114,0,0,0,115,254,121,107,93,93,92,91,90,89,89,84,72,65,63,63,62, - 62,59,72,169,185,179,178,178,193,191,99,58,76,76,76,77,77,77,77,77,77,76,76,77,75,154,231,114,0,0,0,115, - 247,144,104,92,90,89,88,87,88,82,67,63,63,63,61,61,61,52,110,199,188,185,184,194,180,73,62,78,78,79,80,80, - 81,81,81,81,80,80,79,81,79,183,228,113,0,0,0,115,230,175,99,91,89,88,87,88,79,67,63,63,62,61,60,60, - 60,56,152,206,196,195,200,194,80,66,80,80,81,82,83,83,83,83,83,83,83,82,82,83,81,193,214,125,0,0,0,115, - 207,207,95,91,88,86,86,79,66,62,62,61,60,60,60,60,58,65,183,209,202,203,212,122,62,82,82,83,84,86,87,87, - 87,87,87,87,87,86,85,85,85,204,181,112,0,0,0,115,178,232,99,89,84,84,78,63,62,62,61,59,59,59,59,59, - 58,73,194,206,204,209,203,76,78,84,86,87,88,89,89,90,90,90,90,89,89,88,89,88,100,239,152,84,0,0,0,115, - 147,250,113,86,82,78,63,61,61,60,59,58,58,58,58,59,61,71,179,196,195,202,191,73,83,87,88,89,90,91,90,91, - 91,91,91,91,90,89,90,86,133,238,118,60,0,0,0,115,119,247,181,82,80,66,61,61,59,58,58,57,57,57,59,61, - 65,68,82,88,89,92,91,80,88,89,90,91,91,92,92,92,92,91,91,91,90,91,91,87,189,205,107,23,0,0,0,0, - 115,196,231,72,74,62,60,59,58,57,56,57,56,57,60,65,68,70,70,68,71,73,78,88,90,91,91,92,92,92,92,92, - 92,91,91,91,90,92,90,101,229,146,86,0,0,0,0,0,115,140,253,134,63,61,60,57,57,56,55,56,56,57,62,67, - 70,70,90,124,139,142,126,88,89,91,92,92,92,92,91,91,91,91,90,90,91,92,88,165,242,116,57,0,0,0,0,0, - 115,117,215,229,67,60,59,56,55,55,55,55,56,59,63,68,68,88,174,188,188,189,204,173,89,92,92,91,91,91,90,90, - 90,90,89,90,92,90,100,228,168,97,13,0,0,0,0,0,0,115,138,254,155,58,60,57,53,53,53,53,56,60,65,69, - 68,138,192,181,181,182,187,213,127,84,91,91,90,90,89,88,88,87,88,89,92,90,180,244,116,55,0,0,0,0,0,0, - 0,115,117,198,242,100,57,57,53,52,53,53,57,61,66,70,72,165,194,185,185,185,191,205,137,79,91,89,89,87,87,86, - 86,84,86,90,87,133,240,154,90,7,0,0,0,0,0,0,0,0,115,120,230,222,73,57,55,53,52,55,59,62,68,73, - 71,157,205,194,193,194,199,220,126,79,89,88,87,84,83,83,83,84,87,87,104,223,209,110,38,0,0,0,0,0,0,0, - 0,0,0,114,136,249,207,62,57,55,54,56,59,65,71,76,73,111,211,215,209,211,224,206,87,88,87,86,83,81,81,81, - 82,86,86,93,211,245,117,58,0,0,0,0,0,0,0,0,0,0,0,0,112,147,254,205,73,58,58,59,62,67,72,77, - 81,82,116,167,196,193,147,87,82,88,84,83,80,80,80,81,85,85,97,209,253,126,68,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,110,146,248,217,99,60,63,65,69,74,78,82,86,82,78,86,80,72,87,89,86,83,80,80,79,82,83, - 83,122,218,244,125,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,107,132,227,234,148,63,66,72,77,80, - 83,87,90,91,90,91,91,89,87,85,84,82,83,83,82,82,164,234,217,119,69,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,103,118,187,251,222,128,69,73,81,85,89,91,92,92,92,91,90,88,87,87,87,81,82,136,213, - 250,170,112,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,94,111,132,214,248,211,149,81, - 75,81,85,90,93,94,93,90,86,82,81,90,157,213,246,196,121,96,43,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,52,96,112,130,179,244,237,231,231,194,167,144,136,144,163,188,217,225,237,243,172,122,105, - 65,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,90,103,114,130, - 174,211,230,245,254,254,254,247,230,212,188,129,111,94,65,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,84,93,101,116,116,115,115,115,116,117,98,86,69,41,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,119,146, - 181,213,235,249,254,254,254,249,235,213,181,146,119,115,115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,115,115,118,144,203,250,251,237,216,197,184,171,166,167,179,195,215,236,251,249,202,144,118, - 115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,118,145,222,254,238,204,185, - 198,215,221,221,219,217,212,207,197,188,177,167,197,236,253,222,145,118,115,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,115,123,203,254,238,192,207,233,235,229,224,221,219,218,216,216,212,208,204,199,189,180,166,178,233, - 254,202,123,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,142,235,249,206,204,235,236,228,223, - 223,222,220,219,218,215,214,212,209,207,203,200,194,186,172,155,189,246,234,142,115,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,115,158,250,239,194,231,238,229,223,224,222,220,219,218,216,214,212,210,209,206,205,203,201,197,194,187,176, - 160,159,231,250,159,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,159,254,232,202,236,233,223,224,223,221,219, - 219,216,215,212,209,208,206,204,203,202,201,198,195,193,190,186,177,161,143,217,254,157,115,0,0,0,0,0,0,0,0,0, - 0,0,0,115,142,250,231,209,240,229,223,224,222,220,219,216,213,211,212,211,211,211,209,204,201,195,194,195,193,191,190,187, - 181,174,160,136,216,249,138,115,0,0,0,0,0,0,0,0,0,0,115,123,234,233,200,239,227,222,222,221,219,219,215,214, - 229,245,251,255,255,255,254,249,243,233,205,190,190,189,187,185,182,177,170,155,134,230,232,121,115,0,0,0,0,0,0,0, - 0,115,118,202,246,196,235,226,221,221,219,218,216,213,222,253,255,255,255,255,255,255,255,255,254,254,250,231,187,184,183,181, - 179,176,172,165,149,142,244,193,117,115,0,0,0,0,0,0,0,115,145,254,202,229,231,219,220,218,216,215,214,208,231,255, - 255,255,255,255,255,255,255,255,254,251,246,252,221,177,180,178,175,174,171,168,159,140,177,253,134,114,0,0,0,0,0,0, - 115,118,220,237,199,235,218,219,218,216,214,213,211,205,228,255,255,255,255,255,255,255,255,255,255,253,251,245,255,209,172,175, - 174,172,171,169,162,151,127,229,206,116,107,0,0,0,0,0,115,144,254,189,231,222,218,218,215,213,212,210,209,203,224,255, - 254,255,255,251,250,252,255,255,254,253,252,251,250,230,167,173,172,171,169,167,162,157,141,158,251,130,109,0,0,0,0,0, - 115,203,237,201,229,213,215,214,212,210,208,206,205,200,220,254,247,205,178,180,179,181,202,252,253,252,252,252,250,242,160,170, - 170,168,165,164,162,158,148,127,229,171,110,0,0,0,0,115,119,250,199,225,220,213,212,211,209,206,205,203,201,198,211,220, - 175,155,179,188,187,184,174,209,251,250,251,251,251,250,163,164,169,167,164,164,163,160,151,129,185,226,115,88,0,0,0,115, - 146,251,169,227,212,211,210,206,205,204,202,201,199,196,193,174,182,192,189,185,184,183,179,181,238,247,247,249,250,251,158,160, - 164,163,161,160,159,158,152,136,132,244,128,101,0,0,0,115,179,236,184,216,209,208,206,204,203,202,200,196,195,194,193,192, - 190,187,184,183,181,180,175,181,228,233,235,239,243,236,138,155,157,154,154,153,152,152,148,137,116,227,153,105,0,0,0,115, - 210,214,196,208,205,205,203,202,200,198,195,193,192,190,189,187,184,184,182,180,174,170,164,184,206,212,222,231,242,218,138,155, - 154,153,153,153,152,151,149,140,119,197,179,106,0,0,0,115,233,188,201,204,204,203,201,198,196,194,193,191,190,187,185,184, - 182,179,174,169,164,161,169,190,196,205,216,225,251,184,143,155,153,153,153,152,152,151,150,144,124,204,206,108,0,0,0,115, - 249,166,201,201,201,199,198,195,193,192,190,189,185,184,183,180,173,168,164,163,161,167,184,185,190,199,210,230,210,126,154,154, - 152,153,153,152,152,152,151,147,129,191,221,111,0,0,0,115,254,147,203,199,198,195,193,192,191,189,187,185,183,180,173,169, - 165,164,162,159,170,183,183,182,187,194,210,228,142,145,155,154,154,153,153,153,152,153,153,149,132,160,231,118,0,0,0,115, - 254,137,200,194,195,193,191,190,188,185,184,182,178,171,167,164,163,161,160,164,183,183,181,181,184,200,220,159,140,160,155,155, - 155,155,155,155,155,157,155,153,135,157,231,114,0,0,0,115,254,142,194,190,190,190,189,187,184,183,179,172,168,164,164,161, - 160,158,162,188,188,185,184,184,198,200,147,141,161,159,159,159,159,159,159,160,160,160,160,155,137,170,231,114,0,0,0,115, - 247,157,184,188,188,187,184,183,181,177,169,165,164,162,161,159,158,154,172,198,194,192,191,199,191,130,149,162,161,161,161,161, - 162,162,163,163,163,163,162,156,135,195,228,113,0,0,0,115,230,181,171,184,186,183,182,180,174,168,164,163,161,159,158,158, - 155,153,190,208,203,201,204,201,136,149,163,162,162,163,164,165,167,167,167,168,168,168,165,158,134,200,214,125,0,0,0,115, - 207,208,155,179,182,181,179,173,167,164,162,160,158,157,155,155,153,155,202,212,209,209,214,155,143,165,163,164,165,168,169,170, - 171,171,171,171,171,171,169,158,132,207,181,112,0,0,0,115,178,232,136,173,178,178,172,164,162,161,159,158,155,154,153,152, - 152,158,205,210,209,212,209,134,161,167,167,169,170,172,173,174,174,175,175,175,175,174,171,154,136,240,152,84,0,0,0,115, - 147,250,128,166,173,172,163,161,160,159,157,154,153,151,151,151,151,157,195,199,199,205,199,138,167,169,171,173,174,175,178,179, - 179,180,180,180,180,178,171,147,153,238,118,60,0,0,0,115,119,247,184,143,164,161,159,159,157,155,153,151,150,150,149,151, - 152,154,154,149,150,153,153,158,171,172,174,177,179,180,181,182,182,183,183,183,183,179,167,141,195,205,107,23,0,0,0,0, - 115,196,231,108,152,155,157,155,153,152,150,150,149,148,149,151,152,153,155,158,161,163,167,172,173,175,179,181,182,183,184,185, - 185,187,187,187,186,178,158,137,229,146,86,0,0,0,0,0,115,140,253,140,128,147,152,153,151,150,149,148,148,147,149,151, - 153,154,163,175,180,184,187,173,177,180,182,184,187,188,189,190,190,191,191,190,186,175,147,177,242,116,57,0,0,0,0,0, - 115,117,215,229,99,137,146,149,149,147,145,145,144,147,149,151,152,161,189,189,189,189,205,209,179,183,187,188,190,191,192,193, - 193,193,193,190,184,161,138,228,168,97,13,0,0,0,0,0,0,115,138,254,158,115,138,144,146,145,144,143,144,147,149,151, - 152,179,192,188,187,189,192,213,191,184,189,191,192,194,195,195,198,196,194,188,173,143,187,244,116,55,0,0,0,0,0,0, - 0,115,117,198,242,117,121,136,140,142,143,142,144,145,149,152,155,190,196,191,191,192,196,208,187,182,192,193,195,198,198,198, - 199,198,193,182,152,154,240,154,90,7,0,0,0,0,0,0,0,0,115,120,230,222,97,121,133,138,140,141,143,147,150,154, - 155,191,206,200,199,200,204,220,181,185,195,196,199,200,201,201,200,196,185,159,134,224,209,110,38,0,0,0,0,0,0,0, - 0,0,0,114,136,249,207,92,120,132,137,140,144,148,152,157,159,173,214,215,213,215,224,215,170,195,196,199,201,202,202,201, - 196,186,161,132,213,245,117,58,0,0,0,0,0,0,0,0,0,0,0,0,112,147,254,206,96,115,128,137,143,148,153,158, - 162,164,175,191,205,204,179,162,187,198,199,201,203,203,201,195,183,158,134,211,253,126,68,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,110,146,248,218,113,108,126,137,146,152,159,163,168,170,162,159,157,165,191,196,198,199,201,201,198,190,176, - 148,145,219,244,125,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,107,132,227,234,153,98,119,135,146,154, - 161,167,172,178,182,188,192,192,194,197,197,196,190,180,160,134,173,234,217,119,69,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,103,118,187,251,223,138,100,123,140,151,159,166,172,178,183,185,186,188,186,182,174,157,132,153,215, - 250,170,112,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,94,111,132,214,248,212,154,99, - 109,127,141,153,161,168,167,163,157,146,131,120,164,215,246,196,121,96,43,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,52,96,112,130,179,244,237,232,235,203,181,164,161,167,181,199,223,226,237,243,172,122,105, - 65,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,90,103,114,130, - 174,211,230,245,254,254,254,247,230,212,188,129,111,94,65,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,84,93,101,116,116,115,115,115,116,117,98,86,69,41,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,42,93,139,181,216,242,254,254,254,242,216,181,139,93,42,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,21,90,169,220,209, - 218,235,248,253,255,255,255,253,248,235,218,209,220,169,90,21,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,12,93,203,207,225,252,255,255,255,255,255,255,255,255,255,255,255,255,255,252,225,207,203, - 93,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,176,206,234,253,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,252,233,206,176,55,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,91,212,222,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 253,221,212,92,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,114,204,242,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,241,203,115,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,115,204,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,252,204,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,204,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,204,114,0,0,0,0,0,0,0,0,0, - 0,0,0,92,203,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,252,207,83,0,0,0,0,0,0,0,0,0,0,56,211,241,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,242,216,49,0,0,0,0,0,0,0, - 0,12,176,221,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,221,166,8,0,0,0,0,0,0,0,93,206,253,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,212,77,0,0,0,0,0,0, - 20,200,234,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,232,189,14,0,0,0,0,0,91,206,252,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,217,73,0,0,0,0,0, - 170,224,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,225,141,2,0,0,0,42,220,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,248,222,26,0,0,0,93, - 209,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,223,73,1,0,0,136,218,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,225,124,4,0,0,178, - 233,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,236,165,8,0,0,215,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,251,191,13,1,0,242, - 253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,254,212,19,3,0,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,229,24,6,0,254, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,227,28,8,0,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,228,32,9,0,238, - 253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,224,33,10,0,210,246,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,221,34,10,0,175, - 233,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,246,190,33,10,0,135,218,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,241,145,32,9,0,94, - 209,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,234,103,28,7,0,38,223,251,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,250,222,65,23,5,0,0, - 162,224,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,237,164,46,18,3,0,0,84,209,253,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,233,111,36,12,1,0,0, - 17,197,233,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,243,195,64,27,7,0,0,0,0,81,210,253,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,234,119,46,18,4,0,0,0, - 0,9,173,223,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,239,184,67,32,10,1,0,0,0,0,0,47,218,242,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,249,232,103,48,20,5,0,0,0,0, - 0,0,0,83,208,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,254,232,135,61,31,10,1,0,0,0,0,0,0,0,0,105,209,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,232,155,72,41,17,4,0,0,0,0,0, - 0,0,0,0,1,107,211,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,254,234,158,79,49,24,8,1,0,0,0,0,0,0,0,0,0,0,2,108,213,244,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,252,234,158,81,54,28,10,2,0,0,0,0,0,0, - 0,0,0,0,0,0,3,88,220,228,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,244,235,145,80,54,30,12,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,60,180,217,248,254,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,249,237,205,122,74,51,29,12,3,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,3,20,103,209,220,235,254,255,255,255,255,255,255,255,255,255,255,255,255,255,254,246,238,223, - 150,90,65,44,25,11,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,8,35,107,183,231,225, - 247,255,255,255,255,255,255,255,255,255,255,244,241,203,149,96,70,52,34,19,8,2,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,1,5,13,24,70,124,166,200,233,247,255,255,255,249,237,208,181,151,113,78,66,52, - 37,24,12,5,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,7,13,22, - 32,43,52,60,67,72,76,77,76,72,67,60,52,43,32,22,13,7,2,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,5,10,16,22,27,31,34,37,38,37,35,31,27,22,16,10,5, - 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 1,2,4,7,9,10,12,12,12,10,9,7,4,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} -},{ - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,116,116,120,147, - 182,213,235,249,254,254,254,249,235,213,182,147,120,116,116,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,116,116,119,144,203,250,251,238,218,192,166,142,129,139,160,187,213,236,251,249,202,144,119, - 116,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,119,145,222,254,239,202,151, - 149,151,145,139,133,128,125,122,119,117,121,132,191,236,253,222,145,119,116,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,116,124,204,254,238,185,157,163,148,132,119,111,106,103,100,99,98,99,100,101,103,107,111,165,233, - 254,203,124,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,143,235,249,203,156,164,146,118,108, - 104,100,99,96,95,92,91,90,88,88,87,88,91,96,100,106,184,246,234,143,116,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,116,159,250,239,172,163,149,117,105,101,98,97,95,94,93,88,81,80,83,85,82,81,80,81,82,85,92, - 97,138,231,250,159,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,160,254,231,158,163,123,105,101,97,95,94, - 93,93,93,83,104,137,132,94,78,81,79,78,76,75,76,78,86,91,107,216,254,158,116,0,0,0,0,0,0,0,0,0, - 0,0,0,116,143,250,231,153,151,115,100,97,94,93,93,91,91,91,83,110,242,255,255,242,103,73,78,76,74,72,71,71, - 73,81,88,95,216,249,138,116,0,0,0,0,0,0,0,0,0,0,116,124,234,233,156,153,111,98,92,90,90,90,90,89, - 89,86,96,236,255,255,255,255,202,71,73,73,72,70,69,66,66,69,77,86,100,230,232,122,116,0,0,0,0,0,0,0, - 0,116,119,203,246,170,150,110,94,90,88,87,87,87,87,87,86,78,121,255,255,255,255,255,255,93,68,71,69,68,65,64, - 62,62,65,74,86,125,244,193,118,116,0,0,0,0,0,0,0,116,145,254,201,155,114,93,88,86,85,86,85,85,85,83, - 83,77,112,255,255,255,255,255,244,81,68,70,68,66,65,63,61,60,59,64,75,86,173,253,135,115,0,0,0,0,0,0, - 116,119,220,237,148,135,93,85,82,83,83,83,82,82,82,82,81,79,77,206,255,255,255,255,163,54,70,68,66,65,63,61, - 60,59,56,57,64,77,87,229,206,117,108,0,0,0,0,0,116,144,254,183,140,99,85,81,80,80,80,80,80,80,80,79, - 79,78,73,81,168,236,229,153,72,65,68,66,64,62,61,60,57,55,55,54,56,66,79,150,251,131,110,0,0,0,0,0, - 116,203,238,140,116,85,79,77,78,78,78,78,78,77,77,76,76,74,76,70,64,74,70,55,63,68,64,63,62,61,60,57, - 56,54,53,51,51,56,71,87,228,172,111,0,0,0,0,116,120,250,197,137,93,77,74,76,76,76,76,76,74,74,73,73, - 73,73,71,64,64,61,61,63,61,67,65,63,61,59,55,54,53,51,51,49,48,50,58,67,180,226,116,89,0,0,0,116, - 147,251,141,117,81,73,72,73,73,73,73,73,73,72,72,72,72,69,68,91,123,123,123,123,93,51,47,40,36,32,30,30, - 30,30,31,32,35,40,48,59,111,244,129,102,0,0,0,116,179,237,131,97,75,71,71,71,71,71,71,70,70,70,70,70, - 69,67,71,198,255,249,240,235,192,40,23,26,27,27,27,28,28,28,27,27,27,28,34,49,75,227,154,106,0,0,0,116, - 210,216,124,86,70,68,68,68,68,68,68,68,68,68,66,66,66,63,76,240,214,201,196,191,225,40,30,28,27,28,27,28, - 28,28,27,27,28,28,32,44,60,195,179,107,0,0,0,116,233,186,113,79,68,65,65,65,65,65,65,66,65,64,64,64, - 56,34,47,230,201,196,191,187,224,40,30,27,27,28,27,28,27,27,27,27,28,27,31,41,56,199,206,109,0,0,0,116, - 249,156,106,74,65,63,63,63,63,63,64,64,63,64,60,42,29,20,46,229,196,190,187,181,223,41,29,27,27,27,27,27, - 27,27,27,27,27,27,29,38,52,182,221,112,0,0,0,116,254,129,101,71,62,61,61,61,61,62,61,62,62,47,34,28, - 29,22,46,224,190,183,181,175,221,41,30,27,27,27,27,27,27,27,27,27,27,27,28,36,50,146,231,118,0,0,0,116, - 254,115,97,68,60,59,59,59,60,59,60,56,42,29,29,29,29,22,46,222,184,179,176,172,219,41,29,27,27,27,27,27, - 27,27,27,27,27,27,28,36,49,139,231,115,0,0,0,116,254,128,95,67,58,56,56,57,56,57,52,35,29,30,30,29, - 29,22,45,218,179,175,173,171,219,41,29,28,28,27,27,27,27,27,27,27,27,27,28,36,50,155,231,115,0,0,0,116, - 247,151,94,67,56,55,55,54,56,49,32,30,30,30,30,29,29,22,43,214,176,172,172,171,219,41,30,28,28,27,28,28, - 28,28,27,27,27,27,29,38,51,184,228,114,0,0,0,116,230,180,94,68,55,53,53,53,47,32,30,31,30,30,29,29, - 29,23,43,212,173,172,173,174,222,42,30,28,28,28,28,28,28,28,28,28,28,27,30,41,55,191,214,126,0,0,0,116, - 207,209,97,69,56,51,52,48,32,30,31,30,30,30,29,29,29,23,42,212,173,174,176,179,223,42,30,28,29,29,28,28, - 28,28,28,28,28,28,32,44,62,203,181,113,0,0,0,116,179,232,99,71,54,50,47,35,31,31,31,30,30,30,29,29, - 29,23,43,212,178,179,182,185,224,41,31,30,29,30,30,30,29,29,29,28,28,30,34,47,81,239,153,85,0,0,0,116, - 148,250,114,73,54,49,37,31,32,31,31,30,30,30,29,29,29,23,43,214,182,184,189,193,228,41,32,30,30,30,30,30, - 30,30,30,29,29,31,38,50,122,238,119,61,0,0,0,116,120,247,183,70,56,45,32,32,31,31,31,30,30,30,29,29, - 29,22,43,218,188,191,196,201,229,41,32,30,30,30,30,30,31,30,30,30,30,33,45,60,184,207,108,23,0,0,0,0, - 116,196,231,66,58,43,32,32,31,31,30,30,30,30,29,29,29,22,45,220,193,198,204,213,234,41,33,31,32,32,32,32, - 31,31,31,30,32,39,51,82,227,150,86,0,0,0,0,0,116,140,253,136,58,45,36,33,31,31,30,30,30,30,29,30, - 30,23,46,224,202,209,218,230,239,40,34,32,32,32,32,32,32,32,32,33,36,47,58,161,242,117,57,0,0,0,0,0, - 116,118,215,229,66,51,41,34,32,31,30,30,30,30,30,30,30,23,46,229,215,224,233,243,243,40,34,34,34,32,34,34, - 34,32,32,35,43,54,82,227,174,98,13,0,0,0,0,0,0,116,139,254,157,60,49,38,33,31,31,30,30,30,30,30, - 30,23,46,235,230,236,244,253,244,40,34,34,34,34,34,34,34,35,36,42,54,65,177,244,117,55,0,0,0,0,0,0, - 0,116,118,198,242,107,53,46,37,32,31,30,30,30,30,30,31,23,48,243,242,247,251,255,244,41,35,35,35,35,35,35, - 36,37,41,53,61,124,240,162,91,7,0,0,0,0,0,0,0,0,116,121,230,222,78,53,45,37,32,31,30,30,31,31, - 31,23,49,247,252,252,252,255,245,41,35,35,35,35,35,36,37,42,54,62,93,223,215,111,38,0,0,0,0,0,0,0, - 0,0,0,115,136,249,207,66,53,46,38,33,31,31,31,31,31,25,49,190,255,255,255,255,184,40,35,35,36,36,37,38, - 44,55,63,82,210,247,120,58,0,0,0,0,0,0,0,0,0,0,0,0,113,148,254,206,76,55,48,40,35,32,31,31, - 32,30,40,83,121,119,119,122,68,33,39,36,37,38,41,48,59,66,90,208,253,132,69,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,111,146,248,218,104,58,50,45,39,35,34,33,34,33,25,22,23,23,22,30,41,37,38,40,45,54,63, - 66,117,218,246,136,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,133,227,234,153,64,54,50,46,41, - 38,38,37,36,40,41,41,42,42,40,42,47,53,62,65,75,166,234,223,126,69,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,104,119,187,251,224,134,62,55,54,52,50,47,46,44,44,46,47,50,54,60,65,64,73,137,214, - 251,183,115,61,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,95,112,133,214,248,212,152,77, - 60,57,56,58,61,63,64,62,61,63,67,86,158,214,248,205,136,98,44,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,52,97,113,130,181,245,237,233,235,200,173,148,140,148,168,192,220,226,237,245,184,136,107, - 66,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,91,104,115,132, - 178,211,230,245,254,254,254,247,230,212,190,147,120,96,66,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,65,85,94,102,117,117,116,116,116,117,118,99,86,70,41,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,119,146, - 181,213,235,249,254,254,254,249,235,213,181,146,119,115,115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,115,115,118,144,203,250,251,238,218,192,167,144,132,141,162,187,213,236,251,249,202,144,118, - 115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,118,145,222,254,239,202,153, - 154,161,161,157,154,150,146,141,135,130,127,135,191,236,253,222,145,118,115,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,115,123,203,254,238,185,161,175,170,158,148,143,139,137,134,133,131,129,129,126,125,122,119,165,233, - 254,202,123,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,142,235,249,204,159,177,169,148,142, - 141,140,138,136,134,132,131,129,128,125,124,122,120,118,116,113,184,246,234,142,115,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,115,158,250,239,173,172,172,147,140,140,138,138,136,134,133,129,123,122,124,125,123,122,120,117,115,115,113, - 110,140,231,250,159,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,159,254,231,160,177,153,140,138,137,136,134, - 134,133,132,127,141,166,163,133,119,122,120,119,116,114,113,112,111,107,113,217,254,157,115,0,0,0,0,0,0,0,0,0, - 0,0,0,115,142,250,231,156,170,145,136,136,134,134,133,132,132,131,125,146,248,255,255,248,139,115,117,116,115,113,111,108, - 108,108,105,102,216,249,138,115,0,0,0,0,0,0,0,0,0,0,115,123,234,233,158,170,142,134,133,132,131,131,131,130, - 130,127,134,243,255,255,255,255,215,112,115,114,113,111,110,107,105,104,105,103,106,230,232,121,115,0,0,0,0,0,0,0, - 0,115,118,202,246,171,167,140,131,130,129,129,129,128,128,127,127,121,154,255,255,255,255,255,255,125,110,112,110,108,106,105, - 103,102,101,102,102,128,244,193,117,115,0,0,0,0,0,0,0,115,145,254,201,165,143,129,127,127,125,127,125,125,124,125, - 124,120,146,255,255,255,255,255,244,112,108,110,107,106,105,104,100,99,98,99,100,99,174,253,134,114,0,0,0,0,0,0, - 115,118,220,237,151,158,127,124,124,123,124,124,123,123,123,123,122,120,117,218,255,255,255,255,176,90,110,107,106,104,103,102, - 99,97,96,96,96,98,96,229,206,116,107,0,0,0,0,0,115,144,254,183,156,131,123,121,121,121,121,121,121,121,120,120, - 120,119,114,119,183,239,231,166,104,105,107,105,104,102,100,99,97,96,95,93,92,94,96,152,251,130,109,0,0,0,0,0, - 115,203,238,145,142,122,119,119,117,119,117,117,117,117,117,116,116,115,114,111,104,108,104,93,104,106,104,103,100,99,98,97, - 95,94,93,90,90,90,94,97,228,171,110,0,0,0,0,115,119,250,197,150,125,116,115,116,116,116,116,115,115,115,114,114, - 113,113,111,105,105,104,104,104,102,107,103,102,98,97,94,93,90,89,89,88,87,86,87,84,181,226,115,88,0,0,0,115, - 146,251,143,140,116,113,114,114,114,114,114,113,113,113,112,112,111,108,106,126,152,152,152,152,127,90,85,79,73,72,70,69, - 69,69,70,71,72,76,81,80,117,244,128,101,0,0,0,115,179,237,136,125,113,112,112,111,111,111,111,111,111,110,110,108, - 108,107,109,210,255,247,239,232,202,70,63,64,65,65,65,66,66,65,65,65,65,65,69,74,86,227,153,105,0,0,0,115, - 210,216,134,117,109,108,108,110,108,108,107,107,107,106,106,106,106,102,112,240,213,201,196,190,226,68,64,66,65,64,64,65, - 65,65,65,65,66,65,67,72,76,196,179,106,0,0,0,115,233,187,129,112,107,106,106,106,106,106,105,105,104,104,105,104, - 95,73,82,230,201,196,191,185,224,68,63,65,65,64,65,64,64,65,64,64,65,65,65,70,75,201,206,108,0,0,0,115, - 249,156,125,108,105,104,104,104,104,103,103,103,103,104,99,80,68,60,82,229,196,189,185,180,224,68,63,65,65,65,65,64, - 64,65,64,64,64,64,65,69,72,185,221,111,0,0,0,115,254,130,123,106,102,103,102,100,102,102,100,100,102,86,72,66, - 68,62,81,224,189,183,180,175,222,68,63,64,64,64,64,64,64,63,63,63,63,64,66,68,71,151,231,118,0,0,0,115, - 254,116,119,102,99,99,99,99,99,99,99,96,80,68,66,68,68,62,81,222,183,179,176,172,221,68,62,64,64,64,64,64, - 64,63,63,63,63,64,63,68,71,144,231,114,0,0,0,115,254,129,116,101,98,97,96,97,96,97,93,74,66,69,68,68, - 68,61,79,218,179,175,173,170,221,68,62,64,63,63,63,63,63,63,63,63,63,63,64,68,71,160,231,114,0,0,0,115, - 247,152,112,100,96,95,94,94,96,89,71,68,69,68,68,68,66,61,77,213,174,172,172,170,221,68,61,63,63,63,63,63, - 63,63,63,63,63,63,64,68,72,188,228,113,0,0,0,115,230,180,108,99,94,93,93,93,87,72,69,69,68,68,68,66, - 66,61,77,212,173,172,173,174,222,68,62,63,63,63,63,63,63,63,63,63,63,63,64,70,74,194,214,125,0,0,0,115, - 207,209,107,98,92,90,90,88,72,69,69,69,68,68,66,66,66,61,77,212,173,174,176,179,224,68,61,64,64,63,63,63, - 63,63,63,63,63,63,65,71,78,204,181,112,0,0,0,115,178,232,104,97,90,88,86,73,70,70,69,68,68,68,66,66, - 66,61,77,213,178,179,182,185,226,66,62,64,64,64,64,63,63,63,63,63,63,64,66,71,94,239,152,84,0,0,0,115, - 147,250,116,94,87,87,77,70,70,70,69,68,68,66,66,66,65,61,77,215,181,184,189,192,229,66,62,64,64,64,64,64, - 64,64,63,63,63,64,68,71,130,238,118,60,0,0,0,115,119,247,183,84,84,80,71,70,70,69,69,68,68,66,66,65, - 65,60,77,218,188,191,196,201,231,65,62,64,64,64,64,64,64,64,64,64,64,66,71,77,187,205,107,23,0,0,0,0, - 115,196,231,71,80,77,71,71,70,69,69,68,66,66,66,65,65,60,79,220,193,198,204,213,235,65,63,65,64,64,64,64, - 64,64,64,64,65,69,74,94,228,146,86,0,0,0,0,0,115,140,253,137,73,74,72,71,70,69,69,66,66,66,66,65, - 65,60,79,224,202,209,218,230,240,65,63,65,65,65,65,65,65,65,64,65,67,73,75,165,242,116,57,0,0,0,0,0, - 115,117,215,229,71,72,73,71,69,69,69,66,66,66,65,65,65,60,79,229,214,224,233,243,243,64,63,65,65,65,65,65, - 65,65,65,67,71,75,93,227,168,97,13,0,0,0,0,0,0,115,138,254,158,70,74,72,70,69,68,66,66,66,65,65, - 65,60,80,236,230,236,244,252,245,64,63,65,65,65,65,65,65,65,66,70,77,80,179,244,116,55,0,0,0,0,0,0, - 0,115,117,198,242,108,69,73,70,69,68,66,66,66,66,65,65,59,81,243,241,247,251,255,245,65,64,66,66,66,66,66, - 65,66,70,77,77,130,240,154,90,7,0,0,0,0,0,0,0,0,115,120,230,222,81,69,72,71,68,66,66,66,65,65, - 65,59,82,248,252,252,251,255,246,65,64,66,66,66,66,66,67,71,77,78,102,223,209,110,38,0,0,0,0,0,0,0, - 0,0,0,114,136,249,207,71,70,73,70,67,66,66,65,66,65,59,82,202,255,255,255,255,196,63,64,66,66,66,67,68, - 71,78,80,91,211,245,117,58,0,0,0,0,0,0,0,0,0,0,0,0,112,147,254,206,80,69,73,71,68,67,66,66, - 66,64,73,108,134,133,133,136,92,59,66,66,66,67,69,73,80,81,97,209,253,126,68,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,110,146,248,218,105,69,71,71,69,68,67,66,66,65,55,51,51,51,50,57,68,68,69,70,73,78,81, - 80,122,219,244,125,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,107,132,227,234,153,70,69,72,72,70, - 68,68,67,67,68,68,68,69,69,70,72,74,78,82,81,84,167,234,217,119,69,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,103,118,187,251,224,134,69,69,73,75,73,72,71,71,71,71,74,76,78,81,84,79,81,139,214, - 250,170,112,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,94,111,132,214,248,212,153,80, - 68,69,71,75,79,82,82,78,76,75,76,91,159,214,246,196,121,96,43,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,52,96,112,130,179,244,237,233,236,201,174,151,143,151,171,194,221,226,237,243,172,122,105, - 65,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,90,103,114,130, - 174,211,230,245,254,254,254,247,230,212,188,129,111,94,65,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,84,93,101,116,116,115,115,115,116,117,98,86,69,41,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,119,146, - 181,213,235,249,254,254,254,249,235,213,181,146,119,115,115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,115,115,118,144,203,250,251,238,218,193,170,149,138,146,166,189,214,236,251,249,202,144,118, - 115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,118,145,222,254,239,203,156, - 166,186,200,204,207,205,198,188,176,161,145,141,192,236,253,222,145,118,115,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,115,123,203,254,238,186,168,201,224,225,222,221,222,223,220,217,212,206,199,189,176,159,137,169,233, - 254,202,123,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,142,235,249,204,166,208,229,226,228, - 233,234,234,233,232,231,230,227,223,218,213,204,193,175,155,130,185,246,234,142,115,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,115,158,250,239,175,194,230,225,229,235,237,236,235,233,233,232,229,226,226,225,223,221,216,211,200,187,166, - 142,148,231,250,159,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,159,254,231,164,210,224,227,233,236,237,235, - 234,233,233,230,233,240,238,229,222,222,219,217,214,212,205,192,173,146,127,217,254,157,115,0,0,0,0,0,0,0,0,0, - 0,0,0,115,142,250,231,162,217,221,227,234,235,235,234,233,232,232,229,234,255,255,255,255,226,217,217,215,214,212,209,204, - 193,174,147,119,216,249,138,115,0,0,0,0,0,0,0,0,0,0,115,123,234,233,163,214,217,225,232,232,232,232,231,230, - 230,229,230,255,255,255,255,255,246,212,216,214,212,209,208,206,202,191,173,146,120,230,232,121,115,0,0,0,0,0,0,0, - 0,115,118,202,246,173,207,215,222,229,230,229,229,229,227,226,226,224,233,255,255,255,255,255,255,204,214,212,210,208,206,206, - 202,198,188,169,141,137,244,193,117,115,0,0,0,0,0,0,0,115,145,254,201,187,215,219,226,227,226,226,226,225,225,224, - 223,222,230,255,255,255,255,255,250,190,213,209,208,207,206,204,201,199,194,184,162,132,177,253,134,114,0,0,0,0,0,0, - 115,118,220,237,160,218,214,223,225,225,224,224,224,224,223,223,222,221,218,246,255,255,255,255,208,184,212,208,207,205,204,202, - 199,199,196,192,178,151,119,229,206,116,107,0,0,0,0,0,115,144,254,184,196,210,217,221,222,222,222,221,222,222,221,219, - 219,218,217,214,223,243,240,201,184,207,209,207,205,202,201,200,199,197,196,192,185,168,138,157,251,130,109,0,0,0,0,0, - 115,203,238,156,208,209,216,218,219,218,218,218,218,218,217,217,217,216,216,214,206,197,190,193,207,209,206,205,204,202,200,199, - 197,196,195,192,189,178,152,124,229,171,110,0,0,0,0,115,119,250,198,184,203,212,216,216,216,217,216,216,215,215,215,215, - 215,214,213,211,211,211,211,211,209,209,207,205,202,200,198,196,193,192,192,190,190,182,162,127,186,226,115,88,0,0,0,115, - 146,251,148,197,203,212,214,214,214,215,214,214,214,213,214,213,213,212,207,216,226,226,226,226,214,197,190,182,178,175,173,172, - 172,173,173,175,176,177,167,135,134,244,128,101,0,0,0,115,179,237,150,196,205,211,210,212,212,212,212,212,212,212,212,210, - 210,210,209,239,253,244,235,227,228,149,168,168,170,170,170,170,171,170,170,170,170,169,162,141,118,228,153,105,0,0,0,115, - 210,216,160,192,203,207,209,209,209,209,209,209,209,209,208,208,209,209,207,241,214,201,196,190,229,144,160,171,171,171,171,171, - 171,171,171,171,170,171,166,148,118,198,179,106,0,0,0,115,233,187,167,193,203,206,206,207,207,207,207,207,207,207,208,207, - 199,182,180,232,200,197,192,184,229,146,161,172,171,171,172,172,171,171,171,171,171,171,168,154,124,206,206,108,0,0,0,115, - 249,157,171,192,202,205,205,205,205,206,205,205,206,206,204,184,172,170,180,229,195,190,185,179,227,146,161,172,172,172,172,172, - 172,172,172,172,171,171,169,158,128,195,221,111,0,0,0,115,254,132,174,190,200,202,202,202,204,202,202,204,205,190,176,172, - 173,171,180,226,188,184,181,174,224,147,161,173,173,173,172,172,173,173,172,172,172,172,171,161,132,163,231,118,0,0,0,115, - 254,118,172,189,199,201,200,201,200,201,202,200,184,173,173,173,173,171,179,222,182,179,176,170,224,148,161,173,173,173,174,173, - 173,173,172,172,172,173,171,162,134,160,231,114,0,0,0,115,254,131,168,187,197,198,198,199,199,200,196,179,172,174,174,174, - 174,173,178,218,178,174,173,168,224,148,161,174,175,175,174,174,174,174,174,173,173,173,172,163,134,173,231,114,0,0,0,115, - 247,153,157,183,195,197,197,197,199,192,176,173,174,174,174,174,174,174,176,215,173,172,172,168,224,149,164,176,176,176,176,176, - 176,176,175,175,175,174,171,161,132,199,228,113,0,0,0,115,230,181,145,178,191,194,196,196,191,176,175,175,174,175,175,175, - 175,174,176,213,172,172,173,173,225,149,166,179,178,179,178,178,178,178,176,176,176,175,171,159,130,200,214,125,0,0,0,115, - 207,209,133,171,187,191,195,192,176,174,175,175,175,175,175,175,175,174,176,213,172,174,176,178,227,152,167,180,181,181,181,181, - 181,180,180,179,178,178,174,156,128,208,181,112,0,0,0,115,178,232,118,164,182,189,190,179,175,175,175,175,175,175,175,175, - 175,175,176,213,176,179,182,184,229,153,169,183,182,183,183,183,183,182,182,182,181,179,173,151,135,240,152,84,0,0,0,115, - 147,250,122,149,172,186,181,175,176,175,175,175,175,175,176,176,178,176,179,216,181,184,189,191,232,153,171,185,185,185,185,185, - 185,184,184,184,182,180,169,140,156,238,118,60,0,0,0,115,119,247,184,118,159,176,175,176,176,176,176,176,176,176,178,178, - 178,178,179,218,185,191,196,199,234,154,173,188,188,187,188,188,188,187,187,185,184,180,163,135,195,205,107,23,0,0,0,0, - 115,196,231,83,142,165,172,176,176,176,176,176,176,178,178,178,179,180,179,221,192,198,204,212,238,155,174,190,189,190,190,190, - 190,189,189,188,186,177,153,136,229,146,86,0,0,0,0,0,115,140,253,138,112,150,169,175,178,178,178,178,178,178,178,180, - 180,181,180,224,201,210,218,229,243,155,177,192,192,192,192,192,192,191,191,189,185,170,139,178,242,116,57,0,0,0,0,0, - 115,117,215,229,83,131,161,174,177,178,178,178,179,179,180,181,182,182,181,229,213,224,234,243,247,155,178,193,193,193,193,193, - 193,193,192,189,181,153,136,228,168,97,13,0,0,0,0,0,0,115,138,254,158,98,143,165,175,177,178,178,179,180,180,181, - 183,183,183,236,229,238,246,252,248,156,180,195,195,196,196,195,195,194,191,185,167,137,187,244,116,55,0,0,0,0,0,0, - 0,115,117,198,242,112,114,148,167,175,178,179,179,181,182,183,184,184,184,243,241,248,252,253,248,157,181,197,197,197,197,197, - 196,195,189,175,144,153,240,154,90,7,0,0,0,0,0,0,0,0,115,120,230,222,91,120,151,168,176,179,180,181,183,184, - 185,185,185,249,251,252,252,253,249,159,182,198,199,199,199,198,196,191,179,150,135,224,209,110,38,0,0,0,0,0,0,0, - 0,0,0,114,136,249,207,83,123,151,168,176,180,182,183,185,187,187,187,231,255,255,255,255,227,157,184,199,199,199,199,197, - 191,178,152,130,213,245,117,58,0,0,0,0,0,0,0,0,0,0,0,0,112,147,254,206,90,115,147,165,175,181,184,187, - 188,189,195,188,185,185,187,188,174,167,185,200,199,198,195,188,174,148,130,211,253,126,68,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,110,146,248,218,112,105,138,158,170,179,184,188,190,191,171,166,167,168,169,174,184,199,198,195,191,181,165, - 140,142,220,244,125,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,107,132,227,234,154,88,118,146,162,173, - 181,185,188,193,182,183,183,183,182,195,193,189,182,168,148,121,173,234,217,119,69,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,103,118,187,251,224,138,92,118,144,157,166,172,179,183,186,186,184,181,177,171,163,144,121,151,215, - 250,170,112,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,94,111,132,214,248,212,155,91, - 95,115,131,144,153,158,156,150,143,130,116,110,164,215,246,196,121,96,43,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,52,96,112,130,179,244,237,233,237,206,183,163,157,164,180,200,224,227,237,243,172,122,105, - 65,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,90,103,114,130, - 174,211,230,245,254,254,254,247,230,212,188,129,111,94,65,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,84,93,101,116,116,115,115,115,116,117,98,86,69,41,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,42,93,139,181,216,242,254,254,254,242,216,181,139,93,42,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,21,90,169,220,209, - 218,235,248,253,255,255,255,253,248,235,218,209,220,169,90,21,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,12,93,203,207,225,252,255,255,255,255,255,255,255,255,255,255,255,255,255,252,225,207,203, - 93,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,176,206,234,253,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,252,233,206,176,55,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,91,212,222,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 253,221,212,92,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,114,204,242,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,241,203,115,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,115,204,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,252,204,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,204,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,204,114,0,0,0,0,0,0,0,0,0, - 0,0,0,92,203,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,252,207,83,0,0,0,0,0,0,0,0,0,0,56,211,241,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,242,216,49,0,0,0,0,0,0,0, - 0,12,176,221,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,221,166,8,0,0,0,0,0,0,0,93,206,253,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,212,77,0,0,0,0,0,0, - 20,200,234,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,232,189,14,0,0,0,0,0,91,206,252,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,217,73,0,0,0,0,0, - 170,224,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,225,141,2,0,0,0,42,220,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,248,222,26,0,0,0,93, - 209,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,223,73,1,0,0,136,218,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,225,124,4,0,0,178, - 233,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,236,165,8,0,0,215,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,251,191,13,1,0,242, - 253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,254,212,19,3,0,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,229,24,6,0,254, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,227,28,8,0,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,228,32,9,0,238, - 253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,224,33,10,0,210,246,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,221,34,10,0,175, - 233,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,246,190,33,10,0,135,218,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,241,145,32,9,0,94, - 209,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,234,103,28,7,0,38,223,251,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,250,222,65,23,5,0,0, - 162,224,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,237,164,46,18,3,0,0,84,209,253,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,233,111,36,12,1,0,0, - 17,197,233,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,243,195,64,27,7,0,0,0,0,81,210,253,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,234,119,46,18,4,0,0,0, - 0,9,173,223,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,239,184,67,32,10,1,0,0,0,0,0,47,218,242,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,249,232,103,48,20,5,0,0,0,0, - 0,0,0,83,208,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,254,232,135,61,31,10,1,0,0,0,0,0,0,0,0,105,209,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,232,155,72,41,17,4,0,0,0,0,0, - 0,0,0,0,1,107,211,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,254,234,158,79,49,24,8,1,0,0,0,0,0,0,0,0,0,0,2,108,213,244,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,252,234,158,81,54,28,10,2,0,0,0,0,0,0, - 0,0,0,0,0,0,3,88,220,228,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,244,235,145,80,54,30,12,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,60,180,217,248,254,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,249,237,205,122,74,51,29,12,3,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,3,20,103,209,220,235,254,255,255,255,255,255,255,255,255,255,255,255,255,255,254,246,238,223, - 150,90,65,44,25,11,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,8,35,107,183,231,225, - 247,255,255,255,255,255,255,255,255,255,255,244,241,203,149,96,70,52,34,19,8,2,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,1,5,13,24,70,124,166,200,233,247,255,255,255,249,237,208,181,151,113,78,66,52, - 37,24,12,5,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,7,13,22, - 32,43,52,60,67,72,76,77,76,72,67,60,52,43,32,22,13,7,2,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,5,10,16,22,27,31,34,37,38,37,35,31,27,22,16,10,5, - 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 1,2,4,7,9,10,12,12,12,10,9,7,4,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} -},{ - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,150,173,179,153,115,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,158,166,182,188,174,119,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,153,168,193,188,194,158,91,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,150,157,196,182,190,193,187,154,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,179,189,177,232,176,196,162,108,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,150,157,202,153,224,255,244,165,193,157,52,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,156,193,176,185,255,252,254,186,201,173,134,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 153,165,205,159,239,255,251,252,248,174,202,159,81,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155,156,205,178,202,255,251,250,250,252,190,208,189,147,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154, - 173,207,165,248,252,250,250,250,250,247,178,209,160,98,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,151,157,214,179,208,252,252,252,252,252,252,253,191,217,201,155,29,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,188, - 207,173,255,240,233,233,233,233,233,243,250,182,218,167,122,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,151,159,221,172,238,246,144,87,87,86,86,94,158,245,241,178,211,158,55, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155,156,209,195, - 200,255,244,112,122,122,120,118,114,136,235,248,185,225,184,135,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,154,172,230,177,243,254,244,116,118,118,117,114,110,136,234,248,237,184,230,161, - 80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,147,156,231,204,210, - 254,251,245,119,114,114,112,109,101,139,237,245,243,188,236,205,149,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,154,187,237,184,247,250,251,245,122,108,109,104,101,88,140,241,244,243,234,188,243, - 166,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,149,157,243,204,215,252, - 248,249,246,123,99,101,97,92,77,139,243,241,240,239,183,241,228,157,28,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,156,206,219,202,250,248,247,249,246,127,91,92,88,83,67,137,244,240,238,239,231,183, - 248,180,123,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,152,164,249,190,240,249,247, - 247,248,244,128,83,82,77,75,65,140,241,238,237,237,238,195,222,240,159,61,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,155,155,225,213,208,250,247,246,246,247,245,130,73,71,71,72,66,147,240,238,237,237,237,233, - 179,246,196,140,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,178,243,182,243,248,246,245, - 245,245,245,130,60,62,65,71,70,154,241,238,236,236,235,235,220,186,245,162,80,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,150,156,236,202,212,250,245,245,244,243,244,241,130,53,60,66,72,75,158,241,237,235,235,234,234, - 231,176,239,209,150,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,192,230,185,247,245,244,244,243, - 241,241,243,126,20,30,40,51,59,154,234,233,231,231,231,231,233,224,178,239,167,109,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,150,159,236,181,235,247,243,243,239,237,235,235,233,124,0,0,17,37,55,154,231,229,229,229,229,229, - 229,229,188,215,219,157,38,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155,155,203,200,194,243,238,236,234,231,231, - 231,231,233,134,0,8,30,51,76,163,231,230,229,229,229,229,229,229,221,174,229,179,122,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,152,166,226,174,231,236,234,233,233,231,231,231,230,234,146,0,14,38,60,89,168,231,229,229,229,229,229, - 227,227,228,186,204,219,159,60,0,0,0,0,0,0,0,0,0,0,0,0,147,155,212,187,196,238,234,233,231,231,230,230, - 230,230,234,159,0,13,39,62,101,168,231,229,229,229,228,228,227,226,227,224,169,221,186,141,0,0,0,0,0,0,0,0, - 0,0,0,0,154,178,214,167,231,235,233,231,230,230,230,230,230,230,232,186,13,30,54,77,93,175,231,229,229,228,227,227, - 227,226,226,226,214,171,218,160,92,0,0,0,0,0,0,0,0,0,0,149,156,214,177,201,236,231,230,230,230,230,230,230, - 230,230,231,226,215,215,215,215,215,225,228,228,228,227,226,226,226,225,224,224,224,167,213,195,151,8,0,0,0,0,0,0, - 0,0,0,155,192,185,183,235,231,230,230,230,230,230,230,230,230,230,229,233,231,208,179,210,234,231,228,228,227,226,226,226, - 225,225,224,224,225,218,165,211,166,108,0,0,0,0,0,0,0,0,153,160,208,161,223,234,230,230,230,230,230,230,229,229, - 229,229,229,235,148,45,46,78,165,230,228,227,226,226,226,225,224,224,224,224,224,225,181,192,197,157,38,0,0,0,0,0, - 0,155,155,198,175,182,236,231,230,230,230,230,230,230,229,229,229,229,230,185,16,12,43,64,89,194,227,226,226,226,225,224, - 224,224,224,224,224,226,220,164,204,172,129,0,0,0,0,0,0,153,167,197,157,230,234,233,231,231,230,231,231,230,230,231, - 231,231,231,138,0,27,55,80,93,167,229,228,227,226,226,226,226,226,226,226,226,226,227,185,184,198,158,62,0,0,0,0, - 150,155,198,165,193,238,234,234,234,233,234,233,233,231,233,233,234,234,233,179,17,33,68,93,109,176,234,229,228,228,228,227, - 227,227,227,228,228,228,228,229,164,196,177,140,0,0,0,0,154,177,188,161,239,237,237,236,236,236,236,236,236,236,237,237, - 236,236,238,237,121,50,75,107,139,210,236,233,233,231,231,231,231,231,231,231,233,233,233,236,194,180,195,159,91,0,0,150, - 157,197,158,204,245,240,240,240,240,241,241,241,241,241,241,243,241,241,241,244,239,184,150,173,215,238,238,237,237,237,236,236, - 237,237,237,237,238,238,239,239,241,166,189,183,154,16,0,157,186,183,183,243,238,238,238,238,237,238,237,238,238,238,238,238, - 238,238,237,236,238,240,235,234,236,235,234,234,234,233,233,233,233,234,234,235,236,236,237,237,239,231,176,190,163,110,0,160, - 196,187,194,170,167,169,169,170,172,175,176,177,178,181,183,184,186,187,188,190,190,191,193,192,191,191,190,189,187,186,185,183, - 179,178,177,176,175,172,171,170,169,167,193,189,185,114,0,117,186,189,189,190,192,192,193,195,198,203,207,211,216,220,225,229, - 234,238,241,245,248,250,252,252,251,249,246,241,239,234,230,226,220,217,211,207,203,200,196,193,192,192,192,192,169,87,0,28, - 107,108,108,108,108,108,108,109,109,110,110,111,112,113,113,114,114,115,116,116,117,117,117,117,116,115,114,113,112,112,111,110, - 110,109,108,107,106,106,105,105,104,104,105,105,89,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,156,174,179,153,115,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,157,167,182,188,174,119,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,153,168,193,188,194,158,91,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,150,157,196,182,190,193,187,154,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,179,190,176,228,175,196,162,108,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,150,157,202,153,220,255,238,165,193,157,52,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,156,193,177,183,250,248,248,182,203,174,134,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 153,165,205,159,235,250,246,246,240,172,203,159,81,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155,156,205,178,199,252,246,245,243,244,183,209,189,147,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154, - 173,208,164,241,246,244,243,241,241,235,176,210,160,98,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,151,157,214,179,204,246,245,245,245,245,245,243,180,217,201,155,29,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,188, - 207,171,247,233,226,226,226,226,226,235,234,177,219,167,122,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,151,159,221,171,230,239,142,87,87,86,86,94,153,228,225,177,212,158,55, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155,156,209,196, - 195,247,236,112,122,122,120,118,115,132,218,227,175,227,184,135,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,154,172,230,176,234,243,235,115,118,118,117,114,110,131,215,228,215,178,231,161, - 80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,147,156,231,204,204, - 243,239,235,117,115,114,112,109,102,133,217,224,218,171,237,205,149,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,154,187,237,180,236,237,237,234,119,108,109,104,101,91,133,217,220,218,206,178,245, - 166,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,149,157,244,204,205,238, - 234,235,234,121,99,101,97,92,80,129,218,217,215,210,161,241,228,157,28,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,156,206,219,198,236,233,231,233,234,122,91,92,88,83,70,126,217,214,210,209,198,168, - 250,180,123,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,152,164,249,189,228,234,231, - 230,230,233,123,85,82,77,75,66,128,213,209,207,206,205,165,219,241,159,61,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,155,155,225,214,201,234,230,229,227,227,231,122,73,71,71,72,67,134,210,208,205,203,201,193, - 161,248,196,140,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,178,243,180,227,230,228,226, - 225,224,229,120,61,62,65,71,71,137,208,205,201,199,197,197,177,178,247,162,80,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,150,156,236,202,202,231,226,225,223,221,220,217,117,54,60,66,73,76,139,207,200,198,196,195,193, - 186,148,240,210,150,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,192,230,178,229,226,225,223,220, - 218,216,216,112,23,30,40,51,60,132,188,192,192,189,187,186,186,172,165,243,167,109,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,150,159,236,180,220,227,223,218,213,208,205,203,196,108,0,0,17,38,57,128,182,185,184,182,180,178, - 177,176,151,215,220,157,38,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155,155,203,201,186,218,211,206,203,200,197, - 196,195,196,115,0,8,30,51,77,134,182,183,180,179,177,177,176,175,165,152,233,179,122,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,152,166,226,171,208,204,201,200,199,197,196,194,193,196,123,0,14,38,60,91,135,181,180,178,177,176,175, - 173,173,173,140,201,220,159,60,0,0,0,0,0,0,0,0,0,0,0,0,147,155,212,190,182,206,201,199,198,196,194,194, - 193,193,195,131,0,14,39,62,102,135,181,178,177,175,174,173,173,172,170,164,143,224,186,141,0,0,0,0,0,0,0,0, - 0,0,0,0,154,178,214,164,203,200,199,197,196,194,193,192,192,190,193,150,14,33,55,77,93,137,180,177,175,173,173,173, - 170,169,168,168,156,161,220,160,92,0,0,0,0,0,0,0,0,0,0,149,156,214,177,181,201,197,196,194,194,193,192,190, - 189,188,187,177,167,166,166,166,166,173,174,175,173,172,172,170,168,167,167,166,163,133,214,195,151,8,0,0,0,0,0,0, - 0,0,0,155,192,187,172,200,197,194,193,193,192,192,188,188,187,186,183,184,185,164,143,164,183,177,174,173,172,169,169,168, - 167,167,165,164,164,155,150,215,166,108,0,0,0,0,0,0,0,0,153,160,209,160,194,196,194,193,192,192,189,188,187,185, - 184,182,182,185,118,43,47,76,131,175,174,170,169,168,168,167,165,165,164,164,164,163,140,191,197,157,38,0,0,0,0,0, - 0,155,155,198,176,167,197,194,193,193,190,189,187,187,186,183,183,182,185,146,16,13,43,66,89,150,172,170,169,168,167,166, - 165,165,165,165,165,166,157,140,208,173,129,0,0,0,0,0,0,153,167,199,152,197,197,194,194,193,190,188,188,187,186,184, - 183,183,186,112,0,27,55,80,95,135,174,173,172,170,169,168,168,168,168,168,168,168,169,138,176,201,158,62,0,0,0,0, - 150,155,199,165,172,203,198,197,195,195,194,193,192,192,189,188,187,187,188,144,19,33,68,95,111,140,180,178,177,175,175,175, - 175,175,175,175,175,175,176,173,131,198,177,140,0,0,0,0,154,177,190,152,207,206,204,203,201,200,199,199,197,197,197,196, - 195,195,195,194,103,50,76,108,123,167,189,186,185,185,185,185,185,185,185,185,185,185,186,188,152,169,197,159,91,0,0,151, - 157,197,157,185,216,213,211,211,210,209,209,208,207,208,207,206,206,205,205,206,200,157,132,147,178,197,198,197,197,196,196,196, - 196,196,197,197,197,198,198,198,200,138,187,183,154,16,0,156,186,185,173,214,209,209,208,207,206,206,205,204,204,204,204,203, - 203,203,201,199,200,201,196,195,197,196,195,195,195,195,194,195,195,195,195,197,197,198,198,198,200,189,158,193,163,110,0,160, - 196,187,192,158,149,152,152,153,155,156,157,159,160,162,164,166,168,170,171,171,171,173,174,174,173,172,171,171,170,168,166,164, - 162,160,159,158,156,155,153,152,150,150,188,189,185,114,0,117,186,189,190,192,194,194,195,197,201,205,209,214,218,223,227,231, - 236,240,244,247,250,254,255,255,254,251,248,245,241,236,233,228,223,219,215,209,205,203,198,195,194,194,192,192,169,87,0,28, - 107,108,108,108,108,108,108,109,109,110,110,111,112,113,113,114,114,115,116,116,117,117,117,117,116,115,114,113,112,112,111,110, - 110,109,108,107,106,106,105,105,104,104,105,105,89,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,153,175,179,154,116,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,158,166,183,189,175,120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155,168,196,198,196,159,92,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,150,157,198,179,136,190,189,155,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,179,203,116,0,114,210,163,109,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,150,157,205,161,57,0,50,164,196,158,52,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,156,193,189,114,5,0,0,101,219,175,135,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 153,165,210,150,44,0,3,0,22,149,212,160,81,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155,156,206,190,92,0,3,6,9,0,81,224,191,148,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154, - 174,216,143,26,0,9,10,12,12,26,148,220,161,99,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,151,157,216,187,79,7,9,11,12,12,13,11,62,224,203,156,29,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,188, - 219,125,19,10,12,13,13,13,14,14,23,125,230,168,122,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,151,159,226,165,60,9,77,91,88,87,87,104,66,21,62,173,216,159,55, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155,156,210,209, - 116,11,15,101,129,124,123,122,129,75,29,30,116,238,186,136,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,154,172,237,159,48,14,18,94,124,118,117,114,123,68,31,37,48,161,236,162, - 81,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,147,156,232,213,98, - 16,24,20,91,122,114,112,109,114,66,34,43,30,96,249,206,150,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,154,187,247,153,37,23,31,21,86,115,109,104,101,103,62,36,42,38,43,157,251, - 167,107,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,149,157,248,207,86,23, - 32,34,23,81,109,101,97,92,92,56,36,42,40,26,68,248,231,158,28,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,156,207,230,146,34,31,36,38,24,73,101,92,88,85,83,52,36,40,36,35,24,130, - 255,181,124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,152,164,254,179,68,29,38, - 40,42,24,69,93,82,77,75,77,48,33,36,34,31,21,43,217,245,160,62,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,155,155,226,224,119,31,38,41,42,42,24,63,85,71,71,72,77,48,31,32,30,26,24,10, - 107,255,197,141,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,178,250,163,58,35,42,42, - 43,43,24,56,73,62,65,71,78,45,26,27,25,23,21,13,17,165,253,163,80,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,150,156,238,208,98,35,41,42,43,43,43,35,48,66,60,66,73,83,42,23,24,21,19,15,13, - 0,71,248,211,151,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,193,239,136,46,38,43,45,44, - 42,41,33,35,35,30,40,53,66,31,6,12,10,9,9,7,5,0,131,251,168,109,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,150,159,241,178,83,36,42,38,31,25,21,17,11,22,0,0,17,39,62,22,1,2,1,1,1,1, - 1,0,49,222,222,158,38,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155,156,204,211,127,26,21,16,12,10,10, - 11,10,9,21,0,8,30,53,80,20,1,1,1,1,0,1,0,0,0,111,241,180,123,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,152,166,231,160,44,2,9,10,12,12,12,11,10,9,19,1,14,38,62,92,17,1,0,0,0,0,0, - 1,2,0,22,198,224,160,60,0,0,0,0,0,0,0,0,0,0,0,0,147,155,213,200,91,3,11,12,12,12,12,11, - 10,9,8,15,2,16,40,66,104,11,1,0,0,0,0,1,1,3,3,0,91,234,187,142,0,0,0,0,0,0,0,0, - 0,0,0,0,154,178,221,138,27,6,12,12,12,12,11,10,9,7,8,7,22,35,59,83,89,2,1,0,0,0,1,2, - 3,3,5,2,12,150,225,161,92,0,0,0,0,0,0,0,0,0,0,149,156,218,180,63,5,12,12,12,11,10,9,9, - 6,6,4,1,1,1,1,2,1,0,2,0,0,1,2,3,3,5,6,7,0,59,219,198,152,8,0,0,0,0,0,0, - 0,0,0,155,193,196,111,10,10,12,12,11,10,9,9,6,5,3,3,2,4,4,11,1,1,0,0,0,0,2,3,4, - 4,6,7,7,6,0,119,224,167,108,0,0,0,0,0,0,0,0,153,160,214,153,40,5,12,11,11,10,9,7,6,5, - 4,3,1,0,10,34,52,66,20,0,0,0,2,3,4,5,6,7,7,7,9,0,48,196,200,157,38,0,0,0,0,0, - 0,155,155,199,185,92,7,12,12,12,11,11,10,7,6,5,4,3,4,4,16,20,44,72,88,13,2,4,5,7,9,9, - 10,11,11,11,11,10,0,97,218,174,130,0,0,0,0,0,0,153,167,207,128,34,15,20,19,19,17,16,15,14,13,12, - 11,10,5,20,10,27,55,81,101,38,4,13,14,15,16,17,17,17,17,17,17,17,11,27,167,206,159,63,0,0,0,0, - 150,155,201,166,65,26,33,33,33,32,31,31,30,29,27,27,25,25,10,25,21,36,68,97,112,36,26,30,31,32,33,33, - 33,33,33,32,32,32,31,17,67,205,178,141,0,0,0,0,154,177,199,110,47,53,54,54,54,53,52,52,51,50,50,48, - 48,48,47,47,43,53,80,109,72,41,52,53,54,54,54,54,54,54,54,54,53,53,53,51,42,152,203,160,92,0,0,150, - 157,201,153,81,74,78,78,77,77,77,77,77,76,76,76,75,75,75,75,75,73,67,67,65,65,76,78,78,78,80,80,80, - 80,80,78,78,78,77,77,77,72,73,189,185,155,16,0,157,187,193,129,83,87,88,87,88,88,87,87,87,87,87,86,86, - 85,85,85,85,86,85,82,83,86,87,87,88,88,88,88,88,89,89,88,88,89,88,88,88,88,77,130,198,164,111,0,161, - 197,189,184,135,125,128,128,129,131,131,133,135,136,139,141,142,143,144,147,148,149,149,150,150,149,149,148,147,145,143,142,141, - 139,137,136,134,132,131,129,128,127,126,183,192,186,115,0,117,187,190,193,197,199,199,200,203,206,210,214,218,223,228,231,237, - 240,245,249,251,255,255,255,255,255,255,252,249,246,241,237,233,227,224,219,215,210,207,204,200,199,199,194,192,170,88,0,28, - 108,109,109,109,109,109,109,109,110,110,111,112,113,114,114,115,115,116,116,117,117,117,118,118,117,116,115,114,113,113,112,111, - 110,109,109,108,107,107,106,105,105,105,106,106,90,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,159,208,154,52,7,1,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,6,137,255,255,254,146,29,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,101,250,255,255,255,249,117,20,2,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,28,249,255,255,255,255,255,246,61,13,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,182,253,255,255,255,255,255,248,165,34,4,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,54,248,255,255,255,255,255,255,255,250,83,17,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,219,255,255,255,255,255,255,255,255,252,212,42,8,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 111,249,255,255,255,255,255,255,255,255,255,251,121,24,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,242,255,255,255,255,255,255,255,255,255,255,254,234,51,11,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154, - 248,255,255,255,255,255,255,255,255,255,255,255,249,151,30,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,249,255,255,255,255,255,255,255,255,255,255,255,255,255,246,67,15, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,198,253, - 255,255,255,255,255,255,255,255,255,255,255,255,255,249,185,37,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,83,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,250,88, - 19,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,229,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,252,213,43,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,125,249,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,252, - 122,25,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,19,245,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,236,54,11,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,169,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 249,162,31,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,50,250,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,247,70,16,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,216,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,251,192,38,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,97,248,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,251,94,20,1,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,12,240,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,252,222,45,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,152,249,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,251,124,26,2,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,28,245,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,254,236,54,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,184,249,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,250,165,32,4,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,62,245,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,249,76,16,1,0,0,0,0,0,0,0,0,0,0,0,0,3,224,253,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,251,194,39,6,0,0,0,0,0,0,0, - 0,0,0,0,0,113,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,252,97,21,1,0,0,0,0,0,0,0,0,0,0,19,244,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,253,223,46,9,0,0,0,0,0,0, - 0,0,0,0,165,248,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,251,136,27,3,0,0,0,0,0,0,0,0,50,248,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,241,57,13,0,0,0,0,0, - 0,0,0,211,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,252,167,33,4,0,0,0,0,0,0,76,242,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,249,76,17,1,0,0,0, - 0,6,234,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,252,203,40,7,0,0,0,0,129,245,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,251,101,22,1,0,0, - 28,246,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,253,224,47,9,0,0,178,248,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,251,138,27,3,33, - 247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,244,61,13,184,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,251,175,34,179, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,198,58,169,228,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,245,187,70,44, - 188,228,234,235,235,235,235,235,235,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,233,233,233,233,233,232, - 232,232,232,232,232,232,231,231,231,231,231,231,209,135,60,7,31,63,81,85,86,86,86,86,86,86,86,86,86,86,86,86, - 86,86,86,86,86,86,86,86,86,85,85,85,85,85,85,85,85,85,85,84,84,84,84,84,84,84,84,84,81,65,34,1, - 7,18,25,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27, - 26,26,26,26,26,26,26,26,26,26,26,26,25,19,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} -} -}; - -static LCUI_BOOL msgbox_list_init = FALSE; -static LCUI_Queue msgbox_list; - -static int LoadMsgIcon( LCUI_Graph *buff, int img_res_id ) -{ - if( img_res_id >= IMG_TOTAL_NUM ) { - return -1; - } - if( Graph_IsValid( buff ) ) { - Graph_Free( buff ); - } - Graph_Init( buff ); - buff->color_type = COLOR_TYPE_ARGB;; - buff->alpha = 255; - if( Graph_Create( buff, 48, 48 ) != 0 ) { - return -2; - } - Graph_SetRedBits( buff, msgbox_icon[img_res_id][0], 48*48 ); - Graph_SetGreenBits( buff, msgbox_icon[img_res_id][1], 48*48 ); - Graph_SetBlueBits( buff, msgbox_icon[img_res_id][2], 48*48 ); - Graph_SetAlphaBits( buff, msgbox_icon[img_res_id][3], 48*48 ); - return 0; -} - -static LCUI_MainLoop* -msgbox_mainloop_new( LCUI_Widget msgbox ) -{ - MB_data *data; - if( !msgbox_list_init ) { - Queue_Init( &msgbox_list, sizeof(MB_data), NULL ); - msgbox_list_init = TRUE; - } - - data = (MB_data*)malloc( sizeof(MB_data) ); - if( data == NULL ) { - return NULL; - } - - data->msgbox = msgbox; - data->mainloop = LCUI_MainLoop_New(); - Queue_InsertPointer( &msgbox_list, 0, data ); - return data->mainloop; -} - -static MB_data * -msgbox_data_find( LCUI_Widget msgbox ) -{ - int i, n; - MB_data *data; - n = Queue_GetTotal( &msgbox_list ); - for(i=0; imsgbox == msgbox ) { - return data; - } - } - return NULL; -} - -static int -msgbox_data_delete( LCUI_Widget msgbox ) -{ - int i, n; - MB_data *data; - n = Queue_GetTotal( &msgbox_list ); - for(i=0; imsgbox == msgbox ) { - Queue_Delete( &msgbox_list, i ); - return 0; - } - } - return -1; -} - -static void -msgbox_mainloop_quit( LCUI_Widget btn, LCUI_WidgetEvent *unused ) -{ - LCUI_Widget msgbox; - MB_data *data; - - msgbox = Widget_GetParent( btn, "window" ); - data = msgbox_data_find( msgbox ); - if( !data ) { - return; - } - data->clicked_button = btn->self_id; - LCUI_MainLoop_Quit( data->mainloop ); -} - -/* 响应用于显示文本的label部件的尺寸变动,并自动调整消息框的尺寸 */ -static void -auto_resize_msgbox(LCUI_Widget textlabel, LCUI_WidgetEvent *event ) -{ - int area_height; - LCUI_Widget msgbox, *msg_area; - LCUI_Size msgbox_size; - - msgbox = Widget_GetParent( textlabel, "window" ); - if( !msgbox ) { - return; - } - if( (msgbox->self_id & WIDGET_ID_MESSAGEBOX) != WIDGET_ID_MESSAGEBOX ) { - return; - } - /* 以下只是估算消息框的尺寸,不要纠结 为何要+=14、为何要+=30 等之类的问题 */ - if( (msgbox->self_id & MSGBOX_NONE_ICON) == MSGBOX_NONE_ICON ) { - msgbox_size.h = area_height = MB_MSG_AREA_HEIGHT; - msgbox_size.w = 0; - } else { - msgbox_size = MB_ICONBOX_SIZE; - } - msgbox_size.w += 14; - msgbox_size.w += event->resize.new_size.w; - area_height = msgbox_size.h; - if( area_height < event->resize.new_size.h ) { - area_height = event->resize.new_size.h; - } - if( area_height < MB_MSG_AREA_HEIGHT ) { - area_height = MB_MSG_AREA_HEIGHT; - } - - DEBUG_MSG("area_height: %d\n", area_height); - /* 加上按钮区域的固定高度 */ - msgbox_size.h = area_height + MB_BTN_AREA_HEIGHT; - /* 加上窗口边框尺寸 */ - msgbox_size.w += 14; - msgbox_size.h += 30; - - DEBUG_MSG("widget: %p, old size: (%d,%d), new size: (%d,%d)\n", - textlabel, - event->resize.old_size.w, event->resize.old_size.h, - event->resize.new_size.w, event->resize.new_size.h); - DEBUG_MSG("msgbox size: (%d,%d)\n", msgbox_size.w, msgbox_size.h); - - /* 获取消息框内的消息区域的指针 */ - msg_area = Widget_GetChildByID( Window_GetClientArea(msgbox), - WIDGET_ID_MB_MSG_AREA ); - if( !msg_area ) { - return; - } - Widget_SetHeight( msg_area, area_height ); - Widget_Resize( msgbox, msgbox_size ); -} - -static void -msgbox_add_BTN_OK( LCUI_Widget btn_area ) -{ - LCUI_Widget btn; - btn = Widget_New("button"); - btn->self_id = MB_BTN_IS_OK; - Widget_Resize( btn, MB_BTN_SIZE ); - Widget_SetAutoSize( btn, FALSE, 0 ); - Button_TextW( btn, TEXT_MB_BTN_OK ); - Widget_Container_Add( btn_area, btn ); - Widget_SetAlign( btn, ALIGN_MIDDLE_CENTER, Pos(0,0) ); - Widget_ConnectEvent( btn, EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_Show( btn ); -} - -static void -msgbox_add_BTN_OKCANCEL( LCUI_Widget btn_area ) -{ - LCUI_Size btn_size; - LCUI_Widget btn[2]; - btn[0] = Widget_New("button"); - btn[1] = Widget_New("button"); - btn[0]->self_id = MB_BTN_IS_OK; - btn[1]->self_id = MB_BTN_IS_CANCEL; - Widget_Resize( btn[0], MB_BTN_SIZE ); - Widget_Resize( btn[1], MB_BTN_SIZE ); - Widget_SetAutoSize( btn[0], FALSE, 0 ); - Widget_SetAutoSize( btn[1], FALSE, 0 ); - Button_TextW( btn[0], TEXT_MB_BTN_OK ); - Button_TextW( btn[1], TEXT_MB_BTN_CANCEL ); - Widget_Container_Add( btn_area, btn[0] ); - Widget_Container_Add( btn_area, btn[1] ); - btn_size = MB_BTN_SIZE; - Widget_SetAlign( btn[0], ALIGN_MIDDLE_CENTER, Pos(0-(btn_size.w/2.0+3),0) ); - Widget_SetAlign( btn[1], ALIGN_MIDDLE_CENTER, Pos((btn_size.w/2.0+3),0) ); - Widget_ConnectEvent( btn[0], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_ConnectEvent( btn[1], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_Show( btn[0] ); - Widget_Show( btn[1] ); -} - -static void -msgbox_add_BTN_ABORTRETRYIGNORE( LCUI_Widget btn_area ) -{ - LCUI_Size btn_size; - LCUI_Widget btn[3]; - btn[0] = Widget_New("button"); - btn[1] = Widget_New("button"); - btn[2] = Widget_New("button"); - btn[0]->self_id = MB_BTN_IS_ABORT; - btn[1]->self_id = MB_BTN_IS_RETRY; - btn[2]->self_id = MB_BTN_IS_IGNORE; - Widget_Resize( btn[0], MB_BTN_SIZE ); - Widget_Resize( btn[1], MB_BTN_SIZE ); - Widget_Resize( btn[2], MB_BTN_SIZE ); - Widget_SetAutoSize( btn[0], FALSE, 0 ); - Widget_SetAutoSize( btn[1], FALSE, 0 ); - Widget_SetAutoSize( btn[2], FALSE, 0 ); - Button_TextW( btn[0], TEXT_MB_BTN_ABORT ); - Button_TextW( btn[1], TEXT_MB_BTN_RETRY ); - Button_TextW( btn[2], TEXT_MB_BTN_IGNORE ); - Widget_Container_Add( btn_area, btn[0] ); - Widget_Container_Add( btn_area, btn[1] ); - Widget_Container_Add( btn_area, btn[2] ); - btn_size = MB_BTN_SIZE; - Widget_SetAlign( btn[0], ALIGN_MIDDLE_CENTER, Pos(0-(btn_size.w+3),0) ); - Widget_SetAlign( btn[1], ALIGN_MIDDLE_CENTER, Pos(0,0) ); - Widget_SetAlign( btn[2], ALIGN_MIDDLE_CENTER, Pos((btn_size.w+3),0) ); - Widget_ConnectEvent( btn[0], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_ConnectEvent( btn[1], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_ConnectEvent( btn[2], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_Show( btn[0] ); - Widget_Show( btn[1] ); - Widget_Show( btn[2] ); -} - -static void -msgbox_add_BTN_RETRYCANCEL( LCUI_Widget btn_area ) -{ - LCUI_Size btn_size; - LCUI_Widget btn[3]; - btn[0] = Widget_New("button"); - btn[1] = Widget_New("button"); - btn[0]->self_id = MB_BTN_IS_RETRY; - btn[1]->self_id = MB_BTN_IS_CANCEL; - Widget_Resize( btn[0], MB_BTN_SIZE ); - Widget_Resize( btn[1], MB_BTN_SIZE ); - Widget_SetAutoSize( btn[0], FALSE, 0 ); - Widget_SetAutoSize( btn[1], FALSE, 0 ); - Button_TextW( btn[0], TEXT_MB_BTN_RETRY ); - Button_TextW( btn[1], TEXT_MB_BTN_CANCEL ); - Widget_Container_Add( btn_area, btn[0] ); - Widget_Container_Add( btn_area, btn[1] ); - btn_size = MB_BTN_SIZE; - Widget_SetAlign( btn[0], ALIGN_MIDDLE_CENTER, Pos(0-(btn_size.w/2.0+3),0) ); - Widget_SetAlign( btn[1], ALIGN_MIDDLE_CENTER, Pos((btn_size.w/2.0+3),0) ); - Widget_ConnectEvent( btn[0], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_ConnectEvent( btn[1], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_Show( btn[0] ); - Widget_Show( btn[1] ); -} - -static void -msgbox_add_BTN_YESNO( LCUI_Widget btn_area ) -{ - LCUI_Size btn_size; - LCUI_Widget btn[2]; - btn[0] = Widget_New("button"); - btn[1] = Widget_New("button"); - btn[0]->self_id = MB_BTN_IS_YES; - btn[1]->self_id = MB_BTN_IS_NO; - Widget_Resize( btn[0], MB_BTN_SIZE ); - Widget_Resize( btn[1], MB_BTN_SIZE ); - Widget_SetAutoSize( btn[0], FALSE, 0 ); - Widget_SetAutoSize( btn[1], FALSE, 0 ); - Button_TextW( btn[0], TEXT_MB_BTN_YES ); - Button_TextW( btn[1], TEXT_MB_BTN_NO ); - Widget_Container_Add( btn_area, btn[0] ); - Widget_Container_Add( btn_area, btn[1] ); - btn_size = MB_BTN_SIZE; - Widget_SetAlign( btn[0], ALIGN_MIDDLE_CENTER, Pos(0-(btn_size.w/2.0+3),0) ); - Widget_SetAlign( btn[1], ALIGN_MIDDLE_CENTER, Pos((btn_size.w/2.0+3),0) ); - Widget_ConnectEvent( btn[0], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_ConnectEvent( btn[1], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_Show( btn[0] ); - Widget_Show( btn[1] ); -} - -static void -msgbox_add_BTN_YESNOCANCEL( LCUI_Widget btn_area ) -{ - LCUI_Size btn_size; - LCUI_Widget btn[3]; - btn[0] = Widget_New("button"); - btn[1] = Widget_New("button"); - btn[2] = Widget_New("button"); - btn[0]->self_id = MB_BTN_IS_YES; - btn[1]->self_id = MB_BTN_IS_NO; - btn[2]->self_id = MB_BTN_IS_CANCEL; - Widget_Resize( btn[0], MB_BTN_SIZE ); - Widget_Resize( btn[1], MB_BTN_SIZE ); - Widget_Resize( btn[2], MB_BTN_SIZE ); - Widget_SetAutoSize( btn[0], FALSE, 0 ); - Widget_SetAutoSize( btn[1], FALSE, 0 ); - Widget_SetAutoSize( btn[2], FALSE, 0 ); - Button_TextW( btn[0], TEXT_MB_BTN_YES ); - Button_TextW( btn[1], TEXT_MB_BTN_NO ); - Button_TextW( btn[2], TEXT_MB_BTN_CANCEL ); - Widget_Container_Add( btn_area, btn[0] ); - Widget_Container_Add( btn_area, btn[1] ); - Widget_Container_Add( btn_area, btn[2] ); - btn_size = MB_BTN_SIZE; - Widget_SetAlign( btn[0], ALIGN_MIDDLE_CENTER, Pos(0-(btn_size.w+3),0) ); - Widget_SetAlign( btn[1], ALIGN_MIDDLE_CENTER, Pos(0,0) ); - Widget_SetAlign( btn[2], ALIGN_MIDDLE_CENTER, Pos((btn_size.w+3),0) ); - Widget_ConnectEvent( btn[0], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_ConnectEvent( btn[1], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_ConnectEvent( btn[2], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_Show( btn[0] ); - Widget_Show( btn[1] ); - Widget_Show( btn[2] ); -} - - -/* 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 ) -{ - int ret, icon_flag; - LCUI_Graph icon; - LCUI_MainLoop *loop; - MB_data *msgbox_data; - LCUI_Border btn_area_border; - LCUI_Widget iconbox, *textbox, *msgbox; - LCUI_Widget btn_close; - LCUI_Widget msg_area, *btn_area; - LCUI_Size min_size, max_size; - - iconbox = Widget_New("picture_box"); - textbox = Label_New(); - msg_area = Widget_New(NULL); - btn_area = Widget_New(NULL); - msg_area->self_id = WIDGET_ID_MB_MSG_AREA; - - Graph_Init( &icon ); - /* 根据参数的值,载入相应的图标 */ - switch(icon_type) { - case MB_ICON_ERROR: - LoadMsgIcon( &icon, IMG_ID_ERROR ); - break; - case MB_ICON_HELP: - LoadMsgIcon( &icon, IMG_ID_HELP ); - break; - case MB_ICON_INFO: - LoadMsgIcon( &icon, IMG_ID_INFO ); - break; - case MB_ICON_WARNING: - LoadMsgIcon( &icon, IMG_ID_WARNING ); - break; - case MB_ICON_NONE: - default:break; - } - /* 添加图标后文本进消息区域 */ - Widget_Container_Add( msg_area, iconbox ); - Widget_Container_Add( msg_area, textbox ); - /* 设定图标框的默认尺寸 */ - Widget_Resize( iconbox, MB_ICONBOX_SIZE ); - /* 为图标框设置需显示的图标 */ - PictureBox_SetImage( iconbox, &icon ); - PictureBox_SetSizeMode( iconbox, SIZE_MODE_CENTER ); - /* 判断是否有图标,并调整文本位置 */ - if( icon_type == MB_ICON_NONE ) { - icon_flag = MSGBOX_NONE_ICON; - Widget_SetAlign( textbox, ALIGN_MIDDLE_CENTER, Pos(0,0) ); - } else { - icon_flag = 0; - Widget_SetAlign( iconbox, ALIGN_MIDDLE_LEFT, Pos(5,0) ); - Widget_SetAlign( textbox, ALIGN_MIDDLE_LEFT, - Pos(icon.w + 10,0) ); - } - /* 根据按钮数量,得出相应的最小尺寸 */ - switch( button ) { - case MB_BTN_OK: - msgbox_add_BTN_OK( btn_area ); - min_size = Size(150,125); - break; - case MB_BTN_OKCANCEL: - msgbox_add_BTN_OKCANCEL( btn_area ); - min_size = Size(180,125); - break; - case MB_BTN_ABORTRETRYIGNORE: - msgbox_add_BTN_ABORTRETRYIGNORE( btn_area ); - min_size = Size(215,125); - break; - case MB_BTN_RETRYCANCEL: - msgbox_add_BTN_RETRYCANCEL( btn_area ); - min_size = Size(180,125); - break; - case MB_BTN_YESNO: - msgbox_add_BTN_YESNO( btn_area ); - min_size = Size(180,125); - break; - case MB_BTN_YESNOCANCEL: - msgbox_add_BTN_YESNOCANCEL( btn_area ); - min_size = Size(215,125); - break; - default: return -1; - } - /* 创建消息框,并设置ID */ - msgbox = Window_New(); - Window_SetTextW( msgbox, title ); - Widget_Resize( msgbox, min_size ); - - msgbox->self_id = WIDGET_ID_MESSAGEBOX | button | icon_flag; - /* 获取窗口右上角的按钮指针,并设定按钮的ID */ - btn_close = Window_GetCloseButton( msgbox ); - btn_close->self_id = MB_BTN_IS_QUIT; - /* 限制消息框的尺寸 */ - LCUIScreen_GetSize( &max_size ); - Widget_LimitSize( msgbox, min_size, max_size ); - /* 设置为模态部件 */ - Widget_SetModal( msgbox, TRUE ); - /* 添加这两个区域至消息框内 */ - Window_ClientArea_Add( msgbox, msg_area ); - Window_ClientArea_Add( msgbox, btn_area ); - /* 设置区域的停靠方式及初始尺寸 */ - Widget_SetDock( msg_area, DOCK_TOP ); - Widget_SetDock( btn_area, DOCK_BOTTOM ); - Widget_SetSize( msg_area, NULL, MB_MSG_AREA_HEIGHT_TEXT ); - Widget_SetSize( btn_area, NULL, MB_BTN_AREA_HEIGHT_TEXT ); - - /* 设定按钮区域的样式 */ - Widget_SetBackgroundTransparent( btn_area, FALSE ); - Widget_SetBackgroundColor( btn_area, MB_BTN_AREA_BGCOLOR ); - Border_Init( &btn_area_border ); - btn_area_border.top_width = 1; - btn_area_border.top_style = BORDER_SOLID; - btn_area_border.top_color = MB_BTN_AREA_LINECOLOR; - Widget_SetBorder( btn_area, btn_area_border ); - - Label_SetTextW( textbox, text ); - Widget_Show( textbox ); - if( icon_type != MB_ICON_NONE ) { - Widget_Show( iconbox ); - } - Widget_Show( btn_area ); - Widget_Show( msg_area ); - Widget_Show( msgbox ); - - loop = msgbox_mainloop_new( msgbox ); - /* 关联消息框右上角关闭按钮的CLICKED事件 */ - Widget_ConnectEvent( btn_close, EVENT_CLICKED, msgbox_mainloop_quit ); - /* 关联用于显示文本的label部件的RESIZE事件 */ - Widget_ConnectEvent( textbox, EVENT_RESIZE, auto_resize_msgbox ); - /* 进入主循环 */ - LCUI_MainLoop_Run( loop ); - msgbox_data = msgbox_data_find( msgbox ); - if( msgbox_data ) { - Widget_Destroy( msgbox ); - ret = msgbox_data->clicked_button; - msgbox_data_delete( msgbox ); - return ret; - } - return -2; -} - -/* UTF-8版的LCUI_MessageBox */ -LCUI_API int -LCUI_MessageBox( MB_ICON_TYPE icon_type, const char *text, - const char *title, MB_BTN_TYPE button ) -{ - int ret; - wchar_t *unicode_text, *unicode_title; - - LCUICharset_UTF8ToUnicode( text, &unicode_text ); - LCUICharset_UTF8ToUnicode( title, &unicode_title ); - ret = LCUI_MessageBoxW( icon_type, unicode_text, unicode_title, button ); - if( unicode_text != NULL ) { - free( unicode_text ); - } - if( unicode_title != NULL ) { - free( unicode_title ); - } - return ret; -} - -/* ANSI版的LCUI_MessageBox */ -LCUI_API int -LCUI_MessageBoxA( MB_ICON_TYPE icon_type, const char *text, - const char *title, MB_BTN_TYPE button ) -{ - int ret; - wchar_t *unicode_text, *unicode_title; - - LCUICharset_GB2312ToUnicode( text, &unicode_text ); - LCUICharset_GB2312ToUnicode( title, &unicode_title ); - ret = LCUI_MessageBoxW( icon_type, unicode_text, unicode_title, button ); - if( unicode_text != NULL ) { - free( unicode_text ); - } - if( unicode_title != NULL ) { - free( unicode_title ); - } - return ret; -} - -#endif diff --git a/src/gui/widget/button.c b/src/gui/widget/button.c index e3425b74..e86d83d9 100755 --- a/src/gui/widget/button.c +++ b/src/gui/widget/button.c @@ -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 ); } diff --git a/src/gui/widget/scrollbar.c b/src/gui/widget/scrollbar.c index 8706aebf..f08a12ca 100644 --- a/src/gui/widget/scrollbar.c +++ b/src/gui/widget/scrollbar.c @@ -37,26 +37,46 @@ * 没有,请查看:. * ****************************************************************************/ +#include #include #include #include #include #include #include +#include #include #include +#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 ); } diff --git a/src/gui/widget/sidebar.c b/src/gui/widget/sidebar.c index 6c463774..159fcc46 100644 --- a/src/gui/widget/sidebar.c +++ b/src/gui/widget/sidebar.c @@ -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 ); } diff --git a/src/gui/widget/textedit.c b/src/gui/widget/textedit.c new file mode 100644 index 00000000..f0a305e6 --- /dev/null +++ b/src/gui/widget/textedit.c @@ -0,0 +1,929 @@ +/* *************************************************************************** + * textedit.c -- textedit widget, used to allow user edit text. + * + * Copyright (C) 2016 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * textedit.c -- 文本编辑部件,用于让用户编辑文本。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +//#define DEBUG +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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" ); +} diff --git a/src/gui/widget/textview.c b/src/gui/widget/textview.c index 41a21658..933854f1 100644 --- a/src/gui/widget/textview.c +++ b/src/gui/widget/textview.c @@ -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 ); } diff --git a/src/gui/widget_background.c b/src/gui/widget_background.c index 6f542ff8..fca12add 100644 --- a/src/gui/widget_background.c +++ b/src/gui/widget_background.c @@ -42,7 +42,6 @@ #include #include #include -#include #include typedef struct ImageCacheRec_ { @@ -125,13 +124,13 @@ static void AsyncLoadImage( LCUI_Widget widget, const char *path ) { ImageCache cache; LCUI_AppTaskRec task = {0}; - LCUI_Style s = &widget->cached_style->sheet[key_background_image]; + LCUI_Style s = &widget->style->sheet[key_background_image]; if( !is_inited ) { RBTree_Init( &images ); RBTree_Init( &refs ); - RBTree_OnJudge( &refs, OnCompareWidget ); - RBTree_OnJudge( &images, OnComparePath ); + RBTree_OnCompare( &refs, OnCompareWidget ); + RBTree_OnCompare( &images, OnComparePath ); RBTree_OnDestroy( &refs, free ); RBTree_OnDestroy( &images, OnDestroyCache ); is_inited = TRUE; @@ -153,6 +152,7 @@ static void AsyncLoadImage( LCUI_Widget widget, const char *path ) task.func = ExecLoadImage; task.arg[0] = widget; task.arg[1] = strdup( path ); + task.destroy_arg[1] = free; LCUI_PostTask( &task ); } @@ -162,9 +162,9 @@ void Widget_UpdateBackground( LCUI_Widget widget ) LCUI_Style s; LCUI_StyleSheet ss = widget->style; LCUI_Background *bg = &widget->computed_style.background; - int key = key_background_start + 1; + int key = key_background_start; - for( ; key < key_background_end; ++key ) { + for( ; key <= key_background_end; ++key ) { s = &ss->sheet[key]; if( !s->is_valid ) { continue; diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 046efb48..e2c80b54 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -48,18 +48,20 @@ #define max(a,b) (((a) > (b)) ? (a) : (b)) static struct LCUIWidgetModule { - LCUI_Widget root; /** 获取根级部件 */ + LCUI_Widget root; /** 根级部件 */ LCUI_RBTree ids; /** 各种部件的ID索引 */ } LCUIWidget; +#define StrList_Destroy freestrs + LCUI_Widget LCUIWidget_GetRoot(void) { return LCUIWidget.root; } /** 刷新在追加部件后的状态,例如 :first-child 和 :last-child */ -static void Widget_UpdateStatusAfterAppend( LCUI_Widget w, - LCUI_BOOL is_remove_mode ) +static void Widget_UpdateStatusAfterAppend( LCUI_Widget w, + LCUI_BOOL is_remove_mode ) { LinkedListNode *node = Widget_GetNode( w ); if( w->index == 0 ) { @@ -94,7 +96,6 @@ int Widget_Append( LCUI_Widget parent, LCUI_Widget widget ) { LCUI_Widget child; LinkedListNode *node, *snode; - DEBUG_MSG("parent: %p, widget: %p\n", parent, widget); if( !parent || !widget || parent == widget->parent ) { return -1; } @@ -118,20 +119,21 @@ int Widget_Append( LCUI_Widget parent, LCUI_Widget widget ) Widget_PostSurfaceEvent( widget, WET_REMOVE ); } widget->parent = parent; + widget->state = WSTATE_CREATED; widget->index = parent->children.length; LinkedList_AppendNode( &parent->children, node ); LinkedList_AppendNode( &parent->children_show, snode ); - Widget_UpdateZIndex( widget ); Widget_PostSurfaceEvent( widget, WET_ADD ); Widget_AddTaskForChildren( widget, WTT_REFRESH_STYLE ); Widget_UpdateTaskStatus( widget ); - Widget_AddTask( parent, WTT_LAYOUT ); + Widget_UpdateLayout( parent ); Widget_UpdateStatusAfterAppend( widget, FALSE ); return 0; } int Widget_Unwrap( LCUI_Widget widget ) { + int i; LCUI_Widget child; LinkedList *list, *list_show; LinkedListNode *target, *node, *prev, *snode; @@ -141,24 +143,36 @@ int Widget_Unwrap( LCUI_Widget widget ) } list = &widget->parent->children; list_show = &widget->parent->children_show; + if( widget->children.length > 0 ) { + node = LinkedList_GetNode( &widget->children, 0 ); + Widget_RemoveStatus( node->data, "first-child" ); + node = LinkedList_GetNode( &widget->children, -1 ); + Widget_RemoveStatus( node->data, "last-child" ); + } node = Widget_GetNode( widget ); + i = widget->children.length; target = node->prev; - LinkedList_ForEach( node, &widget->children ) { + node = widget->children.tail.prev; + while( i-- > 0 ) { prev = node->prev; child = node->data; snode = Widget_GetShowNode( child ); - Widget_UpdateStatusAfterAppend( child, TRUE ); LinkedList_Unlink( &widget->children, node ); LinkedList_Unlink( &widget->children_show, snode ); child->parent = widget->parent; LinkedList_Link( list, target, node ); LinkedList_AppendNode( list_show, snode ); - Widget_UpdateStatusAfterAppend( child, FALSE ); - Widget_UpdateZIndex( child ); Widget_AddTaskForChildren( child, WTT_REFRESH_STYLE ); Widget_UpdateTaskStatus( child ); node = prev; } + if( widget->index == 0 ) { + Widget_AddStatus( target->next->data, "first-child" ); + } + if( widget->index == list->length - 1 ) { + node = LinkedList_GetNode( list, -1 ); + Widget_AddStatus( node->data, "last-child" ); + } Widget_Destroy( widget ); return 0; } @@ -167,14 +181,14 @@ int Widget_Unwrap( LCUI_Widget widget ) static void Widget_Init( LCUI_Widget widget ) { memset( widget, 0, sizeof(struct LCUI_WidgetRec_)); - widget->deleted = FALSE; + widget->state = WSTATE_CREATED; widget->trigger = EventTrigger(); widget->style = StyleSheet(); widget->custom_style = StyleSheet(); - widget->cached_style = StyleSheet(); widget->inherited_style = StyleSheet(); widget->computed_style.opacity = 1.0; widget->computed_style.visible = TRUE; + widget->computed_style.focusable = TRUE; widget->computed_style.display = SV_BLOCK; widget->computed_style.position = SV_STATIC; widget->computed_style.pointer_events = SV_AUTO; @@ -192,7 +206,6 @@ static void Widget_Init( LCUI_Widget widget ) Border_Init( &widget->computed_style.border ); LinkedList_Init( &widget->children ); LinkedList_Init( &widget->children_show ); - LinkedList_Init( &widget->children_trash ); LinkedList_Init( &widget->dirty_rects ); LCUIMutex_Init( &widget->mutex ); Graph_Init( &widget->graph ); @@ -229,15 +242,37 @@ static void Widget_OnDestroy( void *arg ) void Widget_ExecDestroy( LCUI_Widget widget ) { + LCUI_WidgetClass *wc; + wc = LCUIWidget_GetClass( widget->type ); + Widget_ReleaseMouseCapture( widget ); + Widget_ReleaseTouchCapture( widget, -1 ); + Widget_StopEventPropagation( widget ); LCUIWidget_ClearEventTarget( widget ); /* 先释放显示列表,后销毁部件列表,因为部件在这两个链表中的节点是和它共用 * 一块内存空间的,销毁部件列表会把部件释放掉,所以把这个操作放在后面 */ LinkedList_ClearData( &widget->children_show, NULL ); LinkedList_ClearData( &widget->children, Widget_OnDestroy ); + if( wc && wc->methods.destroy ) { + wc->methods.destroy( widget ); + } LinkedList_Clear( &widget->dirty_rects, free ); + StyleSheet_Delete( widget->inherited_style ); + StyleSheet_Delete( widget->custom_style ); + StyleSheet_Delete( widget->style ); Widget_PostSurfaceEvent( widget, WET_REMOVE ); Widget_UpdateLayout( widget->parent ); Widget_SetId( widget, NULL ); + if( widget->type ) { + free( widget->type ); + widget->type = NULL; + } + if( widget->title ) { + free( widget->title ); + widget->title = NULL; + } + widget->classes ? StrList_Destroy( widget->classes ):0; + widget->status ? StrList_Destroy( widget->status ):0; + LCUIMutex_Destroy( &widget->mutex ); EventTrigger_Destroy( widget->trigger ); widget->trigger = NULL; free( widget ); @@ -249,10 +284,13 @@ void Widget_Destroy( LCUI_Widget w ) while( root->parent ) { root = root->parent; } - w->deleted = TRUE; + if( root != LCUIWidget.root ) { + Widget_ExecDestroy( w ); + return; + } if( w->parent ) { LCUI_Widget child; - LinkedListNode *node, *snode; + LinkedListNode *node; node = Widget_GetNode( w ); node = node->next; while( node ) { @@ -260,31 +298,34 @@ void Widget_Destroy( LCUI_Widget w ) child->index -= 1; node = node->next; } - node = Widget_GetNode( w ); - snode = Widget_GetShowNode( w ); - LinkedList_Unlink( &w->parent->children, node ); - LinkedList_Unlink( &w->parent->children_show, snode ); - LinkedList_AppendNode( &w->parent->children_trash, node ); if( w->computed_style.position != SV_ABSOLUTE ) { Widget_UpdateLayout( w->parent ); } - Widget_InvalidateArea( w->parent, &w->box.graph, - SV_PADDING_BOX ); - } - if( root != LCUIWidget.root ) { - Widget_ExecDestroy( w ); - return; + Widget_PushInvalidArea( w, NULL, SV_GRAPH_BOX ); + Widget_AddToTrash( w ); } } -void Widget_Empty( LCUI_Widget widget ) +void Widget_Empty( LCUI_Widget w ) { - LinkedListNode *node, *prev; - node = widget->children.head.next; - while( node ) { - prev = node->prev; - Widget_Destroy( node->data ); - node = prev->next; + LCUI_Widget root = w; + + while( root->parent ) { + root = root->parent; + } + if( root == LCUIWidget.root ) { + LinkedListNode *next, *node; + node = w->children.head.next; + while( node ) { + next = node->next; + Widget_AddToTrash( node->data ); + node = next; + } + Widget_PushInvalidArea( w, NULL, SV_GRAPH_BOX ); + Widget_AddTask( w, WTT_LAYOUT ); + } else { + LinkedList_ClearData( &w->children_show, NULL ); + LinkedList_ClearData( &w->children, Widget_OnDestroy ); } } @@ -298,7 +339,7 @@ LCUI_Widget Widget_At( LCUI_Widget widget, int x, int y ) } do { is_hit = FALSE; - LinkedList_ForEach( node, &target->children_show ) { + for( LinkedList_Each( node, &target->children_show ) ) { c = node->data; if( !c->computed_style.visible ) { continue; @@ -381,8 +422,8 @@ int Widget_SetId( LCUI_Widget w, const char *idstr ) static void ComputeBorderStyle( LCUI_StyleSheet ss, LCUI_Border *b ) { LCUI_Style style; - int key = key_border_start + 1; - for( ; key < key_border_end; ++key ) { + int key = key_border_start ; + for( ; key <= key_border_end; ++key ) { style = &ss->sheet[key]; if( !style->is_valid ) { continue; @@ -497,8 +538,9 @@ void Widget_UpdateBorder( LCUI_Widget w ) static void ComputeBoxShadowStyle( LCUI_StyleSheet ss, LCUI_BoxShadow *bsd ) { LCUI_Style style; - int key = key_box_shadow_start + 1; - for( ; key < key_box_shadow_end; ++key ) { + int key = key_box_shadow_start; + memset( bsd, 0, sizeof( *bsd ) ); + for( ; key <= key_box_shadow_end; ++key ) { style = &ss->sheet[key]; if( !style->is_valid ) { continue; @@ -519,16 +561,18 @@ void Widget_UpdateBoxShadow( LCUI_Widget w ) LCUI_BoxShadow bs = w->computed_style.shadow; ComputeBoxShadowStyle( w->style, &w->computed_style.shadow ); /* 如果阴影变化并未导致图层尺寸变化,则只重绘阴影 */ - if( bs.x == w->computed_style.shadow.x && - bs.y == w->computed_style.shadow.y && - bs.spread == w->computed_style.shadow.spread ) { + if( bs.x == w->computed_style.shadow.x && + bs.y == w->computed_style.shadow.y && + bs.blur == w->computed_style.shadow.blur ) { + int i; LCUI_Rect rects[4]; LCUIRect_CutFourRect( &w->box.border, &w->box.graph, rects ); - Widget_InvalidateArea( w, &rects[0], SV_GRAPH_BOX ); - Widget_InvalidateArea( w, &rects[1], SV_GRAPH_BOX ); - Widget_InvalidateArea( w, &rects[2], SV_GRAPH_BOX ); - Widget_InvalidateArea( w, &rects[3], SV_GRAPH_BOX ); + for( i = 0; i < 4; ++i ) { + rects[i].x -= w->box.graph.x; + rects[i].y -= w->box.graph.y; + Widget_InvalidateArea( w, &rects[i], SV_GRAPH_BOX ); + } return; } Widget_AddTask( w, WTT_RESIZE ); @@ -537,6 +581,7 @@ void Widget_UpdateBoxShadow( LCUI_Widget w ) void Widget_UpdateVisibility( LCUI_Widget w ) { + int display = w->computed_style.display; LCUI_Style s = &w->style->sheet[key_visible]; LCUI_BOOL visible = w->computed_style.visible; if( w->computed_style.display == SV_NONE ) { @@ -557,12 +602,9 @@ void Widget_UpdateVisibility( LCUI_Widget w ) } visible = w->computed_style.visible; if( w->parent ) { - Widget_InvalidateArea( w->parent, &w->box.graph, - SV_PADDING_BOX ); - if( (w->computed_style.display == SV_BLOCK || - w->computed_style.display == SV_INLINE_BLOCK) - && w->computed_style.position == SV_STATIC - && w->computed_style.float_mode == SV_NONE ) { + Widget_PushInvalidArea( w, NULL, SV_GRAPH_BOX ); + if( w->computed_style.display != display || + w->computed_style.position != SV_ABSOLUTE ) { Widget_UpdateLayout( w->parent ); } } @@ -598,21 +640,28 @@ void Widget_UpdateZIndex( LCUI_Widget w ) void Widget_ExecUpdateZIndex( LCUI_Widget w ) { + int z_index; LinkedList *list; LinkedListNode *cnode, *csnode, *snode; LCUI_Style s = &w->style->sheet[key_z_index]; if( s->is_valid && s->type == SVT_VALUE ) { - w->computed_style.z_index = s->value; + z_index = s->value; } else { - w->computed_style.z_index = 0; + z_index = 0; } if( !w->parent ) { return; } + if( w->state == WSTATE_NORMAL ) { + if( w->computed_style.z_index == z_index ) { + return; + } + } + w->computed_style.z_index = z_index; snode = Widget_GetShowNode( w ); list = &w->parent->children_show; LinkedList_Unlink( list, snode ); - LinkedList_ForEach( cnode, list ) { + for( LinkedList_Each( cnode, list ) ) { LCUI_Widget child = cnode->data; LCUI_WidgetStyle *ccs = &child->computed_style; csnode = Widget_GetShowNode( child ); @@ -697,7 +746,7 @@ void Widget_UpdatePosition( LCUI_Widget w ) Widget_UpdateLayout( w->parent ); } w->computed_style.position = position; - Widget_AddTask( w, WTT_ZINDEX ); + Widget_UpdateZIndex( w ); w->x = w->origin_x; w->y = w->origin_y; switch( position ) { @@ -778,8 +827,8 @@ void Widget_UpdatePosition( LCUI_Widget w ) DEBUG_MSG("new-rect: %d,%d,%d,%d\n", w->box.graph.x, w->box.graph.y, w->box.graph.w, w->box.graph.h); DEBUG_MSG("old-rect: %d,%d,%d,%d\n", rect.x, rect.y, rect.w, rect.h); /* 标记移动前后的区域 */ - Widget_InvalidateArea( w->parent, &w->box.graph, SV_PADDING_BOX ); - Widget_InvalidateArea( w->parent, &rect, SV_PADDING_BOX ); + Widget_PushInvalidArea( w, NULL, SV_GRAPH_BOX ); + Widget_PushInvalidArea( w->parent, &rect, SV_PADDING_BOX ); } /* 检测是否为顶级部件并做相应处理 */ Widget_PostSurfaceEvent( w, WET_MOVE ); @@ -822,7 +871,7 @@ static void Widget_ComputeContentSize( LCUI_Widget w, int *width, int *height ) LinkedListNode *node; *width = *height = 0; - LinkedList_ForEach( node, &w->children_show ) { + for( LinkedList_Each( node, &w->children_show ) ) { child = node->data; /* 忽略不可见、绝对定位的部件 */ if( !child->computed_style.visible || @@ -934,6 +983,76 @@ static void Widget_ComputeSize( LCUI_Widget w ) } w->width = w->box.border.width; w->height = w->box.border.height; + w->box.outer.width = w->box.border.width; + w->box.outer.height = w->box.border.height; + w->box.outer.width += w->margin.left + w->margin.right; + w->box.outer.height += w->margin.top + w->margin.bottom; +} + +static void Widget_SendResizeEvent( LCUI_Widget w ) +{ + LCUI_Style s; + LCUI_Widget child; + LCUI_WidgetEventRec e; + LinkedListNode *node; + e.target = w; + e.data = NULL; + e.type = WET_RESIZE; + e.cancel_bubble = TRUE; + Widget_TriggerEvent( w, &e, NULL ); + Widget_AddTask( w, WTT_REFRESH ); + Widget_PostSurfaceEvent( w, WET_RESIZE ); + for( LinkedList_Each( node, &w->children ) ) { + child = node->data; + s = child->style->sheet; + if( s[key_width].type == SVT_SCALE || + s[key_height].type == SVT_SCALE ) { + Widget_AddTask( child, WTT_RESIZE ); + } + if( child->computed_style.position == SV_ABSOLUTE ) { + if( s[key_right].is_valid || s[key_bottom].is_valid ) { + Widget_AddTask( child, WTT_POSITION ); + } + } + if( s[key_margin_left].is_valid && + s[key_margin_left].value == SV_AUTO ) { + Widget_AddTask( child, WTT_MARGIN ); + } + else if( s[key_margin_right].is_valid && + s[key_margin_right].value == SV_AUTO ) { + Widget_AddTask( child, WTT_MARGIN ); + } + if( child->computed_style.vertical_align != SV_TOP ) { + Widget_AddTask( child, WTT_POSITION ); + } + } +} + +void Widget_UpdateMargin( LCUI_Widget w ) +{ + int i; + LCUI_BoundBox *mbox = &w->computed_style.margin; + struct { + LCUI_Style sval; + int *ival; + int key; + } pd_map[4] = { + { &mbox->top, &w->margin.top, key_margin_top }, + { &mbox->right, &w->margin.right, key_margin_right }, + { &mbox->bottom, &w->margin.bottom, key_margin_bottom }, + { &mbox->left, &w->margin.left, key_margin_left } + }; + for( i = 0; i < 4; ++i ) { + LCUI_Style s = &w->style->sheet[pd_map[i].key]; + if( !s->is_valid || s->type != SVT_PX ) { + pd_map[i].sval->type = SVT_PX; + pd_map[i].sval->px = 0; + *pd_map[i].ival = 0; + continue; + } + *pd_map[i].sval = *s; + *pd_map[i].ival = s->px; + } /* 如果有父级部件,则处理 margin-left 和 margin-right 的值 */ if( w->parent ) { int width = w->parent->box.content.width; @@ -966,64 +1085,38 @@ static void Widget_ComputeSize( LCUI_Widget w ) } } } - w->box.outer.width = w->box.border.width; - w->box.outer.height = w->box.border.height; - w->box.outer.width += w->margin.left + w->margin.right; - w->box.outer.height += w->margin.top + w->margin.bottom; -} - -static void Widget_SendResizeEvent( LCUI_Widget w ) -{ - LCUI_Widget child; - LCUI_WidgetEventRec e; - LinkedListNode *node; - e.target = w; - e.data = NULL; - e.type = WET_RESIZE; - e.cancel_bubble = TRUE; - Widget_TriggerEvent( w, &e, NULL ); - Widget_AddTask( w, WTT_REFRESH ); - Widget_PostSurfaceEvent( w, WET_RESIZE ); - LinkedList_ForEach( node, &w->children ) { - child = node->data; - if( child->style->sheet[key_width].type == SVT_SCALE || - child->style->sheet[key_height].type == SVT_SCALE ) { - Widget_AddTask( child, WTT_RESIZE ); + if( w->parent ) { + if( w->parent->style->sheet[key_width].type == SVT_AUTO + || w->parent->style->sheet[key_height].type == SVT_AUTO ) { + Widget_AddTask( w->parent, WTT_RESIZE ); } - if( child->computed_style.position == SV_ABSOLUTE && - (child->style->sheet[key_right].is_valid || - child->style->sheet[key_bottom].is_valid) ) { - Widget_AddTask( child, WTT_POSITION ); - } - if( child->computed_style.vertical_align != SV_TOP ) { - Widget_AddTask( child, WTT_POSITION ); + if( w->computed_style.display != SV_NONE && + w->computed_style.position == SV_STATIC ) { + Widget_UpdateLayout( w->parent ); } } + Widget_AddTask( w, WTT_POSITION ); } void Widget_UpdateSize( LCUI_Widget w ) { LCUI_Rect rect; int i, box_sizing; - LCUI_BoundBox *mbox = &w->computed_style.margin; + LCUI_Rect2 padding = w->padding; LCUI_BoundBox *pbox = &w->computed_style.padding; struct { LCUI_Style sval; int *ival; int key; - } pd_map[8] = { + } pd_map[4] = { { &pbox->top, &w->padding.top, key_padding_top }, { &pbox->right, &w->padding.right, key_padding_right }, { &pbox->bottom, &w->padding.bottom, key_padding_bottom }, - { &pbox->left, &w->padding.left, key_padding_left }, - { &mbox->top, &w->margin.top, key_margin_top }, - { &mbox->right, &w->margin.right, key_margin_right }, - { &mbox->bottom, &w->margin.bottom, key_margin_bottom }, - { &mbox->left, &w->margin.left, key_margin_left } + { &pbox->left, &w->padding.left, key_padding_left } }; rect = w->box.graph; /* 内边距的单位暂时都用 px */ - for( i = 0; i < 8; ++i ) { + for( i = 0; i < 4; ++i ) { LCUI_Style s = &w->style->sheet[pd_map[i].key]; if( !s->is_valid || s->type != SVT_PX ) { pd_map[i].sval->type = SVT_PX; @@ -1038,9 +1131,21 @@ void Widget_UpdateSize( LCUI_Widget w ) w->computed_style.box_sizing = box_sizing; Widget_ComputeSize( w ); Widget_UpdateGraphBox( w ); + /* 如果左右外间距是 auto 类型的,则需要计算外间距 */ + if( w->style->sheet[key_margin_left].is_valid && + w->style->sheet[key_margin_left].type == SVT_AUTO ) { + Widget_UpdateMargin( w ); + } else if( w->style->sheet[key_margin_right].is_valid && + w->style->sheet[key_margin_right].type == SVT_AUTO ) { + Widget_UpdateMargin( w ); + } /* 若尺寸无变化则不继续处理 */ if( rect.width == w->box.graph.width && - rect.height == w->box.graph.height ) { + rect.height == w->box.graph.height && + padding.top == w->padding.top && + padding.right == w->padding.right && + padding.bottom == w->padding.bottom && + padding.left == w->padding.left) { return; } /* 若在变化前后的宽高中至少有一个为 0,则不继续处理 */ @@ -1077,8 +1182,15 @@ void Widget_UpdateSize( LCUI_Widget w ) void Widget_UpdateProps( LCUI_Widget w ) { + LCUI_Style s; int prop = ComputeStyleOption( w, key_pointer_events, SV_AUTO ); w->computed_style.pointer_events = prop; + s = &w->style->sheet[key_focusable]; + if( s->is_valid && s->type == SVT_BOOL && s->value == 0 ) { + w->computed_style.focusable = FALSE; + } else { + w->computed_style.focusable = TRUE; + } } /** 设置内边距 */ @@ -1132,6 +1244,16 @@ void Widget_SetBackgroundColor( LCUI_Widget w, LCUI_Color color ) w->computed_style.background.color = color; } +void Widget_SetDisabled( LCUI_Widget w, LCUI_BOOL disabled ) +{ + w->disabled = disabled; + if( w->disabled ) { + Widget_AddStatus( w, "disabled" ); + } else { + Widget_RemoveStatus( w, "disabled" ); + } +} + void Widget_Lock( LCUI_Widget w ) { LCUIMutex_Lock( &w->mutex ); @@ -1142,139 +1264,20 @@ void Widget_Unlock( LCUI_Widget w ) LCUIMutex_Unlock( &w->mutex ); } -static int StrList_AddOne( char ***strlist, const char *str ) -{ - int i = 0; - char **newlist; - - if( !*strlist ) { - newlist = (char**)malloc( sizeof(char*) * 2 ); - goto check_done; - } - for( i = 0; (*strlist)[i]; ++i ) { - if( strcmp((*strlist)[i], str) == 0 ) { - return 0; - } - } - newlist = (char**)realloc( *strlist, (i+2)*sizeof(char*) ); -check_done: - if( !newlist ) { - return 0; - } - newlist[i] = strdup(str); - newlist[i+1] = NULL; - *strlist = newlist; - return 1; -} - -int StrList_Add( char ***strlist, const char *str ) -{ - char buff[256]; - int count = 0, i, head; - for( head = 0, i = 0; str[i]; ++i ) { - if( str[i] != ' ' ) { - continue; - } - if( i - 1 > head ) { - strncpy( buff, &str[head], i - head ); - buff[i - head] = 0; - count += StrList_AddOne( strlist, buff ); - } - head = i + 1; - } - if( i - 1 > head ) { - strncpy( buff, &str[head], i - head ); - buff[i - head] = 0; - count += StrList_AddOne( strlist, buff ); - } - return count; -} - -LCUI_BOOL StrList_Has( char **strlist, const char *str ) -{ - int i; - if( !strlist ) { - return FALSE; - } - for( i = 0; strlist[i]; ++i ) { - if( strcmp(strlist[i], str) == 0 ) { - return TRUE; - } - } - return FALSE; -} - -static int StrList_RemoveOne( char ***strlist, const char *str ) -{ - int i, pos, len; - char **newlist; - - if( !*strlist ) { - return 0; - } - for( pos = -1, i = 0; (*strlist)[i]; ++i ) { - if( strcmp( (*strlist)[i], str ) == 0 ) { - pos = i; - } - } - if( pos == -1 ) { - return 0; - } - if( pos == 0 && i < 2 ) { - free( *strlist ); - *strlist = NULL; - return 1; - } - len = i - 1; - newlist = (char**)malloc( i * sizeof(char*) ); - for( i = 0; i < pos; ++i ) { - newlist[i] = (*strlist)[i]; - } - for( i = pos; i < len; ++i ) { - newlist[i] = (*strlist)[i+1]; - } - newlist[i] = NULL; - free( (*strlist)[pos] ); - free( *strlist ); - *strlist = newlist; - return 1; -} - -int StrList_Remove( char ***strlist, const char *str ) -{ - char buff[256]; - int count = 0, i, head; - - for( head = 0, i = 0; str[i]; ++i ) { - if( str[i] != ' ' ) { - continue; - } - if( i - 1 > head ) { - strncpy( buff, &str[head], i - head ); - buff[i - head] = 0; - count += StrList_RemoveOne( strlist, buff ); - } - head = i + 1; - } - if( i - 1 > head ) { - strncpy( buff, &str[head], i - head ); - buff[i - head] = 0; - count += StrList_RemoveOne( strlist, buff ); - } - return count; -} - /** 为部件添加一个类 */ int Widget_AddClass( LCUI_Widget w, const char *class_name ) { - if( StrList_Has( w->classes, class_name ) ) { + Widget_Lock( w ); + if( strshas( w->classes, class_name ) ) { + Widget_Unlock( w ); return 1; } - if( StrList_Add(&w->classes, class_name) <= 0 ) { + if( strsadd(&w->classes, class_name) <= 0 ) { + Widget_Unlock( w ); return 0; } - /* 标记需要更新该部件及子级部件的样式表 */ - Widget_AddTaskForChildren( w, WTT_REFRESH_STYLE ); + Widget_Unlock( w ); + Widget_HandleChildrenStyleChange( w, 0, class_name ); Widget_UpdateStyle( w, TRUE ); return 1; } @@ -1282,49 +1285,73 @@ int Widget_AddClass( LCUI_Widget w, const char *class_name ) /** 判断部件是否包含指定的类 */ LCUI_BOOL Widget_HasClass( LCUI_Widget w, const char *class_name ) { - return StrList_Has( w->classes, class_name ); + Widget_Lock( w ); + if( strshas( w->classes, class_name ) ) { + Widget_Unlock( w ); + return TRUE; + } + Widget_Unlock( w ); + return FALSE; } /** 从部件中移除一个类 */ int Widget_RemoveClass( LCUI_Widget w, const char *class_name ) { - if( StrList_Remove( &w->classes, class_name ) <= 0 ) { - return 0; + Widget_Lock( w ); + if( strshas( w->classes, class_name ) ) { + Widget_HandleChildrenStyleChange( w, 0, class_name ); + strsdel( &w->classes, class_name ); + Widget_UpdateStyle( w, TRUE ); + Widget_Unlock( w ); + return 1; } - Widget_AddTaskForChildren( w, WTT_REFRESH_STYLE ); - Widget_UpdateStyle( w, TRUE ); - return 1; + Widget_Unlock( w ); + return 0; } /** 为部件添加一个状态 */ int Widget_AddStatus( LCUI_Widget w, const char *status_name ) { - if( StrList_Has( w->status, status_name ) ) { + Widget_Lock( w ); + if( strshas( w->status, status_name ) ) { + Widget_Unlock( w ); return 0; } - if( StrList_Add( &w->status, status_name ) <= 0 ) { + if( strsadd( &w->status, status_name ) <= 0 ) { + Widget_Unlock( w ); return 0; } + Widget_Unlock( w ); + Widget_HandleChildrenStyleChange( w, 1, status_name ); Widget_UpdateStyle( w, TRUE ); - Widget_AddTaskForChildren( w, WTT_REFRESH_STYLE ); return 1; } /** 判断部件是否包含指定的状态 */ LCUI_BOOL Widget_HasStatus( LCUI_Widget w, const char *status_name ) { - return StrList_Has( w->status, status_name ); + Widget_Lock( w ); + if( strshas( w->status, status_name ) ) { + Widget_Unlock( w ); + return TRUE; + } + Widget_Unlock( w ); + return FALSE; } /** 从部件中移除一个状态 */ int Widget_RemoveStatus( LCUI_Widget w, const char *status_name ) { - if( StrList_Remove( &w->status, status_name ) != 1 ) { - return 0; + Widget_Lock( w ); + if( strshas( w->status, status_name ) ) { + Widget_HandleChildrenStyleChange( w, 1, status_name ); + strsdel( &w->status, status_name ); + Widget_UpdateStyle( w, TRUE ); + Widget_Unlock( w ); + return 1; } - Widget_UpdateStyle( w, TRUE ); - Widget_AddTaskForChildren( w, WTT_REFRESH_STYLE ); - return 1; + Widget_Unlock( w ); + return 0; } int Widget_ComputeMaxWidth( LCUI_Widget w ) @@ -1342,8 +1369,11 @@ int Widget_ComputeMaxWidth( LCUI_Widget w ) break; case SVT_SCALE: scale *= s->val_scale; - padding += child->parent->padding.left; - padding += child->parent->padding.right; + if( child == w ) { + break; + } + padding += child->padding.left; + padding += child->padding.right; case SVT_AUTO: default: continue; } @@ -1388,9 +1418,22 @@ void Widget_ExecUpdateLayout( LCUI_Widget w ) LinkedListNode *node; ctx.max_width = Widget_ComputeMaxWidth( w ); - LinkedList_ForEach( node, &w->children ) { + for( LinkedList_Each( node, &w->children ) ) { child = node->data; - if( child->computed_style.position != SV_STATIC ) { + if( child->computed_style.position != SV_STATIC && + child->computed_style.position != SV_RELATIVE ) { + /* 如果部件还处于未准备完毕的状态 */ + if( child->state < WSTATE_READY ) { + child->state |= WSTATE_LAYOUTED; + /* 如果部件已经准备完毕则触发 ready 事件 */ + if( child->state == WSTATE_READY ) { + LCUI_WidgetEventRec e; + e.type = WET_READY; + e.cancel_bubble = TRUE; + Widget_TriggerEvent( child, &e, NULL ); + child->state = WSTATE_NORMAL; + } + } continue; } switch( child->computed_style.display ) { @@ -1425,11 +1468,21 @@ void Widget_ExecUpdateLayout( LCUI_Widget w ) default: continue; } Widget_UpdatePosition( child ); + if( child->state < WSTATE_READY ) { + child->state |= WSTATE_LAYOUTED; + if( child->state == WSTATE_READY ) { + LCUI_WidgetEventRec e; + e.type = WET_READY; + e.cancel_bubble = TRUE; + Widget_TriggerEvent( child, &e, NULL ); + child->state = WSTATE_NORMAL; + } + } ctx.prev = child; ctx.prev_display = child->computed_style.display; } - if( w->style->sheet[key_width].type == SVT_AUTO - || w->style->sheet[key_height].type == SVT_AUTO ) { + if( w->style->sheet[key_width].type == SVT_AUTO || + w->style->sheet[key_height].type == SVT_AUTO ) { Widget_AddTask( w, WTT_RESIZE ); } e.cancel_bubble = TRUE; @@ -1446,7 +1499,7 @@ static void _LCUIWidget_PrintTree( LCUI_Widget w, int depth, const char *prefix len = strlen(prefix); strcpy( child_prefix, prefix ); - LinkedList_ForEach( node, &w->children ) { + for( LinkedList_Each( node, &w->children ) ) { if( node == w->children.tail.prev ) { strcpy( str, "└" ); strcpy( &child_prefix[len], " " ); @@ -1501,8 +1554,9 @@ extern void LCUIWidget_AddTextView( void ); extern void LCUIWidget_AddButton( void ); extern void LCUIWidget_AddSideBar( void ); extern void LCUIWidget_AddTScrollBar( void ); +extern void LCUIWidget_AddTextEdit( void ); -void LCUI_InitWidget(void) +void LCUI_InitWidget( void ) { LCUIWidget_InitTask(); LCUIWidget_InitEvent(); @@ -1512,9 +1566,9 @@ void LCUI_InitWidget(void) LCUIWidget_AddButton(); LCUIWidget_AddSideBar(); LCUIWidget_AddTScrollBar(); + LCUIWidget_AddTextEdit(); RBTree_Init( &LCUIWidget.ids ); - RBTree_SetDataNeedFree( &LCUIWidget.ids, FALSE ); - RBTree_OnJudge( &LCUIWidget.ids, CompareWidgetId ); + RBTree_OnCompare( &LCUIWidget.ids, CompareWidgetId ); LCUIWidget.root = LCUIWidget_New("root"); Widget_SetTitleW( LCUIWidget.root, L"LCUI Display" ); } diff --git a/src/gui/widget_event.c b/src/gui/widget_event.c index ab951849..97fd445b 100644 --- a/src/gui/widget_event.c +++ b/src/gui/widget_event.c @@ -37,14 +37,22 @@ * 没有,请查看:. * ***************************************************************************/ //#define DEBUG +#include #include #include #include #include #include +#include #include #include +typedef struct TouchCapturerRec_ { + LinkedList points; + LCUI_Widget widget; + LinkedListNode node; +} TouchCapturerRec, *TouchCapturer; + typedef struct WidgetEventHandlerRec_ { LCUI_WidgetEventFunc func; void *data; @@ -62,16 +70,40 @@ typedef struct LCUI_WidgetEventPackRec_ { enum WidgetStatusType { WST_HOVER, WST_ACTIVE, + WST_FOCUS, WST_TOTAL }; +/** 部件事件记录结点 */ +typedef struct EventRecordNodeRec_ { + LCUI_Widget widget; /**< 所属部件 */ + LinkedList records; /**< 事件记录列表 */ +} EventRecordNodeRec, *EventRecordNode; + +/** 当前功能模块的相关数据 */ static struct LCUIWidgetEvnetModule { + LCUI_Widget mouse_capturer; + LinkedList touch_capturers; LCUI_Widget targets[WST_TOTAL]; /**< 相关的部件 */ + LCUI_RBTree event_records; /**< 当前正执行的事件的记录 */ LCUI_RBTree event_names; /**< 事件标识号 -> 名称映射表 */ Dict *event_ids; /**< 事件名称 -> 标识号映射表 */ int base_event_id; /**< 事件标识号计数器 */ + LCUI_Mutex mutex; /**< 互斥锁 */ } self; +static int CompareEventRecord( void *data, const void *keydata ) +{ + EventRecordNode node = data; + if( node->widget == (LCUI_Widget)keydata ) { + return 0; + } else if( node->widget < (LCUI_Widget)keydata ) { + return -1; + } else { + return 1; + } +} + static void DestroyWidgetEventHandler( void *arg ) { WidgetEventHandler handler = arg; @@ -82,6 +114,44 @@ static void DestroyWidgetEventHandler( void *arg ) free( handler ); } +/** 添加事件记录 */ +static void Widget_AddEventRecord( LCUI_Widget widget, LCUI_WidgetEvent e ) +{ + EventRecordNode node; + LCUIMutex_Lock( &self.mutex ); + node = RBTree_CustomGetData( &self.event_records, widget ); + if( !node ) { + node = NEW( EventRecordNodeRec, 1 ); + LinkedList_Init( &node->records ); + node->widget = widget; + RBTree_CustomInsert( &self.event_records, widget, node ); + } + LinkedList_Append( &node->records, e ); + LCUIMutex_Unlock( &self.mutex ); +} + +/** 删除事件记录 */ +static int Widget_DeleteEventRecord( LCUI_Widget widget, LCUI_WidgetEvent e ) +{ + EventRecordNode enode; + LinkedListNode *node, *prev; + LCUIMutex_Lock( &self.mutex ); + enode = RBTree_CustomGetData( &self.event_records, widget ); + if( !enode ) { + LCUIMutex_Unlock( &self.mutex ); + return -1; + } + for( LinkedList_Each( node, &enode->records ) ) { + prev = node->prev; + if( node->data == e ) { + LinkedList_DeleteNode( &enode->records, node ); + node = prev; + } + } + LCUIMutex_Unlock( &self.mutex ); + return 0; +} + /** 将原始事件转换成部件事件 */ static void WidgetEventTranslator( LCUI_Event e, LCUI_WidgetEventPack pack ) { @@ -89,30 +159,82 @@ static void WidgetEventTranslator( LCUI_Event e, LCUI_WidgetEventPack pack ) LCUI_Widget w = pack->widget; pack->event.type = e->type; pack->event.data = handler->data; + Widget_AddEventRecord( w, &pack->event ); handler->func( w, &pack->event, pack->data ); - while( w && !w->deleted ) { - w = w->parent; - } - if( w && w->deleted ) { - pack->event.cancel_bubble = TRUE; - } - w = pack->widget; + Widget_DeleteEventRecord( w, &pack->event ); if( pack->event.cancel_bubble || !w->parent ) { if( pack->data && pack->destroy_data ) { pack->destroy_data( pack->data ); } return; } - pack->event.x += w->box.border.x; - pack->event.y += w->box.border.y; w = w->parent; - pack->event.x += w->padding.left; - pack->event.y += w->padding.top; pack->widget = w; /** 向父级部件冒泡传递事件 */ EventTrigger_Trigger( w->trigger, e->type, pack ); } +/** 复制部件事件包 */ +static void CopyWidgetEventPack( LCUI_WidgetEventPack dst, + const LCUI_WidgetEventPack src ) +{ + int n; + size_t size; + LCUI_WidgetEvent e; + + *dst = *src; + e = &dst->event; + switch( src->event.type ) { + case WET_TOUCH: + if( e->touch.n_points <= 0 ) { + break; + } + n = e->touch.n_points; + size = sizeof( LCUI_TouchPointRec ) * n; + e->touch.points = malloc( size ); + if( !e->touch.points ) { + return; + } + memcpy( e->touch.points, + src->event.touch.points, size ); + break; + case WET_TEXTINPUT: + if( !e->text.text ) { + return; + } + e->text.text = NEW( wchar_t, e->text.length + 1 ); + if( !e->text.text ) { + return; + } + wcsncpy( e->text.text, e->text.text, e->text.length + 1 ); + default:break; + } +} + +/** 销毁部件事件包 */ +static void DestroyWidgetEventPack( void *arg ) +{ + LCUI_WidgetEventPack pack = arg; + LCUI_WidgetEvent e = &pack->event; + switch( e->type ) { + case WET_TOUCH: + if( e->touch.points ) { + free( e->touch.points ); + } + e->touch.points = NULL; + e->touch.n_points = 0; + break; + case WET_TEXTINPUT: + if( e->text.text ) { + free( e->text.text ); + } + e->text.text = NULL; + e->text.length = 0; + break; + } + free( pack ); +} + /** 响应原始事件 */ static void OnWidgetEvent( LCUI_Event e, void *arg ) { @@ -129,26 +251,117 @@ static void OnWidgetEvent( LCUI_Event e, void *arg ) task.arg[1] = malloc( sizeof( LCUI_WidgetEventPackRec ) ); /* 这两个参数都需要在任务执行完后释放 */ task.destroy_arg[0] = free; - task.destroy_arg[1] = free; + task.destroy_arg[1] = DestroyWidgetEventPack; /* 复制所需数据,因为在本函数退出后,这两个参数会被销毁 */ *((LCUI_Event)task.arg[0]) = *e; - *((LCUI_WidgetEventPack)task.arg[1]) = *pack; + CopyWidgetEventPack( task.arg[1], pack ); /* 把任务扔给当前跑主循环的线程 */ LCUI_PostTask( &task ); } +static void DestroyTouchCapturer( void *arg ) +{ + TouchCapturer tc = arg; + LinkedList_Clear( &tc->points, free ); + tc->widget = NULL; + free( tc ); +} + +#define TouchCapturers_Clear(LIST) \ +LinkedList_ClearData( LIST, DestroyTouchCapturer ) + +static void TouchCapturers_Add( LinkedList *list, LCUI_Widget w, int point_id ) +{ + int *data; + TouchCapturer tc = NULL; + LinkedListNode *node, *ptnode; + if( point_id < 0 ) { + tc = NEW( TouchCapturerRec, 1 ); + tc->widget = w; + LinkedList_Init( &tc->points ); + TouchCapturers_Clear( list ); + LinkedList_Append( list, tc ); + return; + } + /* 获取该部件的触点捕捉记录 */ + for( LinkedList_Each( node, list ) ) { + tc = node->data; + /* 清除与该触点绑定的其它捕捉记录 */ + for( LinkedList_Each( ptnode, &tc->points ) ) { + if( point_id != *(int*)ptnode->data ) { + continue; + } + if( tc->widget == w ) { + return; + } + free( ptnode->data ); + LinkedList_DeleteNode( &tc->points, ptnode ); + break; + } + if( tc->widget == w ) { + break; + } + } + /* 如果没有该部件的触点捕捉记录 */ + if( !tc || tc->widget != w ) { + tc = NEW( TouchCapturerRec, 1 ); + tc->widget = w; + tc->node.data = tc; + LinkedList_Init( &tc->points ); + LinkedList_AppendNode( list, &tc->node ); + } + /* 追加触点捕捉记录 */ + data = NEW( int, 1 ); + *data = point_id; + LinkedList_Append( &tc->points, data ); +} + +static int TouchCapturers_Delete( LinkedList *list, LCUI_Widget w, int point_id ) +{ + TouchCapturer tc = NULL; + LinkedListNode *node, *ptnode; + for( LinkedList_Each( node, list ) ) { + tc = node->data; + if( tc->widget == w ) { + break; + } + } + if( !tc || tc->widget != w ) { + return -1; + } + if( point_id < 0 ) { + LinkedList_Clear( &tc->points, free ); + } else { + for( LinkedList_Each( ptnode, &tc->points ) ) { + if( *(int*)ptnode->data == point_id ) { + free( node->data ); + LinkedList_DeleteNode( &tc->points, ptnode ); + } + } + } + if( tc->points.length == 0 ) { + LinkedList_Unlink( &self.touch_capturers, &tc->node ); + free( tc ); + } + return 0; +} + int LCUIWidget_SetEventName( int event_id, const char *event_name ) { - int *id; char *name; + int *id, ret; + LCUIMutex_Lock( &self.mutex ); if( Dict_FetchValue( self.event_ids, event_name ) ) { + LCUIMutex_Unlock( &self.mutex ); return -1; } id = malloc( sizeof( int ) ); name = strdup( event_name ); *id = event_id; RBTree_Insert( &self.event_names, event_id, name ); - return Dict_Add( self.event_ids, name, id ); + ret = Dict_Add( self.event_ids, name, id ); + LCUIMutex_Unlock( &self.mutex ); + return ret; } int LCUIWidget_AllocEventId( void ) @@ -158,15 +371,23 @@ int LCUIWidget_AllocEventId( void ) const char *LCUIWidget_GetEventName( int event_id ) { - return RBTree_GetData( &self.event_names, event_id ); + char *name; + LCUIMutex_Lock( &self.mutex ); + name = RBTree_GetData( &self.event_names, event_id ); + LCUIMutex_Unlock( &self.mutex ); + return name; } int LCUIWidget_GetEventId( const char *event_name ) { - int *val = Dict_FetchValue( self.event_ids, event_name ); + int *val; + LCUIMutex_Lock( &self.mutex ); + val = Dict_FetchValue( self.event_ids, event_name ); if( val ) { + LCUIMutex_Unlock( &self.mutex ); return *val; } + LCUIMutex_Unlock( &self.mutex ); return -1; } @@ -247,9 +468,10 @@ static int Widget_TriggerEventEx( LCUI_Widget widget, LCUI_WidgetEvent e, void *data, void (*destroy_data)(void*), LCUI_BOOL direct_run ) { - int ret; LCUI_Widget w; + LCUI_BOOL is_pointer_event; LCUI_WidgetEventPackRec pack; + int ret, pointer_x, pointer_y; pack.event = *e; pack.data = data; pack.widget = widget; @@ -258,8 +480,8 @@ static int Widget_TriggerEventEx( LCUI_Widget widget, LCUI_WidgetEvent e, switch( e->type ) { case WET_CLICK: case WET_MOUSEDOWN: - case WET_MOUSEMOVE: case WET_MOUSEUP: + case WET_MOUSEMOVE: case WET_MOUSEOVER: case WET_MOUSEOUT: if( widget->computed_style.pointer_events == SV_NONE ) { @@ -268,30 +490,50 @@ static int Widget_TriggerEventEx( LCUI_Widget widget, LCUI_WidgetEvent e, default: ret = EventTrigger_Trigger( widget->trigger, e->type, &pack ); if( ret <= 0 ) { - if( !widget->parent ) { + if( !widget->parent || e->cancel_bubble ) { return -1; } /* 如果事件投递失败,则向父级部件冒泡 */ return Widget_PostEvent( widget->parent, e, data, destroy_data ); } + return 0; } - if( !widget->parent ) { + if( !widget->parent || e->cancel_bubble ) { return -1; } - /* 转换成相对于父级部件内容框的坐标 */ - pack.event.x += widget->box.border.x; - pack.event.y += widget->box.border.y; - /* 从当前部件后面找到当前坐标点命中的兄弟部件 */ - w = Widget_GetNextAt( widget, pack.event.x, pack.event.y ); - /* 找不到就向父级部件冒泡 */ - if( !w ) { - return Widget_PostEvent( widget->parent, e, - data, destroy_data ); + is_pointer_event = TRUE; + switch( e->type ) { + case WET_CLICK: + case WET_MOUSEDOWN: + case WET_MOUSEUP: + pointer_x = e->button.x; + pointer_y = e->button.y; + break; + case WET_MOUSEMOVE: + case WET_MOUSEOVER: + case WET_MOUSEOUT: + pointer_x = e->motion.x; + pointer_y = e->motion.y; + break; + default: + is_pointer_event = FALSE; + break; } - pack.event.x -= widget->box.border.x; - pack.event.y -= widget->box.border.y; - return EventTrigger_Trigger( widget->trigger, e->type, &pack ); + if( is_pointer_event ) { + int x, y; + Widget_GetAbsXY( widget->parent, NULL, &x, &y ); + /* 转换成相对于父级部件内容框的坐标 */ + x = pointer_x - x; + y = pointer_y - y; + /* 从当前部件后面找到当前坐标点命中的兄弟部件 */ + w = Widget_GetNextAt( widget, x, y ); + if( w ) { + return EventTrigger_Trigger( w->trigger, + e->type, &pack ); + } + } + return Widget_PostEvent( widget->parent, e, data, destroy_data ); } int Widget_PostEvent( LCUI_Widget widget, LCUI_WidgetEvent e, void *data, @@ -305,14 +547,23 @@ int Widget_TriggerEvent( LCUI_Widget widget, LCUI_WidgetEvent e, void *data ) return Widget_TriggerEventEx( widget, e, data, NULL, TRUE ); } -void LCUIWidget_ClearEventTarget( LCUI_Widget widget ) +int Widget_StopEventPropagation(LCUI_Widget widget ) { - int i; - for( i = 0; i < WST_TOTAL; ++i ) { - if( self.targets[i] == widget ) { - self.targets[i] = NULL; - } + LCUI_WidgetEvent e; + LinkedListNode *node; + EventRecordNode enode; + LCUIMutex_Lock( &self.mutex ); + enode = RBTree_CustomGetData( &self.event_records, widget ); + if( !enode ) { + LCUIMutex_Unlock( &self.mutex ); + return -1; } + for( LinkedList_Each( node, &enode->records ) ) { + e = node->data; + e->cancel_bubble = TRUE; + } + LCUIMutex_Unlock( &self.mutex ); + return 0; } /** 更新状态 */ @@ -332,7 +583,12 @@ static void Widget_UpdateStatus( LCUI_Widget widget, int type ) for( w = new_w; w != root && w; w = w->parent ) { ++depth; } + i = depth; for( w = old_w; w != root && w; w = w->parent ) { + if( w->state == WSTATE_DELETED ) { + depth = i; + old_w = w; + } --depth; } i = depth > 0 ? depth : -depth; @@ -363,77 +619,284 @@ static void Widget_UpdateStatus( LCUI_Widget widget, int type ) } } +void LCUIWidget_ClearEventTarget( LCUI_Widget widget ) +{ + int i; + LCUI_Widget w; + for( i = 0; i < WST_TOTAL; ++i ) { + if( !widget ) { + Widget_UpdateStatus( NULL, i ); + continue; + } + for( w = self.targets[i]; w; w = w->parent ) { + if( w == widget ) { + Widget_UpdateStatus( NULL, i ); + break; + } + } + } +} + +int LCUIWidget_SetFocus( LCUI_Widget widget ) +{ + LCUI_Widget w; + LCUI_WidgetEventRec ev; + /* 开始处理焦点 */ + for( w = widget; w; w = w->parent ) { + if( w->computed_style.pointer_events != SV_NONE && + w->computed_style.focusable && !w->disabled ) { + break; + } + } + if( self.targets[WST_FOCUS] == w ) { + return 0; + } + if( self.targets[WST_FOCUS] ) { + ev.type = WET_BLUR; + ev.target = self.targets[WST_FOCUS]; + Widget_RemoveStatus( ev.target, "focus" ); + Widget_PostEvent( ev.target, &ev, NULL, NULL ); + } + if( !w->computed_style.focusable || w->disabled ) { + return -1; + } + ev.target = w; + ev.type = WET_FOCUS; + self.targets[WST_FOCUS] = w; + Widget_AddStatus( ev.target, "focus" ); + Widget_PostEvent( ev.target, &ev, NULL, NULL ); + return 0; +} + /** 响应系统的鼠标移动事件,向目标部件投递相关鼠标事件 */ -static void OnMouseEvent( LCUI_SysEvent e, void *arg ) +static void OnMouseEvent( LCUI_SysEvent sys_ev, void *arg ) { LCUI_Pos pos; - LCUI_WidgetEventRec ebuff; - LCUI_Widget target, root; - root = LCUIWidget_GetRoot(); + LCUI_Widget target, w; + LCUI_WidgetEventRec ev; + w = LCUIWidget_GetRoot(); LCUICursor_GetPos( &pos ); - target = Widget_At( root, pos.x, pos.y ); - if( !target ) { - Widget_UpdateStatus( NULL, WST_HOVER ); - return; + if( self.mouse_capturer ) { + target = self.mouse_capturer; + } else { + target = Widget_At( w, pos.x, pos.y ); + if( !target ) { + Widget_UpdateStatus( NULL, WST_HOVER ); + return; + } } - Widget_GetAbsXY( target, NULL, &ebuff.x, &ebuff.y ); - ebuff.cancel_bubble = FALSE; - ebuff.x = pos.x - ebuff.x; - ebuff.y = pos.y - ebuff.y; - ebuff.screen_x = pos.x; - ebuff.screen_y = pos.y; - ebuff.target = target; - ebuff.which = 0; - switch( e->type ) { + for( w = target; w; w = w->parent ) { + if( w->event_blocked ) { + return; + } + } + ev.cancel_bubble = FALSE; + ev.target = target; + switch( sys_ev->type ) { case LCUI_MOUSEDOWN: - ebuff.type = WET_MOUSEDOWN; - Widget_PostEvent( target, &ebuff, NULL, NULL ); + ev.type = WET_MOUSEDOWN; + ev.button.x = pos.x; + ev.button.y = pos.y; + ev.button.button = sys_ev->button.button; + Widget_PostEvent( target, &ev, NULL, NULL ); Widget_UpdateStatus( target, WST_ACTIVE ); + LCUIWidget_SetFocus( target ); break; case LCUI_MOUSEUP: - ebuff.type = WET_MOUSEUP; - Widget_PostEvent( target, &ebuff, NULL, NULL ); + ev.type = WET_MOUSEUP; + ev.button.x = pos.x; + ev.button.y = pos.y; + ev.button.button = sys_ev->button.button; + Widget_PostEvent( target, &ev, NULL, NULL ); if( self.targets[WST_ACTIVE] == target ) { - ebuff.type = WET_CLICK; - Widget_PostEvent( target, &ebuff, NULL, NULL ); + if( ev.button.button == 1 ) { + ev.type = WET_CLICK; + Widget_PostEvent( target, &ev, NULL, NULL ); + } } Widget_UpdateStatus( NULL, WST_ACTIVE ); break; case LCUI_MOUSEMOVE: - ebuff.type = WET_MOUSEMOVE; - Widget_PostEvent( target, &ebuff, NULL, NULL ); + ev.type = WET_MOUSEMOVE; + ev.motion.x = pos.x; + ev.motion.y = pos.y; + Widget_PostEvent( target, &ev, NULL, NULL ); break; case LCUI_MOUSEWHEEL: - ebuff.type = WET_MOUSEWHEEL; - ebuff.z_delta = e->z_delta; - Widget_PostEvent( target, &ebuff, NULL, NULL ); + ev.type = WET_MOUSEWHEEL; + ev.wheel.delta = sys_ev->wheel.delta; + Widget_PostEvent( target, &ev, NULL, NULL ); default:return; } Widget_UpdateStatus( target, WST_HOVER ); } -/** 响应按键的按下 */ -static void OnKeyDown( LCUI_SysEvent e, void *arg ) +static void OnKeyboardEvent( LCUI_SysEvent e, void *arg ) { - -} - -/** 响应按键的释放 */ -static void OnKeyUp( LCUI_SysEvent e, void *arg ) -{ - -} - -/** 响应按键的输入 */ -static void OnKeyPress( LCUI_SysEvent e, void *arg ) -{ - + LCUI_WidgetEventRec ev; + if( !self.targets[WST_FOCUS] ) { + return; + } + switch( e->type ) { + case LCUI_KEYDOWN: ev.type = WET_KEYDOWN; break; + case LCUI_KEYUP: ev.type = WET_KEYUP; break; + case LCUI_KEYPRESS: ev.type = WET_KEYPRESS; break; + default: return; + } + ev.target = self.targets[WST_FOCUS]; + ev.key.code = e->key.code; + Widget_TriggerEvent( ev.target, &ev, NULL ); } /** 响应输入法的输入 */ -static void OnInput( LCUI_SysEvent e, void *arg ) +static void OnTextInput( LCUI_SysEvent e, void *arg ) { + LCUI_WidgetEventRec ev; + LCUI_Widget target = LCUIIME_GetTarget(); + if( !target ) { + return; + } + ev.target = target; + ev.type = WET_TEXTINPUT; + ev.text.length = e->text.length; + ev.text.text = NEW( wchar_t, e->text.length + 1 ); + if( !ev.text.text ) { + return; + } + wcsncpy( ev.text.text, e->text.text, e->text.length + 1 ); + Widget_TriggerEvent( ev.target, &ev, NULL ); + free( ev.text.text ); + ev.text.text = NULL; + ev.text.length = 0; +} +static void ConvertTouchPoint( LCUI_TouchPoint point ) +{ + switch( point->state ) { + case LCUI_TOUCHUP: point->state = WET_TOUCHUP; break; + case LCUI_TOUCHDOWN: point->state = WET_TOUCHDOWN; break; + case LCUI_TOUCHMOVE: point->state = WET_TOUCHMOVE; break; + default:break; + } +} + +/** 分发触控事件给对应的部件 */ +static int DispatchTouchEvent( LinkedList *capturers, + LCUI_TouchPoint points, int n_points ) +{ + int i, count; + LCUI_WidgetEventRec ev; + LCUI_Widget target, root, w; + LinkedListNode *node, *ptnode; + + ev.type = WET_TOUCH; + ev.cancel_bubble = FALSE; + root = LCUIWidget_GetRoot(); + ev.touch.points = NEW( LCUI_TouchPointRec, n_points ); + /* 先将各个触点按命中的部件进行分组 */ + for( i = 0; i < n_points; ++i ) { + target = Widget_At( root, points[i].x, points[i].y ); + if( !target ) { + continue; + } + for( w = target; w; w = w->parent ) { + if( w->event_blocked ) { + break; + } + } + if( w && w->event_blocked ) { + continue; + } + TouchCapturers_Add( capturers, target, points[i].id ); + } + count = 0; + ev.touch.n_points = 0; + /* 然后向命中的部件发送触控事件 */ + for( LinkedList_Each( node, capturers ) ) { + TouchCapturer tc = node->data; + for( i = 0; i < n_points; ++i ) { + for( LinkedList_Each( ptnode, &tc->points ) ) { + LCUI_TouchPoint point; + if( points[i].id != *(int*)ptnode->data ) { + continue; + } + point = &ev.touch.points[ev.touch.n_points]; + *point = points[i]; + ConvertTouchPoint( point ); + ++ev.touch.n_points; + } + } + if( ev.touch.n_points == 0 ) { + continue; + } + Widget_PostEvent( tc->widget, &ev, NULL, NULL ); + ev.touch.n_points = 0; + ++count; + } + free( ev.touch.points ); + return count; +} + +/** 响应系统触控事件 */ +static void OnTouch( LCUI_SysEvent sys_ev, void *arg ) +{ + int i, n; + LinkedList capturers; + LCUI_TouchPoint points; + LinkedListNode *node, *ptnode; + + n = sys_ev->touch.n_points; + points = sys_ev->touch.points; + LinkedList_Init( &capturers ); + LCUIMutex_Lock( &self.mutex ); + /* 合并现有的触点捕捉记录 */ + for( LinkedList_Each( node, &self.touch_capturers ) ) { + TouchCapturer tc = node->data; + for( i = 0; i < n; ++i ) { + /* 如果没有触点记录,则说明是捕获全部触点 */ + if( tc->points.length == 0 ) { + TouchCapturers_Add( &capturers, tc->widget, + points[i].id ); + continue; + } + for( LinkedList_Each( ptnode, &tc->points ) ) { + if( points[i].id != *(int*)ptnode->data ) { + continue; + } + TouchCapturers_Add( &capturers, tc->widget, + points[i].id ); + } + } + } + DispatchTouchEvent( &capturers, points, n ); + TouchCapturers_Clear( &capturers ); + LCUIMutex_Unlock( &self.mutex ); +} + +void Widget_SetMouseCapture( LCUI_Widget w ) +{ + self.mouse_capturer = w; +} + +void Widget_ReleaseMouseCapture( LCUI_Widget w ) +{ + self.mouse_capturer = NULL; +} + +void Widget_SetTouchCapture( LCUI_Widget w, int point_id ) +{ + LCUIMutex_Lock( &self.mutex ); + TouchCapturers_Add( &self.touch_capturers, w, point_id ); + LCUIMutex_Unlock( &self.mutex ); +} + +int Widget_ReleaseTouchCapture( LCUI_Widget w, int point_id ) +{ + int ret; + LCUIMutex_Lock( &self.mutex ); + ret = TouchCapturers_Delete( &self.touch_capturers, w, point_id ); + LCUIMutex_Unlock( &self.mutex ); + return ret; } int Widget_PostSurfaceEvent( LCUI_Widget w, int event_type ) @@ -447,7 +910,6 @@ int Widget_PostSurfaceEvent( LCUI_Widget w, int event_type ) } e.target = w; e.type = WET_SURFACE; - DEBUG_MSG("widget: %s, post event: %d\n", w->type, event_type ); return Widget_PostEvent( root, &e, *((int**)n), NULL ); } @@ -471,8 +933,9 @@ static int Dict_KeyCompare( void *privdata, const void *key1, const void *key2 ) static void *Dict_KeyDup( void *privdata, const void *key ) { - char *newkey = malloc( (wcslen( key ) + 1)*sizeof( char ) ); - strcpy( newkey, key ); + int len = strlen( key ) + 1; + char *newkey = malloc( len * sizeof( char ) ); + strncpy( newkey, key, len ); return newkey; } @@ -509,6 +972,7 @@ void LCUIWidget_InitEvent(void) int id; const char *name; } mappings[] = { + { WET_READY, "ready" }, { WET_DESTROY, "destroy" }, { WET_MOUSEDOWN, "mousedown" }, { WET_MOUSEUP, "mouseup" }, @@ -517,6 +981,14 @@ void LCUIWidget_InitEvent(void) { WET_CLICK, "click" }, { WET_MOUSEOUT, "mouseout" }, { WET_MOUSEOVER, "mouseover" }, + { WET_KEYDOWN, "keydown" }, + { WET_KEYUP, "keyup" }, + { WET_KEYPRESS, "keypress" }, + { WET_TOUCH, "touch" }, + { WET_TEXTINPUT, "textinput" }, + { WET_TOUCHDOWN, "touchdown" }, + { WET_TOUCHMOVE, "touchmove" }, + { WET_TOUCHUP, "touchup" }, { WET_RESIZE, "resize" }, { WET_AFTERLAYOUT, "afterlayout" }, { WET_FOCUS, "focus" }, @@ -526,27 +998,39 @@ void LCUIWidget_InitEvent(void) { WET_SURFACE, "surface" }, { WET_TITLE, "title" } }; + LCUIMutex_Init( &self.mutex ); RBTree_Init( &self.event_names ); + RBTree_Init( &self.event_records ); self.targets[WST_ACTIVE] = NULL; self.targets[WST_HOVER] = NULL; + self.targets[WST_FOCUS] = NULL; + self.mouse_capturer = NULL; self.base_event_id = WET_USER + 1000; self.event_ids = Dict_Create( &DictType_String, NULL ); n = sizeof( mappings ) / sizeof( mappings[0] ); for( i = 0; i < n; ++i ) { LCUIWidget_SetEventName( mappings[i].id, mappings[i].name ); } + LCUI_BindEvent( LCUI_MOUSEWHEEL, OnMouseEvent, NULL, NULL ); LCUI_BindEvent( LCUI_MOUSEDOWN, OnMouseEvent, NULL, NULL ); LCUI_BindEvent( LCUI_MOUSEMOVE, OnMouseEvent, NULL, NULL ); LCUI_BindEvent( LCUI_MOUSEUP, OnMouseEvent, NULL, NULL ); - LCUI_BindEvent( LCUI_MOUSEWHEEL, OnMouseEvent, NULL, NULL ); - LCUI_BindEvent( LCUI_KEYUP, OnKeyUp, NULL, NULL ); - LCUI_BindEvent( LCUI_KEYDOWN, OnKeyDown, NULL, NULL ); - LCUI_BindEvent( LCUI_KEYPRESS, OnKeyPress, NULL, NULL ); - LCUI_BindEvent( LCUI_INPUT, OnInput, NULL, NULL ); + LCUI_BindEvent( LCUI_KEYPRESS, OnKeyboardEvent, NULL, NULL ); + LCUI_BindEvent( LCUI_KEYDOWN, OnKeyboardEvent, NULL, NULL ); + LCUI_BindEvent( LCUI_KEYUP, OnKeyboardEvent, NULL, NULL ); + LCUI_BindEvent( LCUI_TOUCH, OnTouch, NULL, NULL ); + LCUI_BindEvent( LCUI_TEXTINPUT, OnTextInput, NULL, NULL ); + RBTree_OnCompare( &self.event_records, CompareEventRecord ); + LinkedList_Init( &self.touch_capturers ); } void LCUIWidget_ExitEvent(void) { + LCUIMutex_Lock( &self.mutex ); RBTree_Destroy( &self.event_names ); + RBTree_Destroy( &self.event_records ); Dict_Release( self.event_ids ); + TouchCapturers_Clear( &self.touch_capturers ); + LCUIMutex_Unlock( &self.mutex ); + LCUIMutex_Destroy( &self.mutex ); } diff --git a/src/gui/widget_library.c b/src/gui/widget_library.c index abcfed9c..ce3a6a3c 100644 --- a/src/gui/widget_library.c +++ b/src/gui/widget_library.c @@ -60,8 +60,7 @@ static void OnDestroyWidgetClass( void *arg ) void LCUIWidget_InitLibrary(void) { RBTree_Init( &widget_class_library ); - RBTree_OnJudge( &widget_class_library, CompareName ); - RBTree_SetDataNeedFree( &widget_class_library, FALSE ); + RBTree_OnCompare( &widget_class_library, CompareName ); RBTree_OnDestroy( &widget_class_library, OnDestroyWidgetClass ); } diff --git a/src/gui/widget_paint.c b/src/gui/widget_paint.c index d94221bc..af1c3684 100644 --- a/src/gui/widget_paint.c +++ b/src/gui/widget_paint.c @@ -88,8 +88,8 @@ static void Widget_AdjustArea( LCUI_Widget w, LCUI_Rect *in_rect, out_rect->h = box->h; } else { *out_rect = *in_rect; + LCUIRect_ValidateArea( out_rect, box->w, box->h ); } - LCUIRect_ValidateArea( out_rect, box->w, box->h ); /* 将坐标转换成相对于图像呈现区的坐标 */ out_rect->x += (box->x - w->box.graph.x); out_rect->y += (box->y - w->box.graph.y); @@ -107,6 +107,33 @@ void Widget_InvalidateArea( LCUI_Widget w, LCUI_Rect *r, int box_type ) } } +LCUI_BOOL Widget_PushInvalidArea( LCUI_Widget widget, + LCUI_Rect *r, int box_type ) +{ + LCUI_Rect rect; + LCUI_Widget w = widget; + LCUI_Widget root = LCUIWidget_GetRoot(); + if( !w ) { + w = root; + } + Widget_AdjustArea( w, r, &rect, box_type ); + rect.x += w->box.graph.x; + rect.y += w->box.graph.y; + while( w && w->parent ) { + int width = w->parent->box.padding.width; + int height = w->parent->box.padding.height; + LCUIRect_ValidateArea( &rect, width, height ); + if( rect.width < 0 || rect.height < 0 ) { + return FALSE; + } + w = w->parent; + rect.x += w->box.padding.x; + rect.y += w->box.padding.y; + } + Widget_InvalidateArea( root, &rect, SV_PADDING_BOX ); + return TRUE; +} + int Widget_GetInvalidArea( LCUI_Widget widget, LCUI_Rect *area ) { LCUI_Rect *rect; @@ -135,8 +162,10 @@ static void Widget_OnPaint( LCUI_Widget w, LCUI_PaintContext paint ) LCUI_Rect box; LCUI_WidgetClass *wc; LCUI_WidgetStyle *s; - s = &w->computed_style; + + Widget_Lock( w ); box.x = box.y = 0; + s = &w->computed_style; box.width = w->box.graph.width; box.height = w->box.graph.height; /* 如果是有位图缓存的话,则先清空缓存里的阴影区域 */ @@ -150,12 +179,21 @@ static void Widget_OnPaint( LCUI_Widget w, LCUI_PaintContext paint ) box.height = w->box.border.height; Graph_DrawBackground( paint, &box, &s->background ); Graph_DrawBorder( paint, &box, &s->border ); + Widget_Unlock( w ); wc = LCUIWidget_GetClass( w->type ); if( wc && wc->methods.paint ) { wc->methods.paint( w, paint ); } } +/** + * 处理部件无效区域 + * @param[in] w 部件 + * @param[in] x 当前部件的绝对 X 坐标 + * @param[in] y 当前部件的绝对 Y 坐标 + * @param[in] valid_box 当前部件内的有效框 + * @param[out] rlist 收集到的无效区域列表 + */ static int _Widget_ProcInvalidArea( LCUI_Widget w, int x, int y, LCUI_Rect *valid_box, LinkedList *rlist ) @@ -165,26 +203,21 @@ static int _Widget_ProcInvalidArea( LCUI_Widget w, int x, int y, LinkedListNode *node; LCUI_Rect rect, child_box, *r; count = w->dirty_rects.length; - /* 取出当前记录的脏矩形 */ - DEBUG_MSG( "fixed xy: %d,%d\n", x, y ); - LinkedList_ForEach( node, &w->dirty_rects ) { + /* 取出当前记录的无效区域 */ + for( LinkedList_Each( node, &w->dirty_rects ) ) { r = node->data; /* 若有独立位图缓存,则重绘脏矩形区域 */ - if( w->enable_graph && Graph_IsValid(&w->graph) ) { + if( w->enable_graph && Graph_IsValid( &w->graph ) ) { LCUI_PaintContextRec paint; paint.rect = *r; Graph_Quote( &paint.canvas, &w->graph, &paint.rect ); - DEBUG_MSG("[%s]: paint, rect:(%d,%d,%d,%d)\n", - w->type, r->x, r->y, r->width, r->height); Widget_OnPaint( w, &paint ); } /* 取出与容器内有效区域相交的区域 */ - if( LCUIRect_GetOverlayRect(r, valid_box, &rect) ) { - /* 转换相对于根级部件的坐标 */ + if( LCUIRect_GetOverlayRect( r, valid_box, &rect ) ) { + /* 转换成绝对坐标 */ rect.x += x; rect.y += y; - DEBUG_MSG("[%s]: merge rect:(%d,%d,%d,%d)\n", w->type, - rect.x, rect.y, rect.width, rect.height); RectList_Add( rlist, &rect ); } } @@ -193,26 +226,33 @@ static int _Widget_ProcInvalidArea( LCUI_Widget w, int x, int y, if( !w->has_dirty_child ) { return count; } - /* 缩小有效区域到当前部件内容框内,若没有重叠区域,则不向子级部件递归 */ - if( !LCUIRect_GetOverlayRect(valid_box, &w->box.padding, &child_box) ) { - return count; - } - /* 转换有效区域的坐标,相对于当前部件的内容框 */ - child_box.x -= w->box.padding.x; - child_box.y -= w->box.padding.y; - DEBUG_MSG("child valid box: %d,%d,%d,%d\n", child_box.x, child_box.y, child_box.width, child_box.height); + /* 转换为内边距框的坐标 */ + x += w->box.padding.x - w->box.graph.x; + y += w->box.padding.y - w->box.graph.y; /* 向子级部件递归 */ - LinkedList_ForEach( node, &w->children ) { + for( LinkedList_Each( node, &w->children ) ) { int child_x, child_y; child = node->data; - if( !child->computed_style.visible ) { + if( !child->computed_style.visible || + child->state != WSTATE_NORMAL ) { continue; } - DEBUG_MSG("child graph xy: %d,%d\n", child->box.graph.x, child->box.graph.y); child_x = child->box.graph.x + x; child_y = child->box.graph.y + y; - child_x += w->box.padding.x - w->box.graph.x; - child_y += w->box.padding.y - w->box.graph.y; + child_box = child->box.graph; + /* 部件坐标是相对于内容框的,所以加上内容框XY坐标 */ + child_box.x += w->box.padding.x - w->box.graph.x; + child_box.y += w->box.padding.y - w->box.graph.y; + /* 若有效框与子部件没有重叠区域,则不向子级部件递归 */ + if( !LCUIRect_GetOverlayRect( valid_box, &child_box, + &child_box ) ) { + continue; + } + /* 转换为相对于子部件的坐标 */ + child_box.x -= child->box.graph.x; + child_box.y -= child->box.graph.y; + child_box.x -= w->box.padding.x - w->box.graph.x; + child_box.y -= w->box.padding.y - w->box.graph.y; count += _Widget_ProcInvalidArea( child, child_x, child_y, &child_box, rlist ); } @@ -363,8 +403,9 @@ void Widget_Render( LCUI_Widget w, LCUI_PaintContext paint ) /* 按照显示顺序,从底到顶,递归遍历子级部件 */ LinkedList_ForEachReverse( node, &w->children_show ) { LCUI_Rect child_rect; - LCUI_Widget child = node->data; - if( !child->computed_style.visible ) { + LCUI_Widget child = node->data; + if( !child->computed_style.visible || + child->state != WSTATE_NORMAL ) { continue; } /* 转换子部件区域,由相对于内容框转换为相对于当前脏矩形 */ diff --git a/src/gui/widget_style.c b/src/gui/widget_style.c index 12f728a4..c77b5a5d 100644 --- a/src/gui/widget_style.c +++ b/src/gui/widget_style.c @@ -1,7 +1,7 @@ /* *************************************************************************** * widget_style.c -- widget style library module for LCUI. * - * Copyright (C) 2015 by Liu Chao + * Copyright (C) 2015-2016 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. @@ -22,7 +22,7 @@ /* **************************************************************************** * widget_style.c -- LCUI 的部件样式库模块。 * - * 版权所有 (C) 2015 归属于 刘超 + * 版权所有 (C) 2015-2016 归属于 刘超 * * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 * @@ -37,69 +37,23 @@ * 没有,请查看:. * ****************************************************************************/ +#include #include #include #include #include #include #include +#include -#define MAX_NAME_LEN 256 -#define MAX_NODE_DEPTH 32 -#define MAX_SELECTOR_DEPTH 32 - -enum SelectorRank { - GENERAL_RANK = 0, - TYPE_RANK = 1, - CLASS_RANK = 10, - PCLASS_RANK = 10, - ID_RANK = 100 -}; - -enum SelectorFinderLevel { - LEVEL_NONE, - LEVEL_TYPE, - LEVEL_ID, - LEVEL_CLASS, - LEVEL_CLASS_2, - LEVEL_STATUS, - LEVEL_STATUS_2, - LEVEL_TOTAL_NUM -}; - -typedef struct StyleListNodeRec_ { - LCUI_StyleSheet style; /**< 样式表 */ - LCUI_Selector selector; /**< 作用范围 */ -} StyleListNodeRec, *StyleListNode; - -typedef struct StyleTreeNodeRec_ { - char name[MAX_NAME_LEN]; /**< 作用对象的名称 */ - LinkedList styles; /**< 其它样式表 */ -} StyleTreeNodeRec, *StyleTreeNode; - -/* 样式表查找器的上下文数据结构 */ -typedef struct StyleSheetFinderRec_ { - int level; /**< 当前选择器层级 */ - int class_i; /**< 当前处理到第几个类名 */ - int status_i; /**< 当前处理到第几个状态名(伪类名) */ - int name_i; /**< 选择器名称从第几个字符开始 */ - char name[MAX_NAME_LEN]; /**< 选择器名称缓存 */ - LinkedList classes; /**< 已排序的类名列表 */ - LinkedList status; /**< 已排序的状态列表 */ - LCUI_Widget widget; /**< 针对的部件 */ -} StyleSheetFinderRec, *StyleSheetFinder; - -static struct { - LCUI_BOOL is_inited; - LCUI_RBTree tree; /**< 样式树 */ -} style_library; - +/** 部件的缺省样式 */ const char *global_css = ToString( * { width: auto; - height: auto; + height: auto; background-color: transparent; + border: 0px solid #000; display: block; position: static; padding: 0; @@ -108,964 +62,126 @@ const char *global_css = ToString( ); -/** 获取指针数组的长度 */ -static size_t ptrslen( char *const *list ) +LCUI_Selector Widget_GetSelector( LCUI_Widget w ) { - char *const *p = list; - if( list == NULL ) { - return 0; + int ni = 0; + LinkedList list; + LCUI_Selector s; + LCUI_Widget parent; + LinkedListNode *node; + s = Selector( NULL ); + LinkedList_Init( &list ); + for( parent = w; parent; parent = parent->parent ) { + if( parent->id || parent->type || + parent->classes || parent->status ) { + LinkedList_Append( &list, parent ); + } } - while( *p ) { - p++; - } - return p - list; -} - -static int CompareName( void *data, const void *keydata ) -{ - return strcmp( ((StyleTreeNode)data)->name, (const char*)keydata ); -} - -static void SelectorNode_Delete( LCUI_SelectorNode *node_ptr ) -{ - LCUI_SelectorNode node = *node_ptr; - if( node->type ) { - free( node->type ); - node->type = NULL; - } - if( node->class_name ) { - free( node->class_name ); - node->class_name = NULL; - } - if( node->id ) { - free( node->id ); - node->id = NULL; - } - if( node->pseudo_class_name ) { - free( node->pseudo_class_name ); - node->pseudo_class_name = NULL; - } - free( node ); - *node_ptr = NULL; -} - -void Selector_Delete( LCUI_Selector *s_ptr ) -{ - int i; - LCUI_Selector s = *s_ptr; - for( i = 0; ilist[i] ) { - break; - } - SelectorNode_Delete( &s->list[i] ); - } - s->rank = 0; - s->length = 0; - s->batch_num = 0; - free( s->list ); - free( s ); - *s_ptr = NULL; -} - -static void DestroyStyleListNode( StyleListNode node ) -{ - StyleSheet_Delete( &node->style ); - Selector_Delete( &node->selector ); -} - -static void DestroyStyleTreeNode( void *data ) -{ - StyleTreeNode node = data; - LinkedList_Clear( &node->styles, (FuncPtr)DestroyStyleListNode ); -} - -void LCUIWidget_InitStyle( void ) -{ - RBTree_Init( &style_library.tree ); - RBTree_OnJudge( &style_library.tree, CompareName ); - RBTree_OnDestroy( &style_library.tree, DestroyStyleTreeNode ); - style_library.is_inited = TRUE; - LCUICSS_Init(); - LCUICSS_LoadString( global_css ); -} - -void LCUIWidget_ExitStyle( void ) -{ - RBTree_Destroy( &style_library.tree ); - style_library.is_inited = FALSE; - LCUICSS_Destroy(); -} - -LCUI_StyleSheet StyleSheet( void ) -{ - LCUI_StyleSheet ss; - ss = malloc( sizeof( LCUI_StyleSheetRec ) ); - if( !ss ) { - return ss; - } - ss->length = LCUICSS_GetStyleTotal(); - ss->sheet = NEW(LCUI_StyleRec, ss->length + 1); - return ss; -} - -void StyleSheet_Clear( LCUI_StyleSheet ss ) -{ - int i; - LCUI_Style s; - for( i=0; ilength; ++i ) { - s = &ss->sheet[i]; - switch( s->type ) { - case SVT_STRING: - case SVT_WSTRING: - if( s->is_valid && s->string ) { - free( s->string ); - } - s->string = NULL; - default: break; - } - s->is_valid = FALSE; - s->is_changed = TRUE; - } -} - -void StyleSheet_Delete( LCUI_StyleSheet *ss ) -{ - StyleSheet_Clear( *ss ); - free( (*ss)->sheet ); - free( *ss ); - *ss = NULL; -} - -int StyleSheet_Merge( LCUI_StyleSheet dest, LCUI_StyleSheet src ) -{ - LCUI_Style s; - int i, count, size; - if( src->length > dest->length ) { - size = sizeof(LCUI_StyleRec)*src->length; - s = realloc( dest->sheet, size ); - if( !s ) { - return -1; - } - for( i=dest->length; ilength; ++i ) { - s[i].is_valid = FALSE; - } - dest->sheet = s; - dest->length = src->length; - } - for( count=0,i=0; ilength; ++i ) { - s = &dest->sheet[i]; - if( !src->sheet[i].is_valid || s->is_valid ) { - continue; - } - ++count; - switch( src->sheet[i].type ) { - case SVT_STRING: - s->string = strdup( src->sheet[i].string ); - break; - case SVT_WSTRING: - size = wcslen( src->sheet[i].wstring ) + 1; - s->wstring = malloc( size * sizeof(wchar_t) ); - wcscpy( s->wstring, src->sheet[i].wstring ); - break; - default: - *s = src->sheet[i]; - break; - } - s->is_valid = TRUE; - s->is_changed = TRUE; - s->type = src->sheet[i].type; - } - return 0; -} - -int StyleSheet_Replace( LCUI_StyleSheet dest, LCUI_StyleSheet src ) -{ - LCUI_Style s; - int i, count, size; - if( src->length > dest->length ) { - size = sizeof(LCUI_StyleRec)*src->length; - s = realloc( dest->sheet, size ); - if( !s ) { - return -1; - } - for( i=dest->length; ilength; ++i ) { - s[i].is_valid = FALSE; - } - dest->sheet = s; - dest->length = src->length; - } - for( count=0,i=0; ilength; ++i ) { - if( !src->sheet[i].is_valid ) { - continue; - } - s = &dest->sheet[i]; - switch( src->sheet[i].type ) { - case SVT_STRING: - if( s->is_valid && s->string ) { - free( s->string ); - } - s->string = strdup( src->sheet[i].string ); - break; - case SVT_WSTRING: - if( s->is_valid && s->string ) { - free( s->wstring ); - } - size = wcslen( src->sheet[i].wstring ) + 1; - s->wstring = malloc( size * sizeof(wchar_t) ); - wcscpy( s->wstring, src->sheet[i].wstring ); - break; - default: - *s = src->sheet[i]; - break; - } - s->is_valid = TRUE; - s->is_changed = TRUE; - s->type = src->sheet[i].type; - ++count; - } - return count; -} - -static int SelectorNode_Save( LCUI_SelectorNode node, - const char *name, int len, char type ) -{ - char *str; - if( len < 1 ) { - return 0; - } - str = malloc( (len + 1)*sizeof( char ) ); - strcpy( str, name ); - switch( type ) { - case 0: - if( node->type ) { - break; - } - node->type = str; - return TYPE_RANK; - case ':': - if( node->pseudo_class_name ) { - break; - } - node->pseudo_class_name = str; - return PCLASS_RANK; - case '.': - if( node->class_name ) { - break; - } - node->class_name = str; - return CLASS_RANK; - case '#': - if( node->id ) { - break; - } - node->id = str; - return ID_RANK; - default: break; - } - free( str ); - return 0; -} - -LCUI_Selector Selector( const char *selector ) -{ - const char *p; - int ni, si, rank; - static int batch_num = 0; - char type = 0, name[MAX_NAME_LEN]; - LCUI_BOOL is_saving = FALSE; - LCUI_SelectorNode node = NULL; - LCUI_Selector s = NEW( LCUI_SelectorRec, 1 ); - - s->batch_num = ++batch_num; - s->list = NEW( LCUI_SelectorNode, MAX_SELECTOR_DEPTH ); - for( ni = 0, si = 0, p = selector; *p; ++p ) { - if( !node && is_saving ) { - node = NEW( LCUI_SelectorNodeRec, 1 ); - if( si >= MAX_SELECTOR_DEPTH ) { - _DEBUG_MSG( "%s: selector node list is too long.\n", - selector ); - return NULL; - } - s->list[si] = node; - } - switch( *p ) { - case ':': - case '.': - case '#': - if( !is_saving ) { - is_saving = TRUE; - type = *p; - continue; - } - /* 保存上个结点 */ - rank = SelectorNode_Save( node, name, ni, type ); - if( rank > 0 ) { - s->rank += rank; - } else { - _DEBUG_MSG( "%s: invalid selector node at %ld.\n", - selector, p - selector - ni ); - SelectorNode_Delete( &node ); - } - ni = 0; - is_saving = TRUE; - type = *p; - continue; - case ' ': - case '\r': - case '\n': - case '\t': - if( !is_saving ) { - ni = 0; - node = NULL; - continue; - } - is_saving = FALSE; - rank = SelectorNode_Save( node, name, ni, type ); - if( rank > 0 ) { - si++; - ni = 0; - node = NULL; - s->rank += rank; - continue; - } - _DEBUG_MSG( "%s: invalid selector node at %ld.\n", - selector, p - selector - ni ); - SelectorNode_Delete( &node ); - ni = 0; - continue; - default: break; - } - if( *p == '-' || *p == '_' || *p == '*' - || (*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') - || (*p >= '0' && *p <= '9') ) { - if( !is_saving ) { - type = 0; - is_saving = TRUE; - } - name[ni++] = *p; - name[ni] = 0; - continue; - } - _DEBUG_MSG( "%s: unknown char 0x%02x at %ld.\n", - selector, *p, p - selector ); + if( list.length >= MAX_SELECTOR_DEPTH ) { + LinkedList_Clear( &list, NULL ); + Selector_Delete( s ); return NULL; } - if( is_saving ) { - rank = SelectorNode_Save( s->list[si], name, ni, type ); - if( rank > 0 ) { - s->rank += rank; - si++; - } else { - SelectorNode_Delete( &s->list[si] ); + for( LinkedList_EachReverse( node, &list ) ) { + int i; + LCUI_SelectorNode sn; + parent = node->data; + sn = NEW( LCUI_SelectorNodeRec, 1 ); + Widget_Lock( parent ); + if( parent->id ) { + sn->id = strdup( parent->id ); } + if( parent->type ) { + sn->type = strdup( parent->type ); + } + if( parent->classes ) { + for( i = 0; parent->classes[i]; ++i ) { + sortedstrsadd( &sn->classes, + parent->classes[i] ); + } + } + if( parent->status ) { + for( i = 0; parent->status[i]; ++i ) { + sortedstrsadd( &sn->status, + parent->status[i] ); + } + } + Widget_Unlock( parent ); + SelectorNode_Update( sn ); + s->nodes[ni] = sn; + s->rank += sn->rank; + ni += 1; } - s->list[si] = NULL; - s->length += si; + LinkedList_Clear( &list, NULL ); + s->nodes[ni] = NULL; + s->length = ni; + Selector_Update( s ); return s; } -LCUI_Selector Selector_Dup( const LCUI_Selector src ) +int Widget_HandleChildrenStyleChange( LCUI_Widget w, int type, const char *name ) { - int i; - LCUI_SelectorNode new_sn, *sn_ptr, sn; - LCUI_Selector dst = NEW( LCUI_SelectorRec, 1 ); - dst->list = NEW( LCUI_SelectorNode, src->length + 1 ); - for( sn_ptr = src->list, i = 0; *sn_ptr; ++sn_ptr, ++i ) { - sn = *sn_ptr; - new_sn = NEW( LCUI_SelectorNodeRec, 1 ); - if( sn->type ) { - new_sn->type = strdup( sn->type ); - } - if( sn->id ) { - new_sn->id = strdup( sn->id ); - } - if( sn->class_name ) { - new_sn->class_name = strdup( sn->class_name ); - } - if( sn->pseudo_class_name ) { - new_sn->pseudo_class_name = strdup( sn->pseudo_class_name ); - } - dst->list[i] = new_sn; - } - dst->list[i] = NULL; - dst->length = i; - dst->rank = src->rank; - dst->batch_num = src->batch_num; - return dst; -} - -static int mystrcmp( const char *str1, const char *str2 ) -{ - if( str1 == str2 ) { - return 0; - } - if( str1 == NULL || str2 == NULL ) { - return -1; - } - return strcasecmp( str1, str2 ); -} - -LCUI_BOOL Selector_Compare( LCUI_Selector s1, LCUI_Selector s2 ) -{ - LCUI_SelectorNode *sn1_ptr = s1->list, *sn2_ptr = s2->list; - for( ; *sn1_ptr && *sn2_ptr; ++sn1_ptr,++sn2_ptr ) { - if( mystrcmp((*sn1_ptr)->type, (*sn2_ptr)->type) ) { - return FALSE; - } - if( mystrcmp((*sn1_ptr)->class_name, - (*sn2_ptr)->class_name) ) { - return FALSE; - } - if( mystrcmp((*sn1_ptr)->pseudo_class_name, - (*sn2_ptr)->pseudo_class_name) ) { - return FALSE; - } - if( mystrcmp((*sn1_ptr)->id, (*sn2_ptr)->id) ) { - return FALSE; - } - } - if( sn1_ptr == sn2_ptr ) { - return TRUE; - } - return FALSE; -} - -static LCUI_StyleSheet SelectStyleSheetByName( LCUI_Selector selector, - const char *name ) -{ - StyleTreeNode stn; - StyleListNode sln; - LCUI_RBTreeNode *tn; + LCUI_Selector s; + LinkedList snames; LinkedListNode *node; - int i = 0, pos = -1; - tn = RBTree_CustomSearch( &style_library.tree, (const void*)name ); - if( !tn ) { - stn = NEW( StyleTreeNodeRec, 1 ); - strncpy( stn->name, name, MAX_NAME_LEN ); - LinkedList_Init( &stn->styles ); - tn = RBTree_CustomInsert( &style_library.tree, - (const void*)name, stn ); + int i, n, count = 0; + char ch, **names = NULL; + + /* 选择相应的前缀 */ + switch( type ) { + case 0: ch = '.'; break; + case 1: ch = ':'; break; + default: return 0; } - stn = tn->data; - LinkedList_ForEach( node, &stn->styles ) { - sln = node->data; - if( Selector_Compare(sln->selector, selector) ) { - return sln->style; - } - if( pos != -1 ) { - i += 1; - continue; - } - if( selector->rank > sln->selector->rank ) { - pos = i; - } else if( selector->rank == sln->selector->rank ) { - if( selector->batch_num > sln->selector->batch_num ) { - pos = i; + LinkedList_Init( &snames ); + s = Widget_GetSelector( w ); + n = strsplit( name, " ", &names ); + /* 为分割出来的字符串加上前缀 */ + for( i = 0; i < n; ++i ) { + int len = strlen( names[i] ) + 2; + char *str = malloc( len * sizeof( char ) ); + strncpy( str + 1, names[i], len - 1 ); + str[0] = ch; + free( names[i] ); + names[i] = str; + } + SelectorNode_GetNames( s->nodes[s->length - 1], &snames ); + for( LinkedList_Each( node, &snames ) ) { + char *sname = node->data; + /* 过滤掉不包含 name 中存在的名称 */ + for( i = 0; i < n; ++i ) { + char *p = strstr( sname, names[i] ); + if( p ) { + p += strlen( names[i] ); + switch( *p ) { + case 0: + case ':': + case '.': break; + default: continue; + } break; } } - i += 1; - } - sln = NEW( StyleListNodeRec, 1 ); - sln->style = StyleSheet(); - sln->selector = Selector_Dup( selector ); - if( pos >= 0 ) { - LinkedList_Insert( &stn->styles, pos, sln ); - } else { - LinkedList_Append( &stn->styles, sln ); - } - return sln->style; -} - -static LCUI_StyleSheet SelectStyleSheet( LCUI_Selector selector ) -{ - char fullname[MAX_NAME_LEN] = ""; - LCUI_SelectorNode sn = selector->list[selector->length-1]; - if( sn->type ) { - strcat( fullname, sn->type ); - } - if( sn->id ) { - strcat( fullname, "#" ); - strcat( fullname, sn->id ); - } - if( sn->class_name ) { - strcat( fullname, "." ); - strcat( fullname, sn->class_name ); - } - if( sn->pseudo_class_name ) { - strcat( fullname, ":" ); - strcat( fullname, sn->pseudo_class_name ); - } - if( fullname[0] == 0 ) { - return NULL; - } - return SelectStyleSheetByName( selector, fullname ); -} - -int LCUI_PutStyle( LCUI_Selector selector, LCUI_StyleSheet in_ss ) -{ - LCUI_StyleSheet ss; - ss = SelectStyleSheet( selector ); - if( ss ) { - StyleSheet_Replace( ss, in_ss ); - } - return 0; -} - -LCUI_BOOL Selector_MatchPath( LCUI_Selector selector, LCUI_Widget *wlist ) -{ - int i, n; - LCUI_Widget *obj_ptr = wlist, w; - LCUI_SelectorNode sn, *sn_ptr = selector->list; - /* 定位到最后一个元素 */ - sn_ptr += selector->length-1; - for( ;*obj_ptr; ++obj_ptr ); - --obj_ptr; - /* 从右到左遍历,进行匹配 */ - for( ; obj_ptr >= wlist && sn_ptr >= selector->list; --obj_ptr ) { - w = *obj_ptr; - sn = *sn_ptr; - if( sn->id ) { - if( !w->id || strcmp( w->id, sn->id ) ) { - continue; - } - } - if( sn->type && strcmp("*", sn->type) ) { - if( !w->type || strcmp( w->type, sn->type ) ) { - continue; - } - } - if( sn->class_name ) { - n = ptrslen( w->classes ); - for( i = 0; i < n; ++i ) { - if( strcmp( w->classes[i], - sn->class_name ) == 0 ) { - break; - } - } - if( i >= n ) { - continue; - } - } - if( sn->pseudo_class_name ) { - n = ptrslen( w->status ); - for( i = 0; i < n; ++i ) { - if( strcmp( w->status[i], - sn->pseudo_class_name ) == 0 ) { - break; - } - } - if( i >= n ) { - continue; - } - } - --sn_ptr; - } - /* 匹配成功的标志是遍历完选择器列表 */ - if( sn_ptr < selector->list ) { - return TRUE; - } - return FALSE; -} - -static int InsertStyleSheet( LinkedList *list, LCUI_Selector s, - LCUI_StyleSheet ss ) -{ - int pos = -1, i = 0; - StyleListNode pack; - LinkedListNode *node; - LinkedList_ForEach( node, list ) { - pack = node->data; - if( s->rank > pack->selector->rank ) { - pos = i; - break; - } else if( s->rank == pack->selector->rank ) { - if( s->batch_num > pack->selector->batch_num ) { - pos = i; - break; - } - } - i += 1; - } - pack = NEW( StyleListNodeRec, 1 ); - pack->selector = s; - pack->style = ss; - if( pos >= 0 ) { - LinkedList_Insert( list, pos, pack ); - } else { - LinkedList_Append( list, pack ); - } - return pos; -} - -static int FindStyleNodeByName( const char *name, LCUI_Widget widget, - LinkedList *list ) -{ - int n, count = 0; - StyleListNode sln; - LinkedList *styles; - LCUI_RBTreeNode *tn; - LinkedListNode *node; - LCUI_Widget w, wlist[MAX_SELECTOR_DEPTH]; - tn = RBTree_CustomSearch( &style_library.tree, (const void*)name ); - if( !tn ) { - return 0; - } - for( n = 0, w = widget; w; ++n, w = w->parent ); - if( n >= MAX_SELECTOR_DEPTH ) { - return -1; - } - if( n == 0 ) { - wlist[0] = NULL; - } else { - w = widget; - wlist[n] = NULL; - while( --n >= 0 ) { - wlist[n] = w; - w = w->parent; + if( i < n ) { + count += LCUI_FindStyleSheetFromGroup( 1, sname, + s, NULL ); } } - styles = &((StyleTreeNode)tn->data)->styles; - LinkedList_ForEach( node, styles ) { - sln = node->data; - /* 如果当前元素在该样式结点的作用范围内 */ - if( !Selector_MatchPath( sln->selector, wlist ) ) { - continue; - } - InsertStyleSheet( list, sln->selector, sln->style ); - ++count; + Selector_Delete( s ); + /* 若子部件的样式受到了影响,则标记子部件需要刷新 */ + if( count > 0 ) { + Widget_AddTaskForChildren( w, WTT_REFRESH_STYLE ); } + freestrs( names ); return count; } -/** 从小到大,排序名称列表 */ -static void SortNames( char **names, LinkedList *outnames ) +void Widget_GetInheritStyle( LCUI_Widget w, LCUI_StyleSheet out_ss ) { - char *name; - int i, len; - LinkedListNode *node; - len = ptrslen( names ); - while( --len >= 0 ) { - i = 0; - name = names[len]; - LinkedList_ForEach( node, outnames ) { - if( strcmp(name, node->data) > 0 ) { - ++i; - continue; - } - LinkedList_Insert( outnames, i, name ); - break; - } - if( i >= outnames->length ) { - LinkedList_Append( outnames, name ); - } - } -} - -/** 初始化样式表查找器 */ -static void StyleSheetFinder_Init( StyleSheetFinder sfinder, LCUI_Widget w ) -{ - sfinder->level = 0; - sfinder->class_i = 0; - sfinder->name_i = 0; - sfinder->status_i = 0; - sfinder->name[0] = 0; - sfinder->widget = w; - LinkedList_Init( &sfinder->classes ); - LinkedList_Init( &sfinder->status ); - SortNames( w->classes, &sfinder->classes ); - SortNames( w->status, &sfinder->status ); -} - -/** 销毁样式表查找器 */ -static void StyleSheetFinder_Destroy( StyleSheetFinder sfinder ) -{ - sfinder->name_i = 0; - sfinder->name[0] = 0; - sfinder->class_i = 0; - sfinder->status_i = 0; - sfinder->widget = NULL; - sfinder->level = LEVEL_NONE; - LinkedList_Clear( &sfinder->classes, NULL ); - LinkedList_Clear( &sfinder->status, NULL ); -} - -/* 查找匹配的样式表 */ -int StyleSheetFinder_Find( StyleSheetFinder sfinder, LinkedList *list ) -{ - LinkedListNode *node; - int i, name_len, len, old_len, old_level, count = 0; - char *fullname = sfinder->name + sfinder->name_i; - old_len = len = strlen( fullname ); - old_level = sfinder->level; - switch( sfinder->level ) { - case LEVEL_TYPE: - /* 按类型选择器搜索样式表 */ - if( !sfinder->widget->type ) { - return 0; - } - strcpy( fullname, sfinder->widget->type ); - count = FindStyleNodeByName( fullname, sfinder->widget, list ); - break; - case LEVEL_ID: - /* 按ID选择器搜索样式表 */ - if( !sfinder->widget->id ) { - return 0; - } - fullname[len++] = '#'; - strcpy( fullname + len, sfinder->widget->id ); - count = FindStyleNodeByName( fullname, sfinder->widget, list ); - fullname[old_len] = 0; - break; - case LEVEL_CLASS: - /* 按类选择器搜索样式表 - * 假设当前选择器全名为:textview#main-btn-text,且有 .a .b .c - * 这三个类,那么下面的处理将会拆分成以下三个选择器来匹配样式表: - * textview#test-text.a - * textview#test-text.b - * textview#test-text.a - */ - fullname[len++] = '.'; - LinkedList_ForEach( node, &sfinder->classes ) { - strcpy( fullname + len, node->data ); - count += FindStyleNodeByName( fullname, - sfinder->widget, list ); - /* 将当前选择器名与其它层级的选择器名组合 */ - for( i = sfinder->level + 1; i < LEVEL_TOTAL_NUM; ++i ) { - sfinder->level = i; - count += StyleSheetFinder_Find( sfinder, list ); - } - sfinder->level = LEVEL_CLASS; - sfinder->class_i += 1; - } - sfinder->level = LEVEL_CLASS; - fullname[old_len] = 0; - sfinder->class_i = 0; - return count; - case LEVEL_CLASS_2: - /* 按类选择器搜索交集样式表,结果类似于这样: - * textview#test-text.a.b - * textview#test-text.a.c - * textview#test-text.b.c - * textview#test-text.a.b.c - */ - i = 0; - fullname[len++] = '.'; - LinkedList_ForEach( node, &sfinder->classes ) { - if( i <= sfinder->class_i ) { - i += 1; - continue; - } - name_len = strlen( node->data ); - strcpy( fullname + len, node->data ); - count += FindStyleNodeByName( fullname, - sfinder->widget, list ); - sfinder->class_i += 1; - count += StyleSheetFinder_Find( sfinder, list ); - sfinder->class_i -= 1; - sfinder->level = LEVEL_STATUS; - /** - * 递归拼接伪类名,例如: - * textview#main-btn-text:active - */ - count += StyleSheetFinder_Find( sfinder, list ); - sfinder->level = LEVEL_CLASS_2; - i += 1; - } - fullname[old_len] = 0; - sfinder->level = LEVEL_CLASS_2; - return count; - case LEVEL_STATUS: - fullname[len++] = ':'; - sfinder->level = LEVEL_STATUS_2; - /** - * 按伪类选择器搜索样式表 - * 假设当前选择器全名为:textview#main-btn-text:hover:focus:active - * 那么下面的循环会将它拆分为以下几个选择器来匹配样式: - * textview#main-btn-text:active - * textview#main-btn-text:active:focus - * textview#main-btn-text:active:focus:hover - * textview#main-btn-text:active:hover - * textview#main-btn-text:focus - * textview#main-btn-text:focus:hover - * textview#main-btn-text:hover - */ - LinkedList_ForEach( node, &sfinder->status ) { - strcpy( fullname + len, node->data ); - count += FindStyleNodeByName( fullname, - sfinder->widget, list ); - /** - * 递归调用,以一层层拼接出像下面这样的选择器: - * textview#main-btn-text:active:focus:hover - */ - count += StyleSheetFinder_Find( sfinder, list ); - sfinder->status_i += 1; - } - sfinder->level = LEVEL_STATUS; - fullname[old_len] = 0; - sfinder->status_i = 0; - return count; - case LEVEL_STATUS_2: - /** 按伪类选择器搜索交集样式表 */ - i = 0; - LinkedList_ForEach( node, &sfinder->status ) { - if( i <= sfinder->status_i ) { - i += 1; - continue; - } - fullname[len] = ':'; - name_len = strlen( node->data ); - strcpy( fullname + len + 1, node->data ); - count += FindStyleNodeByName( fullname, - sfinder->widget, list ); - sfinder->status_i += 1; - count += StyleSheetFinder_Find( sfinder, list ); - sfinder->status_i -= 1; - i += 1; - } - fullname[old_len] = 0; - return count; - default:break; - } - for( i = sfinder->level + 1; i < LEVEL_TOTAL_NUM; ++i ) { - if( i == LEVEL_STATUS_2 || i == LEVEL_CLASS_2 ) { - continue; - } - sfinder->level = i; - count += StyleSheetFinder_Find( sfinder, list ); - } - fullname[old_len] = 0; - sfinder->level = old_level; - return count; -} - -/** 查找样式数据节点 */ -static int FindStyleNode( LCUI_Widget w, LinkedList *list ) -{ - int count; - StyleSheetFinderRec sfinder; - StyleSheetFinder_Init( &sfinder, w ); - count = StyleSheetFinder_Find( &sfinder, list ); - StyleSheetFinder_Destroy( &sfinder ); - /* 记录作用于全局元素的样式表 */ - count += FindStyleNodeByName( "*", w, list ); - return count; -} - -void LCUI_PrintStyleSheet( LCUI_StyleSheet ss ) -{ - int key; - const char *name; - for( key = 0; keylength; ++key ) { - if( !ss->sheet[key].is_valid ) { - continue; - } - name = GetStyleName(key); - if( name ) { - printf( "\t\t%s", name ); - } else { - printf( "\t\t", key); - } - printf( "%s: ", key > STYLE_KEY_TOTAL ? " (+)" : "" ); - switch( ss->sheet[key].type ) { - case SVT_AUTO: - printf( "auto\n"); - break; - case SVT_VALUE: { - LCUI_BOOL b = ss->sheet[key].value; - printf( "%s\n", b ? "true" : "false" ); - break; - } - case SVT_COLOR: { - LCUI_Color *clr = &ss->sheet[key].color; - if( clr->alpha < 255 ) { - printf("rgba(%d,%d,%d,%0.2f)\n", clr->r, - clr->g, clr->b, clr->a / 255.0); - } else { - printf("#%02x%02x%02x\n", clr->r, clr->g, clr->b); - } - break; - } - case SVT_PX: - printf("%dpx\n", ss->sheet[key].px); - break; - case SVT_STRING: - printf("%s\n", ss->sheet[key].string); - break; - case SVT_SCALE: - printf("%.2lf%%\n", ss->sheet[key].scale*100); - break; - default: - printf("%d\n", ss->sheet[key].value); - break; - } - } -} - -void LCUI_PrintSelector( LCUI_Selector selector ) -{ - char path[256]; - LCUI_SelectorNode *sn; - - path[0] = 0; - for( sn = selector->list; *sn; ++sn ) { - if( (*sn)->id ) { - strcat( path, "#" ); - strcat( path, (*sn)->id ); - } - if( (*sn)->type ) { - strcat( path, (*sn)->type ); - } - if( (*sn)->class_name ) { - strcat( path, "." ); - strcat( path, (*sn)->class_name ); - } - if( (*sn)->pseudo_class_name ) { - strcat( path, ":" ); - strcat( path, (*sn)->pseudo_class_name ); - } - strcat( path, " " ); - } - printf("\tpath: %s (rank = %d, batch_num = %d)\n", path, - selector->rank, selector->batch_num); -} - -void LCUI_PrintStyleLibrary(void) -{ - LCUI_RBTreeNode *tn; - LinkedListNode *node; - StyleTreeNode stn; - StyleListNode sln; - - printf("style library begin\n"); - tn = RBTree_First( &style_library.tree ); - while( tn ) { - stn = tn->data; - printf("target: %s\n", stn->name); - LinkedList_ForEach( node, &stn->styles ) { - sln = node->data; - LCUI_PrintSelector( sln->selector ); - LCUI_PrintStyleSheet( sln->style ); - } - tn = RBTree_Next( tn ); - } - printf("style library end\n"); -} - -int Widget_ComputeInheritStyle( LCUI_Widget w, LCUI_StyleSheet out_ss ) -{ - LinkedList list; - StyleListNode sln; - LinkedListNode *node; - LinkedList_Init( &list ); - FindStyleNode( w, &list ); - StyleSheet_Clear( out_ss ); - LinkedList_ForEach( node, &list ) { - sln = node->data; - StyleSheet_Merge( out_ss, sln->style ); - } - LinkedList_Clear( &list, free ); - return 0; + LCUI_Selector s; + s = Widget_GetSelector( w ); + LCUI_GetStyleSheet( s, out_ss ); + Selector_Delete( s ); } void Widget_UpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all ) @@ -1081,8 +197,9 @@ void Widget_ExecUpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all ) { int i, key; LCUI_Style s; + LCUI_StyleSheet ss; LCUI_WidgetClass *wc; - LCUI_BOOL need_update_expend_style; + LCUI_BOOL need_update_expend_style = FALSE; typedef struct { int start, end, task; LCUI_BOOL is_valid; @@ -1090,32 +207,36 @@ void Widget_ExecUpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all ) TaskMap task_map[] = { { key_display_start, key_display_end, WTT_VISIBLE, TRUE }, { key_opacity, key_opacity, WTT_OPACITY, TRUE }, + { key_z_index, key_z_index, WTT_ZINDEX, TRUE }, { key_width, key_height, WTT_RESIZE, TRUE }, - { key_padding_top, key_padding_left, WTT_RESIZE, TRUE }, + { key_padding_start, key_padding_end, WTT_RESIZE, TRUE }, + { key_margin_start, key_margin_end, WTT_MARGIN, TRUE }, { key_position_start, key_position_end, WTT_POSITION, TRUE }, { key_vertical_align, key_vertical_align, WTT_POSITION, TRUE }, { key_border_start, key_border_end, WTT_BORDER, TRUE }, { key_background_start, key_background_end, WTT_BACKGROUND, TRUE }, { key_box_shadow_start, key_box_shadow_end, WTT_SHADOW, TRUE }, - { key_pointer_events, key_pointer_events, WTT_PROPS, TRUE }, + { key_pointer_events, key_focusable, WTT_PROPS, TRUE }, { key_box_sizing, key_box_sizing, WTT_RESIZE, TRUE } }; if( is_update_all ) { - Widget_ComputeInheritStyle( w, w->inherited_style ); + Widget_GetInheritStyle( w, w->inherited_style ); } - StyleSheet_Clear( w->style ); + ss = w->style; + w->style = StyleSheet(); StyleSheet_Merge( w->style, w->custom_style ); StyleSheet_Merge( w->style, w->inherited_style ); /* 对比两张样式表,确定哪些需要更新 */ for( key = 0; key < w->style->length; ++key ) { s = &w->style->sheet[key]; - if( !s->is_changed ) { + if( ss->sheet[key].is_valid == s->is_valid && + ss->sheet[key].type == s->type && + ss->sheet[key].value == s->value ) { continue; } - s->is_changed = FALSE; if( key >= STYLE_KEY_TOTAL ) { need_update_expend_style = TRUE; - continue; + break; } for( i = 0; i < sizeof(task_map) / sizeof(TaskMap); ++i ) { if( key >= task_map[i].start && key <= task_map[i].end ) { @@ -1132,4 +253,19 @@ void Widget_ExecUpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all ) wc = LCUIWidget_GetClass( w->type ); wc && wc->methods.update ? wc->methods.update( w ) : 0; } + StyleSheet_Delete( ss ); +} + +void LCUIWidget_InitStyle( void ) +{ + + LCUI_InitCSSLibrary(); + LCUI_InitCSSParser(); + LCUI_LoadCSSString( global_css, NULL ); +} + +void LCUIWidget_ExitStyle( void ) +{ + LCUI_ExitCSSLibrary(); + LCUI_ExitCSSParser(); } diff --git a/src/gui/widget_task.c b/src/gui/widget_task.c index 3871f788..e722bb3b 100644 --- a/src/gui/widget_task.c +++ b/src/gui/widget_task.c @@ -37,43 +37,42 @@ * 没有,请查看:. * ***************************************************************************/ -//#define DEBUG -#define __IN_WIDGET_TASK_SOURCE_FILE__ #include #include #include #include #include +typedef void (*callback)(LCUI_Widget); + +/** 部件任务模块数据 */ +static struct WidgetTaskModule { + size_t count; + int64_t timeout; + LCUI_BOOL is_timeout; + LinkedList trash; /**< 待删除的部件列表 */ + callback handlers[WTT_TOTAL_NUM]; /**< 任务处理器 */ +} self; + static void HandleRefreshStyle( LCUI_Widget w ) { Widget_ExecUpdateStyle( w, TRUE ); w->task.buffer[WTT_UPDATE_STYLE] = FALSE; - w->task.buffer[WTT_CACHE_STYLE] = TRUE; } static void HandleUpdateStyle( LCUI_Widget w ) { Widget_ExecUpdateStyle( w, FALSE ); - w->task.buffer[WTT_CACHE_STYLE] = TRUE; -} - -static void HandleCacheStyle( LCUI_Widget w ) -{ - StyleSheet_Clear( w->cached_style ); - StyleSheet_Replace( w->cached_style, w->style ); } static void HandleSetTitle( LCUI_Widget w ) { - _DEBUG_MSG("widget: %s\n", w->type); Widget_PostSurfaceEvent( w, WET_TITLE ); } /** 处理主体刷新(标记主体区域为脏矩形,但不包括阴影区域) */ static void HandleBody( LCUI_Widget w ) { - DEBUG_MSG( "body\n" ); Widget_InvalidateArea( w, NULL, SV_BORDER_BOX ); } @@ -88,16 +87,12 @@ static void HandleRefresh( LCUI_Widget w ) void Widget_UpdateTaskStatus( LCUI_Widget widget ) { int i; - for( i=0; itask.buffer[i] ) { widget->task.for_self = TRUE; + Widget_AddTask( widget, widget->task.buffer[i] ); } } - widget = widget->parent; - while( widget ) { - widget->task.for_children = TRUE; - widget = widget->parent; - } } void Widget_AddTaskForChildren( LCUI_Widget widget, int task ) @@ -105,7 +100,7 @@ void Widget_AddTaskForChildren( LCUI_Widget widget, int task ) LCUI_Widget child; LinkedListNode *node; widget->task.for_children = TRUE; - LinkedList_ForEach( node, &widget->children ) { + for( LinkedList_Each( node, &widget->children ) ) { child = node->data; Widget_AddTask( child, task ); Widget_AddTaskForChildren( child, task ); @@ -114,7 +109,7 @@ void Widget_AddTaskForChildren( LCUI_Widget widget, int task ) void Widget_AddTask( LCUI_Widget widget, int task ) { - if( widget->deleted ) { + if( widget->state == WSTATE_DELETED ) { return; } widget->task.for_self = TRUE; @@ -127,116 +122,144 @@ void Widget_AddTask( LCUI_Widget widget, int task ) } } -typedef void (*callback)(LCUI_Widget); - -static callback task_handlers[WTT_TOTAL_NUM]; - /** 映射任务处理器 */ static void MapTaskHandler(void) { - task_handlers[WTT_VISIBLE] = Widget_UpdateVisibility; - task_handlers[WTT_POSITION] = Widget_UpdatePosition; - task_handlers[WTT_RESIZE] = Widget_UpdateSize; - task_handlers[WTT_SHADOW] = Widget_UpdateBoxShadow; - task_handlers[WTT_BORDER] = Widget_UpdateBorder; - task_handlers[WTT_OPACITY] = Widget_UpdateOpacity; - task_handlers[WTT_BODY] = HandleBody; - task_handlers[WTT_TITLE] = HandleSetTitle; - task_handlers[WTT_REFRESH] = HandleRefresh; - task_handlers[WTT_UPDATE_STYLE] = HandleUpdateStyle; - task_handlers[WTT_REFRESH_STYLE] = HandleRefreshStyle; - task_handlers[WTT_CACHE_STYLE] = HandleCacheStyle; - task_handlers[WTT_BACKGROUND] = Widget_UpdateBackground; - task_handlers[WTT_LAYOUT] = Widget_ExecUpdateLayout; - task_handlers[WTT_ZINDEX] = Widget_ExecUpdateZIndex; + self.handlers[WTT_VISIBLE] = Widget_UpdateVisibility; + self.handlers[WTT_POSITION] = Widget_UpdatePosition; + self.handlers[WTT_RESIZE] = Widget_UpdateSize; + self.handlers[WTT_SHADOW] = Widget_UpdateBoxShadow; + self.handlers[WTT_BORDER] = Widget_UpdateBorder; + self.handlers[WTT_OPACITY] = Widget_UpdateOpacity; + self.handlers[WTT_MARGIN] = Widget_UpdateMargin; + self.handlers[WTT_BODY] = HandleBody; + self.handlers[WTT_TITLE] = HandleSetTitle; + self.handlers[WTT_REFRESH] = HandleRefresh; + self.handlers[WTT_UPDATE_STYLE] = HandleUpdateStyle; + self.handlers[WTT_REFRESH_STYLE] = HandleRefreshStyle; + self.handlers[WTT_BACKGROUND] = Widget_UpdateBackground; + self.handlers[WTT_LAYOUT] = Widget_ExecUpdateLayout; + self.handlers[WTT_ZINDEX] = Widget_ExecUpdateZIndex; + self.handlers[WTT_PROPS] = Widget_UpdateProps; } -/** 初始化 LCUI 部件任务处理功能 */ -void LCUIWidget_InitTask(void) +void LCUIWidget_InitTask( void ) { MapTaskHandler(); + self.timeout = 0; + LinkedList_Init( &self.trash ); } -/** 销毁(释放) LCUI 部件任务处理功能的相关资源 */ -void LCUIWidget_ExitTask(void) +void LCUIWidget_ExitTask( void ) { - + LinkedList_Clear( &self.trash, NULL ); } -/** 处理部件中当前积累的任务 */ -int Widget_Update( LCUI_Widget w ) +void Widget_AddToTrash( LCUI_Widget w ) { - int ret = 1, i; + LinkedListNode *snode, *node; + + w->state = WSTATE_DELETED; + if( !w->parent ) { + return; + } + node = Widget_GetNode( w ); + snode = Widget_GetShowNode( w ); + LinkedList_Unlink( &w->parent->children, node ); + LinkedList_Unlink( &w->parent->children_show, snode ); + LinkedList_AppendNode( &self.trash, node ); +} + +int Widget_UpdateEx( LCUI_Widget w, LCUI_BOOL has_timeout ) +{ + int i; LCUI_BOOL *buffer; - LCUI_Widget child; LinkedListNode *node, *next; - DEBUG_MSG( "1,widget: %s, for_self: %d, for_children: %d\n", - w->type, w->task.for_self, w->task.for_children ); - /* 如果该部件有任务需要处理 */ - if( w->task.for_self ) { - ret = LCUIMutex_TryLock( &w->mutex ); - if( ret != 0 ) { - ret = 1; - goto skip_proc_self_task; + /* 如果该部件没有任务需要处理、或者被其它线程占用 */ + if( !w->task.for_self || LCUIMutex_TryLock( &w->mutex ) != 0 ) { + goto proc_children_task; + } + w->task.for_self = FALSE; + buffer = w->task.buffer; + /* 如果有用户自定义任务 */ + if( buffer[WTT_USER] ) { + LCUI_WidgetClass *wc; + wc = LCUIWidget_GetClass( w->type ); + wc ? wc->task_handler( w ) : FALSE; + } + for( i = 0; i < WTT_USER; ++i ) { + if( buffer[i] ) { + buffer[i] = FALSE; + if( self.handlers[i] ) { + self.handlers[i]( w ); + } + } else { + buffer[i] = FALSE; } - w->task.for_self = FALSE; - buffer = w->task.buffer; - /* 如果有用户自定义任务 */ - if( buffer[WTT_USER] ) { - LCUI_WidgetClass *wc; - wc = LCUIWidget_GetClass( w->type ); - wc ? wc->task_handler( w ) : FALSE; + } + LCUIMutex_Unlock( &w->mutex ); + /* 如果部件还处于未准备完毕的状态 */ + if( w->state < WSTATE_READY ) { + w->state |= WSTATE_UPDATED; + /* 如果部件已经准备完毕则触发 ready 事件 */ + if( w->state == WSTATE_READY ) { + LCUI_WidgetEventRec e; + e.type = WET_READY; + e.cancel_bubble = TRUE; + Widget_TriggerEvent( w, &e, NULL ); + w->state = WSTATE_NORMAL; } - for( i = 0; i < WTT_USER; ++i ) { - if( buffer[i] ) { - buffer[i] = FALSE; - if( task_handlers[i] ) { - task_handlers[i]( w ); + } + self.count += 1; + +proc_children_task: + + if( !w->task.for_children ) { + return w->task.for_self; + } + /* 如果子级部件中有待处理的部件,则递归进去 */ + w->task.for_children = FALSE; + node = w->children.head.next; + while( node ) { + LCUI_Widget child = node->data; + /* 如果当前部件有销毁任务,结点空间会连同部件一起被 + * 释放,为避免因访问非法空间而出现异常,预先保存下 + * 个结点。 + */ + next = node->next; + /* 如果该级部件的任务需要留到下次再处理 */ + if( Widget_UpdateEx( child, has_timeout ) ) { + w->task.for_children = TRUE; + } + if( has_timeout ) { + if( !self.is_timeout && self.count >= 50 ) { + self.count = 0; + if( LCUI_GetTime() >= self.timeout ) { + self.is_timeout = TRUE; } - } else { - buffer[i] = FALSE; + } + if( self.is_timeout ) { + break; } } - LCUIMutex_Unlock( &w->mutex ); + node = next; } + return w->task.for_self || w->task.for_children; +} + +void LCUIWidget_StepTask( void ) +{ + LinkedListNode *node; + self.is_timeout = FALSE; + self.timeout = LCUI_GetTime() + 20; + Widget_UpdateEx( LCUIWidget_GetRoot(), TRUE ); /* 删除无用部件 */ - node = w->children_trash.head.next; + node = self.trash.head.next; while( node ) { - next = node->next; - LinkedList_Unlink( &w->children_trash, node ); + LinkedListNode *next = node->next; + LinkedList_Unlink( &self.trash, node ); Widget_ExecDestroy( node->data ); node = next; } - -skip_proc_self_task:; - - /* 如果子级部件中有待处理的部件,则递归进去 */ - if( w->task.for_children ) { - w->task.for_children = FALSE; - node = w->children.head.next; - while( node ) { - child = node->data; - /* 如果当前部件有销毁任务,结点空间会连同部件一起被 - * 释放,为避免因访问非法空间而出现异常,预先保存下 - * 个结点。 - */ - next = node->next; - ret = Widget_Update( child ); - /* 如果该级部件的任务需要留到下次再处理 */ - if( ret == 1 ) { - w->task.for_children = TRUE; - } - node = next; - } - } - DEBUG_MSG( "2,widget: %s, for_self: %d, for_children: %d\n", - w->type, w->task.for_self, w->task.for_children ); - return (w->task.for_self || w->task.for_children) ? 1 : 0; -} - -/** 处理一次当前积累的部件任务 */ -void LCUIWidget_StepTask(void) -{ - Widget_Update( LCUIWidget_GetRoot() ); } diff --git a/src/ime.c b/src/ime.c index 9a39e63a..b3b28609 100644 --- a/src/ime.c +++ b/src/ime.c @@ -1,174 +1,192 @@ -// IME: Input Method Editor/Engine -//#define NEED_IME -#ifdef NEED_IME +/* *************************************************************************** + * ime.c -- Input Method Editor/Engine + * + * Copyright (C) 2016 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * ime.c -- 输入法管理器 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +#include +#include +#include #include #include #include #include #include -typedef struct LCUIIME_Info_ { - int id; - LCUI_String name; - LCUIIME_Func func; -} LCUIIME_Info; +/** 输入法相关数据 */ +typedef struct LCUI_IMERec_ { + int id; /**< 输入法ID */ + char *name; /**< 名称 */ + LCUI_IMEHandlerRec handler; /**< 处理器 */ + LinkedListNode node; /**< 在链表中的结点 */ +} LCUI_IMERec, *LCUI_IME; -// 指示输入法列表是否初始化 -LCUI_BOOL imelist_init = FALSE; +/** 输入法管理模块的相关数据 */ +static struct LCUIIMEModule { + LCUI_BOOL is_inited; /**< 是否已经初始化 */ + LinkedList list; /**< 当前记录的输入法列表 */ + LCUI_IME ime; /**< 当前激活的输入法 */ + LCUI_BOOL enable_caps_lock; /**< 是否已经启用大写锁定 */ + int id_count; /**< ID 计数器,用于生成输入法的 ID */ +} self; -// 输入法列表 -LCUI_Queue imelist; - -// 当前选择的输入法 -static LCUIIME_Info* current_ime = NULL; - -// 指示是否开启了大写锁定 -static LCUI_BOOL enable_capitals_lock = FALSE; /* 通过ID查找输入法信息 */ -static LCUIIME_Info* LCUIIME_Find( int ime_id ) +static LCUI_IME LCUIIME_Find( int ime_id ) { - int n, i; - LCUIIME_Info *ptr; - - n = Queue_GetTotal( &imelist ); - for( i=0; iid != ime_id ) { - continue; + LinkedListNode *node; + for( LinkedList_Each( node, &self.list ) ) { + LCUI_IME ime = node->data; + if( ime->id == ime_id ) { + return ime; } - return ptr; } return NULL; } /* 通过名字查找输入法信息 */ -static LCUIIME_Info* LCUIIME_FindByName( const char *name ) +static LCUI_IME LCUIIME_FindByName( const char *name ) { - int n, i; - LCUIIME_Info *ptr; - - n = Queue_GetTotal( &imelist ); - for( i=0; iname, name ) == 0 ) { - return ptr; + LinkedListNode *node; + for( LinkedList_Each( node, &self.list ) ) { + LCUI_IME ime = node->data; + if( strcmp( ime->name, name ) == 0 ) { + return ime; } } return NULL; } /* 注册一个输入法 */ -LCUI_API int LCUIIME_Register( const char *ime_name, LCUIIME_Func *ime_func ) +int LCUIIME_Register( const char *name, LCUI_IMEHandler handler ) { - static int ime_id = 0; // 输入法的ID - LCUIIME_Info *ptr_data; - - if( !imelist_init ) { + size_t len; + LCUI_IME ime; + if( !self.is_inited ) { return -1; } - if( LCUIIME_FindByName( ime_name ) != NULL ) { + if( LCUIIME_FindByName( name ) ) { return -2; } - - ptr_data = (LCUIIME_Info*)malloc( sizeof(LCUIIME_Info) ); - if( !ptr_data ) { - return -3; + ime = NEW( LCUI_IMERec, 1 ); + if( !ime ) { + return -ENOMEM; } - LCUIString_Init( &ptr_data->name ); - _LCUIString_Copy( &ptr_data->name, ime_name ); - ime_id = ime_id + 1; - ptr_data->id = ime_id; - memcpy( &ptr_data->func, ime_func, sizeof(LCUIIME_Func) ); - Queue_AddPointer( &imelist, ptr_data ); - return ime_id; -} - -/* 选定输入法 */ -LCUI_API LCUI_BOOL LCUIIME_Select( int ime_id ) -{ - LCUIIME_Info *ptr_data; - ptr_data = LCUIIME_Find( ime_id ); - if( ptr_data == NULL ) { - return FALSE; + len = strlen( name ) + 1; + ime->name = malloc( len * sizeof(char) ); + if( !ime->name ) { + return -ENOMEM; } - current_ime = ptr_data; - return TRUE; -} - -LCUI_API LCUI_BOOL LCUIIME_SelectByName( const char *name ) -{ - LCUIIME_Info *ptr_data; - ptr_data = LCUIIME_FindByName( name ); - if( ptr_data == NULL ) { - return FALSE; - } - current_ime = ptr_data; - return TRUE; + self.id_count += 1; + ime->id = self.id_count; + ime->node.data = ime; + strncpy( ime->name, name, len ); + memcpy( &ime->handler, handler, sizeof(LCUI_IMEHandlerRec) ); + LinkedList_AppendNode( &self.list, &ime->node ); + return ime->id; } /* 打开输入法 */ -static LCUI_BOOL LCUIIME_Open( LCUIIME_Info *ime ) +static LCUI_BOOL LCUIIME_Open( LCUI_IME ime ) { - if( ime == NULL ) { - return FALSE; + if( ime && ime->handler.open ) { + return ime->handler.open(); } - if( ime->func.open == NULL ) { - return FALSE; - } - return ime->func.open(); + return FALSE; } /* 关闭输入法 */ -static LCUI_BOOL LCUIIME_Close( LCUIIME_Info *ime ) +static LCUI_BOOL LCUIIME_Close( LCUI_IME ime ) { - if( ime == NULL ) { - return FALSE; + if( ime && ime->handler.close ) { + return ime->handler.open(); } - if( ime->func.close == NULL ) { - return FALSE; + return FALSE; +} + +/* 选定输入法 */ +LCUI_BOOL LCUIIME_Select( int ime_id ) +{ + LCUI_IME ime = LCUIIME_Find( ime_id ); + if( ime ) { + LCUIIME_Close( self.ime ); + self.ime = ime; + LCUIIME_Open( self.ime ); + return TRUE; } - return ime->func.close(); + return FALSE; +} + +LCUI_BOOL LCUIIME_SelectByName( const char *name ) +{ + LCUI_IME ime = LCUIIME_FindByName( name ); + if( ime ) { + LCUIIME_Close( self.ime ); + self.ime = ime; + LCUIIME_Open( self.ime ); + return TRUE; + } + return FALSE; } /* 切换至下一个输入法 */ -LCUI_API void LCUIIME_Switch(void) +void LCUIIME_Switch( void ) { - int i=0, n; - LCUIIME_Info *ime_ptr; - - n = Queue_GetTotal( &imelist ); - if( i>=n ) { - i = 0; + LCUI_IME ime; + if( self.ime && self.ime->node.next ) { + ime = self.ime->node.next->data; + LCUIIME_Close( self.ime ); + self.ime = ime; + LCUIIME_Open( self.ime ); } - ime_ptr = Queue_Get( &imelist, i ); - if( ime_ptr == NULL ) { - return; - } - if(ime_ptr != current_ime) { - LCUIIME_Close( current_ime ); - current_ime = ime_ptr; - LCUIIME_Open( current_ime ); - } - ++i; } /* 销毁输入法信息 */ -static void LCUIIME_DestroyInfo( void *arg ) +static void LCUIIME_OnDestroy( void *arg ) { - LCUIIME_Info *p; - p = (LCUIIME_Info*)arg; - LCUIString_Free( &p->name ); + LCUI_IME ime = arg; + free( ime->name ); + ime->name = NULL; } -static void LCUIIME_ToText( const LCUI_KeyboardEvent *event ) +static void LCUIIME_ToText( LCUI_SysEvent e ) { char ch; - switch(event->key_code) { + switch(e->key.code) { #ifdef LCUI_BUILD_IN_WIN32 case 189: ch = '-'; break; case 187: ch = '='; break; @@ -181,19 +199,19 @@ static void LCUIIME_ToText( const LCUI_KeyboardEvent *event ) case 221: ch = ']'; break; case 219: ch = '['; break; #endif - default:ch = event->key_code;break; + default:ch = e->key.code;break; } DEBUG_MSG("key code: %d\n", event->key_code); /* 如果没开启大写锁定,则将字母转换成小写 */ - if( !enable_capitals_lock ) { + if( !self.enable_caps_lock ) { if( ch >= 'A' && ch <= 'Z' ) { - ch = event->key_code + 32; + ch = e->key.code + 32; } } /* 如果shift键处于按下状态 */ - if( LCUIKey_IsHit(LCUIKEY_SHIFT) ) { + if( LCUIKeyboard_IsHit(LCUIKEY_SHIFT) ) { if(ch >='a' && ch <= 'z') { ch = ch - 32; } else if(ch >='A' && ch <= 'Z') { @@ -225,103 +243,113 @@ static void LCUIIME_ToText( const LCUI_KeyboardEvent *event ) } } DEBUG_MSG("ch = %c\n", ch); - current_ime->func.totext( ch ); + self.ime->handler.totext( ch ); } -/* 检测输入法是否要处理按键事件 */ -LCUI_API LCUI_BOOL LCUIIME_ProcessKey( const LCUI_KeyboardEvent *event ) +LCUI_BOOL LCUIIME_ProcessKey( LCUI_SysEvent e ) { int key_state; /* 根据事件类型判定按键状态 */ - if( event->type == LCUI_KEYUP ) { + if( e->type == LCUI_KEYUP ) { key_state = LCUIKEYSTATE_RELEASE; + /* 如果是caps lock按键被释放 */ + if( e->key.code == LCUIKEY_CAPITAL ) { + self.enable_caps_lock = !self.enable_caps_lock; + return FALSE; + } } else { key_state = LCUIKEYSTATE_PRESSED; + /* 如果按下的是 shift 键,但没释放,则直接退出 */ + if( e->key.code == LCUIKEY_SHIFT ) { + return FALSE; + } } - /* 如果按下的是shift键,但没释放,则直接退出 */ - if( event->key_code == LCUIKEY_SHIFT - && event->type == LCUI_KEYDOWN ) { - return FALSE; - } - /* 如果是caps lock按键被释放 */ - if( event->key_code == LCUIKEY_CAPITAL - && event->type == LCUI_KEYUP ) { - enable_capitals_lock = !enable_capitals_lock; - return FALSE; - } - if( current_ime == NULL ) { - return FALSE; - } - if( current_ime->func.prockey == NULL ) { - return FALSE; - } - /* 如果输入法要处理该键,则调用LCUIIME_ToText函数 */ - if( current_ime->func.prockey( event->key_code, key_state ) ) { - LCUIIME_ToText( event ); - return TRUE; + if( self.ime && self.ime->handler.prockey ) { + /* 如果输入法要处理该键,则调用LCUIIME_ToText函数 */ + if( self.ime->handler.prockey( e->key.code, key_state ) ) { + LCUIIME_ToText( e ); + return TRUE; + } } return FALSE; } -/* 提交输入法输入的内容至目标 */ -LCUI_API int LCUIIME_Commit( const wchar_t *str ) +int LCUIIME_Commit( const wchar_t *str, int length ) { - LCUI_Widget widget; - LCUI_WidgetEvent event; - - if( current_ime == NULL ) { - return -1; + LCUI_SysEventRec sys_ev; + if( length < 0 ) { + length = wcslen( str ); } - if( current_ime->func.gettarget == NULL ) { - return -2; + sys_ev.type = LCUI_TEXTINPUT; + sys_ev.text.length = length; + sys_ev.text.text = NEW( wchar_t, length + 1 ); + if( !sys_ev.text.text ) { + return -ENOMEM; } - widget = current_ime->func.gettarget(); - if(! widget ) { - return -3; - } - /* 设置事件 */ - event.type = EVENT_INPUT; - wcscpy( event.input.text, str ); - /* 派发事件 */ - return Widget_DispatchEvent( widget, &event ); -} - -/* 设置输入法的目标 */ -LCUI_API int LCUIIME_SetTarget( LCUI_Widget widget ) -{ - if( current_ime == NULL ) { - return -1; - } - if( current_ime->func.settarget == NULL ) { - return -2; - } - current_ime->func.settarget( widget ); + wcsncpy( sys_ev.text.text, str, length + 1 ); + LCUI_TriggerEvent( &sys_ev, NULL ); + free( sys_ev.text.text ); + sys_ev.text.text = NULL; + sys_ev.text.length = 0; return 0; } -static int LCUI_DefaultIMERegister(void); +int LCUIIME_SetTarget( LCUI_Widget widget ) +{ + if( self.ime && self.ime->handler.settarget ) { + self.ime->handler.settarget( widget ); + return 0; + } + return -1; +} + +LCUI_Widget LCUIIME_GetTarget( void ) +{ + if( self.ime && self.ime->handler.gettarget ) { + return self.ime->handler.gettarget(); + } + return NULL; +} +int LCUIIME_ClearTarget( void ) +{ + if( self.ime && self.ime->handler.cleartarget ) { + self.ime->handler.cleartarget(); + return 0; + } + return -1; +} + +static int LCUI_RegisterDefaultIME( void ); /* 初始化LCUI输入法模块 */ -LCUI_API void LCUI_InitIME(void) +void LCUI_InitIME( void ) { int ime_id; - Queue_Init( &imelist, sizeof(LCUIIME_Info), LCUIIME_DestroyInfo ); - imelist_init = TRUE; - ime_id = LCUI_DefaultIMERegister(); + LinkedList_Init( &self.list ); + self.is_inited = TRUE; + ime_id = LCUI_RegisterDefaultIME(); LCUIIME_Select( ime_id ); } /* 停用LCUI输入法模块 */ -LCUI_API void LCUIModule_IME_End(void) +void LCUI_ExitIME( void ) { - imelist_init = FALSE; + self.is_inited = FALSE; + LinkedList_ClearData( &self.list, LCUIIME_OnDestroy ); } /*-------------------------- 默认的输入法 ------------------------------*/ -// 目标部件 -static LCUI_Widget target_widget = NULL; +#ifdef LCUI_BUILD_IN_WIN32 +#include +#include LCUI_EVENTS_H +#endif + +static struct { + LCUI_Widget target; +} default_ime; + /** 判断按键是否需要处理,也可以用于设置当前的输入法,比如: @@ -403,12 +431,17 @@ static LCUI_BOOL IME_ProcessKey( int key, int key_state ) static void IME_SetTarget( LCUI_Widget widget ) { - target_widget = widget; + default_ime.target = widget; } -static LCUI_Widget* IME_GetTarget( void ) +static LCUI_Widget IME_GetTarget( void ) { - return target_widget; + return default_ime.target; +} + +static void IME_ClearTarget( void ) +{ + default_ime.target = NULL; } static void IME_ToText( char ch ) @@ -424,37 +457,54 @@ static void IME_ToText( char ch ) text[0] = ch; text[1] = '\0'; DEBUG_MSG("%S, %d\n", text, ch); - LCUIIME_Commit( text ); // 直接提交该字符 + LCUIIME_Commit( text, 2 ); // 直接提交该字符 } + +#ifdef LCUI_BUILD_IN_WIN32 + +static void WinIME_OnChar( LCUI_Event e, void *arg ) +{ + MSG *msg = arg; + wchar_t text[2]; + text[0] = msg->wParam; + text[1] = 0; + LCUIIME_Commit( text, 2 ); +} + +#endif + /** - 输入法被打开时的处理 - 可以在输入法被打开时,初始化相关数据,链接至词库什么的 + * 输入法被打开时的处理 + * 可以在输入法被打开时,初始化相关数据,链接至词库什么的 **/ static LCUI_BOOL IME_Open(void) { +#ifdef LCUI_BUILD_IN_WIN32 + LCUI_BindSysEvent( WM_CHAR, WinIME_OnChar, NULL, NULL ); +#endif return TRUE; } - -/* 输入法被关闭时的处理 */ +/** 输入法被关闭时的处理 */ static LCUI_BOOL IME_Close(void) { +#ifdef LCUI_BUILD_IN_WIN32 + LCUI_UnbindSysEvent( WM_CHAR, WinIME_OnChar ); +#endif return TRUE; } -/* 注册LCUI默认的输入法 */ -static int LCUI_DefaultIMERegister(void) +/** 注册LCUI默认的输入法 */ +static int LCUI_RegisterDefaultIME( void ) { - LCUIIME_Func ime_func; - ime_func.gettarget = IME_GetTarget; - ime_func.settarget = IME_SetTarget; - ime_func.prockey = IME_ProcessKey; - ime_func.totext = IME_ToText; - ime_func.close = IME_Close; - ime_func.open = IME_Open; - return LCUIIME_Register( "LCUI Input Method", &ime_func ); + LCUI_IMEHandlerRec handler; + handler.gettarget = IME_GetTarget; + handler.settarget = IME_SetTarget; + handler.cleartarget = IME_ClearTarget; + handler.prockey = IME_ProcessKey; + handler.totext = IME_ToText; + handler.close = IME_Close; + handler.open = IME_Open; + return LCUIIME_Register( "LCUI Input Method", &handler ); } -/*------------------------------ END ----------------------------------*/ - -#endif diff --git a/src/input/Makefile.am b/src/input/Makefile.am deleted file mode 100755 index 231e788a..00000000 --- a/src/input/Makefile.am +++ /dev/null @@ -1,5 +0,0 @@ -AUTOMAKE_OPTIONS=foreign -AM_CFLAGS = -I$(abs_top_srcdir)/include -noinst_LTLIBRARIES = libinput.la -libinput_la_SOURCES = mouse.c keyboard.c touchscreen.c - diff --git a/src/input/keyboard.c b/src/input/keyboard.c deleted file mode 100755 index e1541937..00000000 --- a/src/input/keyboard.c +++ /dev/null @@ -1,312 +0,0 @@ - /* *************************************************************************** - * keyboard.c -- keyboard support - * - * Copyright (C) 2013-2016 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 . - * ***************************************************************************/ - -/* **************************************************************************** - * keyboard.c -- 键盘支持 - * - * 版权所有 (C) 2013-2016 归属于 刘超 - * - * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 - * - * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) - * - * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 - * - * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 - * 定用途的隐含担保,详情请参照GPLv2许可协议。 - * - * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 - * 没有,请查看:. - * ***************************************************************************/ - -#include -#include -#include -#include - -#include - -#include - -typedef struct KeyState { - int key_code; /**< 按键键值 */ - int state; /**< 当前状态 */ - clock_t hit_time; /**< 按下此键时的时间 */ - clock_t interval_time; /**< 近两次按下此键的时间间隔 */ -} KeyState; - -static LCUI_Mutex record_mutex; -static LinkedList key_state_record; - -#ifdef LCUI_KEYBOARD_DRIVER_LINUX - -//#define __NEED_CATCHSCREEN__ -#ifdef __NEED_CATCHSCREEN__ -#include -#include -#endif - -#include -#include -#include - -static struct termios tm;//, tm_old; -static int fd = STDIN_FILENO; -#endif - -/** 获取指定按键的状态数据 */ -static KeyState *GetKeySate( int key_code ) -{ - KeyState *ks; - LinkedListNode *node; - - LinkedList_ForEach( node, &key_state_record ) { - ks = (KeyState*)node->data; - if( ks && ks->key_code == key_code ) { - return ks; - } - } - return NULL; -} - -/** 检测指定键值的按键是否处于按下状态 */ -LCUI_BOOL LCUIKey_IsHit( int key_code ) -{ - KeyState *ks; - LCUIMutex_Lock( &record_mutex ); - ks = GetKeySate( key_code ); - LCUIMutex_Unlock( &record_mutex ); - if( ks && ks->state == LCUIKEYSTATE_PRESSED ) { - return TRUE; - } - return FALSE; -} - -/** -检测指定键值的按键是否按了两次 -@param key_code - 要检测的按键的键值 -@param interval_time - 该按键倒数第二次按下时的时间与当前时间的最大间隔 - */ -LCUI_BOOL LCUIKey_IsDoubleHit( int key_code, int interval_time ) -{ - clock_t ct; - KeyState* ks; - /* 计算当前时间(单位:毫秒) */ - ct = clock()*1000 / CLOCKS_PER_SEC; - LCUIMutex_Lock( &record_mutex ); - ks = GetKeySate( key_code ); - LCUIMutex_Unlock( &record_mutex ); - if( !ks ) { - return FALSE; - } - /* 间隔时间为-1,说明该键是新记录的 */ - if( ks->interval_time == -1 ) { - return FALSE; - } - ct -= (ks->hit_time - ks->interval_time); - /* 判断按键被按下两次时是否在距当前interval_time毫秒的时间内发生 */ - if( ct <= interval_time ) { - return TRUE; - } - return FALSE; -} - -/** 添加已被按下的按键 */ -void LCUIKeyBoard_HitKey( int key_code ) -{ - clock_t ct; - KeyState *ks; - - LCUIMutex_Lock( &record_mutex ); - ct = clock()*1000 / CLOCKS_PER_SEC; - ks = GetKeySate( key_code ); - if( !ks ) { - ks = NEW(KeyState, 1); - ks->key_code = key_code; - ks->interval_time = -1; - ks->hit_time = ct; - ks->state = LCUIKEYSTATE_PRESSED; - LinkedList_Append( &key_state_record, ks ); - LCUIMutex_Unlock( &record_mutex ); - return; - } - if( ks->state == LCUIKEYSTATE_RELEASE ) { - ks->state = LCUIKEYSTATE_PRESSED; - /* 记录与上次此键被按下时的时间间隔 */ - ks->interval_time = ct - ks->hit_time; - /* 记录本次此键被按下时的时间 */ - ks->hit_time = ct; - } - LCUIMutex_Unlock( &record_mutex ); -} - -/** 标记指定键值的按键已释放 */ -void LCUIKeyBoard_ReleaseKey( int key_code ) -{ - KeyState *ks; - LCUIMutex_Lock( &record_mutex ); - ks = GetKeySate( key_code ); - if( ks ) { - ks->state = LCUIKEYSTATE_RELEASE; - } - LCUIMutex_Unlock( &record_mutex ); -} - -/* 初始化键盘输入 */ -static LCUI_BOOL LCUIKeyboard_Init( void ) -{ -#ifdef LCUI_KEYBOARD_DRIVER_LINUX - if(tcgetattr(fd, &tm) < 0) { - return -1; - } - /* 设置终端为无回显无缓冲模式 */ - tm.c_lflag &= ~(ICANON|ECHO); - tm.c_cc[VMIN] = 1; - tm.c_cc[VTIME] = 0; - if(tcsetattr(fd, TCSANOW, &tm) < 0) { - return -1; - } - printf("\033[?25l");/* 隐藏光标 */ -#endif - return 0; -} - -/* 停用键盘输入 */ -static LCUI_BOOL LCUIKeyboard_Exit( void ) -{ -#ifdef LCUI_KEYBOARD_DRIVER_LINUX - tm.c_lflag |= ICANON; - tm.c_lflag |= ECHO; - tm.c_cc[VMIN] = 1; - tm.c_cc[VTIME] = 0; - if(tcsetattr(fd,TCSANOW,&tm)<0) { - return FALSE; - } - printf("\033[?25h"); /* 显示光标 */ -#endif - return TRUE; -} - -static void OnKeyboardEvent( LCUI_SysEvent e, void *arg ) -{ - if( e->type == LCUI_KEYDOWN ) { - LCUIKeyBoard_HitKey( e->key_code ); - } - else if( e->type == LCUI_KEYUP ) { - LCUIKeyBoard_ReleaseKey( e->key_code ); - } -} - -/** 检测键盘是否有按键按下(类似于kbhit函数) */ -LCUI_BOOL LCUIKeyboard_IsHit( void ) -{ -#ifdef LCUI_KEYBOARD_DRIVER_LINUX - struct termios oldt;//, newt; - int ch, oldf; - tcgetattr(STDIN_FILENO, &oldt); - //newt = oldt; - //newt.c_lflag &= ~(ICANON | ECHO); - //tcsetattr(STDIN_FILENO, TCSANOW, &newt); - oldf = fcntl(STDIN_FILENO, F_GETFL, 0); - fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK); - ch = getchar(); /* 获取一个字符 */ - tcsetattr(STDIN_FILENO, TCSANOW, &oldt); - fcntl(STDIN_FILENO, F_SETFL, oldf); - /* 如果字符有效,将字符放回输入缓冲区中 */ - if(ch != EOF) { - ungetc(ch, stdin); - return TRUE; - } - return FALSE; -#endif - return FALSE; -} - -/** 获取被按下的按键的键值(类似于getch函数) */ -int LCUIKeyboard_GetKey( void ) -{ -#ifdef LCUI_KEYBOARD_DRIVER_LINUX - int k,c; - static int input = 0, count = 0; - ++count; - /* 获取输入缓冲中的字符 */ - k = fgetc(stdin); - input += k; - /* 如果还有字符在缓冲中 */ - if(LCUIKeyboard_IsHit()) { - LCUIKeyboard_GetKey(); - } - c = input; - --count; - /* 递归结束后就置0 */ - if(count == 0) { - input = 0; - } - if(c == 3) { - exit(1); - } - return c; -#else - return -1; -#endif -} - -#ifdef LCUI_KEYBOARD_DRIVER_LINUX -static LCUI_BOOL LCUIKeyboard_Proc(void) -{ - LCUI_SysEventRec e; - /* 如果没有按键输入 */ - if ( !LCUIKeyboard_IsHit() ) { - return FALSE; - } - - e.type = LCUI_KEYDOWN; - e.key_code = LCUIKeyboard_GetKey(); - LCUI_TriggerEvent( &e, NULL ); - return TRUE; -} -#endif - -/** 初始化键盘输入模块 */ -int LCUI_InitKeyboard( void ) -{ - int ret; - LCUIMutex_Init( &record_mutex ); - LinkedList_Init( &key_state_record ); - nobuff_printf("[keyboard] set event ... "); - ret = LCUI_BindEvent( LCUI_KEYDOWN, OnKeyboardEvent, NULL, NULL ); - ret |= LCUI_BindEvent( LCUI_KEYUP, OnKeyboardEvent, NULL, NULL ); - nobuff_printf(ret < 0 ? "failed\n":"ok\n"); -#ifdef LCUI_KEYBOARD_DRIVER_LINUX - ret |= LCUIDevice_Add( LCUIKeyboard_Init, LCUIKeyboard_Proc, LCUIKeyboard_Exit ); -#endif - return ret; -} - -/** 停用键盘输入模块 */ -int LCUI_ExitKeyboard( void ) -{ - LinkedList_Clear( &key_state_record, free ); - LCUIMutex_Destroy( &record_mutex ); - return 0; -} diff --git a/src/input/mouse.c b/src/input/mouse.c deleted file mode 100644 index ef27ec76..00000000 --- a/src/input/mouse.c +++ /dev/null @@ -1,217 +0,0 @@ -/* *************************************************************************** - * mouse.c -- mouse input support. - * - * Copyright (C) 2012-2016 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 . - * ***************************************************************************/ - -/* **************************************************************************** - * mouse.c -- 鼠标输入支持。 - * - * 版权所有 (C) 2012-2016 归属于 刘超 - * - * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 - * - * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) - * - * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 - * - * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 - * 定用途的隐含担保,详情请参照GPLv2许可协议。 - * - * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 - * 没有,请查看:. - * ***************************************************************************/ - -#include -#include -#include -#include - -#ifdef LCUI_MOUSE_DRIVER_LINUX -#include -#include -#include - -#define MS_DEV "/dev/input/mice" /* 鼠标设备 */ -#endif - -enum LCUIMouseState { - STATE_REMOVE, - STATE_INSIDE -}; - -static struct LCUIMouseDeviceContext { -#ifdef LCUI_MOUSE_DRIVER_LINUX - int fd; /**< 鼠标设备标示符 */ - int state; /**< 鼠标设备的状态 */ -#elif defined(LCUI_BUILD_IN_WIN32) - int x, y; -#endif - int button_state[2]; /** 鼠标左右键的状态 */ -} mouse = { -#ifdef LCUI_MOUSE_DRIVER_LINUX - 0, 0, -#elif defined(LCUI_BUILD_IN_WIN32) - 0, 0, -#endif - {LCUIKEYSTATE_RELEASE, LCUIKEYSTATE_RELEASE} -}; - -static void OnMouseButtonEvent( LCUI_SysEvent e, void *arg ) -{ - if( e->key_code < 1 || e->key_code > 2 ) { - return; - } - DEBUG_MSG("key_code: %d\n", e->key_code); - switch( e->type ) { - case LCUI_MOUSEDOWN: - mouse.button_state[e->key_code] = LCUIKEYSTATE_PRESSED; - break; - case LCUI_MOUSEUP: - mouse.button_state[e->key_code] = LCUIKEYSTATE_RELEASE; - default:break; - } -} - -#ifdef LCUI_MOUSE_DRIVER_LINUX -static LCUI_BOOL MouseProc( void ) -{ - static int tmp; - static char buf[6]; - static fd_set readfds; - static struct timeval tv; - - if (mouse.state == STATE_REMOVE || mouse.fd < 0) { - return FALSE; - } - /* 设定select等待I/o的最长时间 */ - tv.tv_sec = 0; - tv.tv_usec = 0; - - FD_ZERO (&readfds); - FD_SET (mouse.fd, &readfds); - - tmp = select (mouse.fd+1, &readfds, NULL, NULL, &tv); - if (tmp == 0) { - //printf("Time out!\n"); - return FALSE; - } - if ( !FD_ISSET (mouse.fd, &readfds) ) { - return FALSE; - } - tmp = read (mouse.fd, buf, 6); - if (tmp <= 0){ - if (tmp < 0) { - mouse.state = STATE_REMOVE; - } - return FALSE; - } - - return TRUE; -} -#else - -static LCUI_BOOL MouseProc( void ) -{ - POINT new_pos; - LCUI_SysEventRec e; - static LCUI_Pos old_pos = {0, 0}; - - /* 如果是无缝模式则获取系统鼠标游标的坐标 */ - if( LCUIDisplay_GetMode() == LDM_SEAMLESS ) { - GetCursorPos( &new_pos ); - } else { - new_pos.x = mouse.x; - new_pos.y = mouse.y; - } - e.type = LCUI_MOUSEMOVE; - e.rel_x = new_pos.x - old_pos.x; - e.rel_y = new_pos.y - old_pos.y; - if( e.rel_x == 0 && e.rel_y == 0 ) { - return FALSE; - } - old_pos.x = new_pos.x; - old_pos.y = new_pos.y; - DEBUG_MSG("x: %d, y: %d, rel_x: %d, rel_y: %d\n", new_pos.x, new_pos.y, e.rel_x, e.rel_y); - LCUI_TriggerEvent( &e, NULL ); - return TRUE; -} - -void LCUIMouse_SetPos( int x, int y ) -{ - mouse.x = x; - mouse.y = y; -} -#endif - -/** 初始化鼠标输入处理 */ -static LCUI_BOOL MouseInit(void) -{ -#ifdef LCUI_MOUSE_DRIVER_LINUX - char *msdev, err_str[64]; - - if(mouse.state != STATE_REMOVE) { - return FALSE; - } - msdev = getenv("LCUI_MOUSE_DEVICE"); - if( msdev == NULL ) { - msdev = MS_DEV; - } - if ((mouse.fd = open (MS_DEV, O_RDONLY)) < 0) { - sprintf(err_str, "[mouse] failed to open %s", msdev); - perror(err_str); - mouse.state = STATE_REMOVE; - return FALSE; - } - mouse.state = STATE_INSIDE; - printf("[mouse] open %s successfuly.\n", msdev); -#else - /* 隐藏windows的鼠标游标 */ - ShowCursor( FALSE ); -#endif - return TRUE; -} - -/** 退出鼠标输入处理 */ -static LCUI_BOOL MouseExit(void) -{ -#ifdef LCUI_MOUSE_DRIVER_LINUX - if( mouse.state != STATE_INSIDE ) { - return FALSE; - } - close( mouse.fd ); - mouse.state = STATE_REMOVE; -#endif - return TRUE; -} - -/** 初始化鼠标输入模块 */ -int LCUI_InitMouse( void ) -{ - int ret; -#ifdef LCUI_MOUSE_DRIVER_LINUX - mouse.fd = -1; - mouse.state = STATE_REMOVE; /* 鼠标为移除状态 */ -#endif - nobuff_printf("[mouse] set event ... "); - ret = LCUI_BindEvent( LCUI_MOUSEDOWN, OnMouseButtonEvent, NULL, NULL ); - ret |= LCUI_BindEvent( LCUI_MOUSEUP, OnMouseButtonEvent, NULL, NULL ); - nobuff_printf(ret < 0 ? "failed\n":"ok\n"); - ret |= LCUIDevice_Add( MouseInit, MouseProc, MouseExit ); - return ret; -} diff --git a/src/input/touchscreen.c b/src/input/touchscreen.c deleted file mode 100755 index a4215de3..00000000 --- a/src/input/touchscreen.c +++ /dev/null @@ -1,171 +0,0 @@ -/* *************************************************************************** - * touchscreen.c -- touchscreen support - * - * 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 . - * ****************************************************************************/ - -/* **************************************************************************** - * touchscreen.c -- 触屏支持 - * - * 版权所有 (C) 2013 归属于 - * 刘超 - * - * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 - * - * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) - * - * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 - * - * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 - * 定用途的隐含担保,详情请参照GPLv2许可协议。 - * - * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 - * 没有,请查看:. - * ****************************************************************************/ - -#include -#include -#include -#include -#include - -#define STATE_REMOVE 0 -#define STATE_INSIDE 1 - -#define TS_DEV "/dev/ts" - -#ifdef USE_TSLIB -#include -#endif - -typedef struct _LCUI_TS { - void *td; - int state; -} LCUI_TS; - -static LCUI_TS ts_data; - -static LCUI_BOOL proc_touchscreen(void) -{ -#ifdef USE_TSLIB - struct ts_sample samp; - int button, ret; - static LCUI_Pos pos; - - if (ts_data.state != STATE_INSIDE) { - return FALSE; - } - - /* 开始获取触屏点击处的坐标 */ - ret = ts_read (ts_data.td, &samp, 1); - if (ret < 0) { - perror ("ts_read"); - return FALSE; - } - - if (ret != 1) { - return FALSE; - } - pos.x = samp.x; - pos.y = samp.y; - - if (pos.x > LCUIScreen_GetWidth ()) { - pos.x = LCUIScreen_GetWidth (); - } - if (pos.y > LCUIScreen_GetHeight ()) { - pos.y = LCUIScreen_GetHeight (); - } - pos.x = pos.x<0 ? 0:pos.x; - pos.y = pos.y<0 ? 0:pos.y; - LCUICursor_SetPos( pos ); - LCUI_PushMouseMotionEvent( pos ); - if( samp.pressure > 0 ) { - LCUIMouse_ButtonDown( new_pos, LCUIKEY_LEFTBUTTON ); - LCUIMouse_ButtonUp( new_pos, LCUIKEY_RIGHTBUTTON ); - } - //printf("%ld.%06ld: %6d %6d %6d\n", samp.tv.tv_sec, samp.tv.tv_usec, samp.x, samp.y, samp.pressure); - return TRUE; -#else - return FALSE; -#endif -} - -/** 启用触屏输入处理 */ -LCUI_BOOL EnableTouchScreenInput(void) -{ -#ifdef USE_TSLIB - char *tsdevice; - char str[256]; - if (ts_data.state != STATE_INSIDE) { - tsdevice = getenv("TSLIB_TSDEVICE"); - if( tsdevice ) { - ts_data.td = ts_open(tsdevice, 0); - } else { - tsdevice = TS_DEV; - } - ts_data.td = ts_open (tsdevice, 0); - if (!ts_data.td) { - sprintf (str, "ts_open: %s", tsdevice); - perror (str); - ts_data.state = STATE_REMOVE; - return FALSE; - } - - if (ts_config (ts_data.td)) { - perror ("ts_config"); - ts_data.state = STATE_REMOVE; - return FALSE; - } - ts_data.state = STATE_INSIDE; - } - return TRUE; -#else - return FALSE; -#endif -} - -/** 禁用触屏输入处理 */ -LCUI_BOOL DisableTouchScreenInput(void) -{ -#ifdef USE_TSLIB - if(ts_data.state == STATE_INSIDE) { - ts_close(ts_data.td); - ts_data.state = STATE_REMOVE; - return TRUE; - } - return FALSE; -#else - return FALSE; -#endif -} - -/* 获取触屏的私有数据 */ -void* Get_TouchScreen(void) -{ - return ts_data.td; -} - -/* 初始化触屏输入模块 */ -void LCUI_InitTouchScreen( void ) -{ - ts_data.td = NULL; - ts_data.state = STATE_REMOVE; - LCUIDevice_Add( EnableTouchScreenInput, proc_touchscreen, - DisableTouchScreenInput ); -} diff --git a/src/keyboard.c b/src/keyboard.c new file mode 100644 index 00000000..c30d6e6f --- /dev/null +++ b/src/keyboard.c @@ -0,0 +1,161 @@ +/* *************************************************************************** + * keyboard.c -- keyboard input management + * + * Copyright (C) 2016 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * keyboard.c -- 键盘输入管理 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +typedef struct KeyStateNodeRec_ { + int state; /**< 当前状态 */ + clock_t hit_time; /**< 按下此键时的时间 */ + clock_t interval_time; /**< 近两次按下此键的时间间隔 */ +} KeyStateNodeRec, *KeyStateNode; + +static struct LCUIKeyboardModule { + LCUI_Mutex mutex; + LCUI_RBTree state_tree; +} self; + +/** 检测指定键值的按键是否处于按下状态 */ +LCUI_BOOL LCUIKeyboard_IsHit( int key_code ) +{ + KeyStateNode node; + LCUIMutex_Lock( &self.mutex ); + node = RBTree_GetData( &self.state_tree, key_code ); + LCUIMutex_Unlock( &self.mutex ); + if( node && node->state == LCUIKEYSTATE_PRESSED ) { + return TRUE; + } + return FALSE; +} + +/** + * 检测指定键值的按键是否按了两次 + * @param key_code 要检测的按键的键值 + * @param interval_time 该按键倒数第二次按下时的时间与当前时间的最大间隔 +*/ +LCUI_BOOL LCUIKeyboard_IsDoubleHit( int key_code, int interval_time ) +{ + clock_t ct; + KeyStateNode node; + /* 计算当前时间(单位:毫秒) */ + ct = clock() * 1000 / CLOCKS_PER_SEC; + LCUIMutex_Lock( &self.mutex ); + node = RBTree_GetData( &self.state_tree, key_code ); + LCUIMutex_Unlock( &self.mutex ); + if( !node ) { + return FALSE; + } + /* 间隔时间为-1,说明该键是新记录的 */ + if( node->interval_time == -1 ) { + return FALSE; + } + ct -= node->hit_time - node->interval_time; + /* 判断按键被按下两次时是否在距当前 interval_time 毫秒的时间内发生 */ + if( ct <= interval_time ) { + return TRUE; + } + return FALSE; +} + +/** 添加已被按下的按键 */ +void LCUIKeyboard_HitKey( int key_code ) +{ + clock_t ct; + KeyStateNode node; + LCUIMutex_Lock( &self.mutex ); + ct = clock() * 1000 / CLOCKS_PER_SEC; + node = RBTree_GetData( &self.state_tree, key_code ); + if( !node ) { + node = NEW( KeyStateNodeRec, 1 ); + node->interval_time = -1; + node->hit_time = ct; + node->state = LCUIKEYSTATE_PRESSED; + RBTree_Insert( &self.state_tree, key_code, node ); + LCUIMutex_Unlock( &self.mutex ); + return; + } + if( node->state == LCUIKEYSTATE_RELEASE ) { + node->state = LCUIKEYSTATE_PRESSED; + /* 记录与上次此键被按下时的时间间隔 */ + node->interval_time = ct - node->hit_time; + /* 记录本次此键被按下时的时间 */ + node->hit_time = ct; + } + LCUIMutex_Unlock( &self.mutex ); +} + +/** 标记指定键值的按键已释放 */ +void LCUIKeyboard_ReleaseKey( int key_code ) +{ + KeyStateNode node; + LCUIMutex_Lock( &self.mutex ); + node = RBTree_GetData( &self.state_tree, key_code ); + if( node ) { + node->state = LCUIKEYSTATE_RELEASE; + } + LCUIMutex_Unlock( &self.mutex ); +} + +static void OnKeyboardEvent( LCUI_SysEvent e, void *arg ) +{ + if( e->type == LCUI_KEYDOWN ) { + LCUIKeyboard_HitKey( e->key.code ); + } else if( e->type == LCUI_KEYUP ) { + LCUIKeyboard_ReleaseKey( e->key.code ); + } +} + +void LCUI_InitKeyboard( void ) +{ + LCUIMutex_Init( &self.mutex ); + RBTree_Init( &self.state_tree ); + RBTree_OnDestroy( &self.state_tree, free ); + LCUI_BindEvent( LCUI_KEYDOWN, OnKeyboardEvent, NULL, NULL ); + LCUI_BindEvent( LCUI_KEYUP, OnKeyboardEvent, NULL, NULL ); +} + +void LCUI_ExitKeyboard( void ) +{ + RBTree_Destroy( &self.state_tree ); + LCUIMutex_Destroy( &self.mutex ); +} diff --git a/src/main.c b/src/main.c index d1c7e317..49468c74 100644 --- a/src/main.c +++ b/src/main.c @@ -37,8 +37,6 @@ * 没有,请查看:. * ***************************************************************************/ //#define DEBUG -#define __IN_MAIN_SOURCE_FILE__ - #include #include #include @@ -50,6 +48,7 @@ #include #include #include +#include #include #include LCUI_EVENTS_H #include LCUI_MOUSE_H @@ -82,27 +81,27 @@ static struct LCUI_System { int state; /**< 状态 */ int mode; /**< LCUI的运行模式 */ LCUI_BOOL is_inited; /**< 标志,指示LCUI是否初始化过 */ - unsigned long int main_tid; /**< 主线程ID */ - struct { LCUI_EventTrigger trigger; /**< 系统事件容器 */ LCUI_Mutex mutex; /**< 互斥锁 */ } event; - - int exit_code; /**< 退出码 */ - void (*func_atexit)(void); /**< 在LCUI退出时调用的函数 */ } System; /** LCUI 应用程序数据 */ static struct LCUI_App { - LinkedList tasks; /**< 程序的任务队列 */ - LCUI_Mutex tasks_mutex; /**< 任务记录互斥锁 */ LCUI_Mutex loop_mutex; /**< 互斥锁,确保一次只允许一个线程跑主循环 */ LCUI_Cond loop_changed; /**< 条件变量,用于指示当前运行的主循环是否改变 */ LCUI_MainLoop loop; /**< 当前运行的主循环 */ LinkedList loops; /**< 主循环列表 */ LCUI_AppDriverRec driver; /**< 程序事件驱动支持 */ + LCUI_BOOL driver_ready; /**< 事件驱动支持是否已经准备就绪 */ + struct LCUI_AppTaskAgent { + int state; /**< 状态 */ + LinkedList tasks; /**< 任务队列 */ + LCUI_Mutex mutex; /**< 互斥锁 */ + LCUI_Cond cond; /**< 条件变量 */ + } agent; } MainApp; /*-------------------------- system event ---------------------------*/ @@ -177,14 +176,68 @@ int LCUI_TriggerEvent( LCUI_SysEvent e, void *arg ) return ret; } +void LCUI_DestroyEvent( LCUI_SysEvent e ) +{ + switch( e->type ) { + case LCUI_TOUCH: + if( e->touch.points ) { + free( e->touch.points ); + } + e->touch.points = NULL; + e->touch.n_points = 0; + break; + case LCUI_TEXTINPUT: + if( e->text.text ) { + free( e->text.text ); + } + e->text.text = NULL; + e->text.length = 0; + break; + } + e->type = LCUI_NONE; +} + /*--------------------------- system event ----------------------------*/ +static void LCUI_DispatchEvent( void ) +{ + LCUI_AppTask task; + LinkedListNode *node; + LCUIMutex_Lock( &MainApp.agent.mutex ); + node = LinkedList_GetNode( &MainApp.agent.tasks, 0 ); + if( node ) { + task = node->data; + LinkedList_Unlink( &MainApp.agent.tasks, node ); + LCUIMutex_Unlock( &MainApp.agent.mutex ); + LCUI_RunTask( task ); + LCUI_DeleteTask( task ); + free( task ); + free( node ); + return; + } else { + LCUIMutex_Unlock( &MainApp.agent.mutex ); + } + if( MainApp.agent.state == STATE_RUNNING ) { + return; + } + if( MainApp.driver_ready ) { + MainApp.driver.DispatchEvent(); + } +} + LCUI_BOOL LCUI_PostTask( LCUI_AppTask task ) { - LCUI_AppTask buff; - buff = NEW( LCUI_AppTaskRec, 1 ); - *buff = *task; - return MainApp.driver.PostTask( buff ); + LCUI_AppTask newtask; + newtask = NEW( LCUI_AppTaskRec, 1 ); + *newtask = *task; + LCUIMutex_Lock( &MainApp.agent.mutex ); + LinkedList_Append( &MainApp.agent.tasks, newtask ); + LCUICond_Signal( &MainApp.agent.cond ); + LCUIMutex_Unlock( &MainApp.agent.mutex ); + if( MainApp.driver_ready ) { + return MainApp.driver.PostTask( newtask ); + } + return TRUE; } void LCUI_DeleteTask( LCUI_AppTask task ) @@ -237,11 +290,11 @@ int LCUI_MainLoop_Run( LCUI_MainLoop loop ) } else { LinkedList_Insert( &MainApp.loops, 0, loop ); } - _DEBUG_MSG("loop: %p, enter\n", loop); + DEBUG_MSG("loop: %p, enter\n", loop); MainApp.loop = loop; while( loop->state != STATE_EXITED ) { LCUI_WaitEvent(); - LCUI_PumbEvents(); + LCUI_DispatchEvent(); /* 如果当前运行的主循环不是自己 */ while( MainApp.loop != loop ) { loop->state = STATE_PAUSED; @@ -271,38 +324,75 @@ void LCUI_MainLoop_Quit( LCUI_MainLoop loop ) /** 初始化程序数据结构体 */ static void LCUIApp_Init(void) { + MainApp.driver_ready = FALSE; LCUICond_Init( &MainApp.loop_changed ); LCUIMutex_Init( &MainApp.loop_mutex ); LinkedList_Init( &MainApp.loops ); - LCUIMutex_Init( &MainApp.tasks_mutex ); - LinkedList_Init( &MainApp.tasks ); - LCUI_InitApp( &MainApp.driver ); + LCUIMutex_Init( &MainApp.agent.mutex ); + LCUICond_Init( &MainApp.agent.cond ); + LinkedList_Init( &MainApp.agent.tasks ); + if( LCUI_InitApp( &MainApp.driver ) == 0 ) { + MainApp.driver_ready = TRUE; + } + MainApp.agent.state = STATE_RUNNING; } LCUI_BOOL LCUI_WaitEvent( void ) { - return MainApp.driver.WaitEvent(); + if( MainApp.agent.tasks.length > 0 ) { + return TRUE; + } + if( MainApp.agent.state != STATE_RUNNING ) { + return MainApp.driver.WaitEvent(); + } + LCUIMutex_Lock( &MainApp.agent.mutex ); + while( MainApp.agent.state == STATE_RUNNING ) { + if( MainApp.agent.tasks.length > 0 ) { + LCUIMutex_Unlock( &MainApp.agent.mutex ); + return TRUE; + } + LCUICond_Wait( &MainApp.agent.cond, &MainApp.agent.mutex ); + } + LCUIMutex_Unlock( &MainApp.agent.mutex ); + return FALSE; } int LCUI_BindSysEvent( int event_id, LCUI_EventFunc func, void *data, void( *destroy_data )(void*) ) { - return MainApp.driver.BindSysEvent( event_id, func, data, destroy_data ); + if( MainApp.driver_ready ) { + return MainApp.driver.BindSysEvent( event_id, func, + data, destroy_data ); + } + return -1; } int LCUI_UnbindSysEvent( int event_id, LCUI_EventFunc func ) { - return MainApp.driver.UnbindSysEvent( event_id, func ); -} - -void LCUI_PumbEvents( void ) -{ - MainApp.driver.PumbEvents(); + if( MainApp.driver_ready ) { + return MainApp.driver.UnbindSysEvent( event_id, func ); + } + return -1; } void *LCUI_GetAppData( void ) { - return MainApp.driver.GetData(); + if( MainApp.driver_ready ) { + return MainApp.driver.GetData(); + } + return NULL; +} + +void LCUI_SetTaskAgent( LCUI_BOOL enabled ) +{ + LCUIMutex_Lock( &MainApp.agent.mutex ); + if( enabled ) { + MainApp.agent.state = STATE_RUNNING; + } else { + MainApp.agent.state = STATE_PAUSED; + } + LCUICond_Signal( &MainApp.agent.cond ); + LCUIMutex_Unlock( &MainApp.agent.mutex ); } /** 退出所有主循环 */ @@ -310,7 +400,7 @@ static void LCUIApp_QuitAllMainLoop(void) { LCUI_MainLoop loop; LinkedListNode *node; - LinkedList_ForEach( node, &MainApp.loops ) { + for( LinkedList_Each( node, &MainApp.loops ) ) { loop = node->data; if( loop ) { loop->state = STATE_EXITED; @@ -318,12 +408,18 @@ static void LCUIApp_QuitAllMainLoop(void) } } +static void OnDeleteTask( void *arg ) +{ + LCUI_DeleteTask( arg ); + free( arg ); +} + /* 销毁程序占用的资源 */ static void LCUIApp_Destroy(void) { LCUI_MainLoop loop; LinkedListNode *node; - LinkedList_ForEach( node, &MainApp.loops ) { + for( LinkedList_Each( node, &MainApp.loops ) ) { loop = node->data; LCUI_MainLoop_Quit( loop ); LCUIThread_Join( loop->tid, NULL ); @@ -331,8 +427,10 @@ static void LCUIApp_Destroy(void) /* 开始清理 */ LCUIMutex_Destroy( &MainApp.loop_mutex ); LCUICond_Destroy( &MainApp.loop_changed ); - LCUIMutex_Destroy( &MainApp.tasks_mutex ); + LCUIMutex_Destroy( &MainApp.agent.mutex ); + LCUICond_Destroy( &MainApp.agent.cond ); LinkedList_Clear( &MainApp.loops, free ); + LinkedList_Clear( &MainApp.agent.tasks, OnDeleteTask ); } /** 打印LCUI的信息 */ @@ -374,7 +472,7 @@ static void LCUI_ShowCopyrightText(void) "\n" #endif "Build at "__DATE__" - "__TIME__"\n" - "Copyright (C) 2012-2015 Liu Chao .\n" + "Copyright (C) 2012-2016 Liu Chao .\n" "This is free software, licensed under GPLv2. \n" "See source distribution for detailed copyright notices.\n" "To learn more, visit http://www.lcui.org.\n\n" @@ -409,18 +507,18 @@ int LCUI_Init(void) return -1; } System.is_inited = TRUE; - System.func_atexit = NULL; - System.exit_code = 0; System.state = STATE_ACTIVE; System.main_tid = LCUIThread_SelfID(); LCUI_ShowCopyrightText(); LCUIApp_Init(); /* 初始化各个模块 */ + LCUI_InitMemDebug(); LCUI_InitEvent(); LCUI_InitFont(); LCUI_InitTimer(); LCUI_InitMouseDriver(); LCUI_InitKeyboardDriver(); + LCUI_InitIME(); LCUI_InitWidget(); LCUI_InitDisplay(); LCUI_InitCursor(); @@ -434,14 +532,16 @@ static int LCUI_Destroy( void ) e.type = LCUI_QUIT; LCUI_TriggerEvent( &e, NULL ); System.state = STATE_KILLED; + LCUI_ExitIME(); LCUI_ExitEvent(); LCUI_ExitCursor(); LCUI_ExitWidget(); LCUI_ExitFont(); LCUI_ExitTimer(); LCUI_ExitDisplay(); + LCUI_ExitMemDebug(); LCUIApp_Destroy(); - return System.exit_code; + return 0; } void LCUI_Quit(void) @@ -450,12 +550,6 @@ void LCUI_Quit(void) LCUIApp_QuitAllMainLoop(); } -void LCUI_Exit( int exit_code ) -{ - System.exit_code = exit_code; - LCUI_Quit(); -} - /* * 功能:LCUI程序的主循环 * 说明:每个LCUI程序都需要调用它,此函数会让程序执行LCUI分配的任务 diff --git a/src/output/Makefile.am b/src/output/Makefile.am deleted file mode 100755 index 1e495df3..00000000 --- a/src/output/Makefile.am +++ /dev/null @@ -1,4 +0,0 @@ -AUTOMAKE_OPTIONS=foreign -AM_CFLAGS = -I$(abs_top_srcdir)/include -noinst_LTLIBRARIES = liboutput.la -liboutput_la_SOURCES = dummy.c win32_surface.c linuxfb_surface.c graph_display.c diff --git a/src/output/dummy.c b/src/output/dummy.c deleted file mode 100755 index a10c4695..00000000 --- a/src/output/dummy.c +++ /dev/null @@ -1,101 +0,0 @@ -/* *************************************************************************** - * dummy.c -- if not found graphical output support, use this sourcefile - * - * 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 . - * ****************************************************************************/ - -/* **************************************************************************** - * dummy.c -- 通常在找不到合适的图形输出支持的情况下,使用该源文件,用虚设函数凑数 - * - * 版权所有 (C) 2013 归属于 - * 刘超 - * - * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 - * - * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) - * - * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 - * - * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 - * 定用途的隐含担保,详情请参照GPLv2许可协议。 - * - * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 - * 没有,请查看:. - * ****************************************************************************/ - -#include -#include - -#ifdef LCUI_VIDEO_DRIVER_NONE - -LCUI_API void -LCUIScreen_FillPixel( LCUI_Pos pos, LCUI_RGB color ) -{ - return; -} - -LCUI_API int -LCUIScreen_GetGraph( LCUI_Graph *out ) -{ - return -1; -} - - -LCUI_API int -LCUIScreen_Init( int w, int h, int mode ) -{ - return -1; -} - - -/* 设置视频输出模式 */ -LCUI_API int -LCUIScreen_SetMode( int w, int h, int mode ) -{ - return -1; -} - - -LCUI_API int -LCUIScreen_Destroy( void ) -{ - return -1; -} - - -LCUI_API void -LCUIScreen_SyncFrameBuffer( void ) -{ - return; -} - - -LCUI_API int -LCUIScreen_PutGraph (LCUI_Graph *graph, LCUI_Pos des_pos ) -{ - return -1; -} - -LCUI_API void -LCUIScreen_CatchGraph( LCUI_Rect area, LCUI_Graph *out ) -{ - return; -} - -#endif diff --git a/src/output/linuxfb_surface.c b/src/output/linuxfb_surface.c deleted file mode 100644 index 1e89b6b2..00000000 --- a/src/output/linuxfb_surface.c +++ /dev/null @@ -1,476 +0,0 @@ -/* *************************************************************************** - * linuxfb_surface.c -- surface support for linux framebuffer. - * - * Copyright (C) 2015 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 . - * ***************************************************************************/ - -/* **************************************************************************** - * linuxfb_surface.c -- 基于linux平台帧缓冲(framebuffer)的 surface 功能支持。 - * - * 版权所有 (C) 2015 归属于 刘超 - * - * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 - * - * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) - * - * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 - * - * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 - * 定用途的隐含担保,详情请参照GPLv2许可协议。 - * - * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 - * 没有,请查看:. - * ***************************************************************************/ - -#include -#ifdef LCUI_VIDEO_DRIVER_FRAMEBUFFER -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#define FB_DEV "/dev/fb0" -#define FB_BACKUP_FILE "/tmp/framebuffer.bak" - -static struct LinuxFBContext { - int dev_fd; - uchar_t *mem; - int mem_len; - int bits_per_pixel; - int bytes_per_line; - int width, height; - LCUI_SurfaceMethods methods; -} linuxfb; - -/** 备份帧缓冲内容 */ -static int LinuxFB_Backup(void) -{ - char cmd[256], *fb_dev; - fb_dev = getenv("LCUI_FB_DEVICE"); - if(fb_dev == NULL) { - fb_dev = FB_DEV; - } - sprintf( cmd, "cat %s > %s", fb_dev, FB_BACKUP_FILE ); - return system( cmd ); -} - -/** 恢复帧缓冲内容 */ -static int LinuxFB_Restore(void) -{ - char cmd[256], *fb_dev; - fb_dev = getenv("LCUI_FB_DEVICE"); - if(fb_dev == NULL) { - fb_dev = FB_DEV; - } - sprintf( cmd, "cat %s > %s", FB_BACKUP_FILE, fb_dev ); - return system( cmd ); -} - -static int LinuxFB_GetWidth(void) -{ - return linuxfb.width; -} - -static int LinuxFB_GetHeight(void) -{ - return linuxfb.height; -} - -/** 打印屏幕相关的信息 */ -static void print_screeninfo( struct fb_var_screeninfo fb_vinfo, - struct fb_fix_screeninfo fb_fix ) -{ - char visual[256], type[256]; - - switch(fb_fix.type) { - case FB_TYPE_PACKED_PIXELS: - strcpy(type, "packed pixels");break; - case FB_TYPE_PLANES: - strcpy(type, "non interleaved planes");break; - case FB_TYPE_INTERLEAVED_PLANES: - strcpy(type, "interleaved planes");break; - case FB_TYPE_TEXT: - strcpy(type, "text/attributes");break; - case FB_TYPE_VGA_PLANES: - strcpy(type, "EGA/VGA planes");break; - default: - strcpy(type, "unkown");break; - } - - switch(fb_fix.visual) { - case FB_VISUAL_MONO01: - strcpy(visual, "Monochr. 1=Black 0=White");break; - case FB_VISUAL_MONO10: - strcpy(visual, "Monochr. 1=White 0=Black");break; - case FB_VISUAL_TRUECOLOR: - strcpy(visual, "true color");break; - case FB_VISUAL_PSEUDOCOLOR: - strcpy(visual, "pseudo color (like atari)");break; - case FB_VISUAL_DIRECTCOLOR: - strcpy(visual, "direct color");break; - case FB_VISUAL_STATIC_PSEUDOCOLOR: - strcpy(visual, "pseudo color readonly");break; - default: - strcpy(type, "unkown");break; - } - printf( - "============== screen info =============\n" - "FB mem start : 0x%08lX\n" - "FB mem length : %d\n" - "FB type : %s\n" - "FB visual : %s\n" - "accel : %d\n" - "geometry : %d %d %d %d %d\n" - "timings : %d %d %d %d %d %d\n" - "rgba : %d/%d, %d/%d, %d/%d, %d/%d\n" - "========================================\n", - fb_fix.smem_start, fb_fix.smem_len, - type, visual, - fb_fix.accel, - fb_vinfo.xres, fb_vinfo.yres, - fb_vinfo.xres_virtual, fb_vinfo.yres_virtual, - fb_vinfo.bits_per_pixel, - fb_vinfo.upper_margin, fb_vinfo.lower_margin, - fb_vinfo.left_margin, fb_vinfo.right_margin, - fb_vinfo.hsync_len, fb_vinfo.vsync_len, - fb_vinfo.red.length, fb_vinfo.red.offset, - fb_vinfo.green.length, fb_vinfo.green.offset, - fb_vinfo.blue.length, fb_vinfo.blue.offset, - fb_vinfo. transp.length, fb_vinfo. transp.offset - ); -} - -static LCUI_Surface LinuxFB_New(void) -{ - return (void*)&linuxfb.dev_fd; -} - -static void LinuxFB_Delete( LCUI_Surface surface ) -{ - -} - -static void LinuxFB_Resize( LCUI_Surface surface, int w, int h ) -{ - // ... -} - -static LCUI_BOOL LinuxFB_IsReady( LCUI_Surface surface ) -{ - return TRUE; -} - -static void LinuxFB_Update( LCUI_Surface surface ) -{ - -} - -static void LinuxFB_SetRenderMode( LCUI_Surface surface, int mode ) -{ - // ... -} - -LCUI_PaintContext LinuxFB_BeginPaint( LCUI_Surface surface, LCUI_Rect *rect ) -{ - LCUI_PaintContext paint; - paint = (LCUI_PaintContext)malloc(sizeof(LCUI_PaintContextRec)); - Graph_Init( &paint->canvas ); - Graph_Create( &paint->canvas, rect->w, rect->h ); - paint->rect = *rect; - _DEBUG_MSG("canvas: %p, rect: %d,%d,%d,%d\n", - &paint->canvas, rect->x, rect->y, rect->w, rect->h); - return paint; -} - -/** - * 将图形绘制到帧缓存中,适用于像素数据格式为BGRA的32位色模式 - * 一个像素点的数据共占32位,其中RGB各占8位,剩下的8位用于alpha,共4个字节 - * @warning 目前是默认将所有 Graph 都视为使用32位BGRA色彩模式,其它模式暂不做处理 - */ -static void LinuxFB_PutGraph32( LCUI_Rect rect, LCUI_Graph *canvas ) -{ - int y, des_row_bytes; - uchar_t *des_row, *src_row; - LCUI_Rect read_rect; - - des_row_bytes = linuxfb.width*4; - des_row = linuxfb.mem + rect.y*des_row_bytes + rect.x*4; - Graph_GetValidRect( canvas, &read_rect ); - if( read_rect.width <= 0 || read_rect.height <= 0 ) { - return; - } - canvas = Graph_GetQuote( canvas ); - src_row = canvas->bytes + read_rect.y*canvas->bytes_per_row; - src_row += read_rect.x * canvas->bytes_per_pixel; - for( y=0; yh; ++y ) { - /* 将当前行像素转换成ARGB格式,并直接覆盖至帧缓存中 */ - PixelsFormat( src_row, canvas->color_type, - des_row, COLOR_TYPE_ARGB, - canvas->w ); - des_row += des_row_bytes; - src_row += canvas->bytes_per_row; - } -} - -/** - * 将图形绘制到帧缓存中,适用于像素数据格式为BGR的24位色模式 - * 一个像素点的数据共占24位,RGB各占8位,共3个字节 - */ -static void LinuxFB_PutGraph24( LCUI_Rect rect, LCUI_Graph *canvas ) -{ - int x, y, dest_line_bytes; - uchar_t *dest_line, *dest, *src_pixel_line; - LCUI_Color *src_pixel; - - dest_line = linuxfb.mem + rect.y*linuxfb.width + rect.x; - dest_line_bytes = linuxfb.width*3; - src_pixel_line = canvas->bytes; - for( y=0; yh; ++y ) { - dest = dest_line; - src_pixel = (LCUI_Color*)src_pixel_line; - for( x=0; xw; ++x ) { - *dest++ = src_pixel->blue; - *dest++ = src_pixel->green; - *dest++ = src_pixel->red; - ++src_pixel; - } - dest_line += dest_line_bytes; - src_pixel_line += canvas->w; - } -} - -/** - * 将图形绘制到帧缓存中,适用于像素数据格式为RGB565的16位色模式 - * 一个像素点的数据共占16位,rgb分别占5位,6位,5位,共2个字节 - */ -static void LinuxFB_PutGraph16( LCUI_Rect rect, LCUI_Graph *canvas ) -{ - int x, y, dest_line_bytes; - uchar_t *dest_line, *dest, *src_pixel_line; - LCUI_Color *src_pixel; - - dest_line = linuxfb.mem + rect.y*linuxfb.width + rect.x; - dest_line_bytes = linuxfb.width*2; - src_pixel_line = canvas->bytes; - for( y=0; yh; ++y ) { - dest = dest_line; - src_pixel = (LCUI_Color*)src_pixel_line; - for( x=0; xw; ++x ) { - /* - * 低字节的前5位用来表示B(BLUE) - * 低字节的后三位+高字节的前三位用来表示G(Green) - * 高字节的后5位用来表示R(RED) - * */ - *dest = ((src_pixel->green & 0x1c)<<3); - *dest += ((src_pixel->blue & 0xf8)>>3); - ++dest; - *dest = ((src_pixel->red & 0xf8)); - *dest += ((src_pixel->green & 0xe0)>>5); - ++dest; - ++src_pixel; - } - dest_line += dest_line_bytes; - src_pixel_line += canvas->w; - } -} - -/** 将图形绘制到帧缓存中,适用于像素数据格式为8位色模式 */ -static void LinuxFB_PutGraph8( LCUI_Rect rect, LCUI_Graph *canvas ) -{ - int x, y, dest_line_bytes; - uchar_t *dest_line, *dest, *src_pixel_line; - struct fb_cmap kolor; - LCUI_Color *src_pixel; - unsigned int r, g, b, i; - - kolor.start = 0; - kolor.len = 255; - kolor.red = calloc(256, sizeof(__u16)); - kolor.green = calloc(256, sizeof(__u16)); - kolor.blue = calloc(256, sizeof(__u16)); - kolor.transp = 0; - dest_line = linuxfb.mem + rect.y*linuxfb.width + rect.x; - dest_line_bytes = linuxfb.width; - src_pixel_line = canvas->bytes; - - for( i=0; i<256; ++i ) { - kolor.red[i] = 0; - kolor.green[i] = 0; - kolor.blue[i] = 0; - } - for( y=0; yh; ++y ) { - src_pixel = (LCUI_Color*)src_pixel_line; - dest = dest_line; - for( x=0; xw; ++x ) { - r = src_pixel->red * 0.92; - g = src_pixel->green * 0.92; - b = src_pixel->blue * 0.92; - i = (r & 0xc0) + ((g & 0xf0)>>2) + ((b & 0xc0)>>6); - kolor.red[i] = r*256; - kolor.green[i] = g*256; - kolor.blue[i] = b*256; - *dest++ = i; - ++src_pixel; - } - dest_line += dest_line_bytes; - src_pixel_line += canvas->w; - } - - ioctl( linuxfb.dev_fd, FBIOPUTCMAP, &kolor ); - free( kolor.red ); - free( kolor.green ); - free( kolor.blue ); -} - -void LinuxFB_EndPaint( LCUI_Surface surface, LCUI_PaintContext paint_ctx ) -{ - LCUI_Rect cut_rect; - LCUI_Graph canvas; - - LCUIRect_GetCutArea( linuxfb.width, linuxfb.height, - paint_ctx->rect, &cut_rect ); - if( cut_rect.w <= 0 || cut_rect.h <= 0 ) { - free( paint_ctx ); - return; - } - Graph_Init( &canvas ); - /* 如果需要裁剪图形 */ - if( cut_rect.x != 0 || cut_rect.y != 0 - || cut_rect.w != paint_ctx->rect.w - || cut_rect.h != paint_ctx->rect.h ) { - paint_ctx->rect.x += cut_rect.x; - paint_ctx->rect.y += cut_rect.y; - paint_ctx->rect.w = cut_rect.w; - paint_ctx->rect.h = cut_rect.h; - Graph_Quote( &canvas, &paint_ctx->canvas, &cut_rect ); - } else { - Graph_Quote( &canvas, &paint_ctx->canvas, NULL ); - } - - _DEBUG_MSG("linuxfb.bits_per_pixel: %d\n", linuxfb.bits_per_pixel); - switch( linuxfb.bits_per_pixel ) { - case 32: - LinuxFB_PutGraph32( paint_ctx->rect, &canvas ); - break; - case 24: - LinuxFB_PutGraph24( paint_ctx->rect, &canvas ); - break; - case 16: - LinuxFB_PutGraph16( paint_ctx->rect, &canvas ); - break; - case 8: - LinuxFB_PutGraph8( paint_ctx->rect, &canvas ); - break; - default: break; - } - Graph_Free( &canvas ); - free( paint_ctx ); - _DEBUG_MSG("%d,%d,%d,%d\n", paint_ctx->rect.x, paint_ctx->rect.y, paint_ctx->rect.w, paint_ctx->rect.h); -} - -static void LinuxFB_Present( LCUI_Surface surface ) -{ - -} - -/** 初始化适用于 Linux 帧缓冲(FrameBuffer) 的 surface 支持 */ -LCUI_SurfaceMethods *LCUIDisplay_InitLinuxFB( LCUI_DisplayInfo *info ) -{ - char *fb_dev; - __u16 rr[256],gg[256],bb[256]; - struct fb_var_screeninfo fb_vinfo; - struct fb_fix_screeninfo fb_fix; - struct fb_cmap oldcmap = {0,256,rr,gg,bb}; - - /* 获取环境变量中指定的帧缓冲设备的位置 */ - fb_dev = getenv("LCUI_FB_DEVICE"); - if( fb_dev == NULL ) { - fb_dev = FB_DEV; - } - nobuff_printf("[linuxfb] open video output device..."); - linuxfb.dev_fd = open(fb_dev, O_RDWR); - if( linuxfb.dev_fd == -1 ) { - printf("failed\n[linuxfb] %s: %s\n", fb_dev, strerror(errno)); - return NULL; - } else { - printf("ok\n"); - } - /* 获取屏幕相关信息 */ - ioctl( linuxfb.dev_fd, FBIOGET_VSCREENINFO, &fb_vinfo ); - ioctl( linuxfb.dev_fd, FBIOGET_FSCREENINFO, &fb_fix ); - /* 打印屏幕信息 */ - print_screeninfo( fb_vinfo, fb_fix ); - if( fb_vinfo.bits_per_pixel == 8 ) { - ioctl( linuxfb.dev_fd, FBIOGETCMAP, &oldcmap ); - } - nobuff_printf("[linuxfb] mapping framebuffer..."); - linuxfb.bits_per_pixel = fb_vinfo.bits_per_pixel; - linuxfb.bytes_per_line = fb_fix.line_length; - linuxfb.mem_len = fb_fix.smem_len; - /* 映射帧缓存至内存空间 */ - linuxfb.mem = mmap( NULL, fb_fix.smem_len, - PROT_READ|PROT_WRITE, MAP_SHARED, - linuxfb.dev_fd, 0 ); - - if( (void *)-1 == linuxfb.mem ) { - printf("fail\n"); - perror(strerror(errno)); - return NULL; - } else { - printf("success\n"); - } - LinuxFB_Backup(); - linuxfb.width = fb_vinfo.xres; - linuxfb.height = fb_vinfo.yres; - strncpy( info->name, "linux framebuffer", 32 ); - info->getWidth = LinuxFB_GetWidth; - info->getHeight = LinuxFB_GetHeight; - linuxfb.methods.new = LinuxFB_New; - linuxfb.methods.delete = LinuxFB_Delete; - linuxfb.methods.isReady = LinuxFB_IsReady; - linuxfb.methods.show = NULL; - linuxfb.methods.hide = NULL; - linuxfb.methods.move = NULL; - linuxfb.methods.resize = LinuxFB_Resize; - linuxfb.methods.update = LinuxFB_Update; - linuxfb.methods.present = LinuxFB_Present; - linuxfb.methods.setCaptionW = NULL; - linuxfb.methods.setRenderMode = LinuxFB_SetRenderMode; - linuxfb.methods.setOpacity = NULL; - linuxfb.methods.beginPaint = LinuxFB_BeginPaint; - linuxfb.methods.endPaint = LinuxFB_EndPaint; - linuxfb.methods.onInvalidRect = NULL; - linuxfb.methods.onEvent = NULL; - return &linuxfb.methods; -} - -int LCUIDisplay_ExitLinuxFB(void) -{ - LinuxFB_Restore(); - return 0; -} - -#endif diff --git a/src/output/win32.c b/src/output/win32.c deleted file mode 100755 index 58f65a55..00000000 --- a/src/output/win32.c +++ /dev/null @@ -1,403 +0,0 @@ -/* *************************************************************************** - * win32.c -- win32 platform support for graphical output - * - * 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 . - * ****************************************************************************/ - -/* **************************************************************************** - * win32.c -- win32平台上的图形输出支持 - * - * 版权所有 (C) 2013 归属于 - * 刘超 - * - * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 - * - * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) - * - * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 - * - * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 - * 定用途的隐含担保,详情请参照GPLv2许可协议。 - * - * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 - * 没有,请查看:. - * ****************************************************************************/ - -#include -#include - -#ifdef LCUI_VIDEO_DRIVER_WIN32 - -#include -#include -#include -#include -#include -#include "resource.h" - -#define WIN32_WINDOW_STYLE (WS_OVERLAPPEDWINDOW &~WS_THICKFRAME &~WS_MAXIMIZEBOX) - -static HWND current_hwnd = NULL; -static HINSTANCE win32_hInstance = NULL, dll_hInstance = NULL; -static LCUI_Mutex screen_mutex; -static LCUI_Thread th_win32; -static LCUI_Graph framebuffer; -static HDC hdc_framebuffer; -static HBITMAP client_bitmap; -static LCUI_Cond win32_init_cond; -static LCUI_BOOL win32_init_error = TRUE; -static LCUI_BOOL is_running = FALSE; - -void Win32_LCUI_Init__( HINSTANCE hInstance ) -{ - win32_hInstance = hInstance; -} - -HWND Win32_GetSelfHWND( void ) -{ - return current_hwnd; -} - -void Win32_SetSelfHWND( HWND hwnd ) -{ - current_hwnd = hwnd; -} - -/** win32的动态库的入口函数 */ -BOOL APIENTRY DllMain__( HMODULE hModule, DWORD ul_reason_for_call, - LPVOID lpReserved ) -{ - switch (ul_reason_for_call) - { - case DLL_PROCESS_ATTACH: - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - case DLL_PROCESS_DETACH: - break; - } - dll_hInstance = hModule; - return TRUE; -} - -static LRESULT CALLBACK Win32_LCUI_WndProc( HWND hwnd, UINT message, - WPARAM wParam, LPARAM lParam ) -{ - PAINTSTRUCT ps; - LCUI_Rect area; - - switch (message) { - case WM_KEYDOWN: - LCUI_PostKeyDownEvent( wParam ); - return 0; - case WM_KEYUP: - LCUI_PostKeyUpEvent( wParam ); - return 0; - case WM_RBUTTONDOWN: - LCUI_PostMouseDownEvent( LCUIKEY_RIGHTBUTTON ); - return 0; - case WM_RBUTTONUP: - LCUI_PostMouseUpEvent( LCUIKEY_RIGHTBUTTON ); - return 0; - case WM_LBUTTONDOWN: - LCUI_PostMouseDownEvent( LCUIKEY_LEFTBUTTON ); - return 0; - case WM_LBUTTONUP: - LCUI_PostMouseUpEvent( LCUIKEY_LEFTBUTTON ); - return 0; - case WM_PAINT: - BeginPaint( hwnd, &ps ); - /* 获取区域坐标及尺寸 */ - area.x = ps.rcPaint.left; - area.y = ps.rcPaint.top; - area.width = ps.rcPaint.right - area.x; - area.height = ps.rcPaint.bottom - area.y; - /* 记录该无效区域 */ - LCUIScreen_InvalidateArea( &area ); - EndPaint( hwnd, &ps ); - return 0; - case WM_DESTROY: - PostQuitMessage(0); - LCUI_Quit(); - return 0; - default:break; - } - return DefWindowProc( hwnd, message, wParam, lParam ); -} - -static int Win32_ScreenInit(void) -{ - WNDCLASS wndclass; - TCHAR szAppName[] = TEXT ("LCUI OutPut"); - - wndclass.style = CS_HREDRAW | CS_VREDRAW; - wndclass.lpfnWndProc = Win32_LCUI_WndProc; - wndclass.cbClsExtra = 0; - wndclass.cbWndExtra = 0; - wndclass.hInstance = win32_hInstance; - /* 载入动态库里的图标 */ - wndclass.hIcon = LoadIcon( dll_hInstance, MAKEINTRESOURCE(IDI_MAIN_ICON) ); - wndclass.hCursor = LoadCursor( NULL, IDC_ARROW ); - wndclass.hbrBackground = (HBRUSH) GetStockObject( WHITE_BRUSH ); - wndclass.lpszMenuName = NULL; - wndclass.lpszClassName = szAppName; - - if( !RegisterClass(&wndclass) ) { - MessageBox( NULL, TEXT("This program requires Windows NT!" ), - szAppName, MB_ICONERROR ); - return -1; - } - /* 创建窗口 */ - current_hwnd = CreateWindow( - szAppName, TEXT ("LCUI Application"), - WIN32_WINDOW_STYLE, - CW_USEDEFAULT, CW_USEDEFAULT, - 0, 0, - NULL, NULL, win32_hInstance, NULL); - return 0; -} - -/** Win32的消息循环线程 */ -static void LCUI_Win32_Thread( void *arg ) -{ - MSG msg; - if( Win32_ScreenInit() == -1 ) { - /* 设置标志为TRUE,表示初始化失败 */ - win32_init_error = TRUE; - /* 打断处于睡眠状态的线程的睡眠 */ - LCUICond_Broadcast( &win32_init_cond ); - LCUIThread_Exit(NULL); - return; - } - /* 设置标志为FALSE,表示初始化成功 */ - win32_init_error = FALSE; - /* 隐藏windows的鼠标游标 */ - ShowCursor( FALSE ); - LCUICond_Broadcast( &win32_init_cond ); - while( is_running ) { - /* 获取消息 */ - if( GetMessage( &msg, Win32_GetSelfHWND(), 0, 0 ) ) { - TranslateMessage( &msg ); - DispatchMessage( &msg ); - } - } - LCUIThread_Exit(NULL); -} - -/** 初始化屏幕 */ -static int Win32Screen_Init( int w, int h, int mode ) -{ - HDC hdc_client; - LCUI_ScreenInfo screen_info; - - is_running = TRUE; - /* 初始化屏幕互斥锁 */ - LCUIMutex_Init( &screen_mutex ); - LCUICond_Init( &win32_init_cond ); - /* 创建线程 */ - LCUIThread_Create( &th_win32, LCUI_Win32_Thread, NULL ); - /* 进行睡眠,最长时间为5秒 */ - LCUICond_TimedWait( &win32_init_cond, 5000 ); - /* 若初始化出现错误 */ - if( win32_init_error ) { - return -1; - } - /* 准备屏幕相关信息 */ - screen_info.bits = 32; - screen_info.mode = mode; - strcpy( screen_info.dev_name, "win32 GDI" ); - /* 设置屏幕信息 */ - LCUIScreen_SetInfo( &screen_info ); - /* 设置图形输出模式 */ - LCUIScreen_SetMode( w, h, mode ); - /* 获取屏幕信息 */ - LCUIScreen_GetInfo( &screen_info ); - - framebuffer.color_type = COLOR_TYPE_ARGB; - if( Graph_Create(&framebuffer, w, h) != 0 ) { - return -2; - } - /* 获取客户区的DC */ - hdc_client = GetDC( current_hwnd ); - /* 为帧缓冲创建一个DC */ - hdc_framebuffer = CreateCompatibleDC( hdc_client ); - /* 为客户区创建一个Bitmap */ - client_bitmap = CreateCompatibleBitmap( hdc_client, w, h ); - /* 为帧缓冲的DC选择client_bitmap作为对象 */ - SelectObject( hdc_framebuffer, client_bitmap ); - - Widget_Resize( LCUIRootWidget, screen_info.size.w, screen_info.size.h ); - Widget_SetBackgroundColor( LCUIRootWidget, RGB(255,255,255) ); - Widget_Show( LCUIRootWidget ); - - UpdateWindow( current_hwnd ); - /* 显示窗口 */ - ShowWindow( current_hwnd, SW_SHOWNORMAL ); - /* 前置并激活窗口 */ - SetForegroundWindow( current_hwnd ); - return 0; -} - -/* 设置视频输出模式 */ -static int Win32Screen_SetMode( int w, int h, int mode ) -{ - LCUI_Pos pos; - LCUI_Size real_size; - LCUI_ScreenInfo screen_info; - - LCUIMutex_Lock( &screen_mutex ); - LCUIScreen_GetInfo( &screen_info ); - real_size.w = GetSystemMetrics(SM_CXSCREEN); - real_size.h = GetSystemMetrics(SM_CYSCREEN); - if( mode == LCUI_MODE_AUTO ) { - if( w == 0 && h == 0 ) { - mode = LCUI_MODE_FULLSCREEN; - } else { - mode = LCUI_MODE_WINDOWED; - } - } - if( mode == LCUI_MODE_FULLSCREEN ) { - if( w == 0 ) { - w = real_size.w; - } - if( h == 0 ) { - h = real_size.h; - } - SetWindowLong( current_hwnd, GWL_STYLE, WS_POPUP ); - SetWindowPos( current_hwnd, HWND_NOTOPMOST, 0, 0, - real_size.w, real_size.h, SWP_SHOWWINDOW ); - } else { - RECT rect; - int boader_w, boader_h; - /* 计算边框的尺寸 */ - boader_w = GetSystemMetrics(SM_CXFIXEDFRAME) * 2; - boader_h = GetSystemMetrics(SM_CYFIXEDFRAME) * 2; - boader_h += GetSystemMetrics(SM_CYCAPTION); - /* 计算窗口尺寸 */ - w = w + boader_w; - h = h + boader_h; - pos.x = (real_size.w - w)/2; - pos.y = (real_size.h - h)/2; - - SetWindowLong( current_hwnd, GWL_STYLE, WIN32_WINDOW_STYLE ); - /* 调整窗口尺寸 */ - SetWindowPos( current_hwnd, HWND_NOTOPMOST, - pos.x, pos.y, w, h, SWP_SHOWWINDOW ); - /* 获取客户区的尺寸 */ - GetClientRect( current_hwnd, &rect ); - w = rect.right; - h = rect.bottom; - } - screen_info.size.w = w; - screen_info.size.h = h; - screen_info.mode = mode; - /* 重新调整帧缓冲大小 */ - if( Graph_Create(&framebuffer, w, h) != 0 ) { - return -2; - } - LCUIScreen_SetInfo( &screen_info ); - Widget_Resize( LCUIRootWidget, w, h ); - - LCUIMutex_Unlock( &screen_mutex ); - return 0; -} - -static int Win32Screen_Destroy( void ) -{ - is_running = FALSE; - LCUIMutex_Destroy( &screen_mutex ); - return 0; -} - -static int Win32Screen_PutGraph( const LCUI_Graph *graph, LCUI_Pos pos ) -{ - Graph_Replace( &framebuffer, graph, pos ); - return 0; -} - -static int Win32Screen_MixGraph( const LCUI_Graph *graph, LCUI_Pos pos ) -{ - Graph_Mix( &framebuffer, graph, pos ); - return 0; -} - -static int Win32Screen_Sync( void ) -{ - HDC hdc_client; - RECT client_rect; - - hdc_client = GetDC( current_hwnd ); - LCUIMutex_Lock( &screen_mutex ); - SetBitmapBits( client_bitmap, framebuffer.mem_size, framebuffer.bytes ); - switch(LCUIScreen_GetMode()) { - case LCUI_MODE_FULLSCREEN: - /* 全屏模式下,则使用拉伸模式,将帧拉伸至全屏 */ - GetClientRect( current_hwnd, &client_rect ); - StretchBlt( hdc_client, 0, 0, - client_rect.right, client_rect.bottom, - hdc_framebuffer, 0, 0, - LCUIScreen_GetWidth(), LCUIScreen_GetHeight(), - SRCCOPY ); - break; - case LCUI_MODE_WINDOWED: - /* 将帧缓冲内的位图数据更新至客户区内指定区域(area) */ - BitBlt( hdc_client, 0, 0, - LCUIScreen_GetWidth(), LCUIScreen_GetHeight(), - hdc_framebuffer, 0, 0, - SRCCOPY ); - break; - } - ValidateRect( current_hwnd, NULL ); - LCUIMutex_Unlock( &screen_mutex ); - return 0; -} - -static int Win32Screen_CatchGraph( LCUI_Graph *out, LCUI_Rect area ) -{ - return -1; -#ifdef test - LCUI_Rect cut_rect; - if( !LCUI_Active() ) { - return -1; - } - /* 如果需要裁剪图形 */ - LCUIRect_GetCutArea( Size(framebuffer.w, framebuffer.h), area, &cut_rect ); - if( cut_rect.w <= 0 || cut_rect.h <= 0 ) { - return -2; - } - area.x += cut_rect.x; - area.y += cut_rect.y; - area.width = cut_rect.width; - area.height = cut_rect.height; - Graph_Cut( &framebuffer, cut_rect, out ); - return 0; -#endif -} - -void LCUIScreen_UseWin32( LCUI_Screen *screen ) -{ - screen->Init = Win32Screen_Init; - screen->Sync = Win32Screen_Sync; - screen->Destroy = Win32Screen_Destroy; - screen->SetMode = Win32Screen_SetMode; - screen->PutGraph = Win32Screen_PutGraph; - screen->MixGraph = Win32Screen_MixGraph; - screen->CatchGraph = Win32Screen_CatchGraph; -} - -#endif diff --git a/src/output/win32_surface.c b/src/output/win32_surface.c deleted file mode 100644 index 78210e7e..00000000 --- a/src/output/win32_surface.c +++ /dev/null @@ -1,581 +0,0 @@ -/* *************************************************************************** - * win32_surface.c -- surface support for win32 platform. - * - * Copyright (C) 2014-2016 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 . - * ***************************************************************************/ - -/* **************************************************************************** - * win32_surface.c -- win32平台的 surface 功能支持。 - * - * 版权所有 (C) 2014-2016 归属于 刘超 - * - * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 - * - * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) - * - * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 - * - * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 - * 定用途的隐含担保,详情请参照GPLv2许可协议。 - * - * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 - * 没有,请查看:. - * ***************************************************************************/ -//#define DEBUG -#include -#define __IN_SURFACE_SOURCE_FILE__ -#ifdef LCUI_BUILD_IN_WIN32 -#include -#include -#include -#include -#include "resource.h" - -#define WIN32_WINDOW_STYLE (WS_OVERLAPPEDWINDOW &~WS_THICKFRAME &~WS_MAXIMIZEBOX) -#define MSG_SURFACE_CREATE WM_USER+100 - -enum SurfaceTaskType { - TASK_MOVE, - TASK_RESIZE, - TASK_SHOW, - TASK_SET_CAPTION, - TASK_TOTAL_NUM -}; - -typedef struct LCUI_SurfaceTask { - LCUI_BOOL is_valid; - union { - struct { - int x, y; - }; - struct { - int width, height; - }; - LCUI_BOOL show; - wchar_t *caption; - }; -} LCUI_SurfaceTask; - -struct LCUI_SurfaceRec_ { - HWND hwnd; - int mode; - int w, h; - HDC fb_hdc; - HBITMAP fb_bmp; - LCUI_BOOL is_ready; - LCUI_Graph fb; - LCUI_SurfaceTask task_buffer[TASK_TOTAL_NUM]; -}; - -static struct { - HINSTANCE main_instance; /**< 主程序的资源句柄 */ - HINSTANCE dll_instance; /**< 动态库中的资源句柄 */ - LCUI_Thread loop_thread; /**< 消息循环线程 */ - LCUI_Cond cond; /**< 条件,当消息循环已创建时成立 */ - LCUI_Mutex mutex; /**< 互斥锁 */ - LCUI_BOOL is_ready; /**< 消息循环线程是否已准备好 */ - LinkedList surfaces; /**< surface 记录 */ - LCUI_SurfaceMethods methods; /**< 方法集 */ -} win32; - -void LCUI_InitWin32Mode( HINSTANCE hInstance ) -{ - win32.main_instance = hInstance; -} - -/** win32的动态库的入口函数 */ -BOOL APIENTRY DllMain( HMODULE hModule, DWORD reason, LPVOID unused ) -{ - switch (reason) { - case DLL_PROCESS_ATTACH: - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - case DLL_PROCESS_DETACH: - break; - } - win32.dll_instance = hModule; - return TRUE; -} - -/** 根据 hwnd 获取 Surface */ -static LCUI_Surface GetSurfaceByHWND( HWND hwnd ) -{ - LinkedListNode *node; - LinkedList_ForEach( node, &win32.surfaces ) { - if( ((LCUI_Surface)node->data)->hwnd == hwnd ) { - return node->data; - } - } - return NULL; -} - -static void Win32Surface_Destroy( LCUI_Surface surface ) -{ - surface->w = 0; - surface->h = 0; - if( surface->hwnd ) { - if( surface->fb_hdc ) { - ReleaseDC( surface->hwnd, surface->fb_hdc ); - } - } - if( surface->fb_bmp ) { - DeleteObject( surface->fb_bmp ); - } - surface->fb_hdc = NULL; - surface->fb_bmp = NULL; - surface->hwnd = NULL; - Graph_Free( &surface->fb ); -} - -static void Win32Surface_ExecDelete( LCUI_Surface surface ) -{ - LinkedListNode *node; - LinkedList_ForEach( node, &win32.surfaces ) { - if( node->data == surface ) { - Win32Surface_Destroy( node->data ); - LinkedList_DeleteNode( &win32.surfaces, node ); - break; - } - } -} - -/** 删除 Surface */ -static void Win32Surface_Delete( LCUI_Surface surface ) -{ - if( surface->hwnd ) { - PostMessage( surface->hwnd, WM_CLOSE, 0, 0 ); - } -} - -static LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, - WPARAM arg1, LPARAM arg2 ) -{ - LCUI_SysEventRec e = {0}; - LCUI_Surface surface = GetSurfaceByHWND(hwnd); - DEBUG_MSG( "surface: %p, msg: %d\n", surface, msg ); - if( !surface ) { - return DefWindowProc( hwnd, msg, arg1, arg2 ); - } - switch( msg ) { - case WM_KEYDOWN: - e.type = LCUI_KEYDOWN; - e.key_code = arg1; - break; - case WM_KEYUP: - e.type = LCUI_KEYUP; - e.key_code = arg1; - break; - case WM_MOUSEMOVE: { - POINT new_pos; - GetCursorPos( &new_pos ); - ScreenToClient( hwnd, &new_pos ); - e.rel_x = new_pos.x; - e.rel_y = new_pos.y; - e.type = LCUI_MOUSEMOVE; - break; - } - case WM_LBUTTONDOWN: - e.type = LCUI_MOUSEDOWN; - e.key_code = 1; - break; - case WM_LBUTTONUP: - e.type = LCUI_MOUSEUP; - e.key_code = 1; - break; - case WM_RBUTTONDOWN: - e.type = LCUI_MOUSEDOWN; - e.key_code = 2; - break; - case WM_RBUTTONUP: - e.type = LCUI_MOUSEUP; - e.key_code = 2; - break; - case WM_MOUSEWHEEL: - e.type = LCUI_MOUSEWHEEL; - e.z_delta = GET_WHEEL_DELTA_WPARAM(arg1); - break; - case WM_PAINT: { - PAINTSTRUCT ps; - LCUI_Rect area; - - BeginPaint( hwnd, &ps ); - /* 获取区域坐标及尺寸 */ - area.x = ps.rcPaint.left; - area.y = ps.rcPaint.top; - area.width = ps.rcPaint.right - area.x; - area.height = ps.rcPaint.bottom - area.y; - if( win32.methods.onInvalidRect ) { - win32.methods.onInvalidRect( surface, &area ); - } - EndPaint( hwnd, &ps ); - return 0; - } - case WM_CLOSE: - if( LCUIDisplay_GetMode() != LDM_SEAMLESS ) { - LCUI_Quit(); - } - break; - case WM_DESTROY: - Win32Surface_ExecDelete( surface ); - break; - case WM_SHOWWINDOW: - if( arg1 ) { - //Widget_Show( surface->target ); - } else { - //Widget_Hide( surface->target ); - } - break; - case WM_ACTIVATE: - break; - default:break; - } - if( e.type != LCUI_NONE && win32.methods.onEvent ) { - win32.methods.onEvent( surface, &e ); - } - return DefWindowProc( hwnd, msg, arg1, arg2 ); -} - -/** 新建一个 Surface */ -static LCUI_Surface Win32Surface_New(void) -{ - int i; - LCUI_Surface surface; - surface = NEW(struct LCUI_SurfaceRec_, 1); - surface->mode = RENDER_MODE_BIT_BLT; - surface->hwnd = NULL; - surface->fb_hdc = NULL; - surface->fb_bmp = NULL; - surface->is_ready = FALSE; - Graph_Init( &surface->fb ); - surface->fb.color_type = COLOR_TYPE_ARGB; - for( i=0; itask_buffer[i].is_valid = FALSE; - } - LinkedList_Append( &win32.surfaces, surface ); - if( !win32.is_ready ) { - LCUIMutex_Lock( &win32.mutex ); - /* 等待 Surface 线程创建完 windows 消息队列 */ - LCUICond_Wait( &win32.cond, &win32.mutex ); - LCUIMutex_Unlock( &win32.mutex ); - } - /* 让 Surface 线程去完成 windows 窗口的创建 */ - PostThreadMessage( win32.loop_thread, MSG_SURFACE_CREATE, 0, (LPARAM)surface ); - return surface; -} - -static LCUI_BOOL Win32Surface_IsReady( LCUI_Surface surface ) -{ - return surface->is_ready; -} - -static void Win32Surface_ExecMove( LCUI_Surface surface, int x, int y ) -{ - x += GetSystemMetrics( SM_CXFIXEDFRAME ); - y += GetSystemMetrics( SM_CYFIXEDFRAME ); - SetWindowPos( surface->hwnd, HWND_NOTOPMOST, - x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER ); - return; -} - -static void Win32Surface_Move( LCUI_Surface surface, int x, int y ) -{ - /* 缓存任务,等获得窗口句柄后处理 */ - surface->task_buffer[TASK_MOVE].x = x; - surface->task_buffer[TASK_MOVE].y = y; - surface->task_buffer[TASK_MOVE].is_valid = TRUE; -} - -static void Win32Surface_ExecResize( LCUI_Surface surface, int w, int h ) -{ - HDC hdc_client; - HBITMAP old_bmp; - RECT rect_client, rect_window; - surface->w = w; - surface->h = h; - _DEBUG_MSG("w = %d, h = %d\n", w, h); - Graph_Create( &surface->fb, w, h ); - hdc_client = GetDC( surface->hwnd ); - surface->fb_bmp = CreateCompatibleBitmap( hdc_client, w, h ); - old_bmp = (HBITMAP)SelectObject( surface->fb_hdc, surface->fb_bmp ); - if( old_bmp ) { - DeleteObject( old_bmp ); - } - GetClientRect( surface->hwnd, &rect_client ); - GetWindowRect( surface->hwnd, &rect_window ); - w += rect_window.right - rect_window.left; - w -= rect_client.right - rect_client.left; - h += rect_window.bottom - rect_window.top; - h -= rect_client.bottom - rect_client.top; - //SetWindowLong( surface->hwnd, GWL_STYLE, WIN32_WINDOW_STYLE ); - SetWindowPos( surface->hwnd, HWND_NOTOPMOST, - 0, 0, w, h, SWP_NOMOVE | SWP_NOZORDER ); -} - -static void Win32Surface_Resize( LCUI_Surface surface, int w, int h ) -{ - surface->task_buffer[TASK_RESIZE].width = w; - surface->task_buffer[TASK_RESIZE].height = h; - surface->task_buffer[TASK_RESIZE].is_valid = TRUE; -} - -static void Win32Surface_Show( LCUI_Surface surface ) -{ - DEBUG_MSG("surface: %p, buffer show.\n", surface); - surface->task_buffer[TASK_SHOW].show = TRUE; - surface->task_buffer[TASK_SHOW].is_valid = TRUE; -} - -static void Win32Surface_Hide( LCUI_Surface surface ) -{ - surface->task_buffer[TASK_SHOW].show = FALSE; - surface->task_buffer[TASK_SHOW].is_valid = TRUE; -} - -static void Win32Surface_SetCaptionW( LCUI_Surface surface, const wchar_t *str ) -{ - int len; - wchar_t *caption = NULL; - - if( str ) { - len = wcslen(str) + 1; - caption = (wchar_t*)malloc(sizeof(wchar_t)*len); - wcsncpy( caption, str, len ); - } - if( surface->task_buffer[TASK_SET_CAPTION].is_valid - && surface->task_buffer[TASK_SET_CAPTION].caption ) { - free( surface->task_buffer[TASK_SET_CAPTION].caption ); - } - surface->task_buffer[TASK_SET_CAPTION].caption = caption; - surface->task_buffer[TASK_SET_CAPTION].is_valid = TRUE; -} - -void Win32Surface_SetOpacity( LCUI_Surface surface, float opacity ) -{ - -} - -/** 设置 Surface 的渲染模式 */ -static void Win32Surface_SetRenderMode( LCUI_Surface surface, int mode ) -{ - surface->mode = mode; -} - -/** - * 准备绘制 Surface 中的内容 - * @param[in] surface 目标 surface - * @param[in] rect 需进行绘制的区域,若为NULL,则绘制整个 surface - * @return 返回绘制上下文句柄 - */ -static LCUI_PaintContext Win32Surface_BeginPaint( LCUI_Surface surface, LCUI_Rect *rect ) -{ - LCUI_PaintContext paint; - paint = malloc(sizeof(LCUI_PaintContextRec)); - paint->rect = *rect; - Graph_Init( &paint->canvas ); - LCUIRect_ValidateArea( &paint->rect, surface->w, surface->h ); - Graph_Quote( &paint->canvas, &surface->fb, &paint->rect ); - Graph_FillRect( &paint->canvas, RGB( 255, 255, 255 ), NULL, TRUE ); - return paint; -} - -/** - * 结束对 Surface 的绘制操作 - * @param[in] surface 目标 surface - * @param[in] paint_ctx 绘制上下文句柄 - */ -static void Win32Surface_EndPaint( LCUI_Surface surface, LCUI_PaintContext paint_ctx ) -{ - free( paint_ctx ); -} - -/** 将帧缓存中的数据呈现至Surface的窗口内 */ -static void Win32Surface_Present( LCUI_Surface surface ) -{ - HDC hdc_client; - RECT client_rect; - - DEBUG_MSG("surface: %p, hwnd: %p\n", surface, surface->hwnd); - hdc_client = GetDC( surface->hwnd ); - SetBitmapBits( surface->fb_bmp, surface->fb.mem_size, surface->fb.bytes ); - switch(surface->mode) { - case RENDER_MODE_STRETCH_BLT: - GetClientRect( surface->hwnd, &client_rect ); - StretchBlt( hdc_client, 0, 0, - client_rect.right, client_rect.bottom, - surface->fb_hdc, 0, 0, - surface->w, surface->h, SRCCOPY ); - break; - case RENDER_MODE_BIT_BLT: - default: - BitBlt( hdc_client, 0, 0, surface->w, surface->h, - surface->fb_hdc, 0, 0, SRCCOPY ); - break; - } - ValidateRect( surface->hwnd, NULL ); -} - -/** 更新 surface,应用缓存的变更 */ -static void Win32Surface_Update( LCUI_Surface surface ) -{ - LCUI_SurfaceTask *t; - if( !surface->hwnd ) { - return; - } - DEBUG_MSG("surface: %p\n", surface); - t = &surface->task_buffer[TASK_MOVE]; - if( t->is_valid ) { - Win32Surface_ExecMove( surface, t->x, t->y ); - t->is_valid = FALSE; - } - t = &surface->task_buffer[TASK_RESIZE]; - if( t->is_valid ) { - Win32Surface_ExecResize( surface, t->width, t->height ); - t->is_valid = FALSE; - } - t = &surface->task_buffer[TASK_SET_CAPTION]; - if( t->is_valid ) { - SetWindowText( surface->hwnd, t->caption ); - if( t->caption ) { - free( t->caption ); - t->caption = NULL; - } - } - t->is_valid = FALSE; - t = &surface->task_buffer[TASK_SHOW]; - DEBUG_MSG("surface: %p, hwnd: %p, is_valid: %d, show: %d\n", - surface, surface->hwnd, t->is_valid, t->show); - if( t->is_valid ) { - if( t->show ) { - ShowWindow( surface->hwnd, SW_SHOWNORMAL ); - } else { - ShowWindow( surface->hwnd, SW_HIDE ); - } - } - t->is_valid = FALSE; -} - -static void* Win32Surface_GetHandle( LCUI_Surface s ) -{ - return s->hwnd; -} - -static void LCUISurface_Loop( void *args ) -{ - MSG msg; - LCUI_Surface surface; - DEBUG_MSG("start\n"); - /* 创建消息队列 */ - PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE); - win32.is_ready = TRUE; - LCUIMutex_Lock( &win32.mutex ); - LCUICond_Broadcast( &win32.cond ); - LCUIMutex_Unlock( &win32.mutex ); - while( GetMessage( &msg, NULL, 0, 0 ) ) { - if( msg.message == MSG_SURFACE_CREATE ) { - HDC hdc_client; - surface = (LCUI_Surface)msg.lParam; - /* 为 Surface 创建窗口 */ - surface->hwnd = CreateWindow( - TEXT("LCUI"), TEXT("LCUI Surface"), - WIN32_WINDOW_STYLE, - CW_USEDEFAULT, CW_USEDEFAULT, - 0, 0, NULL, NULL, - win32.main_instance, NULL - ); - hdc_client = GetDC( surface->hwnd ); - surface->fb_hdc = CreateCompatibleDC( hdc_client ); - surface->is_ready = TRUE; - DEBUG_MSG("surface: %p, surface->hwnd: %p\n", surface, surface->hwnd); - continue; - } - TranslateMessage( &msg ); - DispatchMessage( &msg ); - } - DEBUG_MSG("quit\n"); - LCUIThread_Exit(NULL); -} - -static int Win32Display_GetWidth( void ) -{ - return GetSystemMetrics( SM_CXSCREEN ); -} - -static int Win32Display_GetHeight( void ) -{ - return GetSystemMetrics( SM_CYSCREEN ); -} - -/** 初始化适用于 Win32 平台的 surface 支持 */ -LCUI_SurfaceMethods *LCUIDisplay_InitWin32( LCUI_DisplayInfo *info ) -{ - WNDCLASS wndclass; - TCHAR szAppName[] = TEXT ("LCUI"); - - wndclass.style = CS_HREDRAW | CS_VREDRAW; - wndclass.lpfnWndProc = WndProc; - wndclass.cbClsExtra = 0; - wndclass.cbWndExtra = 0; - wndclass.hInstance = win32.main_instance; - /* 载入动态库里的图标 */ - wndclass.hIcon = LoadIcon( win32.dll_instance, MAKEINTRESOURCE(IDI_LCUI_ICON) ); - wndclass.hCursor = LoadCursor( NULL, IDC_ARROW ); - wndclass.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH ); - wndclass.lpszMenuName = NULL; - wndclass.lpszClassName = szAppName; - - if( !RegisterClass(&wndclass) ) { - wchar_t str[256]; - wsprintf(str, L"LCUISurface_Init(): error code: %d\n", GetLastError()); - MessageBox( NULL, str, szAppName, MB_ICONERROR ); - return NULL; - } - info->getWidth = Win32Display_GetWidth; - info->getHeight = Win32Display_GetHeight; - strncpy( info->name, "win32", 32 ); - win32.is_ready = FALSE; - win32.methods.new = Win32Surface_New; - win32.methods.delete = Win32Surface_Delete; - win32.methods.isReady = Win32Surface_IsReady; - win32.methods.show = Win32Surface_Show; - win32.methods.hide = Win32Surface_Hide; - win32.methods.move = Win32Surface_Move; - win32.methods.resize = Win32Surface_Resize; - win32.methods.update = Win32Surface_Update; - win32.methods.present = Win32Surface_Present; - win32.methods.setCaptionW = Win32Surface_SetCaptionW; - win32.methods.setRenderMode = Win32Surface_SetRenderMode; - win32.methods.setOpacity = Win32Surface_SetOpacity; - win32.methods.getHandle = Win32Surface_GetHandle; - win32.methods.beginPaint = Win32Surface_BeginPaint; - win32.methods.endPaint = Win32Surface_EndPaint; - win32.methods.onInvalidRect = NULL; - win32.methods.onEvent = NULL; - LCUICond_Init( &win32.cond ); - LCUIMutex_Init( &win32.mutex ); - LinkedList_Init( &win32.surfaces ); - LCUIThread_Create( &win32.loop_thread, LCUISurface_Loop, NULL ); - return &win32.methods; -} - -int LCUIDisplay_ExitWin32(void) -{ - // ... - return 0; -} - -#endif diff --git a/src/platform/Makefile.am b/src/platform/Makefile.am index f5f05bff..8e53117e 100755 --- a/src/platform/Makefile.am +++ b/src/platform/Makefile.am @@ -2,7 +2,8 @@ AUTOMAKE_OPTIONS=foreign subdir-objects AM_CFLAGS = -I$(abs_top_srcdir)/include noinst_LTLIBRARIES = libplatform.la libplatform_la_SOURCES = linux/linux_keyboard.c linux/linux_display.c \ -linux/linux_x11events.c linux/linux_events.c linux/linux_mouse.c \ -linux/linux_fbdisplay.c linux/linux_x11display.c windows/windows_events.c \ -windows/windows_keyboard.c windows/windows_display.c windows/windows_mouse.c +linux/linux_events.c linux/linux_mouse.c linux/linux_x11events.c \ +linux/linux_x11mouse.c linux/linux_x11display.c linux/linux_fbdisplay.c \ +windows/windows_events.c linux/linux_fbdisplay.c windows/windows_keyboard.c \ +windows/windows_display.c windows/windows_mouse.c diff --git a/src/platform/linux/linux_display.c b/src/platform/linux/linux_display.c index 7b2b7998..5d97fc5f 100644 --- a/src/platform/linux/linux_display.c +++ b/src/platform/linux/linux_display.c @@ -4,9 +4,15 @@ #include #include #include +#include LCUI_EVENTS_H +#include LCUI_DISPLAY_H int LCUI_InitLinuxDisplay( LCUI_DisplayDriver driver ) { + LCUI_BOOL is_x11_mode = TRUE; + if( is_x11_mode ) { + return LCUI_InitLinuxX11Display( driver ); + } return -1; } diff --git a/src/platform/linux/linux_events.c b/src/platform/linux/linux_events.c index 8c90705a..6092f322 100644 --- a/src/platform/linux/linux_events.c +++ b/src/platform/linux/linux_events.c @@ -13,6 +13,10 @@ void LCUI_PreInitLinuxApp( void *data ) int LCUI_InitLinuxApp( LCUI_AppDriver app ) { + LCUI_BOOL is_x11_mode = TRUE; + if( is_x11_mode ) { + return LCUI_InitLinuxX11App( app ); + } return -1; } #endif diff --git a/src/platform/linux/linux_mouse.c b/src/platform/linux/linux_mouse.c index 2f800bf5..1ab8a80b 100644 --- a/src/platform/linux/linux_mouse.c +++ b/src/platform/linux/linux_mouse.c @@ -1,10 +1,55 @@ +/* *************************************************************************** + * linux_x11mouse.c -- mouse support for linux. + * + * Copyright (C) 2016 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * linux_x11mouse.c -- linux 平台的鼠标支持 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ #include #ifdef LCUI_BUILD_IN_LINUX +#include +#include +#include LCUI_EVENTS_H +#include LCUI_MOUSE_H void LCUI_InitLinuxMouse( void ) { - + LCUI_BOOL is_x11_mode = TRUE; + if( is_x11_mode ) { + LCUI_InitLinuxX11Mouse(); + } } void LCUI_ExitLinuxMouse( void ) diff --git a/src/platform/linux/linux_x11display.c b/src/platform/linux/linux_x11display.c index 8b137891..bc8bc126 100644 --- a/src/platform/linux/linux_x11display.c +++ b/src/platform/linux/linux_x11display.c @@ -1 +1,469 @@ +/* *************************************************************************** + * linux_x11display.c -- surface support for linux xwindow. + * + * Copyright (C) 2016 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 . + * ****************************************************************************/ +/* **************************************************************************** + * linux_x11display.c -- linux 平台的图形显示功能支持,基于 xwindow。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +//#define DEBUG +#include +#include +#include +#define LCUI_SURFACE_C +#ifdef LCUI_BUILD_IN_LINUX +#include +#include +#include +#include +#include LCUI_DISPLAY_H +#include LCUI_EVENTS_H + +#define MIN_WIDTH 50 +#define MIN_HEIGHT 50 + +enum SurfaceTaskType { + TASK_CREATE, + TASK_MOVE, + TASK_RESIZE, + TASK_SHOW, + TASK_SET_CAPTION, + TASK_PRESENT, + TASK_DELETE, + TASK_TOTAL_NUM +}; + +typedef struct LCUI_SurfaceTaskRec_ { + int type; + union { + struct { + int x, y; + }; + struct { + int width, height; + }; + LCUI_BOOL show; + struct { + char *caption; + size_t caption_len; + }; + }; +} LCUI_SurfaceTaskRec, *LCUI_SurfaceTask; + +typedef struct LCUI_SurfaceRec_ { + int mode; + int width; + int height; + GC gc; + Window window; + XImage *ximage; + LCUI_BOOL is_ready; + LCUI_Graph fb; + LinkedList rects; + LinkedListNode node; +} LCUI_SurfaceRec; + +static struct X11_Display { + XVisualInfo vinfo; + LCUI_BOOL is_inited; + LinkedList surfaces; + LCUI_X11AppDriver app; + LCUI_EventTrigger trigger; +} x11; + +static void ReleaseSurfaceTask( void *arg ) +{ + LCUI_SurfaceTask task = arg; + if( task->type == TASK_SET_CAPTION ) { + free( task->caption ); + task->caption = NULL; + } +} + +static LCUI_Surface GetSurfaceByWindow( Window win ) +{ + LinkedListNode *node; + LinkedList_ForEach( node, &x11.surfaces ) { + if( ((LCUI_Surface)node->data)->window == win ) { + return node->data; + } + } + return NULL; +} + +static void X11Surface_OnResize( LCUI_Surface s, int width, int height ) +{ + int depth; + XGCValues gcv; + Visual *visual; + if( s->ximage ) { + XDestroyImage( s->ximage ); + s->ximage = NULL; + } + if( s->gc ) { + XFreeGC( x11.app->display, s->gc ); + s->gc = NULL; + } + Graph_Init( &s->fb ); + s->width = width; + s->height = height; + depth = DefaultDepth( x11.app->display, x11.app->screen ); + switch( depth ) { + case 32: + case 24: + s->fb.color_type = COLOR_TYPE_ARGB; + break; + default: + printf("[x11display] unsupport depth: %d.\n", depth); + break; + } + Graph_Create( &s->fb, width, height ); + visual = DefaultVisual( x11.app->display, x11.app->screen ); + s->ximage = XCreateImage( x11.app->display, visual, depth, ZPixmap, + 0, (char *)(s->fb.bytes), + width, height, 32, 0 ); + if( !s->ximage ) { + Graph_Free( &s->fb ); + printf("[x11display] create XImage faild.\n"); + return; + } + gcv.graphics_exposures = False; + s->gc = XCreateGC( x11.app->display, s->window, + GCGraphicsExposures, &gcv ); + if( !s->gc ) { + printf("[x11display] create graphics context faild.\n"); + return; + } +} + +static void X11Surface_OnCreate( LCUI_Surface s ) +{ + unsigned long bdcolor = BlackPixel(x11.app->display, x11.app->screen); + unsigned long bgcolor = WhitePixel(x11.app->display, x11.app->screen); + s->window = XCreateSimpleWindow( x11.app->display, x11.app->win_root, + 0, 100, MIN_WIDTH, MIN_HEIGHT, 1, + bdcolor, bgcolor ); + LinkedList_Init( &s->rects ); + X11Surface_OnResize( s, MIN_WIDTH, MIN_HEIGHT ); + s->is_ready = TRUE; + LCUI_SetLinuxX11MainWindow( s->window ); +} + +static void X11Surface_OnTask( LCUI_Surface surface, LCUI_SurfaceTask task ) +{ + Window win = surface->window; + Display *dpy = x11.app->display; + + switch( task->type ) { + case TASK_CREATE: + X11Surface_OnCreate( surface ); + break; + case TASK_RESIZE: { + int w = task->width , h = task->height; + w = MIN_WIDTH > w ? MIN_WIDTH: w; + h = MIN_HEIGHT > h ? MIN_HEIGHT: h; + X11Surface_OnResize( surface, w, h ); + XResizeWindow( dpy, win, w, h ); + break; + } + case TASK_MOVE: + XMoveWindow( dpy, win, task->x, task->y ); + break; + case TASK_SHOW: + if( task->show ) { + XMapWindow( dpy, win ); + } else { + XUnmapWindow( dpy, win ); + } + break; + case TASK_SET_CAPTION: { + XTextProperty name; + name.value = (unsigned char*)task->caption; + name.encoding = XA_STRING; + name.format = 8 * sizeof(char); + name.nitems = task->caption_len; + XSetWMName( dpy, win, &name ); + break; + } + case TASK_PRESENT: { + LinkedListNode *node; + LinkedList_ForEach( node, &surface->rects ) { + LCUI_Rect *rect = node->data; + XPutImage( x11.app->display, surface->window, + surface->gc, surface->ximage, + rect->x, rect->y, rect->x, rect->y, + rect->width, rect->height ); + } + LinkedList_Clear( &surface->rects, free ); + break; + } + case TASK_DELETE: + default: break; + } +} + +static void X11Surface_SendTask( LCUI_Surface surface, LCUI_SurfaceTask task ) +{ + LCUI_AppTaskRec apptask; + LCUI_SurfaceTask newtask; + newtask = NEW( LCUI_SurfaceTaskRec, 1 ); + *newtask = *task; + apptask.arg[0] = surface; + apptask.arg[1] = newtask; + apptask.destroy_arg[0] = NULL; + apptask.destroy_arg[1] = ReleaseSurfaceTask; + apptask.func = (LCUI_AppTaskFunc)X11Surface_OnTask; + LCUI_PostTask( &apptask ); +} + +static void X11Surface_Delete( LCUI_Surface surface ) +{ + LCUI_SurfaceTaskRec task; + task.type = TASK_DELETE; + LinkedList_Unlink( &x11.surfaces, &surface->node ); + X11Surface_SendTask( surface, &task ); +} + +static LCUI_Surface X11Surface_New( void ) +{ + LCUI_Surface surface; + LCUI_SurfaceTaskRec task; + task.type = TASK_CREATE; + surface = NEW( LCUI_SurfaceRec, 1 ); + surface->is_ready = FALSE; + surface->node.data = surface; + surface->gc = NULL; + surface->ximage = NULL; + Graph_Init( &surface->fb ); + surface->fb.color_type = COLOR_TYPE_ARGB; + LinkedList_AppendNode( &x11.surfaces, &surface->node ); + X11Surface_SendTask( surface, &task ); + return surface; +} + +static LCUI_BOOL X11Surface_IsReady( LCUI_Surface surface ) +{ + return surface->is_ready; +} + +static void X11Surface_Move( LCUI_Surface surface, int x, int y ) +{ + LCUI_SurfaceTaskRec task; + task.type = TASK_MOVE; + task.x = x; + task.y = y; + X11Surface_SendTask( surface, &task ); +} + +static void X11Surface_Resize( LCUI_Surface surface, int width, int height ) +{ + LCUI_SurfaceTaskRec task; + task.type = TASK_RESIZE; + task.width = width; + task.height = height; + X11Surface_SendTask( surface, &task ); +} + +static void X11Surface_Show( LCUI_Surface surface ) +{ + LCUI_SurfaceTaskRec task; + task.type = TASK_SHOW; + task.show = TRUE; + X11Surface_SendTask( surface, &task ); +} + +static void X11Surface_Hide( LCUI_Surface surface ) +{ + LCUI_SurfaceTaskRec task; + task.type = TASK_SHOW; + task.show = FALSE; + X11Surface_SendTask( surface, &task ); +} + +static void X11Surface_SetCaptionW( LCUI_Surface surface, const wchar_t *wstr ) +{ + int len; + LCUI_SurfaceTaskRec task; + + if( wstr ) { + char *caption; + len = LCUI_EncodeString( NULL, wstr, 0, ENCODING_UTF8 ) + 1; + caption = malloc( sizeof(char) * len ); + if( !caption ) { + return; + } + LCUI_EncodeString( caption, wstr, len, ENCODING_UTF8 ); + task.caption = caption; + task.caption_len = len - 1; + } else { + task.caption = NULL; + task.caption_len = 0; + } + task.type = TASK_SET_CAPTION; + X11Surface_SendTask( surface, &task ); +} + +void X11Surface_SetOpacity( LCUI_Surface surface, float opacity ) +{ + +} + +/** 设置 Surface 的渲染模式 */ +static void X11Surface_SetRenderMode( LCUI_Surface surface, int mode ) +{ + surface->mode = mode; +} + +static LCUI_PaintContext X11Surface_BeginPaint( LCUI_Surface surface, + LCUI_Rect *rect ) +{ + LCUI_PaintContext paint; + paint = malloc(sizeof(LCUI_PaintContextRec)); + paint->rect = *rect; + paint->with_alpha = FALSE; + Graph_Init( &paint->canvas ); + LCUIRect_ValidateArea( &paint->rect, surface->width, surface->height ); + Graph_Quote( &paint->canvas, &surface->fb, &paint->rect ); + Graph_FillRect( &paint->canvas, RGB( 255, 255, 255 ), NULL, TRUE ); + return paint; +} + +static void X11Surface_EndPaint( LCUI_Surface surface, + LCUI_PaintContext paint ) +{ + LCUI_Rect *r; + r = NEW( LCUI_Rect, 1 ); + *r = paint->rect; + LinkedList_Append( &surface->rects, r ); + free( paint ); +} + +/** 将帧缓存中的数据呈现至Surface的窗口内 */ +static void X11Surface_Present( LCUI_Surface surface ) +{ + + LCUI_SurfaceTaskRec task; + task.type = TASK_PRESENT; + X11Surface_SendTask( surface, &task ); +} + +/** 更新 surface,应用缓存的变更 */ +static void X11Surface_Update( LCUI_Surface surface ) +{ + return; +} + +static int WinDisplay_BindEvent( int event_id, LCUI_EventFunc func, + void *data, void (*destroy_data)(void*) ) +{ + return EventTrigger_Bind( x11.trigger, event_id, func, + data, destroy_data ); +} + +static void* X11Surface_GetHandle( LCUI_Surface s ) +{ + return NULL; +} + +static int X11Display_GetWidth( void ) +{ + Screen *s = DefaultScreenOfDisplay( x11.app->display ); + return XWidthOfScreen( s ); +} + +static int X11Display_GetHeight( void ) +{ + Screen *s = DefaultScreenOfDisplay( x11.app->display ); + return XHeightOfScreen( s ); +} + +static void OnExpose( LCUI_Event e, void *arg ) +{ + LCUI_Rect rect; + XEvent *ev = arg; + LCUI_Surface surface; + LCUI_DisplayEventRec dpy_ev; + rect.x = ev->xexpose.x; + rect.y = ev->xexpose.y; + rect.width = ev->xexpose.width; + rect.height = ev->xexpose.height; + surface = GetSurfaceByWindow( ev->xexpose.window ); + if( !surface ) { + return; + } + dpy_ev.type = DET_PAINT; + dpy_ev.surface = surface; + dpy_ev.paint.rect = rect; + EventTrigger_Trigger( x11.trigger, DET_PAINT, &dpy_ev ); +} + +int LCUI_InitLinuxX11Display( LCUI_DisplayDriver driver ) +{ + strcpy( driver->name, "x11" ); + x11.app = LCUI_GetAppData(); + if( !x11.app ) { + return -1; + } + driver->getWidth = X11Display_GetWidth; + driver->getHeight = X11Display_GetHeight; + driver->new = X11Surface_New; + driver->delete = X11Surface_Delete; + driver->isReady = X11Surface_IsReady; + driver->show = X11Surface_Show; + driver->hide = X11Surface_Hide; + driver->move = X11Surface_Move; + driver->resize = X11Surface_Resize; + driver->update = X11Surface_Update; + driver->present = X11Surface_Present; + driver->setCaptionW = X11Surface_SetCaptionW; + driver->setRenderMode = X11Surface_SetRenderMode; + driver->setOpacity = X11Surface_SetOpacity; + driver->getHandle = X11Surface_GetHandle; + driver->beginPaint = X11Surface_BeginPaint; + driver->endPaint = X11Surface_EndPaint; + driver->bindEvent = WinDisplay_BindEvent; + LinkedList_Init( &x11.surfaces ); + LCUI_BindSysEvent( Expose, OnExpose, NULL, NULL ); + x11.trigger = EventTrigger(); + x11.is_inited = TRUE; + return 0; +} + +int LCUI_ExitLinuxX11Display( void ) +{ + // ... + return 0; +} + +#endif diff --git a/src/platform/linux/linux_x11events.c b/src/platform/linux/linux_x11events.c index 59542060..076b0a62 100644 --- a/src/platform/linux/linux_x11events.c +++ b/src/platform/linux/linux_x11events.c @@ -1,31 +1,81 @@ +/* *************************************************************************** + * linux_x11events.c -- event loop support for linux xwindow. + * + * Copyright (C) 2016 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * linux_x11events.c -- linux 平台的事件驱动支持,基于 xwindow。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +#include +#include #include -#if defined(LCUI_BUILD_IN_LINUX) -#include -#include -#include +#ifdef LCUI_BUILD_IN_LINUX #include #include #include #include LCUI_EVENTS_H -static struct X11Driver { - int screen; - Display *display; - Window rootwin; - Colormap cmap; - LCUI_EventTrigger trigger; -} x11; +static LCUI_X11AppDriverRec x11; + +void LCUI_SetLinuxX11MainWindow( Window win ) +{ + x11.win_main = win; + XSelectInput( x11.display, win, ExposureMask | KeyPressMask | + ButtonPress | StructureNotifyMask | ButtonReleaseMask | + KeyReleaseMask | EnterWindowMask | LeaveWindowMask | + PointerMotionMask | Button1MotionMask | + VisibilityChangeMask ); + LCUI_SetTaskAgent( FALSE ); +} static LCUI_BOOL X11_PostTask( LCUI_AppTask task ) { - return FALSE; + XEvent ev; + memset( &ev, 0, sizeof (ev) ); + ev.xclient.type = ClientMessage; + ev.xclient.window = x11.win_main; + ev.xclient.format = 32; + ev.xclient.message_type = x11.wm_lcui; + XSendEvent( x11.display, x11.win_main, FALSE, NoEventMask, &ev ); + return TRUE; } static LCUI_BOOL X11_WaitEvent( void ) { int fd; fd_set fdset; - struct timeval zero_time; + struct timeval tv; XFlush( x11.display ); fd = ConnectionNumber( x11.display ); if( XEventsQueued(x11.display, QueuedAlready) ) { @@ -33,15 +83,26 @@ static LCUI_BOOL X11_WaitEvent( void ) } FD_ZERO( &fdset ); FD_SET( fd, &fdset ); - if( select(fd + 1, &fdset, NULL, NULL, &zero_time) == 1 ) { + tv.tv_sec = 0; + tv.tv_usec = 10000; + if( select(fd + 1, &fdset, NULL, NULL, &tv) == 1 ) { return XPending( x11.display ); } return FALSE; } -static void X11_PumpEvents( void ) +static void X11_DispatchEvent( void ) { - + XEvent xevent; + if( !XEventsQueued(x11.display, QueuedAlready) ) { + return; + } + XNextEvent( x11.display, &xevent ); + switch( xevent.type ) { + case ClientMessage: + default: break; + } + EventTrigger_Trigger( x11.trigger, xevent.type, &xevent ); } static int X11_BindSysEvent( int event_id, LCUI_EventFunc func, @@ -62,7 +123,7 @@ static int X11_UnbindSysEvent2( int handler_id ) static void *X11_GetData( void ) { - return NULL; + return &x11; } void LCUI_PreInitLinuxX11App( void *data ) @@ -72,15 +133,17 @@ void LCUI_PreInitLinuxX11App( void *data ) int LCUI_InitLinuxX11App( LCUI_AppDriver app ) { - x11.display = XOpenDisplay(NULL); + x11.display = XOpenDisplay( NULL ); if( !x11.display ) { return -1; } x11.screen = DefaultScreen( x11.display ); - x11.rootwin = RootWindow( x11.display, x11.screen ); + x11.win_root = RootWindow( x11.display, x11.screen ); x11.cmap = DefaultColormap( x11.display, x11.screen ); + x11.wm_lcui = XInternAtom( x11.display, "WM_LCUI", FALSE ); + XSetWMProtocols( x11.display, x11.win_root, &x11.wm_lcui, 1 ); app->WaitEvent = X11_WaitEvent; - app->PumbEvents = X11_PumpEvents; + app->DispatchEvent = X11_DispatchEvent; app->PostTask = X11_PostTask; app->BindSysEvent = X11_BindSysEvent; app->UnbindSysEvent = X11_UnbindSysEvent; @@ -89,4 +152,5 @@ int LCUI_InitLinuxX11App( LCUI_AppDriver app ) x11.trigger = EventTrigger(); return 0; } + #endif diff --git a/src/platform/linux/linux_x11mouse.c b/src/platform/linux/linux_x11mouse.c new file mode 100644 index 00000000..839661d4 --- /dev/null +++ b/src/platform/linux/linux_x11mouse.c @@ -0,0 +1,101 @@ +/* *************************************************************************** + * linux_x11mouse.c -- mouse support for linux xwindow. + * + * Copyright (C) 2016 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * linux_x11mouse.c -- linux 平台的鼠标支持,基于 xwindow。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +#include +#include +#include +#ifdef LCUI_BUILD_IN_LINUX +#include +#include +#include LCUI_EVENTS_H +#include LCUI_MOUSE_H + +static void OnMotionNotify( LCUI_Event e, void *arg ) +{ + XEvent *ev = arg; + LCUI_SysEventRec sys_ev; + static LCUI_Pos mouse_pos = {0, 0}; + sys_ev.type = LCUI_MOUSEMOVE; + sys_ev.motion.x = ev->xmotion.x; + sys_ev.motion.y = ev->xmotion.y; + sys_ev.motion.xrel = ev->xmotion.x - mouse_pos.x; + sys_ev.motion.yrel = ev->xmotion.y - mouse_pos.y; + mouse_pos.x = ev->xmotion.x; + mouse_pos.y = ev->xmotion.y; + LCUI_TriggerEvent( &sys_ev, NULL ); + LCUI_DestroyEvent( &sys_ev ); +} + +static void OnButtonPress( LCUI_Event e, void *arg ) +{ + XEvent *ev = arg; + LCUI_SysEventRec sys_ev; + sys_ev.type = LCUI_MOUSEDOWN; + sys_ev.button.x = ev->xbutton.x; + sys_ev.button.y = ev->xbutton.y; + sys_ev.button.button = ev->xbutton.button; + LCUI_TriggerEvent( &sys_ev, NULL ); + LCUI_DestroyEvent( &sys_ev ); +} + +static void OnButtonRelease( LCUI_Event e, void *arg ) +{ + XEvent *ev = arg; + LCUI_SysEventRec sys_ev; + sys_ev.type = LCUI_MOUSEUP; + sys_ev.button.x = ev->xbutton.x; + sys_ev.button.y = ev->xbutton.y; + sys_ev.button.button = ev->xbutton.button; + LCUI_TriggerEvent( &sys_ev, NULL ); + LCUI_DestroyEvent( &sys_ev ); +} + +void LCUI_InitLinuxX11Mouse( void ) +{ + LCUI_BindSysEvent( MotionNotify, OnMotionNotify, NULL, NULL ); + LCUI_BindSysEvent( ButtonPress, OnButtonPress, NULL, NULL ); + LCUI_BindSysEvent( ButtonRelease, OnButtonRelease, NULL, NULL ); +} + +void LCUI_ExitLinuxX11Mouse( void ) +{ + LCUI_UnbindSysEvent( MotionNotify, OnMotionNotify ); +} + +#endif diff --git a/src/platform/windows/windows_display.c b/src/platform/windows/windows_display.c index 47f5e3cb..15f21f63 100644 --- a/src/platform/windows/windows_display.c +++ b/src/platform/windows/windows_display.c @@ -40,10 +40,9 @@ //#define DEBUG #include #include -#define __IN_SURFACE_SOURCE_FILE__ +#define LCUI_SURFACE_C #ifdef LCUI_BUILD_IN_WIN32 #include -#include #include #include #include LCUI_DISPLAY_H @@ -98,7 +97,7 @@ static struct WIN_Display { static LCUI_Surface GetSurfaceByHWND( HWND hwnd ) { LinkedListNode *node; - LinkedList_ForEach( node, &win.surfaces ) { + for( LinkedList_Each( node, &win.surfaces ) ) { if( ((LCUI_Surface)node->data)->hwnd == hwnd ) { return node->data; } @@ -127,7 +126,7 @@ static void WinSurface_Destroy( LCUI_Surface surface ) static void WinSurface_ExecDelete( LCUI_Surface surface ) { LinkedListNode *node; - LinkedList_ForEach( node, &win.surfaces ) { + for( LinkedList_Each( node, &win.surfaces ) ) { if( node->data == surface ) { WinSurface_Destroy( node->data ); LinkedList_DeleteNode( &win.surfaces, node ); @@ -158,9 +157,12 @@ static void OnCreateSurface( void *arg1, void *arg2 ) instance, NULL ); hdc_client = GetDC( surface->hwnd ); + RegisterTouchWindow( surface->hwnd, 0 ); surface->fb_hdc = CreateCompatibleDC( hdc_client ); surface->is_ready = TRUE; DEBUG_MSG("surface: %p, surface->hwnd: %p\n", surface, surface->hwnd); + LCUI_SetMainWindow( surface->hwnd ); + LCUI_SetTaskAgent( FALSE ); } /** 新建一个 Surface */ @@ -384,19 +386,19 @@ static void WinSurface_Update( LCUI_Surface surface ) static void OnWMPaint( LCUI_Event e, void *arg ) { + MSG *msg = arg; PAINTSTRUCT ps; LCUI_Rect area; LCUI_Surface surface; LCUI_DisplayEventRec dpy_ev; - WIN_SysEvent sys_event = arg; - BeginPaint( sys_event->hwnd, &ps ); + BeginPaint( msg->hwnd, &ps ); /* 获取区域坐标及尺寸 */ area.x = ps.rcPaint.left; area.y = ps.rcPaint.top; area.width = ps.rcPaint.right - area.x; area.height = ps.rcPaint.bottom - area.y; - EndPaint( sys_event->hwnd, &ps ); - surface = GetSurfaceByHWND( sys_event->hwnd ); + EndPaint( msg->hwnd, &ps ); + surface = GetSurfaceByHWND( msg->hwnd ); if( !surface ) { return; } @@ -408,26 +410,26 @@ static void OnWMPaint( LCUI_Event e, void *arg ) static void OnWMGetMinMaxInfo( LCUI_Event e, void *arg ) { + MSG *msg = arg; MINMAXINFO *mminfo; - WIN_SysEvent sys_event = arg; - mminfo = (PMINMAXINFO)sys_event->lparam; + mminfo = (PMINMAXINFO)msg->lParam; mminfo->ptMinTrackSize.x = MIN_WIDTH; mminfo->ptMinTrackSize.y = MIN_HEIGHT; } static void OnWMSize( LCUI_Event e, void *arg ) { + MSG *msg = arg; LCUI_Surface surface; LCUI_DisplayEventRec dpy_ev; - WIN_SysEvent sys_event = arg; - surface = GetSurfaceByHWND( sys_event->hwnd ); + surface = GetSurfaceByHWND( msg->hwnd ); if( !surface ) { return; } dpy_ev.surface = surface; dpy_ev.type = DET_RESIZE; - dpy_ev.resize.width = LOWORD( sys_event->lparam ); - dpy_ev.resize.height = HIWORD( sys_event->lparam ); + dpy_ev.resize.width = LOWORD( msg->lParam ); + dpy_ev.resize.height = HIWORD( msg->lParam ); EventTrigger_Trigger( win.trigger, DET_RESIZE, &dpy_ev ); } diff --git a/src/platform/windows/windows_events.c b/src/platform/windows/windows_events.c index 8b4326e4..d11a167a 100644 --- a/src/platform/windows/windows_events.c +++ b/src/platform/windows/windows_events.c @@ -20,24 +20,19 @@ static struct WindowsDriver { static LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM arg1, LPARAM arg2 ) { - LCUI_AppTask task; - WIN_SysEventRec win_event; + MSG win_ev; switch( msg ) { case WM_LCUI_EVENT: - task = (LCUI_AppTask)arg2; - LCUI_RunTask( task ); - LCUI_DeleteTask( task ); return 0; case WM_CLOSE: LCUI_Quit(); default:break; } - win_event.msg = msg; - win_event.data = NULL; - win_event.hwnd = hwnd; - win_event.wparam = arg1; - win_event.lparam = arg2; - if( EventTrigger_Trigger( win.trigger, msg, &win_event ) == 0 ) { + win_ev.hwnd = hwnd; + win_ev.wParam = arg1; + win_ev.lParam = arg2; + win_ev.message = msg; + if( EventTrigger_Trigger( win.trigger, msg, &win_ev ) == 0 ) { return DefWindowProc( hwnd, msg, arg1, arg2 ); } return 0; @@ -57,10 +52,10 @@ static LCUI_BOOL WIN_WaitEvent( void ) return WaitMessage(); } -static void WIN_PumpEvents( void ) +static void WIN_DispatchEvent( void ) { MSG msg; - while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { + if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } @@ -87,6 +82,11 @@ static void *WIN_GetData( void ) return win.main_instance; } +void LCUI_SetMainWindow( HWND hwnd ) +{ + win.main_hwnd = hwnd; +} + /** win32的动态库的入口函数 */ BOOL APIENTRY DllMain( HMODULE hModule, DWORD reason, LPVOID unused ) { @@ -131,21 +131,11 @@ int LCUI_InitWinApp( LCUI_AppDriver app ) app->GetData = WIN_GetData; app->PostTask = WIN_PostTask; app->WaitEvent = WIN_WaitEvent; - app->PumbEvents = WIN_PumpEvents; + app->DispatchEvent = WIN_DispatchEvent; app->BindSysEvent = WIN_BindSysEvent; app->UnbindSysEvent = WIN_UnbindSysEvent; app->UnbindSysEvent2 = WIN_UnbindSysEvent2; win.trigger = EventTrigger(); - /** - * 创建一个隐藏的主窗体,用于接收 LCUI 的任务 - * 之前用 PostThreadMessage() 无法发送自定义消息到主线程的消息循环,因此 - * 改成创建隐藏窗体兵用 PostMessage() 发送任务。 - */ - win.main_hwnd = CreateWindow( - TEXT("LCUI"), TEXT("LCUI Task Receiver"), 0, - CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, - win.main_instance, NULL - ); return 0; } diff --git a/src/platform/windows/windows_keyboard.c b/src/platform/windows/windows_keyboard.c index 4c25ffbc..0771c133 100644 --- a/src/platform/windows/windows_keyboard.c +++ b/src/platform/windows/windows_keyboard.c @@ -8,17 +8,17 @@ static void OnKeyboardMessage( LCUI_Event ev, void *arg ) { + MSG* msg = arg; static POINT mouse_pos; LCUI_SysEventRec sys_ev; - WIN_SysEvent win_ev = arg; - switch( win_ev->msg ) { + switch( msg->message ) { case WM_KEYDOWN: sys_ev.type = LCUI_KEYDOWN; - sys_ev.key_code = win_ev->wparam; + sys_ev.key.code = msg->wParam; break; case WM_KEYUP: sys_ev.type = LCUI_KEYUP; - sys_ev.key_code = win_ev->wparam; + sys_ev.key.code = msg->wParam; break; default: return; } diff --git a/src/platform/windows/windows_mouse.c b/src/platform/windows/windows_mouse.c index b8432ffd..75e5b4cf 100644 --- a/src/platform/windows/windows_mouse.c +++ b/src/platform/windows/windows_mouse.c @@ -8,17 +8,19 @@ static void OnMouseMessage( LCUI_Event ev, void *arg ) { + MSG *msg = arg; LCUI_SysEventRec sys_ev; - WIN_SysEvent win_ev = arg; static POINT mouse_pos = {0, 0}; sys_ev.type = LCUI_NONE; - switch( win_ev->msg ) { + switch( msg->message ) { case WM_MOUSEMOVE: { POINT new_pos; GetCursorPos( &new_pos ); - ScreenToClient( win_ev->hwnd, &new_pos ); - sys_ev.rel_x = new_pos.x - mouse_pos.x; - sys_ev.rel_y = new_pos.y - mouse_pos.y; + ScreenToClient( msg->hwnd, &new_pos ); + sys_ev.motion.x = new_pos.x; + sys_ev.motion.y = new_pos.y; + sys_ev.motion.xrel = new_pos.x - mouse_pos.x; + sys_ev.motion.yrel = new_pos.y - mouse_pos.y; mouse_pos.x = new_pos.x; mouse_pos.y = new_pos.y; sys_ev.type = LCUI_MOUSEMOVE; @@ -26,28 +28,89 @@ static void OnMouseMessage( LCUI_Event ev, void *arg ) } case WM_LBUTTONDOWN: sys_ev.type = LCUI_MOUSEDOWN; - sys_ev.key_code = 1; + sys_ev.button.button = 1; + sys_ev.button.x = mouse_pos.x; + sys_ev.button.y = mouse_pos.y; + SetCapture( msg->hwnd ); break; case WM_LBUTTONUP: sys_ev.type = LCUI_MOUSEUP; - sys_ev.key_code = 1; + sys_ev.button.button = 1; + sys_ev.button.x = mouse_pos.x; + sys_ev.button.y = mouse_pos.y; + ReleaseCapture(); break; case WM_RBUTTONDOWN: sys_ev.type = LCUI_MOUSEDOWN; - sys_ev.key_code = 2; + sys_ev.button.button = 2; + sys_ev.button.x = mouse_pos.x; + sys_ev.button.y = mouse_pos.y; + SetCapture( msg->hwnd ); break; case WM_RBUTTONUP: sys_ev.type = LCUI_MOUSEUP; - sys_ev.key_code = 2; + sys_ev.button.button = 2; + sys_ev.button.x = mouse_pos.x; + sys_ev.button.y = mouse_pos.y; + ReleaseCapture(); break; case WM_MOUSEWHEEL: sys_ev.type = LCUI_MOUSEWHEEL; - sys_ev.z_delta = GET_WHEEL_DELTA_WPARAM( win_ev->wparam ); + sys_ev.wheel.x = mouse_pos.x; + sys_ev.wheel.y = mouse_pos.y; + sys_ev.wheel.delta = GET_WHEEL_DELTA_WPARAM( msg->wParam ); break; + case WM_TOUCH: { + UINT i, n = LOWORD( msg->wParam ); + PTOUCHINPUT inputs = NEW( TOUCHINPUT, n ); + HTOUCHINPUT handle = (HTOUCHINPUT)msg->lParam; + if( inputs == NULL ) { + break; + } + sys_ev.type = LCUI_TOUCH; + sys_ev.touch.n_points = n; + sys_ev.touch.points = NEW( LCUI_TouchPointRec, n ); + if( sys_ev.touch.points == NULL ) { + free( inputs ); + break; + } + if( !GetTouchInputInfo( handle, n, inputs, + sizeof( TOUCHINPUT ) ) ) { + free( inputs ); + break; + } + for( i = 0; i < n; ++i ) { + POINT pos; + pos.x = inputs[i].x / 100; + pos.y = inputs[i].y / 100; + ScreenToClient( msg->hwnd, &pos ); + sys_ev.touch.points[i].x = pos.x; + sys_ev.touch.points[i].y = pos.y; + sys_ev.touch.points[i].id = inputs[i].dwID; + if( inputs[i].dwFlags & TOUCHEVENTF_PRIMARY ) { + sys_ev.touch.points[i].is_primary = TRUE; + } else { + sys_ev.touch.points[i].is_primary = FALSE; + } + if( inputs[i].dwFlags & TOUCHEVENTF_DOWN ) { + sys_ev.touch.points[i].state = LCUI_TOUCHDOWN; + } else if( inputs[i].dwFlags & TOUCHEVENTF_UP ) { + sys_ev.touch.points[i].state = LCUI_TOUCHUP; + } else if( inputs[i].dwFlags & TOUCHEVENTF_MOVE ) { + sys_ev.touch.points[i].state = LCUI_TOUCHMOVE; + } + } + free( inputs ); + if( !CloseTouchInputHandle( handle ) ) { + break; + } + break; + } default: break; } if( sys_ev.type != LCUI_NONE ) { LCUI_TriggerEvent( &sys_ev, NULL ); + LCUI_DestroyEvent( &sys_ev ); } } @@ -59,6 +122,7 @@ void LCUI_InitWinMouse( void ) LCUI_BindSysEvent( WM_RBUTTONDOWN, OnMouseMessage, NULL, NULL ); LCUI_BindSysEvent( WM_RBUTTONUP, OnMouseMessage, NULL, NULL ); LCUI_BindSysEvent( WM_MOUSEWHEEL, OnMouseMessage, NULL, NULL ); + LCUI_BindSysEvent( WM_TOUCH, OnMouseMessage, NULL, NULL ); } void LCUI_ExitWinMouse( void ) @@ -69,5 +133,6 @@ void LCUI_ExitWinMouse( void ) LCUI_UnbindSysEvent( WM_RBUTTONDOWN, OnMouseMessage ); LCUI_UnbindSysEvent( WM_RBUTTONUP, OnMouseMessage ); LCUI_UnbindSysEvent( WM_MOUSEWHEEL, OnMouseMessage ); + LCUI_UnbindSysEvent( WM_TOUCH, OnMouseMessage ); } #endif diff --git a/src/thread/pthread/mutex.c b/src/thread/pthread/mutex.c index e4fcb77e..000b5499 100755 --- a/src/thread/pthread/mutex.c +++ b/src/thread/pthread/mutex.c @@ -45,7 +45,10 @@ /* init the mutex */ int LCUIMutex_Init( LCUI_Mutex *mutex ) { - return pthread_mutex_init( mutex, NULL ); + pthread_mutexattr_t attr; + pthread_mutexattr_init( &attr ); + pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE ); + return pthread_mutex_init( mutex, &attr ); } /* Free the mutex */ diff --git a/src/thread/win32/cond.c b/src/thread/win32/cond.c index 83ab7a22..ef1ae35d 100644 --- a/src/thread/win32/cond.c +++ b/src/thread/win32/cond.c @@ -37,6 +37,7 @@ * 没有,请查看:. * ***************************************************************************/ +#include #include #include #include @@ -73,25 +74,41 @@ int LCUICond_Wait( LCUI_Cond *cond, LCUI_Mutex *mutex ) LCUIMutex_Unlock( mutex ); ret = WaitForSingleObject( *cond, INFINITE ); switch( ret ) { - case WAIT_TIMEOUT: break; - case WAIT_OBJECT_0: LCUIMutex_Lock( mutex ); return 0; + case WAIT_TIMEOUT: + ret = ETIMEDOUT; + break; + case WAIT_OBJECT_0: + ret = 0; + break; case WAIT_FAILED: - default: return -1; + default: + ret = GetLastError(); + break; } - return 1; + LCUIMutex_Lock( mutex ); + return ret; } /** 计时阻塞当前线程,等待条件成立 */ int LCUICond_TimedWait( LCUI_Cond *cond, LCUI_Mutex *mutex, unsigned int ms ) { + int ret; LCUIMutex_Unlock( mutex ); - switch( WaitForSingleObject( *cond, ms ) ) { - case WAIT_TIMEOUT: break; - case WAIT_OBJECT_0: LCUIMutex_Lock( mutex ); return 0; + ret = WaitForSingleObject( *cond, ms ); + switch( ret ) { + case WAIT_TIMEOUT: + ret = ETIMEDOUT; + break; + case WAIT_OBJECT_0: + ret = 0; + break; case WAIT_FAILED: - default: return -1; + default: + ret = GetLastError(); + break; } - return 1; + LCUIMutex_Lock( mutex ); + return ret; } /** 唤醒一个阻塞等待条件成立的线程 */ diff --git a/src/thread/win32/thread.c b/src/thread/win32/thread.c index 4d669699..ba67c202 100644 --- a/src/thread/win32/thread.c +++ b/src/thread/win32/thread.c @@ -92,7 +92,7 @@ static LCUI_ThreadData *LCUIThread_Find( LCUI_Thread tid ) { LinkedListNode *node; LCUI_ThreadData *thread_data; - LinkedList_ForEach( node, &thread_database ) { + for( LinkedList_Each( node, &thread_database ) ) { thread_data = (LCUI_ThreadData*)node->data; if( thread_data && thread_data->tid == tid ) { return thread_data; @@ -108,7 +108,7 @@ static int LCUIThread_Destroy( LCUI_Thread thread ) if(!thread){ return -1; } - LinkedList_ForEach( node, &thread_database ) { + for( LinkedList_Each( node, &thread_database ) ) { thread_data = (LCUI_ThreadData*)node->data; if( thread_data && thread_data->tid == thread ) { LinkedList_DeleteNode( &thread_database, node ); diff --git a/src/timer.c b/src/timer.c index a2cf87d5..ac16c26c 100644 --- a/src/timer.c +++ b/src/timer.c @@ -82,11 +82,11 @@ static void TimerList_AddNode( LinkedListNode *node ) LinkedListNode *cur; /* 计算该定时器的剩余定时时长 */ timer = node->data; - t = LCUI_GetTicks( timer->start_time ); + t = LCUI_GetTimeDelta( timer->start_time ); t = timer->total_ms - t + timer->pause_ms; - LinkedList_ForEach( cur, &self.timer_list ) { + for( LinkedList_Each( cur, &self.timer_list ) ) { timer = cur->data; - tt = LCUI_GetTicks( timer->start_time ); + tt = LCUI_GetTimeDelta( timer->start_time ); tt = timer->total_ms - tt + timer->pause_ms; if( t <= tt ) { LinkedList_Link( &self.timer_list, cur->prev, node ); @@ -105,10 +105,10 @@ static void TimerList_Print( void ) Timer timer; LinkedListNode *node; _DEBUG_MSG("timer list(%d) start:\n", self.timer_list.length); - LinkedList_ForEach( node, &self.timer_list ) { + for( LinkedList_Each( node, &self.timer_list ) { timer = node->data; _DEBUG_MSG("[%02d] %ld, func: %p, cur_ms: %ldms, total_ms: %ldms\n", - i++, timer->id, timer->func, timer->total_ms - (long int)LCUI_GetTicks(timer->start_time), timer->total_ms ); + i++, timer->id, timer->func, timer->total_ms - (long int)LCUI_GetTimeDelta(timer->start_time), timer->total_ms ); } _DEBUG_MSG("timer list end\n\n"); } @@ -122,11 +122,10 @@ static void TimerThread( void *arg ) int64_t lost_ms; LinkedListNode *node; LCUI_AppTaskRec task = {0}; - self.is_running = TRUE; LCUIMutex_Lock( &self.mutex ); while( self.is_running ) { Timer timer = NULL; - LinkedList_ForEach( node, &self.timer_list ) { + for( LinkedList_Each( node, &self.timer_list ) ) { timer = node->data; if( timer && timer->state == STATE_RUN ) { break; @@ -139,7 +138,7 @@ static void TimerThread( void *arg ) LCUIMutex_Lock( &self.mutex ); continue; } - lost_ms = LCUI_GetTicks( timer->start_time ); + lost_ms = LCUI_GetTimeDelta( timer->start_time ); /* 减去处于暂停状态的时长 */ lost_ms -= timer->pause_ms; /* 若流失的时间未达到总定时时长,则睡眠一段时间 */ @@ -156,7 +155,7 @@ static void TimerThread( void *arg ) LinkedList_Unlink( &self.timer_list, node ); if( timer->reuse ) { timer->pause_ms = 0; - timer->start_time = LCUI_GetTickCount(); + timer->start_time = LCUI_GetTime(); TimerList_AddNode( node ); } else { free( timer ); @@ -172,7 +171,7 @@ static Timer TimerList_Find( int timer_id ) { Timer timer; LinkedListNode *node; - LinkedList_ForEach( node, &self.timer_list ) { + for( LinkedList_Each( node, &self.timer_list ) ) { timer = node->data; if( timer && timer->id == timer_id ) { return timer; @@ -200,7 +199,7 @@ int LCUITimer_Set( long int n_ms, void (*func)(void*), timer->total_ms = n_ms; timer->state = STATE_RUN; timer->id = ++self.id_count; - timer->start_time = LCUI_GetTickCount(); + timer->start_time = LCUI_GetTime(); timer->node.next = NULL; timer->node.prev = NULL; timer->node.data = timer; @@ -240,7 +239,7 @@ int LCUITimer_Pause( int timer_id ) timer = TimerList_Find( timer_id ); if( timer ) { /* 记录暂停时的时间 */ - timer->pause_time = LCUI_GetTickCount(); + timer->pause_time = LCUI_GetTime(); timer->state = STATE_PAUSE; } LCUICond_Signal( &self.sleep_cond ); @@ -258,7 +257,7 @@ int LCUITimer_Continue( int timer_id ) timer = TimerList_Find( timer_id ); if( timer ) { /* 计算处于暂停状态的时长 */ - timer->pause_ms += (long int)LCUI_GetTicks( timer->pause_time ); + timer->pause_ms += (long int)LCUI_GetTimeDelta( timer->pause_time ); timer->state = STATE_RUN; } LCUICond_Signal( &self.sleep_cond ); @@ -277,7 +276,7 @@ int LCUITimer_Reset( int timer_id, long int n_ms ) if( timer ) { timer->pause_ms = 0; timer->total_ms = n_ms; - timer->start_time = LCUI_GetTickCount(); + timer->start_time = LCUI_GetTime(); } LCUICond_Signal( &self.sleep_cond ); LCUIMutex_Unlock( &self.mutex ); @@ -286,11 +285,12 @@ int LCUITimer_Reset( int timer_id, long int n_ms ) void LCUI_InitTimer( void ) { - LCUI_StartTicks(); + LCUITime_Init(); LCUIMutex_Init( &self.mutex ); LCUICond_Init( &self.sleep_cond ); LinkedList_Init( &self.timer_list ); LCUIThread_Create( &self.tid, TimerThread, NULL ); + self.is_running = TRUE; } void LCUI_ExitTimer( void ) @@ -300,7 +300,7 @@ void LCUI_ExitTimer( void ) LCUICond_Broadcast( &self.sleep_cond ); LCUIMutex_Unlock( &self.mutex ); LCUIThread_Join( self.tid, NULL ); - LinkedList_Clear( &self.timer_list, free ); + LinkedList_ClearData( &self.timer_list, free ); LCUICond_Destroy( &self.sleep_cond ); LCUIMutex_Destroy( &self.mutex ); } diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 7a6c292e..ebc9b1e3 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -2,5 +2,5 @@ AUTOMAKE_OPTIONS=foreign AM_CFLAGS = -I$(abs_top_srcdir)/include noinst_LTLIBRARIES = libutil.la libutil_la_SOURCES = rbtree.c dict.c linkedlist.c time.c event.c rect.c string.c \ -delay.c dirent.c parse.c framectrl.c +dirent.c parse.c framectrl.c memdebug.c diff --git a/src/util/delay.c b/src/util/delay.c deleted file mode 100644 index 94de0240..00000000 --- a/src/util/delay.c +++ /dev/null @@ -1,69 +0,0 @@ -/* *************************************************************************** - * delay.c -- time delay function. - * - * 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 . - * ****************************************************************************/ - -/* **************************************************************************** - * delay.c -- 一些提供延时功能的函数 - * - * 版权所有 (C) 2013 归属于 - * 刘超 - * - * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 - * - * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) - * - * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 - * - * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 - * 定用途的隐含担保,详情请参照GPLv2许可协议。 - * - * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 - * 没有,请查看:. - * ****************************************************************************/ -#include -#include - -#ifdef LCUI_BUILD_IN_WIN32 -#include -#else -#include -#endif -/* 秒级延时 */ -LCUI_API void -LCUI_Sleep( unsigned int s ) -{ -#ifdef LCUI_BUILD_IN_WIN32 - Sleep(s*1000); -#else - sleep(s); -#endif -} - -/* 毫秒级延时 */ -LCUI_API void -LCUI_MSleep( unsigned int ms ) -{ -#ifdef LCUI_BUILD_IN_WIN32 - Sleep(ms); -#else - usleep(ms*1000); -#endif -} diff --git a/src/util/dict.c b/src/util/dict.c index 7b3b0d0f..07df84a6 100644 --- a/src/util/dict.c +++ b/src/util/dict.c @@ -222,7 +222,7 @@ int Dict_Rehash( Dict *d, int n ) return 1; } -#define timeInMilliseconds LCUI_GetTickCount +#define timeInMilliseconds LCUI_GetTime int Dict_RehashMilliseconds( Dict *d, int ms ) { @@ -658,3 +658,63 @@ void Dict_DisableResize( void ) { dict_can_resize = 0; } + +static unsigned int StringCopyKeyDict_KeyHash( const void *key ) +{ + const char *buf = key; + unsigned int hash = 5381; + while( *buf ) { + hash = ((hash << 5) + hash) + (*buf++); + } + return hash; +} + +static int StringCopyKeyDict_KeyCompare( void *privdata, const void *key1, + const void *key2 ) +{ + if( strcmp( key1, key2 ) == 0 ) { + return 1; + } + return 0; +} + +static void *StringCopyKeyDict_KeyDup( void *privdata, const void *key ) +{ + char *newkey = malloc( (strlen( key ) + 1)*sizeof( char ) ); + strcpy( newkey, key ); + return newkey; +} + +static void StringCopyKeyDict_KeyDestructor( void *privdata, void *key ) +{ + free( key ); +} + +static unsigned int IntKeyDict_KeyHash( const void *key ) +{ + unsigned int hash = (unsigned int)key; + return Dict_IntHashFunction( hash ); +} + +static unsigned int IdentityKeyDict_KeyHash( const void *key ) +{ + return (unsigned int)key; +} + +DictType DictType_StringKey = { + StringCopyKeyDict_KeyHash, + NULL, + NULL, + StringCopyKeyDict_KeyCompare, + NULL, + NULL +}; + +DictType DictType_StringCopyKey = { + StringCopyKeyDict_KeyHash, + StringCopyKeyDict_KeyDup, + NULL, + StringCopyKeyDict_KeyCompare, + StringCopyKeyDict_KeyDestructor, + NULL +}; diff --git a/src/util/event.c b/src/util/event.c index ff4538ad..f32c31ac 100644 --- a/src/util/event.c +++ b/src/util/event.c @@ -108,7 +108,7 @@ int EventTrigger_Unbind( LCUI_EventTrigger trigger, int event_id, return -1; } handlers = event_node->data; - LinkedList_ForEach( handler_node, handlers ) { + for( LinkedList_Each( handler_node, handlers ) ) { handler = handler_node->data; if( handler->func != func ) { continue; @@ -154,7 +154,7 @@ int EventTrigger_Unbind3( LCUI_EventTrigger trigger, int event_id, return -1; } handlers = event_node->data; - LinkedList_ForEach( handler_node, handlers ) { + for( LinkedList_Each( handler_node, handlers ) ) { handler = handler_node->data; if( !compare_func(key, handler->data) ) { continue; diff --git a/src/util/framectrl.c b/src/util/framectrl.c index 0fbd408a..bf7b4b55 100644 --- a/src/util/framectrl.c +++ b/src/util/framectrl.c @@ -38,21 +38,22 @@ * 没有,请查看:. * ****************************************************************************/ -#define __IN_FRAME_CONTROL_SOURCE_FILE__ +#define LCUI_UTIL_FRAMECTRL_C #include #include #include #include -#define FRAME_CTRL_STATE_RUN 0 -#define FRAME_CTRL_STATE_PAUSE 1 -#define FRAME_CTRL_STATE_QUIT 2 +enum FrameControlState { + STATE_RUN, + STATE_PAUSE, + STATE_QUIT +}; -struct FrameControlContext { +typedef struct FrameControlRec_ { int state; - LCUI_Cond wait_continue; - LCUI_Cond wait_pause; + LCUI_Cond cond; LCUI_Mutex mutex; unsigned int temp_fps; unsigned int current_fps; @@ -60,59 +61,53 @@ struct FrameControlContext { unsigned int pause_time; int64_t prev_frame_start_time; int64_t prev_fps_update_time; -}; +} FrameControlRec; -/** 新建帧数控制实例 */ -FrameCtrlCtx FrameControl_Create( void ) +FrameControl FrameControl_Create( void ) { - FrameCtrlCtx ctx; - ctx = (FrameCtrlCtx)malloc(sizeof(struct FrameControlContext)); + FrameControl ctx; + ctx = NEW( FrameControlRec, 1 ); ctx->temp_fps = 0; ctx->current_fps = 0; ctx->pause_time = 0; ctx->one_frame_remain_time = 10; - ctx->prev_frame_start_time = LCUI_GetTickCount(); - ctx->prev_fps_update_time = LCUI_GetTickCount(); - LCUICond_Init( &ctx->wait_continue ); - LCUICond_Init( &ctx->wait_pause ); + ctx->prev_frame_start_time = LCUI_GetTime(); + ctx->prev_fps_update_time = LCUI_GetTime(); + LCUICond_Init( &ctx->cond ); LCUIMutex_Init( &ctx->mutex ); - LCUIMutex_Lock( &ctx->mutex ); return ctx; } -/** 销毁帧数控制相关资源 */ -void FrameControl_Destroy( FrameCtrlCtx ctx ) +void FrameControl_Destroy( FrameControl ctx ) { LCUIMutex_Unlock( &ctx->mutex ); - LCUICond_Destroy( &ctx->wait_continue ); - LCUICond_Destroy( &ctx->wait_pause ); + LCUICond_Destroy( &ctx->cond ); LCUIMutex_Destroy( &ctx->mutex ); free( ctx ); } -/** 设置最大FPS(帧数/秒) */ -void FrameControl_SetMaxFPS( FrameCtrlCtx ctx, unsigned int fps ) +void FrameControl_SetMaxFPS( FrameControl ctx, unsigned int fps ) { ctx->one_frame_remain_time = (int)(1000.0/fps); } -/** 获取当前FPS */ -int FrameControl_GetFPS( FrameCtrlCtx ctx ) +int FrameControl_GetFPS( FrameControl ctx ) { return ctx->current_fps; } -/** 让当前帧停留一定时间 */ -void FrameControl_Remain( FrameCtrlCtx ctx ) +void FrameControl_Remain( FrameControl ctx ) { - unsigned int n_ms, lost_ms; int64_t current_time; + unsigned int n_ms, lost_ms; - if( ctx->state == FRAME_CTRL_STATE_QUIT ) { + if( ctx->state == STATE_QUIT ) { return; } - current_time = LCUI_GetTickCount(); - n_ms = (int)(current_time - ctx->prev_frame_start_time); + lost_ms = 0; + current_time = LCUI_GetTime(); + LCUIMutex_Lock( &ctx->mutex ); + n_ms = (unsigned int)(current_time - ctx->prev_frame_start_time); if( n_ms > ctx->one_frame_remain_time ) { goto normal_exit; } @@ -120,22 +115,27 @@ void FrameControl_Remain( FrameCtrlCtx ctx ) if( n_ms < 1 ) { goto normal_exit; } - /* 进行睡眠,直到需要暂停为止 */ - LCUICond_TimedWait( &ctx->wait_pause, &ctx->mutex, n_ms ); - /* 睡眠结束后,如果当前状态不为PAUSE,则说明睡眠不是因为要暂停而终止的 */ - if( ctx->state != FRAME_CTRL_STATE_PAUSE ) { - goto normal_exit; + /* 睡眠一段时间 */ + while( lost_ms < n_ms && ctx->state == STATE_RUN ) { + LCUICond_TimedWait( &ctx->cond, &ctx->mutex, n_ms - lost_ms ); + lost_ms = (unsigned int)LCUI_GetTimeDelta( current_time ); + } + /* 睡眠结束后,如果当前状态为 PAUSE,则说明睡眠是因为要暂停而终止的 */ + if( ctx->state == STATE_PAUSE ) { + current_time = LCUI_GetTime(); + /* 等待状态改为“继续” */ + while( ctx->state == STATE_PAUSE ) { + LCUICond_Wait( &ctx->cond, &ctx->mutex ); + } + lost_ms = (unsigned int)LCUI_GetTimeDelta( current_time ); + ctx->pause_time = lost_ms; + ctx->prev_frame_start_time += lost_ms; + LCUIMutex_Unlock( &ctx->mutex ); + return; } - current_time = LCUI_GetTickCount(); - /* 需要暂停,进行睡眠,直到需要继续为止 */ - LCUICond_Wait( &ctx->wait_continue, &ctx->mutex ); - lost_ms = (unsigned int)LCUI_GetTicks( current_time ); - ctx->pause_time = lost_ms; - ctx->prev_frame_start_time += lost_ms; - return; normal_exit:; - current_time = LCUI_GetTickCount(); + current_time = LCUI_GetTime(); if( current_time - ctx->prev_fps_update_time >= 1000 ) { ctx->current_fps = ctx->temp_fps; ctx->prev_fps_update_time = current_time; @@ -143,22 +143,20 @@ normal_exit:; } ctx->prev_frame_start_time = current_time; ++ctx->temp_fps; + LCUIMutex_Unlock( &ctx->mutex ); } -/** 暂停数据帧的更新 */ -void FrameControl_Pause( FrameCtrlCtx ctx, LCUI_BOOL need_pause ) +void FrameControl_Pause( FrameControl ctx, LCUI_BOOL need_pause ) { - if( ctx->state == FRAME_CTRL_STATE_RUN && need_pause ) { + if( ctx->state == STATE_RUN && need_pause ) { LCUIMutex_Lock( &ctx->mutex ); - ctx->state = FRAME_CTRL_STATE_PAUSE; - LCUICond_Signal( &ctx->wait_pause ); + ctx->state = STATE_PAUSE; + LCUICond_Signal( &ctx->cond ); LCUIMutex_Unlock( &ctx->mutex ); - } - else if( ctx->state == FRAME_CTRL_STATE_PAUSE && !need_pause ){ + } else if( ctx->state == STATE_PAUSE && !need_pause ) { LCUIMutex_Lock( &ctx->mutex ); - ctx->state = FRAME_CTRL_STATE_RUN; - LCUICond_Signal( &ctx->wait_continue ); + ctx->state = STATE_RUN; + LCUICond_Signal( &ctx->cond ); LCUIMutex_Unlock( &ctx->mutex ); } } - diff --git a/src/util/linkedlist.c b/src/util/linkedlist.c index e8d943d4..ff34be0f 100644 --- a/src/util/linkedlist.c +++ b/src/util/linkedlist.c @@ -38,6 +38,7 @@ * ****************************************************************************/ //#define DEBUG +#include #include #include #include @@ -52,7 +53,9 @@ void LinkedList_Init( LinkedList *list ) void LinkedList_Unlink( LinkedList *list, LinkedListNode *node ) { - (list)->length -= 1; + if( list->length > 0 ) { + list->length -= 1; + } if( node->next ) { node->next->prev = node->prev; } @@ -78,7 +81,6 @@ void LinkedList_ClearEx( LinkedList *list, void(*on_destroy)(void*), if( node->data && on_destroy ) { on_destroy( node->data ); } - node->data = NULL; if( free_node ) { free( node ); } @@ -93,6 +95,9 @@ LinkedListNode *LinkedList_GetNode( LinkedList *list, int pos ) if( pos < 0 ) { pos += list->length; } + if( pos >= list->length ) { + return NULL; + } if( pos > list->length / 2 ) { pos = list->length - pos - 1; node = list->tail.prev; @@ -196,3 +201,149 @@ void LinkedList_Concat( LinkedList *list1, LinkedList *list2 ) list1->length += list2->length; list2->length = 0; } + + +typedef struct SortRange_ { + int start, end; + LinkedListNode *snode, *enode; +} SortRange; + +static SortRange NewSortRange( int s, LinkedListNode *snode, + int e, LinkedListNode *enode ) +{ + SortRange r; + r.end = e; + r.start = s; + r.enode = enode; + r.snode = snode; + return r; +} + +void LinkedList_SwapNode( LinkedList *list, LinkedListNode *a, LinkedListNode *b ) +{ + LinkedListNode *node;/* + void *data; + data = a->data; + a->data = b->data; + b->data = data; + return;*/ + if( list->tail.prev == a ) { + list->tail.prev = b; + } else if( list->tail.prev == b ) { + list->tail.prev = a; + } + if( a->prev == b ) { + a->prev = b->prev; + a->prev->next = a; + b->prev = a; + b->next = a->next; + if( b->next ) { + b->next->prev = b; + } + a->next = b; + } else if( b->prev == a ) { + b->prev = a->prev; + b->prev->next = b; + a->prev = b; + a->next = b->next; + if( a->next ) { + a->next->prev = a; + } + b->next = a; + } else { + node = a->prev; + a->prev = b->prev; + a->prev->next = a; + b->prev = node; + b->prev->next = b; + node = a->next; + a->next = b->next; + if( a->next ) { + a->next->prev = a; + } + b->next = node; + if( b->next ) { + b->next->prev = b; + } + } +} + +void LinkedList_QuickSort( LinkedList *list, int (*cmp)(void*, void*) ) +{ + int p = 0; + SortRange *r; + if( list->length <= 0 ) { + return; + } + r = malloc( list->length * sizeof(SortRange) ); + r[p++] = NewSortRange( 0, list->head.next, + list->length - 1, list->tail.prev ); + while( p ) { + int left, right; + SortRange range = r[--p]; + LinkedListNode *mnode, *lnode, *rnode, *node; + if( range.start >= range.end ) { + continue; + } + mnode = range.enode; + left = range.start, right = range.end - 1; + lnode = range.snode, rnode = range.enode->prev; + while( left < right ) { + while( left < right && + cmp( lnode->data, mnode->data ) < 0 ) { + left++, lnode = lnode->next; + } + while( left < right && + cmp( rnode->data, mnode->data ) >= 0 ) { + right--, rnode = rnode->prev; + } + LinkedList_SwapNode( list, lnode, rnode ); + if( lnode == range.snode ) { + range.snode = rnode; + } + node = lnode; + lnode = rnode; + rnode = node; + } + if( cmp( lnode->data, range.enode->data) >= 0 ) { + LinkedList_SwapNode( list, lnode, range.enode ); + if( mnode == range.enode ) { + mnode = lnode; + } + node = lnode; + lnode = range.enode; + range.enode = node; + } else { + left++, lnode = lnode->next; + } + r[p++] = NewSortRange( range.start, range.snode, + left - 1, lnode->prev ); + r[p++] = NewSortRange( left + 1, lnode->next, + range.end, range.enode ); + } + free( r ); +} + +void LinkedList_BubbleSort( LinkedList *list, int( *cmp )(void*, void*) ) +{ + int i, j; + LinkedListNode *node, *cur, *next; + for( i = 0; i < list->length - 1; ++i ) { + LCUI_BOOL no_swap = TRUE; + cur = list->head.next; + for( j = 0; j < list->length - 1 - i; ++j ) { + next = cur->next; + if( cmp( cur->data, next->data ) >= 0 ) { + LinkedList_SwapNode( list, cur, next ); + node = cur; + cur = next; + next = node; + no_swap = FALSE; + } + cur = cur->next; + } + if( no_swap ) { + break; + } + } +} diff --git a/src/util/mem_debug.c b/src/util/mem_debug.c deleted file mode 100644 index f2eedff3..00000000 --- a/src/util/mem_debug.c +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include -#include - -//#define DEBUG -#ifdef DEBUG -static struct { - int alloc_count; - int free_count; - int saved_count; - int alloc_total_size; - int free_total_size; - int saved_total_size; -} mem_debug = { 0, 0, 0, 0, 0, 0 }; - -void *malloc( size_t size ) -{ - int *head; - mem_debug.saved_total_size += size; - if( size > 32 ) { - _DEBUG_MSG( "malloc[%d]: %lu bytes, saved_total: %d bytes\n", mem_debug.saved_count, size, mem_debug.saved_total_size ); - } - head = (int*)malloc(size+sizeof(int)); - *head = size; - ++mem_debug.saved_count; - ++mem_debug.alloc_count; - mem_debug.alloc_total_size += size; - return (void*)(head+1); -} - -void free( void *p ) -{ - int *head; - head = p; - head -= 1; - ++mem_debug.free_count; - mem_debug.saved_count = mem_debug.alloc_count - mem_debug.free_count; - mem_debug.free_total_size += *head; - mem_debug.saved_total_size = mem_debug.alloc_total_size - mem_debug.free_total_size; - if( *head > 32 ) { - _DEBUG_MSG( "free[%d]: %d bytes, saved_total: %d bytes\n", mem_debug.saved_count, *head, mem_debug.saved_total_size ); - } - free(head); -} -#endif diff --git a/src/util/memdebug.c b/src/util/memdebug.c new file mode 100644 index 00000000..8b929bdd --- /dev/null +++ b/src/util/memdebug.c @@ -0,0 +1,185 @@ +/* *************************************************************************** + * memdebug.c -- memory debug module, used for memory usage statistics. + * + * Copyright (C) 2016 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * memdebug.c -- 内存调试模块,用于统计各个内存块的使用情况,方便调试。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +#define ENABLE_MEMDEBUG +#include +#include +#include +#include +#include +#include + +#define HEAD_SIGN 123456 +#define TAIL_SIGN 654321 + +/** 内存块组 */ +typedef struct MemBlockGroupRec_ { + int id; /**< 组的标识号 */ + char *name; /**< 组的名称 */ + size_t size; /**< 当前组内内存块的总占用大小 */ + size_t count; /**< 内存块总数 */ +} MemBlockGroupRec, *MemBlockGroup; + +/** 内存块 */ +typedef struct MemBlockRec_ { + int head_sign; /**< 头部标识 */ + size_t size; /**< 内存块大小 */ + MemBlockGroup group; /**< 内存块所属组 */ + int tail_sign; /**< 尾部标识 */ +} MemBlockRec, *MemBlock; + +static struct { + int id_count; + Dict *groups; + LCUI_Mutex mutex; + DictType dtype; +} self; + +void LCUI_InitMemDebug( void ) +{ + self.dtype = DictType_StringCopyKey; + self.dtype.keyDup = NULL; + self.dtype.keyDestructor = NULL; + self.id_count = 1; + self.groups = Dict_Create( &self.dtype, NULL ); + LCUIMutex_Init( &self.mutex ); +} + +void LCUI_ExitMemDebug( void ) +{ + +} + +void LCUI_PrintMemStats( void ) +{ + DictEntry *entry; + DictIterator *iter; + printf("mem stats list start\n"); + LCUIMutex_Lock( &self.mutex ); + iter = Dict_GetIterator( self.groups ); + while( (entry = Dict_Next(iter)) ) { + MemBlockGroup group = DictEntry_GetVal( entry ); + printf( "[%40s] size: %.02f KB, count: %d\n", group->name, + 1.0 * group->size / 1024., group->count ); + } + LCUIMutex_Unlock( &self.mutex ); + printf("mem stats list end\n"); +} + +static void SetMemBlock( MemBlock blk, size_t size, const char *name ) +{ + MemBlockGroup group; + LCUIMutex_Lock( &self.mutex ); + group = Dict_FetchValue( self.groups, name ); + if( !group ) { + group = malloc( sizeof(MemBlockGroupRec) ); + group->id = self.id_count++; + group->name = strdup( name ); + group->size = 0; + group->count = 0; + Dict_Add( self.groups, group->name, group ); + } + group->count += 1; + group->size += size; + LCUIMutex_Unlock( &self.mutex ); + blk->head_sign = HEAD_SIGN; + blk->tail_sign = TAIL_SIGN; + blk->size = size; + blk->group = group; +} + +void LCUI_SetMemBlockName( void *ptr, const char *name ) +{ + MemBlock blk = (MemBlock)((char*)ptr - sizeof( MemBlockRec )); + if( blk->head_sign != HEAD_SIGN || blk->tail_sign != TAIL_SIGN ) { + abort(); + } + LCUIMutex_Lock( &self.mutex ); + blk->group->size -= blk->size; + blk->group->count -= 1; + LCUIMutex_Unlock( &self.mutex ); + SetMemBlock( blk, blk->size, name ); +} + +void *LCUI_Calloc( size_t count, size_t size, const char *name ) +{ + MemBlock blk; + size_t totalsize = size * count + sizeof( MemBlockRec ); + blk = calloc( count, (size_t)(1.0 * totalsize / count + 0.5) ); + SetMemBlock( blk, size * count, name ); + return ((char*)blk) + sizeof( MemBlockRec ); +} + +void *LCUI_Malloc( size_t size, const char *name ) +{ + MemBlock blk = malloc( size + sizeof( MemBlockRec ) ); + SetMemBlock( blk, size, name ); + return ((char*)blk) + sizeof( MemBlockRec ); +} + +void *LCUI_Realloc( void *ptr, size_t size ) +{ + MemBlock newblk; + MemBlock blk = (MemBlock)((char*)ptr - sizeof( MemBlockRec )); + if( blk->head_sign != HEAD_SIGN || blk->tail_sign != TAIL_SIGN ) { + abort(); + } + newblk = realloc( blk, size + sizeof( MemBlockRec ) ); + if( newblk ) { + LCUIMutex_Lock( &self.mutex ); + newblk->group->size += size - newblk->size; + newblk->size = size; + LCUIMutex_Unlock( &self.mutex ); + return ((char*)blk) + sizeof( MemBlockRec ); + } + return NULL; +} + +void LCUI_Free( void *ptr ) +{ + MemBlock blk = (MemBlock)((char*)ptr - sizeof( MemBlockRec )); + if( blk->head_sign != HEAD_SIGN || blk->tail_sign != TAIL_SIGN ) { + abort(); + } + LCUIMutex_Lock( &self.mutex ); + blk->group->size -= blk->size; + blk->group->count -= 1; + LCUIMutex_Unlock( &self.mutex ); + free( blk ); +} diff --git a/src/util/rbtree.c b/src/util/rbtree.c index 561b30bb..a0e78fe5 100644 --- a/src/util/rbtree.c +++ b/src/util/rbtree.c @@ -55,10 +55,9 @@ void RBTree_Init( LCUI_RBTree *rbt ) { rbt->root = NULL; - rbt->judge = NULL; + rbt->compare = NULL; rbt->destroy = NULL; rbt->total_node = 0; - rbt->need_free_data = 0; } static void DestroyRBTreeNode( LCUI_RBTree *rbt, LCUI_RBTreeNode *node ) @@ -75,13 +74,11 @@ static void DestroyRBTreeNode( LCUI_RBTree *rbt, LCUI_RBTreeNode *node ) node->parent->right = NULL; } } - if( rbt->destroy ) { + if( rbt->destroy && node->data ) { rbt->destroy( node->data ); } - if( rbt->need_free_data ) { - free( node->data ); - } node->data = NULL; + free( node ); } /** 销毁红黑树 */ @@ -89,6 +86,7 @@ void RBTree_Destroy( LCUI_RBTree *rbt ) { rbt->total_node = 0; DestroyRBTreeNode( rbt, rbt->root ); + rbt->root = NULL; } /** 获取第一个结点 */ @@ -282,18 +280,18 @@ rb_search_auxiliary( LCUI_RBTreeNode *root, int key, const void *keydata, LCUI_RBTreeNode* RBTree_CustomSearch( LCUI_RBTree* rbt, const void *keydata ) { - return rb_search_auxiliary( rbt->root, 0, keydata, rbt->judge, NULL ); + return rb_search_auxiliary( rbt->root, 0, keydata, rbt->compare, NULL ); } LCUI_RBTreeNode* RBTree_Search( LCUI_RBTree* rbt, int key ) { - return rb_search_auxiliary( rbt->root, key, NULL, rbt->judge, NULL ); + return rb_search_auxiliary( rbt->root, key, NULL, rbt->compare, NULL ); } void* RBTree_CustomGetData( LCUI_RBTree* rbt, const void *keydata ) { LCUI_RBTreeNode *node; - node = rb_search_auxiliary( rbt->root, 0, keydata, rbt->judge, NULL ); + node = rb_search_auxiliary( rbt->root, 0, keydata, rbt->compare, NULL ); if( node ) { return node->data; } @@ -303,7 +301,7 @@ void* RBTree_CustomGetData( LCUI_RBTree* rbt, const void *keydata ) void* RBTree_GetData( LCUI_RBTree* rbt, int key ) { LCUI_RBTreeNode *node; - node = rb_search_auxiliary( rbt->root, key, NULL, rbt->judge, NULL ); + node = rb_search_auxiliary( rbt->root, key, NULL, rbt->compare, NULL ); if( node ) { return node->data; } @@ -317,7 +315,7 @@ rb_insert( LCUI_RBTree *rbt, int key, const void *keydata, void *data ) parent_node = NULL; root = rbt->root; - node = rb_search_auxiliary( root, key, keydata, rbt->judge, &parent_node ); + node = rb_search_auxiliary( root, key, keydata, rbt->compare, &parent_node ); if( node ) { return NULL; } @@ -331,8 +329,8 @@ rb_insert( LCUI_RBTree *rbt, int key, const void *keydata, void *data ) node->color = RED; if( parent_node ) { - if( rbt->judge && keydata ) { - if( rbt->judge( parent_node->data, keydata ) > 0 ) { + if( rbt->compare && keydata ) { + if( rbt->compare( parent_node->data, keydata ) > 0 ) { parent_node->left = node; } else { parent_node->right = node; @@ -443,101 +441,106 @@ rb_erase_rebalance( LCUI_RBTreeNode *node, LCUI_RBTreeNode *parent, return root; } +static void rb_erase_by_node( LCUI_RBTree *rbt, LCUI_RBTreeNode *node ) +{ + unsigned char color; + LCUI_RBTreeNode *parent; + LCUI_RBTreeNode *old = node; + LCUI_RBTreeNode *child = NULL; + LCUI_RBTreeNode *root = rbt->root; + if( node->left && node->right ) { + LCUI_RBTreeNode *left; + node = node->right; + while( (left = node->left) != NULL ) { + node = left; + } + child = node->right; + parent = node->parent; + color = node->color; + + if( child ) { + child->parent = parent; + } + if( parent ) { + if( parent->left == node ) { + parent->left = child; + } else { + parent->right = child; + } + } else { + root = child; + } + + if( node->parent == old ) { + parent = node; + } + + node->parent = old->parent; + node->color = old->color; + node->right = old->right; + node->left = old->left; + + if( old->parent ) { + if( old->parent->left == old ) { + old->parent->left = node; + } else { + old->parent->right = node; + } + } else { + root = node; + } + + old->left->parent = node; + if( old->right ) { + old->right->parent = node; + } + } else { + if( !node->left ) { + child = node->right; + } else if( !node->right ) { + child = node->left; + } + parent = node->parent; + color = node->color; + + if( child ) { + child->parent = parent; + } + if( parent ) { + if( parent->left == node ) { + parent->left = child; + } else { + parent->right = child; + } + } else { + root = child; + } + } + + if( rbt->destroy && old->data ) { + rbt->destroy( old->data ); + } + free( old ); + if( color == BLACK ) { + /* 恢复红黑树性质 */ + root = rb_erase_rebalance( child, parent, root ); + } + rbt->root = root; + rbt->total_node -= 1; +} + /** 删除红黑树中的结点 */ static int rb_erase( LCUI_RBTree *rbt, int key, const void *keydata ) { - unsigned char color; - LCUI_RBTreeNode *root, *child = NULL, *parent, *old, *left, *node; - - root = rbt->root; - /* 查找要删除的结点 */ - node = rb_search_auxiliary( root, key, keydata, rbt->judge, NULL ); - if( !node ) { - return -1; - } - old = node; - if (node->left && node->right) { - node = node->right; - while ((left = node->left) != NULL) { - node = left; - } - child = node->right; - parent = node->parent; - color = node->color; - - if (child) { - child->parent = parent; - } - if (parent) { - if (parent->left == node) { - parent->left = child; - } else { - parent->right = child; - } - } else { - root = child; - } - - if (node->parent == old) { - parent = node; - } - - node->parent = old->parent; - node->color = old->color; - node->right = old->right; - node->left = old->left; - - if (old->parent) { - if (old->parent->left == old) { - old->parent->left = node; - } else { - old->parent->right = node; - } - } else { - root = node; - } - - old->left->parent = node; - if (old->right) { - old->right->parent = node; - } - } else { - if (!node->left) { - child = node->right; - } else if (!node->right) { - child = node->left; - } - parent = node->parent; - color = node->color; - - if (child) { - child->parent = parent; - } - if (parent) { - if (parent->left == node) { - parent->left = child; - } else { - parent->right = child; - } - } else { - root = child; - } - } - - if( rbt->destroy ) { - rbt->destroy( old->data ); + LCUI_RBTreeNode *node; + /* 查找要删除的结点 */ + node = rb_search_auxiliary( rbt->root, key, keydata, + rbt->compare, NULL ); + if( !node ) { + return -1; } - if( rbt->need_free_data ) { - free( old->data ); - } - free( old ); - if (color == BLACK) { - /* 恢复红黑树性质 */ - root = rb_erase_rebalance( child, parent, root ); - } - rbt->root = root; - rbt->total_node -= 1; - return 0; + rb_erase_by_node( rbt, node ); + return 0; } int RBTree_Erase( LCUI_RBTree *rbt, int key ) @@ -545,6 +548,11 @@ int RBTree_Erase( LCUI_RBTree *rbt, int key ) return rb_erase( rbt, key, NULL ); } +void RBTree_EraseNode( LCUI_RBTree *rbt, LCUI_RBTreeNode *node ) +{ + rb_erase_by_node( rbt, node ); +} + int RBTree_CustomErase( LCUI_RBTree *rbt, const void *keydata ) { return rb_erase( rbt, 0, keydata ); diff --git a/src/util/rect.c b/src/util/rect.c index 7ee5870c..c4d9582b 100644 --- a/src/util/rect.c +++ b/src/util/rect.c @@ -241,7 +241,7 @@ int RectList_Add( LinkedList *list, LCUI_Rect *rect ) if( rect->w <= 0 || rect->h <= 0 ) { return -1; } - LinkedList_ForEach( node, list ) { + for( LinkedList_Each( node, list ) ) { added_rect = node->data; /* 如果被现有的矩形包含 */ if( LCUIRect_IsIncludeRect( added_rect, rect ) ) { @@ -282,7 +282,7 @@ int RectList_Delete( LinkedList *list, LCUI_Rect *rect ) } DEBUG_MSG("list: %p, total: %d, rect(%d,%d,%d,%d)\n", list, list->length, rect->x, rect->y, rect->w, rect->h); - LinkedList_ForEach( node, list ) { + for( LinkedList_Each( node, list ) ) { p_rect = (LCUI_Rect*)node->data; DEBUG_MSG("p_rect(%d,%d,%d,%d)\n", p_rect->x, p_rect->y, p_rect->w, p_rect->h); diff --git a/src/util/string.c b/src/util/string.c index 6926c7c8..eb56186a 100644 --- a/src/util/string.c +++ b/src/util/string.c @@ -1,7 +1,7 @@ /* *************************************************************************** * string.c -- The string operation set. * - * Copyright (C) 2015 by Liu Chao + * Copyright (C) 2015-2016 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. @@ -22,7 +22,7 @@ /* **************************************************************************** * string.c -- 字符串相关操作函数。 * - * 版权所有 (C) 2015 归属于 刘超 + * 版权所有 (C) 2015-2016 归属于 刘超 * * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 * @@ -37,6 +37,9 @@ * 没有,请查看:. * ****************************************************************************/ +#include +#include +#include #include #include @@ -79,3 +82,219 @@ int strtrim( char *outstr, const char *instr, const char *charlist ) *op = 0; return op - outstr; } + +void freestrs( char **strs ) +{ + int i = 0; + while( strs[i] ) { + free( strs[i] ); + ++i; + } + free( strs ); +} + +int strsplit( const char *instr, const char *sep, char ***outstrs ) +{ + int len, i = 0; + const char *prev = instr; + int sep_len = strlen( sep ); + char *next = strstr( prev, sep ); + char **newstrs = NULL; + + while( 1 ) { + char **tmp, *str; + if( next ) { + len = next - prev + 1; + } else { + len = strlen( prev ) + 1; + } + str = malloc( sizeof( char ) * len ); + tmp = realloc( newstrs, sizeof( char* ) * (i + 2) ); + if( !tmp ) { + freestrs( newstrs ); + return 0; + } + newstrs = tmp; + strncpy( str, prev, len - 1 ); + str[len - 1] = 0; + newstrs[i] = str; + newstrs[i + 1] = NULL; + if( next ) { + prev = next + sep_len; + } else { + break; + } + next = strstr( prev, sep ); + i += 1; + } + *outstrs = newstrs; + return i + 1; +} + +static int strsaddone( char ***strlist, const char *str ) +{ + int i = 0; + char **newlist; + + if( !*strlist ) { + newlist = (char**)malloc( sizeof(char*) * 2 ); + goto check_done; + } + for( i = 0; (*strlist)[i]; ++i ) { + if( strcmp((*strlist)[i], str) == 0 ) { + return 0; + } + } + newlist = (char**)realloc( *strlist, (i+2)*sizeof(char*) ); +check_done: + if( !newlist ) { + return 0; + } + newlist[i] = strdup(str); + newlist[i+1] = NULL; + *strlist = newlist; + return 1; +} + +int strsadd( char ***strlist, const char *str ) +{ + char buff[256]; + int count = 0, i, head; + for( head = 0, i = 0; str[i]; ++i ) { + if( str[i] != ' ' ) { + continue; + } + if( i - 1 > head ) { + strncpy( buff, &str[head], i - head ); + buff[i - head] = 0; + count += strsaddone( strlist, buff ); + } + head = i + 1; + } + if( i - 1 > head ) { + strncpy( buff, &str[head], i - head ); + buff[i - head] = 0; + count += strsaddone( strlist, buff ); + } + return count; +} + +int strshas( char **strlist, const char *str ) +{ + int i; + if( !strlist ) { + return 0; + } + for( i = 0; strlist[i]; ++i ) { + if( strcmp(strlist[i], str) == 0 ) { + return 1; + } + } + return 0; +} + +static int strsdelone( char ***strlist, const char *str ) +{ + int i, pos, len; + char **newlist; + + if( !*strlist ) { + return 0; + } + for( pos = -1, i = 0; (*strlist)[i]; ++i ) { + if( strcmp( (*strlist)[i], str ) == 0 ) { + pos = i; + } + } + if( pos == -1 ) { + return 0; + } + if( pos == 0 && i < 2 ) { + free( *strlist ); + *strlist = NULL; + return 1; + } + len = i - 1; + newlist = (char**)malloc( i * sizeof(char*) ); + for( i = 0; i < pos; ++i ) { + newlist[i] = (*strlist)[i]; + } + for( i = pos; i < len; ++i ) { + newlist[i] = (*strlist)[i+1]; + } + newlist[i] = NULL; + free( (*strlist)[pos] ); + free( *strlist ); + *strlist = newlist; + return 1; +} + +int strsdel( char ***strlist, const char *str ) +{ + char buff[256]; + int count = 0, i, head; + + for( head = 0, i = 0; str[i]; ++i ) { + if( str[i] != ' ' ) { + continue; + } + if( i - 1 > head ) { + strncpy( buff, &str[head], i - head ); + buff[i - head] = 0; + count += strsdelone( strlist, buff ); + } + head = i + 1; + } + if( i - 1 > head ) { + strncpy( buff, &str[head], i - head ); + buff[i - head] = 0; + count += strsdelone( strlist, buff ); + } + return count; +} + +int sortedstrsadd( char ***strlist, const char *str ) +{ + int i, n, len, pos; + char **newlist, *newstr; + + if( *strlist ) { + for( i = 0; (*strlist)[i]; ++i ); + len = i + 2; + } else { + len = 2; + } + newlist = realloc( *strlist, sizeof( char* ) * len ); + if( !newlist ) { + return -ENOMEM; + } + newlist[len - 2] = NULL; + for( i = 0, pos = -1; newlist[i]; ++i ) { + n = strcmp( newlist[i], str ); + if( n < 0 ) { + continue; + } else if( n == 0 ) { + return 1; + } else { + pos = i; + } + } + n = strlen( str ) + 1; + newstr = malloc( sizeof(char) * n ); + if( !newstr ) { + return -ENOMEM; + } + strncpy( newstr, str, n ); + if( pos >= 0 ) { + for( i = len - 2; i > pos; --i ) { + newlist[i] = newlist[i - 1]; + } + newlist[pos] = newstr; + } else { + pos = len - 2; + } + newlist[pos] = newstr; + newlist[len - 1] = NULL; + *strlist = newlist; + return 0; +} diff --git a/src/util/time.c b/src/util/time.c index 6999c5a9..2cdc70ee 100644 --- a/src/util/time.c +++ b/src/util/time.c @@ -1,4 +1,42 @@ - +/* *************************************************************************** +* time.c -- The time operation set. +* +* Copyright (C) 2015-2016 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 . +* ****************************************************************************/ + +/* **************************************************************************** +* time.c -- 时间相关函数集 +* +* 版权所有 (C) 2015-2016 归属于 刘超 +* +* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 +* +* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) +* +* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 +* +* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 +* 定用途的隐含担保,详情请参照GPLv2许可协议。 +* +* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 +* 没有,请查看:. +* ****************************************************************************/ + #include #include #include @@ -14,7 +52,7 @@ static int hires_timer_available; /**< 标志,指示高精度计数器是否可用 */ static double hires_ticks_per_second; /**< 高精度计数器每秒的滴答数 */ -void LCUI_StartTicks( void ) +void LCUITime_Init( void ) { LARGE_INTEGER hires; if( QueryPerformanceFrequency(&hires) ) { @@ -26,11 +64,11 @@ void LCUI_StartTicks( void ) } } -int64_t LCUI_GetTickCount( void ) +int64_t LCUI_GetTime( void ) { LARGE_INTEGER hires_now; - if (hires_timer_available) { - QueryPerformanceCounter(&hires_now); + if( hires_timer_available ) { + QueryPerformanceCounter( &hires_now ); hires_now.QuadPart *= 1000; hires_now.QuadPart /= hires_ticks_per_second; return (int64_t)hires_now.QuadPart; @@ -39,14 +77,16 @@ int64_t LCUI_GetTickCount( void ) } #elif defined LCUI_BUILD_IN_LINUX +#include #include -void LCUI_StartTicks( void ) + +void LCUITime_Init( void ) { return; } -int64_t LCUI_GetTickCount( void ) +int64_t LCUI_GetTime( void ) { int64_t t; struct timeval tv; @@ -58,13 +98,29 @@ int64_t LCUI_GetTickCount( void ) #endif -int64_t LCUI_GetTicks( int64_t start_ticks ) +int64_t LCUI_GetTimeDelta( int64_t start ) { - int64_t now_ticks; - - now_ticks = LCUI_GetTickCount(); - if ( now_ticks < start_ticks ) { - return (TIME_WRAP_VALUE-start_ticks) + now_ticks; + int64_t now = LCUI_GetTime(); + if( now < start ) { + return (TIME_WRAP_VALUE - start) + now; } - return now_ticks - start_ticks; + return now - start; +} + +void LCUI_Sleep( unsigned int s ) +{ +#ifdef LCUI_BUILD_IN_WIN32 + Sleep( s * 1000 ); +#else + sleep( s ); +#endif +} + +void LCUI_MSleep( unsigned int ms ) +{ +#ifdef LCUI_BUILD_IN_WIN32 + Sleep( ms ); +#else + usleep( ms * 1000 ); +#endif } diff --git a/test/.directory b/test/.directory deleted file mode 100644 index a7ebe757..00000000 --- a/test/.directory +++ /dev/null @@ -1,4 +0,0 @@ -[Dolphin] -Timestamp=2013,5,10,18,55,59 -Version=3 -ViewMode=1 diff --git a/test/helloworld.c b/test/helloworld.c index bd60b78a..0a669be0 100755 --- a/test/helloworld.c +++ b/test/helloworld.c @@ -1,42 +1,32 @@ #include #include -#include #include #include +#include +#include -#ifdef LCUI_BUILD_IN_WIN32 -#include -#include - -/* 在运行程序时会打开控制台,以查看打印的调试信息 */ -static void InitConsoleWindow(void) +static void OnBtnClick( LCUI_Widget self, LCUI_WidgetEvent e, void *arg ) { - int hCrt; - FILE *hf; - AllocConsole(); - hCrt=_open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE),_O_TEXT ); - hf=_fdopen( hCrt, "w" ); - *stdout=*hf; - setvbuf (stdout, NULL, _IONBF, 0); - // test code - printf ("InitConsoleWindow OK!\n"); + wchar_t str[256]; + LCUI_Widget edit = LCUIWidget_GetById( "edit" ); + LCUI_Widget txt = LCUIWidget_GetById( "text-hello" ); + TextEdit_GetTextW( edit, 0, 255, str ); + TextView_SetTextW( txt, str ); } -#endif - int main( int argc, char **argv ) { - LCUI_Widget root, box; - -#ifdef LCUI_BUILD_IN_WIN32 - InitConsoleWindow(); -#endif - LCUI_Init(); - box = LCUIBuilder_LoadFile("hello.xml"); - if( box ) { - root = LCUIWidget_GetRoot(); - Widget_Append( root, box ); - Widget_Unwrap( box ); - } - return LCUI_Main(); + LCUI_Widget root, pack, btn; + + LCUI_Init(); + root = LCUIWidget_GetRoot(); + pack = LCUIBuilder_LoadFile( "helloworld.xml" ); + if( !pack ) { + return -1; + } + Widget_Append( root, pack ); + Widget_Unwrap( pack ); + btn = LCUIWidget_GetById( "btn-ok" ); + Widget_BindEvent( btn, "click", OnBtnClick, NULL, NULL ); + return LCUI_Main(); } diff --git a/test/helloworld.css b/test/helloworld.css new file mode 100644 index 00000000..cb279fef --- /dev/null +++ b/test/helloworld.css @@ -0,0 +1,13 @@ +textview.text-hello { + color: #8cc63f; + font-size: 18px; + font-family: "Comic Sans MS"; + text-align: center; + padding: 25px; + margin: 25px 0 0 25px; + border: 1px solid #000; + background-color: #fafafa; +} +#btn-ok, #edit { + margin: 25px 0 0 25px; +} \ No newline at end of file diff --git a/test/helloworld.xml b/test/helloworld.xml new file mode 100644 index 00000000..6e096bc0 --- /dev/null +++ b/test/helloworld.xml @@ -0,0 +1,10 @@ + + + + + + Hello, World! + Hello, World! + 确定 + + \ No newline at end of file diff --git a/test/testtouch.c b/test/testtouch.c new file mode 100644 index 00000000..7c8b611f --- /dev/null +++ b/test/testtouch.c @@ -0,0 +1,95 @@ +/** testtouch.c -- test touch support */ + +#include +#include +#include +#include +#include +#include + +/** 触点绑定记录 */ +typedef struct TouchPointBindingRec_ { + int point_id; /**< 触点 ID */ + LCUI_Widget widget; /**< 部件 */ + LinkedListNode node; /**< 在链表中的结点 */ + LCUI_BOOL is_valid; /**< 是否有效 */ +} TouchPointBindingRec, *TouchPointBinding; + +/** 触点绑定记录列表 */ +static LinkedList touch_bindings; + +static void OnTouchWidget( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) +{ + LCUI_TouchPoint point; + TouchPointBinding binding; + if( e->n_points == 0 ) { + return; + } + binding = e->data; + point = & e->points[0]; + switch( point->state ) { + case WET_TOUCHMOVE: + Widget_Move( binding->widget, point->x - 32, point->y - 32 ); + break; + case WET_TOUCHUP: + if( !binding->is_valid ) { + break; + } + /* 当触点释放后销毁部件及绑定记录 */ + Widget_ReleaseTouchCapture( binding->widget, -1 ); + LinkedList_Unlink( &touch_bindings, &binding->node ); + binding->is_valid = FALSE; + Widget_Destroy( w ); + free( binding ); + break; + case WET_TOUCHDOWN: + default: break; + } +} + +static void OnTouch( LCUI_SysEvent e, void *arg ) +{ + int i; + LinkedListNode *node; + LCUI_StyleSheet sheet; + LCUI_TouchPoint point; + for( i = 0; i < e->touch.n_points; ++i ) { + TouchPointBinding binding; + LCUI_BOOL is_existed = FALSE; + point = &e->touch.points[i]; + /* 检查该触点是否已经被绑定 */ + LinkedList_ForEach( node, &touch_bindings ) { + binding = node->data; + if( binding->point_id == point->id ) { + is_existed = TRUE; + } + } + if( is_existed ) { + continue; + } + /* 新建绑定记录 */ + binding = NEW( TouchPointBindingRec, 1 ); + binding->widget = LCUIWidget_New( NULL ); + binding->point_id = point->id; + binding->is_valid = TRUE; + binding->node.data = binding; + Widget_Resize( binding->widget, 64, 64 ); + Widget_Move( binding->widget, point->x - 32, point->y - 32 ); + /* 设置让该部件捕获当前触点 */ + Widget_SetTouchCapture( binding->widget, binding->point_id ); + Widget_BindEvent( binding->widget, "touch", OnTouchWidget, binding, NULL ); + sheet = binding->widget->custom_style; + SetStyle( sheet, key_position, SV_ABSOLUTE, style ); + SetStyle( sheet, key_background_color, RGB( 255, 0, 0 ), color ); + LinkedList_AppendNode( &touch_bindings, &binding->node ); + Widget_Top( binding->widget ); + } +} + +int main( int argc, char **argv ) +{ + LCUI_Init(); + LinkedList_Init( &touch_bindings ); + LCUI_BindEvent( LCUI_TOUCH, OnTouch, NULL, NULL ); + return LCUI_Main(); +}