YSTest: yfocus.cpp 源文件

YSTest PreAlpha_b500_20140530 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
yfocus.cpp
浏览该文件的文档.
1 /*
2 © 2010-2014 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #include "YSLib/UI/YModules.h"
29 #include YFM_YSLib_UI_YControl
30
31 namespace YSLib
32 {
33
34 namespace UI
35 {
36
37 bool
38 IsFocused(const IWidget& wgt)
39 {
40 const auto p(FetchContainerPtr(wgt));
41
42 return p ? FetchFocusingPtr(*p) == &wgt : false;
43 }
44
45 bool
46 DoRequestFocus(IWidget& wgt, bool release_event)
47 {
48 if(const auto p = FetchContainerPtr(wgt))
49 {
50 auto& pFocusing(p->GetView().FocusingPtr);
51
52 if(pFocusing != &wgt)
53 {
54 if(pFocusing && IsFocused(*pFocusing))
55 {
56 if(release_event)
57 {
58 IWidget* p_sub(pFocusing);
59
60 for(auto p_foc = p_sub; p_foc;
61 p_foc = FetchFocusingPtr(*p_sub))
62 p_sub = p_foc;
63 for(; p_sub != pFocusing; p_sub = FetchContainerPtr(*p_sub))
64 {
65 YAssert(p_sub, "Wrong child focus state found.");
66 if(DoReleaseFocus(*p_sub))
67 CallEvent<LostFocus>(*p_sub, RoutedEventArgs(wgt));
68 }
69 ReleaseFocusFrom(*pFocusing, wgt);
70 }
71 else
72 DoReleaseFocus(*pFocusing);
73 }
74 pFocusing = &wgt;
75 return true;
76 }
77 }
78 return false;
79 }
80
81 bool
82 DoReleaseFocus(IWidget& wgt)
83 {
84 if(const auto p = FetchContainerPtr(wgt))
85 {
86 auto& pFocusing(p->GetView().FocusingPtr);
87
88 if(pFocusing == &wgt)
89 {
90 pFocusing = {};
91 return true;
92 }
93 }
94 return false;
95 }
96
97 void
98 RequestFocusFrom(IWidget& dst, IWidget& src)
99 {
100 if(DoRequestFocus(dst, true))
101 CallEvent<GotFocus>(dst, UIEventArgs(src));
102 }
103
104 void
105 ReleaseFocusFrom(IWidget& dst, IWidget& src)
106 {
107 if(DoReleaseFocus(dst))
108 CallEvent<LostFocus>(dst, UIEventArgs(src));
109 }
110
111 void
112 ClearFocusingOf(IWidget& wgt)
113 {
114 if(const auto p = FetchFocusingPtr(wgt))
115 {
116 wgt.GetView().FocusingPtr = {};
117 CallEvent<LostFocus>(*p, UIEventArgs(wgt));
118 }
119 }
120
121 bool
122 IsFocusedCascade(const IWidget& wgt, const IWidget* p_top)
123 {
124 auto p_wgt(&wgt);
125
126 while(auto p_con = FetchContainerPtr(*p_wgt))
127 {
128 if(p_con == p_top)
129 break;
130 if(FetchFocusingPtr(*p_con) != p_wgt)
131 return false;
132 p_wgt = p_con;
133 }
134 return true;
135 }
136
137 void
138 RequestFocusCascade(IWidget& wgt)
139 {
140 auto p(&wgt);
141
142 do
143 {
144 RequestFocus(*p);
145 }while((p = FetchContainerPtr(*p)));
146 }
147
148 void
149 ReleaseFocusCascade(IWidget& wgt)
150 {
151 auto p(&wgt);
152
153 do
154 {
155 ReleaseFocus(*p);
156 }while((p = FetchContainerPtr(*p)));
157 }
158
159 } // namespace UI;
160
161 } // namespace YSLib;
162
YModules.h
YSLib::UI::ReleaseFocusFrom
YF_API void ReleaseFocusFrom(IWidget &dst, IWidget &src)
释放焦点，并指定 LostFocus 事件发送控件。
Definition: yfocus.cpp:105
YSLib::UI::UIEventArgs
用户界面事件参数基类。
Definition: ywgtevt.h:59
YSLib::UI::ReleaseFocusCascade
YF_API void ReleaseFocusCascade(IWidget &)
级联释放部件及上层容器焦点。
Definition: yfocus.cpp:149
YSLib::UI::IsFocusedCascade
YF_API bool IsFocusedCascade(const IWidget &, const IWidget *={})
判断部件相对于指针指定的部件是否具有级联焦点。
Definition: yfocus.cpp:122
YSLib::UI::DoRequestFocus
YF_API bool DoRequestFocus(IWidget &, bool release_event={})
向部件容器请求获得焦点，并指定 GotFocus 事件发送控件。
Definition: yfocus.cpp:46
YSLib::UI::IsFocused
YF_API bool IsFocused(const IWidget &)
判断部件是否取得焦点。
Definition: yfocus.cpp:38
YSLib::UI::wgt
_tWidget & wgt
Definition: ywgtevt.h:596
YSLib::UI::RequestFocusCascade
YF_API void RequestFocusCascade(IWidget &)
级联请求部件及上层容器焦点。
Definition: yfocus.cpp:138
YSLib::UI::DoReleaseFocus
YF_API bool DoReleaseFocus(IWidget &)
释放焦点，并指定 LostFocus 事件发送控件。
Definition: yfocus.cpp:82
YSLib::UI::RequestFocusFrom
YF_API void RequestFocusFrom(IWidget &dst, IWidget &src)
向部件容器请求获得焦点，并指定 GotFocus 事件发送控件。
Definition: yfocus.cpp:98
YSLib::UI::ClearFocusingOf
wgt wgt YF_API void ClearFocusingOf(IWidget &)
清除焦点指针并以此部件作为事件源调用被清除焦点部件的 LostFocus 事件。
Definition: yfocus.cpp:112
YSLib::UI::RoutedEventArgs
路由事件参数基类。
Definition: ywgtevt.h:93
YSLib::UI::FetchFocusingPtr
pt pt Y FetchFocusingPtr
Definition: ywidget.h:140
YAssert
#define YAssert(_expr, _msg)
Definition: cassert.h:73