1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
10 |
|
|
**************************************************************************/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/**************************************************************************/ |
15 |
|
|
/** */ |
16 |
|
|
/** GUIX Component */ |
17 |
|
|
/** */ |
18 |
|
|
/** System Management (System) */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
#define GX_SOURCE_CODE |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
/* Include necessary system files. */ |
26 |
|
|
|
27 |
|
|
#include "gx_api.h" |
28 |
|
|
#include "gx_system.h" |
29 |
|
|
#include "gx_widget.h" |
30 |
|
|
|
31 |
|
|
|
32 |
|
|
/**************************************************************************/ |
33 |
|
|
/* */ |
34 |
|
|
/* FUNCTION RELEASE */ |
35 |
|
|
/* */ |
36 |
|
|
/* _gx_system_focus_claim PORTABLE C */ |
37 |
|
|
/* 6.1 */ |
38 |
|
|
/* AUTHOR */ |
39 |
|
|
/* */ |
40 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
41 |
|
|
/* */ |
42 |
|
|
/* DESCRIPTION */ |
43 |
|
|
/* */ |
44 |
|
|
/* This service claims the focus for the specified widget. */ |
45 |
|
|
/* */ |
46 |
|
|
/* INPUT */ |
47 |
|
|
/* */ |
48 |
|
|
/* widget Pointer to widget control */ |
49 |
|
|
/* block to claim focus */ |
50 |
|
|
/* */ |
51 |
|
|
/* OUTPUT */ |
52 |
|
|
/* */ |
53 |
|
|
/* status Completion status */ |
54 |
|
|
/* */ |
55 |
|
|
/* CALLS */ |
56 |
|
|
/* */ |
57 |
|
|
/* _gx_system_error_process Processes internal GUIX */ |
58 |
|
|
/* system errors */ |
59 |
|
|
/* _gx_widget_child_detect Detect if one widget is child */ |
60 |
|
|
/* of another. */ |
61 |
|
|
/* [gx_widget_event_process_function] Widget event process routine */ |
62 |
|
|
/* CALLED BY */ |
63 |
|
|
/* */ |
64 |
|
|
/* GUIX Application */ |
65 |
|
|
/* GUIX Internal Code */ |
66 |
|
|
/* */ |
67 |
|
|
/**************************************************************************/ |
68 |
|
13497 |
UINT _gx_system_focus_claim(GX_WIDGET *widget) |
69 |
|
|
{ |
70 |
|
|
GX_EVENT newevent; |
71 |
|
|
GX_WIDGET *parent; |
72 |
|
|
GX_BOOL detect_result; |
73 |
|
|
|
74 |
|
13497 |
newevent.gx_event_target = GX_NULL; |
75 |
|
|
/* is this a visible widget? */ |
76 |
✓✓ |
13497 |
if (widget -> gx_widget_status & GX_STATUS_VISIBLE) |
77 |
|
|
{ |
78 |
✓✓ |
18125 |
while (!(widget -> gx_widget_status & GX_STATUS_ACCEPTS_FOCUS)) |
79 |
|
|
{ |
80 |
|
4744 |
widget = widget -> gx_widget_parent; |
81 |
✓✓ |
4744 |
if (!widget) |
82 |
|
|
{ |
83 |
|
|
/* this should not happened. Somehow we have a portion of |
84 |
|
|
the widget tree that does not accept focus, including the |
85 |
|
|
root window. Return an error. |
86 |
|
|
*/ |
87 |
|
1 |
_gx_system_error_process(GX_PTR_ERROR); |
88 |
|
1 |
return(GX_PTR_ERROR); |
89 |
|
|
} |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
/* check to see if this widget already owns focus, if so |
93 |
|
|
just return |
94 |
|
|
*/ |
95 |
✓✓ |
13381 |
if (widget == _gx_system_focus_owner) |
96 |
|
|
{ |
97 |
|
7282 |
return(GX_NO_CHANGE); |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
/* first figure out who is losing focus */ |
101 |
✓✓ |
6099 |
if (_gx_system_focus_owner) |
102 |
|
|
{ |
103 |
|
5375 |
parent = _gx_system_focus_owner; |
104 |
|
|
|
105 |
|
|
/* is the widget gaining focus a child of widget which currently has focus ? */ |
106 |
|
5375 |
_gx_widget_child_detect(parent, widget, &detect_result); |
107 |
|
|
|
108 |
✓✓ |
5375 |
if (detect_result) |
109 |
|
|
{ |
110 |
|
|
/* yes, do not send focus lost */ |
111 |
|
2514 |
parent = GX_NULL; |
112 |
|
|
} |
113 |
|
|
else |
114 |
|
|
{ |
115 |
✓✓ |
5195 |
while (parent -> gx_widget_parent) |
116 |
|
|
{ |
117 |
|
4920 |
_gx_widget_child_detect(parent -> gx_widget_parent, widget, &detect_result); |
118 |
|
|
|
119 |
|
|
/* does this object have same parent as object gaining focus ? */ |
120 |
✓✓ |
4920 |
if (detect_result) |
121 |
|
|
{ |
122 |
|
|
/* yes, that's where we stop "losing focus" */ |
123 |
|
2586 |
break; |
124 |
|
|
} |
125 |
|
|
/* move up one layer */ |
126 |
|
2334 |
parent = parent -> gx_widget_parent; |
127 |
|
|
} |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
/* tell the top-most "non common ancestor" that he and his children are losing focus */ |
131 |
✓✓ |
5375 |
if (parent) |
132 |
|
|
{ |
133 |
|
2861 |
newevent.gx_event_type = GX_EVENT_FOCUS_LOST; |
134 |
|
2861 |
parent -> gx_widget_event_process_function(parent, &newevent); |
135 |
|
|
} |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
/* now tell the new owner he has focus */ |
139 |
|
6099 |
_gx_system_focus_owner = widget; |
140 |
|
6099 |
newevent.gx_event_type = GX_EVENT_FOCUS_GAINED; |
141 |
|
6099 |
widget -> gx_widget_event_process_function(widget, &newevent); |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
/* send event to add focus */ |
145 |
|
6214 |
return GX_SUCCESS; |
146 |
|
|
} |
147 |
|
|
|