soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SFocusManager.h
Go to the documentation of this file.
1/**
2 * Copyright (C) 2014-2050
3 * All rights reserved.
4 *
5 * @file SFocusManager.h
6 * @brief Focus management module for DUI windows
7 * @version v1.0
8 * @author SOUI group
9 * @date 2014/08/02
10 *
11 * @details Manages focus for DUI windows within the SOUI framework.
12 */
13
14#ifndef __SFOCUSMANAGER__H__
15#define __SFOCUSMANAGER__H__
16
17#include <core/SWnd.h>
18#include <interface/SAccelerator-i.h>
19
20SNSBEGIN
21
22/**
23 * @class FocusSearch
24 * @brief Implements the algorithm to find the next view to focus.
25 *
26 * @details This class is responsible for finding the next focusable view within a given
27 * view hierarchy. It can cycle through the views and handle focus traversal.
28 */
30 public:
31 /**
32 * @brief Constructor
33 * @param root Root of the view hierarchy to traverse
34 * @param cycle TRUE if focus should cycle back to the first view when reaching the end
35 *
36 * @details Initializes the FocusSearch object with the specified root view and cycle behavior.
37 */
38 FocusSearch(SWindow *root, bool cycle);
39
40 /**
41 * @brief Destructor
42 */
43 virtual ~FocusSearch()
44 {
45 }
46
47 /**
48 * @brief Finds the next focusable view
49 * @param starting_view Starting view for the search
50 * @param reverse TRUE to find the previous view, FALSE for the next view
51 * @param check_starting_view TRUE if the starting view may obtain focus
52 * @return Next focusable view or NULL if none found
53 *
54 * @details Finds the next focusable view based on the specified parameters.
55 * If a FocusTraversable is found, it sets the FocusTraversable and returns NULL.
56 */
57 SWindow *FindNextFocusableView(SWindow *starting_view, bool reverse, bool check_starting_view);
58
59 private:
60 /**
61 * @brief Checks if a view is a focusable candidate
62 * @param v View to check
63 * @param pGroupOwner Group owner to skip
64 * @return TRUE if the view is focusable and not part of the specified group, otherwise FALSE
65 *
66 * @details Determines if a view is a valid focusable candidate, excluding views in the specified group.
67 */
68 bool IsViewFocusableCandidate(SWindow *v, SWindow *pGroupOwner);
69
70 /**
71 * @brief Checks if a view is focusable
72 * @param view View to check
73 * @return TRUE if the view is focusable, otherwise FALSE
74 *
75 * @details Determines if a view is focusable by checking its focusability.
76 */
77 bool IsFocusable(const SWindow *view) const;
78
79 /**
80 * @brief Finds the next focusable view
81 * @param starting_view Starting view for the search
82 * @param check_starting_view TRUE if the starting view may obtain focus
83 * @param can_go_up TRUE if traversal can go up the hierarchy
84 * @param can_go_down TRUE if traversal can go down the hierarchy
85 * @param pSkipGroupOwner Group owner to skip
86 * @return Next focusable view or NULL if none found
87 *
88 * @details Implements the logic to find the next focusable view based on the specified parameters.
89 */
90 SWindow *FindNextFocusableViewImpl(SWindow *starting_view, bool check_starting_view, bool can_go_up, bool can_go_down, SWindow *pSkipGroupOwner);
91
92 /**
93 * @brief Finds the previous focusable view
94 * @param starting_view Starting view for the search
95 * @param check_starting_view TRUE if the starting view may obtain focus
96 * @param can_go_up TRUE if traversal can go up the hierarchy
97 * @param can_go_down TRUE if traversal can go down the hierarchy
98 * @param pSkipGroupOwner Group owner to skip
99 * @return Previous focusable view or NULL if none found
100 *
101 * @details Implements the logic to find the previous focusable view based on the specified parameters.
102 */
103 SWindow *FindPreviousFocusableViewImpl(SWindow *starting_view, bool check_starting_view, bool can_go_up, bool can_go_down, SWindow *pSkipGroupOwner);
104
105 SWindow *root_; /**< Root of the view hierarchy to traverse. */
106 bool cycle_; /**< TRUE if focus should cycle back to the first view when reaching the end. */
107};
108
109/**
110 * @class SFocusManager
111 * @brief Focus management object for DUI windows
112 *
113 * @details Manages the focus for DUI windows, handling focus traversal and keyboard accelerators.
114 */
115class SOUI_EXP SFocusManager : public IAcceleratorMgr {
116 public:
117 /**
118 * @enum FocusChangeReason
119 * @brief Reason for focus change
120 *
121 * @details Enumerates the reasons why the focus might change.
122 */
124 {
125 kReasonDirectFocusChange = 0, /**< Focus changed due to a direct action like a click or shortcut. */
126 kReasonFocusTraversal, /**< Focus changed due to keyboard traversal (e.g., Tab, Shift+Tab). */
127 kReasonFocusRestore /**< Focus changed due to restoring the focus. */
128 };
129
130 /**
131 * @brief Constructor
132 */
134
135 /**
136 * @brief Destructor
137 */
138 ~SFocusManager(void);
139
140 /**
141 * @brief Sets the owner window
142 * @param pOwner Pointer to the owner window
143 *
144 * @details Sets the owner window for the focus manager.
145 */
146 void SetOwner(SWindow *pOwner);
147
148 /**
149 * @brief Checks if a key is a tab traversal key
150 * @param vKey Virtual key code
151 * @return TRUE if the key is a tab traversal key, otherwise FALSE
152 *
153 * @details Determines if the specified virtual key code is a tab traversal key.
154 */
155 BOOL IsTabTraversalKey(UINT vKey);
156
157 /**
158 * @brief Handles key down events
159 * @param vKey Virtual key code
160 * @return TRUE if the key event is handled, otherwise FALSE
161 *
162 * @details Handles key down events and performs focus traversal if necessary.
163 */
164 BOOL OnKeyDown(UINT vKey);
165
166 /**
167 * @brief Advances the focus
168 * @param reverse TRUE to advance backward, FALSE to advance forward
169 *
170 * @details Advances the focus to the next or previous focusable view based on the specified direction.
171 */
172 void AdvanceFocus(bool reverse);
173
174 /**
175 * @brief Sets the focused window with a reason
176 * @param swnd Handle to the window to focus
177 * @param reason Reason for the focus change
178 *
179 * @details Sets the focused window and records the reason for the focus change.
180 */
181 void SetFocusedHwndWithReason(SWND swnd, FocusChangeReason reason);
182
183 /**
184 * @brief Sets the focused window
185 * @param swnd Handle to the window to focus
186 *
187 * @details Sets the focused window without specifying a reason.
188 */
189 void SetFocusedHwnd(SWND swnd);
190
191 /**
192 * @brief Clears the focused window
193 *
194 * @details Clears the focused window and sets the native focus to the top root view.
195 */
196 void ClearFocus();
197
198 /**
199 * @brief Gets the focused window
200 * @return Handle to the focused window
201 *
202 * @details Returns the handle to the currently focused window.
203 */
204 SWND GetFocusedHwnd() const;
205
206 /**
207 * @brief Stores the focused view
208 *
209 * @details Stores the currently focused view for later restoration.
210 */
211 void StoreFocusedView();
212
213 /**
214 * @brief Restores the focused view
215 *
216 * @details Restores the focused view from the stored state.
217 */
218 void RestoreFocusedView();
219
220 protected:
221 // IAcceleratorMgr
222
223 /**
224 * @brief Registers a keyboard accelerator for a target
225 * @param pAcc Pointer to the accelerator
226 * @param target Pointer to the accelerator target
227 *
228 * @details Registers a keyboard accelerator for the specified target.
229 */
230 STDMETHOD_(void, RegisterAccelerator)
231 (THIS_ const IAccelerator *pAcc, IAcceleratorTarget *target) OVERRIDE;
232
233 /**
234 * @brief Unregisters a keyboard accelerator for a target
235 * @param pAcc Pointer to the accelerator
236 * @param target Pointer to the accelerator target
237 *
238 * @details Unregisters a keyboard accelerator for the specified target.
239 */
240 STDMETHOD_(void, UnregisterAccelerator)
241 (THIS_ const IAccelerator *pAcc, IAcceleratorTarget *target) OVERRIDE;
242
243 /**
244 * @brief Unregisters all keyboard accelerators for a target
245 * @param target Pointer to the accelerator target
246 *
247 * @details Unregisters all keyboard accelerators for the specified target.
248 */
249 STDMETHOD_(void, UnregisterAccelerators)(THIS_ IAcceleratorTarget *target) OVERRIDE;
250
251 private:
252 /**
253 * @brief Processes a keyboard accelerator
254 * @param pAcc Pointer to the accelerator
255 * @return TRUE if the accelerator was activated, otherwise FALSE
256 *
257 * @details Activates the target associated with the specified accelerator.
258 */
259 bool ProcessAccelerator(const IAccelerator *pAcc);
260
261 /**
262 * @brief Gets the next focusable view
263 * @param pWndStarting Starting view for the search
264 * @param bReverse TRUE to find the previous view, FALSE for the next view
265 * @param bLoop TRUE if focus should cycle back to the first view when reaching the end
266 * @return Next focusable view or NULL if none found
267 *
268 * @details Finds the next focusable view based on the specified parameters.
269 */
270 SWindow *GetNextFocusableView(SWindow *pWndStarting, bool bReverse, bool bLoop);
271
272 /**
273 * @brief Validates the focused view
274 *
275 * @details Validates the focused view and clears it if the window is no longer attached to the hierarchy.
276 */
277 void ValidateFocusedView();
278
279 private:
280 SWND focused_view_; /**< Handle to the currently focused window. */
281 SWND focused_backup_; /**< Backup handle to the focused window for restoration. */
282 FocusChangeReason focus_change_reason_; /**< Reason for the last focus change. */
283 SWindow *m_pOwner; /**< Pointer to the owner window. */
284
285 typedef SList<IAcceleratorTarget *> AcceleratorTargetList; /**< List of accelerator targets. */
286 typedef SMap<DWORD, AcceleratorTargetList> AcceleratorMap; /**< Map of accelerators to targets. */
287 AcceleratorMap accelerators_; /**< Map of registered accelerators. */
288};
289
290SNSEND
291
292#endif // __SFOCUSMANAGER__H__
SOUI基础DUI窗口模块
FocusSearch(SWindow *root, bool cycle)
Constructor.
virtual ~FocusSearch()
Destructor.
SWindow * FindNextFocusableView(SWindow *starting_view, bool reverse, bool check_starting_view)
Finds the next focusable view.
Focus management object for DUI windows.
FocusChangeReason
Reason for focus change.
SFocusManager()
Constructor.
Base class for SOUI DUI windows.
Definition SWnd.h:286
Interface for an accelerator key.
Interface for managing accelerator keys.
Interface for handling accelerator key presses.