Files
msime-windows/ui/src
fanlusky c3bfa69a29 refactor(ui): 按控件拆分 Controls.cpp
Controls.cpp 有 4200 行,Image、Button、CheckBox、ProgressBar、Slider、Separator、
Popup 及其宿主、菜单行、ComboBox、ListView、CandidateList、TreeView、TabControl、
Accordion 的实现,连同它们共用的文字测量与绘制工具全挤在一个文件里。沿用
TextBox.cpp 的做法,按控件拆成以控件命名的翻译单元:

- Image.cpp:Image(含只它用到的 WIC 读图尺寸)
- Button.cpp:Button 与 CheckBox(含只 Button 用到的 DrawTextBlock)
- RangeControls.cpp:ProgressBar 与 Slider
- Separator.cpp:Separator
- Popup.cpp:Popup(含 LayoutOverlay)、PopupHost、ContextMenuHost,以及只有
  Popup 用到的 DeflateSizeLocal / DeflateRectLocal 和 DrawPopupShadow
- Menu.cpp:MenuFlyoutItem 与 MenuSeparator(含托盘菜单字号常量和
  EstimateTrayLabelWidth)
- ComboBox.cpp:ComboBox 与下拉列表 ComboBoxPopupContent
- ListView.cpp:ListView
- CandidateList.cpp:CandidateList 及其文字度量缓存(含 FillRoundedRectCorners
  和彩色字体裁剪选项)
- TreeView.cpp、TabControl.cpp、Accordion.cpp:各自的控件
- ControlsInternal.h / ControlsInternal.cpp:多个控件共用的 GetSharedDWriteFactory、
  PointInRect、PointInRoundedRect、MeasureText、CreateCachedTextLayout、
  FillRoundedRect、DrawLabel 和两个共用圆角常量,只给 src/ 下的实现文件包含

纯搬移,不改行为:函数体、注释和格式都没动。多个文件共用的工具放进
msimeui::controls_detail 命名空间,声明在 ControlsInternal.h、定义只在
ControlsInternal.cpp 里有一份——CreateCachedTextLayout 的函数内静态
formatCache 和 GetSharedDWriteFactory 的静态工厂因此仍是全库唯一的一份,
不会按翻译单元各复制一份。只被一个控件用到的工具和常量仍留在该文件的匿名
命名空间。原来没人用的 MakeInsetRect 和 kCandidateItemGap 原样保留,分别放在
ControlsInternal.cpp 和 CandidateList.cpp 的匿名命名空间里。
using Microsoft::WRL::ComPtr 挪进内部头文件。Controls.cpp 已经没有剩余内容,
删除;ui/CMakeLists.txt 的源文件列表相应更新,Server 通过 add_subdirectory
引入 msimeui,不需要改。

非搬移改动只有两处:CreateCachedTextLayout 和 DrawLabel 的默认实参从定义挪到了
头文件里的声明上,DrawLabel 定义的形参因此由 clang-format 重新折行。

ui/scripts/check-boundary.py 仍然通过,没有新增对产品的依赖。用脚本比对了原文件
与拆分后全部文件的非空、非 #include 行多重集:除上述两个函数签名外,差异只有
新增的声明、命名空间包装、using 指令、#pragma once 和文件头注释。可用
git diff --color-moved 复核。
2026-09-27 17:28:16 +08:00
..
2026-06-12 15:03:39 +08:00