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
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
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
139 {
140  auto p(&wgt);
141 
142  do
143  {
144  RequestFocus(*p);
145  }while((p = FetchContainerPtr(*p)));
146 }
147 
148 void
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 
YF_API void ReleaseFocusFrom(IWidget &dst, IWidget &src)
释放焦点,并指定 LostFocus 事件发送控件。
Definition: yfocus.cpp:105
用户界面事件参数基类。
Definition: ywgtevt.h:59
YF_API void ReleaseFocusCascade(IWidget &)
级联释放部件及上层容器焦点。
Definition: yfocus.cpp:149
YF_API bool IsFocusedCascade(const IWidget &, const IWidget *={})
判断部件相对于指针指定的部件是否具有级联焦点。
Definition: yfocus.cpp:122
YF_API bool DoRequestFocus(IWidget &, bool release_event={})
向部件容器请求获得焦点,并指定 GotFocus 事件发送控件。
Definition: yfocus.cpp:46
YF_API bool IsFocused(const IWidget &)
判断部件是否取得焦点。
Definition: yfocus.cpp:38
_tWidget & wgt
Definition: ywgtevt.h:596
YF_API void RequestFocusCascade(IWidget &)
级联请求部件及上层容器焦点。
Definition: yfocus.cpp:138
YF_API bool DoReleaseFocus(IWidget &)
释放焦点,并指定 LostFocus 事件发送控件。
Definition: yfocus.cpp:82
YF_API void RequestFocusFrom(IWidget &dst, IWidget &src)
向部件容器请求获得焦点,并指定 GotFocus 事件发送控件。
Definition: yfocus.cpp:98
wgt wgt YF_API void ClearFocusingOf(IWidget &)
清除焦点指针并以此部件作为事件源调用被清除焦点部件的 LostFocus 事件。
Definition: yfocus.cpp:112
路由事件参数基类。
Definition: ywgtevt.h:93
pt pt Y FetchFocusingPtr
Definition: ywidget.h:140
#define YAssert(_expr, _msg)
Definition: cassert.h:73