SimpleWindow
载入中...
搜索中...
未找到
UIElement.h
1#pragma once
2
3#include "Alignment.h"
4#include "Binding.h"
5#include "Color.h"
6#include "ContextMenu.h"
7#include "EnumBit.h"
8#include "EventHandlerWrapper.h"
9#include "ILayout.h"
10#include "ITag.h"
11#include "RoutedEvent.h"
12#include "RoutedEventArgs.h"
13#include "Thickness.h"
14#include "WndBase.h"
15#include "WndMsg.h"
16#include <cstdint>
17#include <map>
18#include <string>
19#include <unordered_map>
20#include <vector>
21
22namespace sw
23{
24 // 前向声明
25 class UIElement;
26 class DataBinding;
27
31 using DataContextChangedEventHandler = Delegate<void(UIElement &sender, DynamicObject *oldval)>;
32
36 enum class LayoutUpdateCondition : uint32_t {
40 SizeChanged = 1 << 0,
41
45 PositionChanged = 1 << 1,
46
50 ChildAdded = 1 << 2,
51
55 ChildRemoved = 1 << 3,
56
60 TextChanged = 1 << 4,
61
65 FontChanged = 1 << 5,
66
71 MeasureInvalidated = 1 << 29,
72
78 Supressed = 1 << 30,
79 };
80
84 _SW_ENUM_ENABLE_BIT_OPERATIONS(LayoutUpdateCondition);
85
89 class UIElement : public WndBase,
90 public ILayout,
91 public ITag<uint64_t>
92 {
93 private:
97 sw::LayoutUpdateCondition _layoutUpdateCondition =
98 sw::LayoutUpdateCondition::SizeChanged |
99 sw::LayoutUpdateCondition::ChildAdded |
100 sw::LayoutUpdateCondition::ChildRemoved;
101
105 bool _collapseWhenHide = true;
106
110 Size _desireSize{};
111
115 Size _origionalSize{};
116
120 Size _minSize{-1, -1};
121
125 Size _maxSize{-1, -1};
126
130 Thickness _margin{};
131
135 HorizontalAlignment _horizontalAlignment = HorizontalAlignment::Center;
136
140 VerticalAlignment _verticalAlignment = VerticalAlignment::Center;
141
145 UIElement *_parent = nullptr;
146
150 std::vector<UIElement *> _children{};
151
155 std::vector<UIElement *> _layoutVisibleChildren{};
156
160 std::unordered_map<RoutedEventType, RoutedEventHandler> _eventMap{};
161
165 uint64_t _tag = 0;
166
170 uint64_t _layoutTag = 0;
171
175 sw::ContextMenu *_contextMenu = nullptr;
176
180 double _arrangeOffsetX = 0;
181
185 double _arrangeOffsetY = 0;
186
190 double _childRightmost = 0;
191
195 double _childBottommost = 0;
196
200 bool _float = false;
201
205 bool _tabStop = false;
206
210 Color _backColor{KnownColor::White};
211
215 Color _textColor{KnownColor::Black};
216
220 bool _transparent = false;
221
225 bool _inheritTextColor = false;
226
230 bool _useDefaultCursor = true;
231
235 HCURSOR _hCursor = NULL;
236
240 Size _lastMeasureAvailableSize{};
241
245 HDWP _hdwpChildren = NULL;
246
250 HBRUSH _hCtlColorBrush = NULL;
251
255 COLORREF _lastTextColor = 0;
256
260 COLORREF _lastBackColor = 0;
261
265 bool _isHitTestVisible = true;
266
270 bool _focusedViaTab = false;
271
275 std::unordered_map<FieldId, std::unique_ptr<BindingBase>> _bindings{};
276
280 DynamicObject *_dataContext = nullptr;
281
282 public:
287
292
297
302
307
312
317
322
327
332
337
342
347
352
358
363
369
374
379
384
389
394
400
405
410
415
421
422 public:
427
431 virtual ~UIElement() = 0;
432
439 [[deprecated("Use AddHandler instead to avoid overwriting existing event handlers.")]]
440 void RegisterRoutedEvent(RoutedEventType eventType, const RoutedEventHandler &handler);
441
447 void AddHandler(RoutedEventType eventType, const RoutedEventHandler &handler);
448
455 bool RemoveHandler(RoutedEventType eventType, const RoutedEventHandler &handler);
456
461 void UnregisterRoutedEvent(RoutedEventType eventType);
462
467 bool IsRoutedEventRegistered(RoutedEventType eventType);
468
472 UIElement &operator[](int index) const;
473
477 UIElement &GetChildAt(int index) const;
478
485
492
499
506
512 bool RemoveChildAt(int index);
513
519
525
530
537
544
553 const Point &point,
554 sw::HorizontalAlignment horz = sw::HorizontalAlignment::Left,
555 sw::VerticalAlignment vert = sw::VerticalAlignment::Top);
556
560 void MoveToTop();
561
566
570 bool IsRootElement() const;
571
576
581
586
591
596
602
608
614
619 void SetCursor(StandardCursor cursor);
620
625
631 void SetAlignment(sw::HorizontalAlignment horz, sw::VerticalAlignment vert);
632
637 void Resize(const Size &size);
638
642 bool IsLayoutUpdateConditionSet(sw::LayoutUpdateCondition condition);
643
648
655
664
673
681
687
691 virtual uint64_t GetTag() const override;
692
696 virtual void SetTag(uint64_t tag) override;
697
701 virtual uint64_t GetLayoutTag() const override;
702
707 virtual int GetChildLayoutCount() const override;
708
713 virtual ILayout &GetChildLayoutAt(int index) override;
714
718 virtual Size GetDesireSize() const override;
719
724 virtual void Measure(const Size &availableSize) override;
725
730 virtual void Arrange(const sw::Rect &finalPosition) override;
731
736 virtual UIElement *ToUIElement() override;
737
738 protected:
743 void RaiseRoutedEvent(RoutedEventType eventType);
744
750
756
762
769
776
781
786
791 void ClampDesireSize(sw::Size &size) const;
792
798
805
813
818 virtual void ArrangeOverride(const Size &finalSize);
819
825 virtual void SetBackColor(Color color, bool redraw);
826
832 virtual void SetTextColor(Color color, bool redraw);
833
840
846
852
857 virtual void OnTabMove(bool forward);
858
862 virtual void OnTabStop();
863
867 virtual void OnMinMaxSizeChanged();
868
875
880 virtual bool SetParent(WndBase *parent) override;
881
886 virtual void ParentChanged(WndBase *newParent) override;
887
892 virtual bool OnClose() override;
893
899 virtual bool OnMove(const Point &newClientPosition) override;
900
906 virtual bool OnSize(const Size &newClientSize) override;
907
911 virtual void OnTextChanged() override;
912
917 virtual void FontChanged(HFONT hfont) override;
918
922 virtual void VisibleChanged(bool newVisible) override;
923
929 virtual bool OnSetFocus(HWND hPrevFocus) override;
930
936 virtual bool OnKillFocus(HWND hNextFocus) override;
937
944 virtual bool OnChar(wchar_t ch, const KeyFlags &flags) override;
945
952 virtual bool OnKeyDown(VirtualKey key, const KeyFlags &flags) override;
953
960 virtual bool OnKeyUp(VirtualKey key, const KeyFlags &flags) override;
961
968 virtual bool OnMouseMove(const Point &mousePosition, MouseKey keyState) override;
969
974 virtual bool OnMouseLeave() override;
975
983 virtual bool OnMouseWheel(int wheelDelta, const Point &mousePosition, MouseKey keyState) override;
984
991 virtual bool OnMouseLeftButtonDown(const Point &mousePosition, MouseKey keyState) override;
992
999 virtual bool OnMouseLeftButtonUp(const Point &mousePosition, MouseKey keyState) override;
1000
1007 virtual bool OnMouseRightButtonDown(const Point &mousePosition, MouseKey keyState) override;
1008
1015 virtual bool OnMouseRightButtonUp(const Point &mousePosition, MouseKey keyState) override;
1016
1023 virtual bool OnMouseMiddleButtonDown(const Point &mousePosition, MouseKey keyState) override;
1024
1031 virtual bool OnMouseMiddleButtonUp(const Point &mousePosition, MouseKey keyState) override;
1032
1039 virtual bool OnContextMenu(bool isKeyboardMsg, const Point &mousePosition) override;
1040
1045 virtual void OnMenuCommand(int id) override;
1046
1053 virtual bool OnColor(HDC hdc, HBRUSH &hRetBrush) override;
1054
1063 virtual bool OnSetCursor(HWND hwnd, HitTestResult hitTest, int message, bool &result) override;
1064
1070 virtual bool OnDropFiles(HDROP hDrop) override;
1071
1077 virtual void OnNcHitTest(const Point &testPoint, HitTestResult &result) override;
1078
1079 private:
1085 bool _SetHorzAlignment(sw::HorizontalAlignment value);
1086
1092 bool _SetVertAlignment(sw::VerticalAlignment value);
1093
1097 void _SetMeasureInvalidated();
1098
1102 void _UpdateLayoutVisibleChildren();
1103
1107 void _RemoveFromLayoutVisibleChildren(UIElement *element);
1108
1113 DynamicObject *_GetCurrentDataContext();
1114
1118 void _OnCurrentDataContextChanged(DynamicObject *oldval);
1119
1123 static UIElement *_GetNextElement(UIElement *element, bool searchChildren = true);
1124
1128 static UIElement *_GetDeepestLastElement(UIElement *element);
1129
1133 static UIElement *_GetPreviousElement(UIElement *element);
1134
1138 static void _GetAllChildren(UIElement *element, std::vector<UIElement *> &children);
1139
1140 private:
1144 template <typename T, typename = void>
1145 struct _CanAddChild : std::false_type {
1146 };
1147
1148 // 已移动到类外,防止clang报错不完整的类型
1149 // /**
1150 // * @brief _CanAddChild模板偏特化,当AddChild有对应类型的重载时该偏特化生效
1151 // */
1152 // template <typename T>
1153 // struct _CanAddChild<
1154 // T, decltype(void(std::declval<UIElement>().AddChild(std::declval<T>())))> : std::true_type {
1155 // };
1156
1160 template <typename First, typename... Rest>
1161 struct _CanAddChildren
1162 : std::integral_constant<bool, _CanAddChild<First>::value && _CanAddChildren<Rest...>::value> {
1163 };
1164
1168 template <typename T>
1169 struct _CanAddChildren<T> : _CanAddChild<T> {
1170 };
1171
1172 public:
1179 template <typename First, typename... Rest>
1181 -> typename std::enable_if<_CanAddChildren<First, Rest...>::value, int>::type
1182 {
1183 int count = 0;
1184 if (this->AddChild(std::forward<First>(first)))
1185 count = 1 + this->AddChildren(std::forward<Rest>(rest)...);
1186 return count;
1187 }
1188
1195 template <typename T>
1197 -> typename std::enable_if<_CanAddChild<T>::value, int>::type
1198 {
1199 return this->AddChild(std::forward<T>(child)) ? 1 : 0;
1200 }
1201
1210 template <typename T>
1211 [[deprecated("Use AddHandler instead to avoid overwriting existing event handlers.")]]
1212 void RegisterRoutedEvent(RoutedEventType eventType, T &obj, void (T::*handler)(UIElement &, RoutedEventArgs &))
1213 {
1214 if (handler == nullptr) {
1215 this->UnregisterRoutedEvent(eventType);
1216 } else {
1217 this->RegisterRoutedEvent(eventType, RoutedEventHandler(obj, handler));
1218 }
1219 }
1220
1227 template <typename TEventArgs>
1228 [[deprecated("Use AddHandler instead to avoid overwriting existing event handlers.")]]
1230 -> typename std::enable_if<std::is_base_of<RoutedEventArgs, TEventArgs>::value && sw::_IsTypedRoutedEventArgs<TEventArgs>::value>::type
1231 {
1232 if (!handler) {
1233 this->UnregisterRoutedEvent(TEventArgs::EventType);
1234 } else {
1236 }
1237 }
1238
1247 template <typename TEventArgs, typename THandleObj>
1248 [[deprecated("Use AddHandler instead to avoid overwriting existing event handlers.")]]
1251 {
1252 if (handler == nullptr) {
1253 this->UnregisterRoutedEvent(TEventArgs::EventType);
1254 } else {
1256 }
1257 }
1258
1266 template <typename T>
1267 void AddHandler(RoutedEventType eventType, T &obj, void (T::*handler)(UIElement &, RoutedEventArgs &))
1268 {
1269 if (handler) this->_eventMap[eventType].Add(obj, handler);
1270 }
1271
1277 template <typename TEventArgs>
1279 -> typename std::enable_if<std::is_base_of<RoutedEventArgs, TEventArgs>::value && sw::_IsTypedRoutedEventArgs<TEventArgs>::value>::type
1280 {
1281 if (handler) this->AddHandler(TEventArgs::EventType, RoutedEventHandlerWrapper<TEventArgs>(handler));
1282 }
1283
1291 template <typename TEventArgs, typename THandleObj>
1297
1304 template <typename TEventArgs>
1305 auto AddHandler(RoutedEventType eventType, const Action<UIElement &, TEventArgs &> &handler)
1306 -> typename std::enable_if<
1307 std::is_base_of<RoutedEventArgs, TEventArgs>::value &&
1308 !std::is_same<TEventArgs, RoutedEventArgs>::value &&
1310 {
1312 }
1313
1322 template <typename TEventArgs, typename THandleObj>
1323 auto AddHandler(RoutedEventType eventType, THandleObj &obj, void (THandleObj::*handler)(UIElement &, TEventArgs &))
1324 -> typename std::enable_if<
1325 std::is_base_of<RoutedEventArgs, TEventArgs>::value &&
1326 !std::is_same<TEventArgs, RoutedEventArgs>::value &&
1327 !sw::_IsTypedRoutedEventArgs<TEventArgs>::value>::type
1328 {
1330 }
1331
1340 template <typename T>
1341 bool RemoveHandler(RoutedEventType eventType, T &obj, void (T::*handler)(UIElement &, RoutedEventArgs &))
1342 {
1343 return handler == nullptr ? false : this->_eventMap[eventType].Remove(obj, handler);
1344 }
1345
1352 template <typename TEventArgs>
1354 -> typename std::enable_if<std::is_base_of<RoutedEventArgs, TEventArgs>::value && sw::_IsTypedRoutedEventArgs<TEventArgs>::value, bool>::type
1355 {
1356 if (handler == nullptr) {
1357 return false;
1358 } else {
1359 return this->RemoveHandler(TEventArgs::EventType, RoutedEventHandlerWrapper<TEventArgs>(handler));
1360 }
1361 }
1362
1371 template <typename TEventArgs, typename THandleObj>
1374 {
1375 if (handler == nullptr) {
1376 return false;
1377 } else {
1379 }
1380 }
1381
1389 template <typename TEventArgs>
1390 auto RemoveHandler(RoutedEventType eventType, const Action<UIElement &, TEventArgs &> &handler)
1391 -> typename std::enable_if<
1392 std::is_base_of<RoutedEventArgs, TEventArgs>::value &&
1393 !std::is_same<TEventArgs, RoutedEventArgs>::value &&
1395 bool>::type
1396 {
1397 if (handler == nullptr) {
1398 return false;
1399 } else {
1401 }
1402 }
1403
1413 template <typename TEventArgs, typename THandleObj>
1414 auto RemoveHandler(RoutedEventType eventType, THandleObj &obj, void (THandleObj::*handler)(UIElement &, TEventArgs &))
1415 -> typename std::enable_if<
1416 std::is_base_of<RoutedEventArgs, TEventArgs>::value &&
1417 !std::is_same<TEventArgs, RoutedEventArgs>::value &&
1419 bool>::type
1420 {
1421 if (handler == nullptr) {
1422 return false;
1423 } else {
1425 }
1426 }
1427
1432 template <typename T, typename TProperty>
1434 {
1436 }
1437 };
1438
1442 template <typename T>
1443 struct UIElement::_CanAddChild<
1444 T, decltype(void(std::declval<UIElement>().AddChild(std::declval<T>())))> : std::true_type {
1445 };
1446}
数据绑定基类
Definition Binding.h:38
数据绑定类
Definition Binding.h:73
上下文菜单
Definition ContextMenu.h:11
数据绑定,用于UI元素与DataContext之间的属性绑定
Definition DataBinding.h:11
动态对象基类
Definition Reflection.h:27
布局接口
Definition ILayout.h:13
Tag接口
Definition ITag.h:12
值转换器接口
Definition IValueConverter.h:14
static FieldId GetFieldId(TField T::*field) noexcept
获取字段的唯一标识符
Definition Reflection.h:961
表示界面中的元素
Definition UIElement.h:92
Color GetRealTextColor() const
获取当前要显示的文本颜色
virtual uint64_t GetTag() const override
获取Tag
const Property< HorizontalAlignment > HorizontalAlignment
水平对齐方式
Definition UIElement.h:296
void RaiseRoutedEvent(RoutedEventType eventType)
触发路由事件
UIElement * GetNextElement()
获取当前元素在界面树上的下一个节点,若已是最后一个节点则返回根节点
void RegisterRoutedEvent(RoutedEventType eventType, T &obj, void(T::*handler)(UIElement &, RoutedEventArgs &))
注册成员函数作为路由事件处理函数,当事件已注册时会覆盖已注册的函数
Definition UIElement.h:1212
virtual void SetTag(uint64_t tag) override
设置Tag
void UnregisterRoutedEvent(RoutedEventType eventType)
取消对应类型路由事件的注册,该函数会移除对应事件所有的处理函数
void SetCursor(HCURSOR hCursor)
设置鼠标样式
virtual void OnTabStop()
通过tab键将焦点移动到当前元素时调用该函数
void RaiseRoutedEvent(RoutedEventArgs &eventArgs)
触发路由事件
bool AddChild(UIElement &element)
添加子元素
virtual bool OnMove(const Point &newClientPosition) override
接收到WM_MOVE时调用该函数
UIElement * GetPreviousElement()
获取当前元素在界面树上的上一个节点,若元素为第一个节点则返回最后一个节点
void UpdateSiblingsZOrder(bool invalidateMeasure=true)
更新兄弟元素的Z轴位置
virtual bool OnClose() override
接收到WM_CLOSE时调用该函数
double GetChildRightmost(bool update)
获取所有子元素在当前元素中最右边的位置(只考虑参与布局的子窗口且忽略悬浮的元素)
const ReadOnlyProperty< bool > IsFocusedViaTab
当前元素是否是通过按下Tab键获得的焦点
Definition UIElement.h:409
bool RemoveBinding(TProperty T::*prop)
移除指定属性的绑定对象
Definition UIElement.h:1433
const Property< bool > TabStop
表示用户是否可以通过按下Tab键将焦点移动到当前元素
Definition UIElement.h:341
void RegisterRoutedEvent(RoutedEventType eventType, const RoutedEventHandler &handler)
注册路由事件处理函数,当事件已注册时会覆盖已注册的函数
double & GetInternalArrangeOffsetY()
获取布局时子元素的垂直偏移量
virtual void ArrangeOverride(const Size &finalSize)
安排子元素的位置,可重写该函数以实现自定义布局
bool AddChild(UIElement *element)
添加子元素
const ReadOnlyProperty< DynamicObject * > CurrentDataContext
当前元素的有效数据上下文
Definition UIElement.h:420
const Property< double > MinHeight
最小高度,当值为负数或0时表示不限制
Definition UIElement.h:383
virtual ILayout & GetChildLayoutAt(int index) override
获取对应索引处的子元素,只索引参与布局的子元素
bool AddBinding(Binding *binding)
添加绑定对象
UIElement & operator[](int index) const
通过索引获取子元素
bool AddChild(UIElement &element, uint64_t layoutTag)
添加子元素并设置布局标记
void ResetCursor()
将鼠标样式设置为默认样式
virtual bool OnKeyUp(VirtualKey key, const KeyFlags &flags) override
接收到WM_KEYUP时调用该函数
UIElement & GetChildAt(int index) const
获取子元素
int IndexOf(UIElement *element)
获取指定元素的索引
virtual void OnRoutedEvent(RoutedEventArgs &eventArgs, const RoutedEventHandler &handler)
路由事件经过当前元素时调用该函数
bool RemoveBinding(FieldId propertyId)
移除指定属性的绑定对象
virtual Size GetDesireSize() const override
获取当前元素所需尺寸
virtual bool OnMouseLeftButtonDown(const Point &mousePosition, MouseKey keyState) override
接收到WM_LBUTTONDOWN时调用该函数
auto RegisterRoutedEvent(THandleObj &obj, void(THandleObj::*handler)(UIElement &, TEventArgs &)) -> typename std::enable_if< std::is_base_of< RoutedEventArgs, TEventArgs >::value &&sw::_IsTypedRoutedEventArgs< TEventArgs >::value >::type
根据事件参数类型注册成员函数作为路由事件,当事件已注册时会覆盖已注册的函数
Definition UIElement.h:1249
UIElement * GetRootElement()
获取当前元素所在界面树的根节点
virtual UIElement * ToUIElement() override
尝试将对象转换成UIElement
const ReadOnlyProperty< int > ChildCount
子元素数量
Definition UIElement.h:306
virtual bool OnColor(HDC hdc, HBRUSH &hRetBrush) override
父窗口接收到WM_CTLCOLORxxx时调用对应控件的该函数
void ClampDesireSize(sw::Size &size) const
限定指定尺寸在最小和最大尺寸之间
const ReadOnlyProperty< sw::Rect > LogicalRect
元素的逻辑位置和尺寸,即去除布局偏移以及拉伸影响的位置和尺寸
Definition UIElement.h:399
bool QueryAllChildren(const Func< UIElement *, bool > &queryFunc)
查询所有子元素,直到queryFunc返回false或所有子元素均被查询
virtual bool OnSetCursor(HWND hwnd, HitTestResult hitTest, int message, bool &result) override
接收到WM_SETCURSOR消息时调用该函数
virtual bool OnKeyDown(VirtualKey key, const KeyFlags &flags) override
接收到WM_KEYDOWN时调用该函数
bool RemoveChildAt(int index)
移除指定索引处的子元素
bool AddBinding(DataBinding *binding)
添加绑定到DataContext的绑定对象
UIElement * GetNextTabStopElement()
获取下一个TabStop属性为true的元素
virtual bool OnDropFiles(HDROP hDrop) override
接收到WM_DROPFILES时调用该函数
virtual bool OnKillFocus(HWND hNextFocus) override
接收到WM_KILLFOCUS时调用该函数
bool RemoveHandler(RoutedEventType eventType, T &obj, void(T::*handler)(UIElement &, RoutedEventArgs &))
移除已添加的类型为成员函数的路由事件处理函数
Definition UIElement.h:1341
auto AddChildren(First &&first, Rest &&...rest) -> typename std::enable_if< _CanAddChildren< First, Rest... >::value, int >::type
添加多个子元素
Definition UIElement.h:1180
bool ShowContextMenu(const Point &point, sw::HorizontalAlignment horz=sw::HorizontalAlignment::Left, sw::VerticalAlignment vert=sw::VerticalAlignment::Top)
弹出当前元素的上下文菜单
virtual bool OnSize(const Size &newClientSize) override
接收到WM_SIZE时调用该函数
virtual bool OnMouseMiddleButtonUp(const Point &mousePosition, MouseKey keyState) override
接收到WM_MBUTTONUP时调用该函数
const Property< uint64_t > LayoutTag
布局标记,对于不同的布局有不同含义
Definition UIElement.h:326
virtual void OnTabMove(bool forward)
通过tab键将焦点从当前元素移出时调用该函数
void ClampDesireSize(sw::Rect &rect) const
限定指定矩形的尺寸在最小和最大尺寸之间
const ReadOnlyProperty< bool > IsMeasureValid
当前元素的布局状态是否有效
Definition UIElement.h:373
virtual bool OnMouseRightButtonDown(const Point &mousePosition, MouseKey keyState) override
接收到WM_RBUTTONDOWN时调用该函数
void MoveToBottom()
移动到界面底部
virtual bool OnMouseMiddleButtonDown(const Point &mousePosition, MouseKey keyState) override
接收到WM_MBUTTONDOWN时调用该函数
void SetAlignment(sw::HorizontalAlignment horz, sw::VerticalAlignment vert)
设置对齐方式
virtual void OnNcHitTest(const Point &testPoint, HitTestResult &result) override
接收到WM_NCHITTEST后调用该函数
double GetChildBottommost(bool update)
获取所有子元素在当前元素中最底边的位置(只考虑参与布局的子窗口且忽略悬浮的元素)
void AddHandler(RoutedEventType eventType, const RoutedEventHandler &handler)
添加路由事件处理函数
const Property< bool > InheritTextColor
是否继承父元素的文本颜色
Definition UIElement.h:362
virtual void OnTextChanged() override
Text属性更改时调用此函数
void SetCursor(StandardCursor cursor)
设置鼠标样式
virtual uint64_t GetLayoutTag() const override
获取布局标记
const Property< bool > IsHitTestVisible
当前元素是否响应鼠标事件
Definition UIElement.h:404
virtual void ParentChanged(WndBase *newParent) override
父窗口改变时调用此函数
Color GetRealBackColor() const
获取当前要显示的背景颜色
const Property< uint64_t > Tag
储存用户自定义信息的标记
Definition UIElement.h:321
bool IsRootElement() const
判断当前元素是否为根节点
virtual void FontChanged(HFONT hfont) override
字体改变时调用该函数
virtual Size MeasureOverride(const Size &availableSize)
测量元素所需尺寸,无需考虑边框和边距
auto AddHandler(const Action< UIElement &, TEventArgs & > &handler) -> typename std::enable_if< std::is_base_of< RoutedEventArgs, TEventArgs >::value &&sw::_IsTypedRoutedEventArgs< TEventArgs >::value >::type
根据事件参数类型添加路由事件处理函数
Definition UIElement.h:1278
auto RemoveHandler(RoutedEventType eventType, THandleObj &obj, void(THandleObj::*handler)(UIElement &, TEventArgs &)) -> typename std::enable_if< std::is_base_of< RoutedEventArgs, TEventArgs >::value &&!std::is_same< TEventArgs, RoutedEventArgs >::value &&!sw::_IsTypedRoutedEventArgs< TEventArgs >::value, bool >::type
移除已添加的类型为成员函数的路由事件处理函数
Definition UIElement.h:1414
const Property< Thickness > Margin
边距
Definition UIElement.h:291
int IndexOf(UIElement &element)
获取指定元素的索引
bool RemoveHandler(RoutedEventType eventType, const RoutedEventHandler &handler)
移除已添加的路由事件处理函数
bool RemoveChild(UIElement *element)
移除子元素
virtual bool OnMouseWheel(int wheelDelta, const Point &mousePosition, MouseKey keyState) override
接收到WM_MOUSEWHEEL时调用该函数
virtual bool OnChar(wchar_t ch, const KeyFlags &flags) override
接收到WM_CHAR时调用该函数
auto RemoveHandler(const Action< UIElement &, TEventArgs & > &handler) -> typename std::enable_if< std::is_base_of< RoutedEventArgs, TEventArgs >::value &&sw::_IsTypedRoutedEventArgs< TEventArgs >::value, bool >::type
移除已添加的路由事件处理函数
Definition UIElement.h:1353
const Property< bool > CollapseWhenHide
是否在不可见时不参与布局
Definition UIElement.h:311
void ClearChildren()
移除所有子元素
virtual bool OnSetFocus(HWND hPrevFocus) override
接收到WM_SETFOCUS时调用该函数
auto AddHandler(THandleObj &obj, void(THandleObj::*handler)(UIElement &, TEventArgs &)) -> typename std::enable_if< std::is_base_of< RoutedEventArgs, TEventArgs >::value &&sw::_IsTypedRoutedEventArgs< TEventArgs >::value >::type
根据事件参数类型添加成员函数作为路由事件处理函数
Definition UIElement.h:1292
virtual void VisibleChanged(bool newVisible) override
Visible属性改变时调用此函数
const Property< double > MinWidth
最小宽度,当值为负数或0时表示不限制
Definition UIElement.h:378
bool IsLayoutUpdateConditionSet(sw::LayoutUpdateCondition condition)
判断指定的布局更新条件是否已设置
bool RemoveChild(UIElement &element)
移除子元素
const Property< DynamicObject * > DataContext
数据上下文
Definition UIElement.h:414
virtual bool OnMouseLeftButtonUp(const Point &mousePosition, MouseKey keyState) override
接收到WM_LBUTTONUP时调用该函数
void UpdateChildrenZOrder(bool invalidateMeasure=true)
更新子元素的Z轴位置
auto AddHandler(RoutedEventType eventType, THandleObj &obj, void(THandleObj::*handler)(UIElement &, TEventArgs &)) -> typename std::enable_if< std::is_base_of< RoutedEventArgs, TEventArgs >::value &&!std::is_same< TEventArgs, RoutedEventArgs >::value &&!sw::_IsTypedRoutedEventArgs< TEventArgs >::value >::type
添加成员函数作为路由事件处理函数
Definition UIElement.h:1323
void Resize(const Size &size)
调整当前元素的尺寸
void AddHandler(RoutedEventType eventType, T &obj, void(T::*handler)(UIElement &, RoutedEventArgs &))
添加成员函数作为路由事件处理函数
Definition UIElement.h:1267
const Property< double > MaxHeight
最大高度,当值为负数或0时表示不限制
Definition UIElement.h:393
const Property< bool > Transparent
是否使用透明背景
Definition UIElement.h:357
virtual void OnRemovedChild(UIElement &element)
移除子元素后调用该函数
const Property< Color > BackColor
背景颜色,修改该属性会同时将Transparent属性设为false,对于部分控件该属性可能不生效
Definition UIElement.h:346
UIElement * GetPreviousTabStopElement()
获取上一个TabStop属性为true的元素
const Property< sw::LayoutUpdateCondition > LayoutUpdateCondition
触发布局更新的条件
Definition UIElement.h:368
virtual int GetChildLayoutCount() const override
获取参与布局的子元素数量
virtual void SetTextColor(Color color, bool redraw)
设置文本颜色
auto AddHandler(RoutedEventType eventType, const Action< UIElement &, TEventArgs & > &handler) -> typename std::enable_if< std::is_base_of< RoutedEventArgs, TEventArgs >::value &&!std::is_same< TEventArgs, RoutedEventArgs >::value &&!sw::_IsTypedRoutedEventArgs< TEventArgs >::value >::type
添加路由事件处理函数
Definition UIElement.h:1305
DataContextChangedEventHandler DataContextChanged
数据上下问改变时触发该事件
Definition UIElement.h:286
void MoveToTop()
移动到界面顶部
auto RegisterRoutedEvent(const Action< UIElement &, TEventArgs & > &handler) -> typename std::enable_if< std::is_base_of< RoutedEventArgs, TEventArgs >::value &&sw::_IsTypedRoutedEventArgs< TEventArgs >::value >::type
根据事件参数类型注册路由事件,当事件已注册时会覆盖已注册的函数
Definition UIElement.h:1229
bool AddChild(UIElement *element, uint64_t layoutTag)
添加子元素并设置布局标记
double & GetInternalArrangeOffsetX()
获取布局时子元素的水平偏移量
const Property< bool > Float
元素是否悬浮,若元素悬浮则该元素不会随滚动条滚动而改变位置
Definition UIElement.h:336
virtual bool RequestBringIntoView(const sw::Rect &screenRect)
尝试将指定的矩形区域移动到可视区域内
virtual bool OnMouseLeave() override
接收到WM_MOUSELEAVE时调用该函数
virtual void Arrange(const sw::Rect &finalPosition) override
安排元素位置
virtual void OnMenuCommand(int id) override
当WM_COMMAND接收到菜单命令时调用该函数
virtual ~UIElement()=0
析构函数,这里用纯虚函数使该类成为抽象类
auto RemoveHandler(THandleObj &obj, void(THandleObj::*handler)(UIElement &, TEventArgs &)) -> typename std::enable_if< std::is_base_of< RoutedEventArgs, TEventArgs >::value &&sw::_IsTypedRoutedEventArgs< TEventArgs >::value, bool >::type
移除已添加的类型为成员函数的路由事件处理函数
Definition UIElement.h:1372
const Property< double > MaxWidth
最大宽度,当值为负数或0时表示不限制
Definition UIElement.h:388
virtual bool SetParent(WndBase *parent) override
设置父窗口
const ReadOnlyProperty< UIElement * > Parent
指向父元素的指针,当前元素为顶级窗口时该值为nullptr
Definition UIElement.h:316
const Property< VerticalAlignment > VerticalAlignment
垂直对齐方式
Definition UIElement.h:301
bool BringIntoView()
尝试将当前元素移动到可视区域内
bool IsRoutedEventRegistered(RoutedEventType eventType)
判断路由事件是否已存在事件处理函数
auto RemoveHandler(RoutedEventType eventType, const Action< UIElement &, TEventArgs & > &handler) -> typename std::enable_if< std::is_base_of< RoutedEventArgs, TEventArgs >::value &&!std::is_same< TEventArgs, RoutedEventArgs >::value &&!sw::_IsTypedRoutedEventArgs< TEventArgs >::value, bool >::type
移除已添加的路由事件处理函数
Definition UIElement.h:1390
virtual bool OnMouseMove(const Point &mousePosition, MouseKey keyState) override
接收到WM_MOUSEMOVE时调用该函数
virtual void OnAddedChild(UIElement &element)
添加子元素后调用该函数
const Property< sw::ContextMenu * > ContextMenu
右键按下时弹出的菜单
Definition UIElement.h:331
virtual void OnMinMaxSizeChanged()
当MinWidth、MinHeight、MaxWidth或MaxHeight属性更改时调用此函数
virtual bool OnMouseRightButtonUp(const Point &mousePosition, MouseKey keyState) override
接收到WM_RBUTTONUP时调用该函数
const Property< Color > TextColor
文本颜色,修改该属性会同时将InheritTextColor属性设为false,对于部分控件该属性可能不生效
Definition UIElement.h:351
auto AddChildren(T &&child) -> typename std::enable_if< _CanAddChild< T >::value, int >::type
添加多个子元素
Definition UIElement.h:1196
UIElement()
初始化UIElement
virtual void Measure(const Size &availableSize) override
测量元素所需尺寸
bool AddBinding(BindingBase *binding)
添加绑定对象
virtual bool OnContextMenu(bool isKeyboardMsg, const Point &mousePosition) override
接收到WM_CONTEXTMENU后调用目标控件的该函数
virtual void SetBackColor(Color color, bool redraw)
设置背景颜色
void InvalidateMeasure()
使元素的布局状态失效,并立即触发布局更新
表示一个Windows窗口,是所有窗口和控件的基类
Definition WndBase.h:41
颜色
Definition Color.h:16
表示字段的唯一标识符
Definition Reflection.h:898
https://learn.microsoft.com/en-us/windows/win32/inputdev/about-keyboard-input#keystroke-message-flags
Definition Keys.h:12
表示相对于左上角的点坐标
Definition Point.h:15
表示一个矩形区域
Definition Rect.h:17
路由事件的参数
Definition RoutedEvent.h:149
尺寸
Definition Size.h:15
表示矩形区域周围边框的厚度
Definition Thickness.h:15
结构体模板,用于检测类型T是否包含事件类型信息
Definition RoutedEventArgs.h:51