YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
yfocus.cpp
浏览该文件的文档.
1 /*
2  Copyright by FrankHB 2010 - 2013.
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/ycontrol.h"
29 
31 
33 
34 bool
35 IsFocused(const IWidget& wgt)
36 {
37  const auto p(FetchContainerPtr(wgt));
38 
39  return p ? FetchFocusingPtr(*p) == &wgt : false;
40 }
41 
42 bool
43 DoRequestFocus(IWidget& wgt, bool release_event)
44 {
45  if(const auto p = FetchContainerPtr(wgt))
46  {
47  auto& pFocusing(p->GetView().FocusingPtr);
48 
49  if(pFocusing != &wgt)
50  {
51  if(pFocusing && IsFocused(*pFocusing))
52  {
53  if(release_event)
54  ReleaseFocusFrom(*pFocusing, wgt);
55  else
56  DoReleaseFocus(*pFocusing);
57  }
58  pFocusing = &wgt;
59  return true;
60  }
61  }
62  return false;
63 }
64 
65 bool
66 DoReleaseFocus(IWidget& wgt)
67 {
68  if(const auto p = FetchContainerPtr(wgt))
69  {
70  auto& pFocusing(p->GetView().FocusingPtr);
71 
72  if(pFocusing == &wgt)
73  {
74  pFocusing = nullptr;
75  return true;
76  }
77  }
78  return false;
79 }
80 
81 void
82 RequestFocusFrom(IWidget& dst, IWidget& src)
83 {
84  if(DoRequestFocus(dst, true))
85  CallEvent<GotFocus>(dst, UIEventArgs(src));
86 }
87 
88 void
89 ReleaseFocusFrom(IWidget& dst, IWidget& src)
90 {
91  if(DoReleaseFocus(dst))
92  CallEvent<LostFocus>(dst, UIEventArgs(src));
93 }
94 
95 void
96 ClearFocusingOf(IWidget& wgt)
97 {
98  if(const auto p = FetchFocusingPtr(wgt))
99  {
100  wgt.GetView().FocusingPtr = nullptr;
101  CallEvent<LostFocus>(*p, UIEventArgs(wgt));
102  }
103 }
104 
105 void
106 RequestFocusCascade(IWidget& wgt)
107 {
108  auto p(&wgt);
109 
110  do
111  {
112  RequestFocus(*p);
113  }while((p = FetchContainerPtr(*p)));
114 }
115 
116 void
117 ReleaseFocusCascade(IWidget& wgt)
118 {
119  auto p(&wgt);
120 
121  do
122  {
123  ReleaseFocus(*p);
124  }while((p = FetchContainerPtr(*p)));
125 }
126 
128 
129 YSL_END
130