6#pragma warning(disable : 4800)
18 if (root_->GetChildrenCount() == 0)
33 check_starting_view =
true;
37 SWindow *pStartGroupOwner = NULL;
39 pStartGroupOwner = starting_view->
GetParent();
43 bool can_go_down = !IsFocusable(starting_view);
44 pRet = FindPreviousFocusableViewImpl(starting_view, check_starting_view,
true, can_go_down, pStartGroupOwner);
48 pRet = FindNextFocusableViewImpl(starting_view, check_starting_view,
true,
true, pStartGroupOwner);
50 if (!pRet && cycle_ && starting_view)
66SWindow *FocusSearch::FindNextFocusableViewImpl(
SWindow *starting_view,
bool check_starting_view,
bool can_go_up,
bool can_go_down,
SWindow *pSkipGroupOwner)
68 if (check_starting_view)
70 if (IsViewFocusableCandidate(starting_view, pSkipGroupOwner))
90 SWindow *v = FindNextFocusableViewImpl(pChild,
true,
false,
true, pSkipGroupOwner);
102 SWindow *v = FindNextFocusableViewImpl(sibling,
true,
false,
true, pSkipGroupOwner);
112 SWindow *parent = starting_view->
GetParent();
118 return FindNextFocusableViewImpl(sibling,
true,
true,
true, pSkipGroupOwner);
134SWindow *FocusSearch::FindPreviousFocusableViewImpl(
SWindow *starting_view,
bool check_starting_view,
bool can_go_up,
bool can_go_down,
SWindow *pSkipGroupOwner)
141 SWindow *pRet = FindPreviousFocusableViewImpl(pChild,
true,
false,
true, pSkipGroupOwner);
147 if (check_starting_view && IsViewFocusableCandidate(starting_view, pSkipGroupOwner))
162 return FindPreviousFocusableViewImpl(pPrevSibling,
true,
true,
true, pSkipGroupOwner);
168 return FindPreviousFocusableViewImpl(pParent,
true,
true,
false, pSkipGroupOwner);
174bool FocusSearch::IsViewFocusableCandidate(
SWindow *v,
SWindow *pGroupOwner)
183bool FocusSearch::IsFocusable(
const SWindow *view)
const
214 if (GetKeyState(VK_CONTROL) & 0x8000)
231 if (pFocusWnd && pFocusWnd->
IsSiblingsAutoGroupped() && (vKey == VK_LEFT || vKey == VK_RIGHT || vKey == VK_UP || vKey == VK_DOWN))
260 SAccelerator accelerator(vKey, GetKeyState(VK_CONTROL) & 0x8000, GetKeyState(VK_MENU) & 0x8000, GetKeyState(VK_SHIFT) & 0x8000);
261 if (ProcessAccelerator(&accelerator))
274 ValidateFocusedView();
276 SWindow *pSwnd = GetNextFocusableView(pFocus, reverse,
true);
283SWindow *SFocusManager::GetNextFocusableView(
SWindow *original_starting_view,
bool bReverse,
bool bLoop)
287 return fs.FindNextFocusableView(original_starting_view, bReverse,
false);
292 if (swnd == focused_view_)
294 if (swnd == 0 && focused_backup_)
296 focused_backup_ = swnd;
301 if (focused_backup_ != 0)
303 focused_backup_ = swnd;
312 focus_change_reason_ = reason;
320 focused_view_ = swnd;
321 pNewFocus->
SSendMessage(WM_SETFOCUS, (WPARAM)focused_view_, (LPARAM)reason);
330void SFocusManager::ValidateFocusedView()
338 if (pFocus != m_pOwner)
357 return focused_view_;
362 ValidateFocusedView();
363 focused_backup_ = focused_view_;
373 focused_backup_ = -1;
382 focused_view_ = focused_backup_;
390 DWORD dwAcc = pAcc->
GetAcc();
391 AcceleratorTargetList &targets = accelerators_[dwAcc];
392 targets.AddHead(target);
397 DWORD dwAcc = pAcc->
GetAcc();
398 if (!accelerators_.Lookup(dwAcc))
400 AcceleratorTargetList *targets = &accelerators_[dwAcc];
401 SPOSITION pos = targets->Find(target);
403 targets->RemoveAt(pos);
408 SPOSITION pos = accelerators_.GetStartPosition();
411 AcceleratorTargetList &targets = accelerators_.GetValueAt(pos);
412 SPOSITION pos2 = targets.Find(target);
414 targets.RemoveAt(pos2);
415 accelerators_.GetNext(pos);
419bool SFocusManager::ProcessAccelerator(
const IAccelerator *pAcc)
421 DWORD dwAcc = pAcc->
GetAcc();
422 if (!accelerators_.Lookup(dwAcc))
427 AcceleratorTargetList targets = accelerators_[dwAcc];
429 SPOSITION pos = targets.GetHeadPosition();
Accelerator management module.
Focus management module for DUI windows.
Implements the algorithm to find the next view to focus.
FocusSearch(SWindow *root, bool cycle)
Constructor.
SWindow * FindNextFocusableView(SWindow *starting_view, bool reverse, bool check_starting_view)
Finds the next focusable view.
void AdvanceFocus(bool reverse)
Advances the focus.
void SetFocusedHwndWithReason(SWND swnd, FocusChangeReason reason)
Sets the focused window with a reason.
void SetFocusedHwnd(SWND swnd)
Sets the focused window.
BOOL IsTabTraversalKey(UINT vKey)
Checks if a key is a tab traversal key.
BOOL OnKeyDown(UINT vKey)
Handles key down events.
void SetOwner(SWindow *pOwner)
Sets the owner window.
~SFocusManager(void)
Destructor.
FocusChangeReason
Reason for focus change.
@ kReasonDirectFocusChange
void UnregisterAccelerators(IAcceleratorTarget *target) OVERRIDE
Unregisters all keyboard accelerators for a target.
void UnregisterAccelerator(const IAccelerator *pAcc, IAcceleratorTarget *target) OVERRIDE
Unregisters a keyboard accelerator for a target.
void RestoreFocusedView()
Restores the focused view.
void ClearFocus()
Clears the focused window.
void StoreFocusedView()
Stores the focused view.
SWND GetFocusedHwnd() const
Gets the focused window.
void RegisterAccelerator(const IAccelerator *pAcc, IAcceleratorTarget *target) OVERRIDE
Registers a keyboard accelerator for a target.
SFocusManager()
Constructor.
Base class for SOUI DUI windows.
UINT OnGetDlgCode() SCONST OVERRIDE
Retrieves the dialog code for the window.
SWND GetSwnd() SCONST OVERRIDE
Retrieves the window handle.
SWindow * GetParent() const
Retrieves the parent window.
BOOL IsSiblingsAutoGroupped() SCONST OVERRIDE
Checks if siblings are auto-grouped.
UINT GetChildrenCount() SCONST OVERRIDE
Retrieves the number of child windows.
BOOL IsVisible(BOOL bCheckParent=FALSE) SCONST OVERRIDE
Checks if the window is visible.
SWindow * GetRoot() const
Retrieves the root window in the hierarchy.
LRESULT SSendMessage(UINT uMsg, WPARAM wParam=0, LPARAM lParam=0, BOOL *pbMsgHandled=NULL) OVERRIDE
Sends a message to the window.
SWindow * GetWindow(int uCode) const
Retrieves a window based on a given code.
BOOL IsDisabled(BOOL bCheckParent=FALSE) SCONST OVERRIDE
Checks if the window is disabled.
BOOL IsFocusable() SCONST OVERRIDE
Checks if the window is focusable.
virtual SWindow * GetSelectedSiblingInGroup()
Get selected sibling in group.
static SWindow * GetWindow(SWND swnd)
Retrieves the SWindow pointer from a given handle.
Interface for an accelerator key.
DWORD GetAcc() SCONST PURE
Get the accelerator key combination.
Interface for handling accelerator key presses.
BOOL OnAcceleratorPressed(const IAccelerator *acc) PURE
Handle an accelerator key press.