165908a7eSAndre Fischer /**************************************************************
265908a7eSAndre Fischer  *
365908a7eSAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
465908a7eSAndre Fischer  * or more contributor license agreements.  See the NOTICE file
565908a7eSAndre Fischer  * distributed with this work for additional information
665908a7eSAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
765908a7eSAndre Fischer  * to you under the Apache License, Version 2.0 (the
865908a7eSAndre Fischer  * "License"); you may not use this file except in compliance
965908a7eSAndre Fischer  * with the License.  You may obtain a copy of the License at
1065908a7eSAndre Fischer  *
1165908a7eSAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
1265908a7eSAndre Fischer  *
1365908a7eSAndre Fischer  * Unless required by applicable law or agreed to in writing,
1465908a7eSAndre Fischer  * software distributed under the License is distributed on an
1565908a7eSAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1665908a7eSAndre Fischer  * KIND, either express or implied.  See the License for the
1765908a7eSAndre Fischer  * specific language governing permissions and limitations
1865908a7eSAndre Fischer  * under the License.
1965908a7eSAndre Fischer  *
2065908a7eSAndre Fischer  *************************************************************/
2165908a7eSAndre Fischer 
2265908a7eSAndre Fischer #include "precompiled_sfx2.hxx"
2365908a7eSAndre Fischer 
2465908a7eSAndre Fischer #include "FocusManager.hxx"
2565908a7eSAndre Fischer #include "Panel.hxx"
26*f35c6d02SAndre Fischer #include "sfx2/sidebar/Tools.hxx"
2765908a7eSAndre Fischer #include "TitleBar.hxx"
2865908a7eSAndre Fischer #include <vcl/button.hxx>
2965908a7eSAndre Fischer #include <vcl/toolbox.hxx>
3065908a7eSAndre Fischer #include <toolkit/helper/vclunohelper.hxx>
3165908a7eSAndre Fischer 
3265908a7eSAndre Fischer 
3365908a7eSAndre Fischer namespace sfx2 { namespace sidebar {
3465908a7eSAndre Fischer 
3565908a7eSAndre Fischer namespace
3665908a7eSAndre Fischer {
3765908a7eSAndre Fischer     enum PanelComponent
3865908a7eSAndre Fischer     {
3965908a7eSAndre Fischer         PC_TitleBar,
4065908a7eSAndre Fischer         PC_ToolBox,
4165908a7eSAndre Fischer         PC_Content,
4265908a7eSAndre Fischer         PC_None
4365908a7eSAndre Fischer     };
4465908a7eSAndre Fischer 
4565908a7eSAndre Fischer     PanelComponent GetFocusedComponent (const Panel& rPanel)
4665908a7eSAndre Fischer     {
4765908a7eSAndre Fischer         if (rPanel.HasFocus())
4865908a7eSAndre Fischer             return PC_Content;
4965908a7eSAndre Fischer         else if (rPanel.GetTitleBar() != NULL)
5045da7d5eSAndre Fischer         {
5165908a7eSAndre Fischer             if (rPanel.GetTitleBar()->HasFocus())
5265908a7eSAndre Fischer                 return PC_TitleBar;
5365908a7eSAndre Fischer             else if (rPanel.GetTitleBar()->GetToolBox().HasFocus())
5465908a7eSAndre Fischer                 return PC_ToolBox;
5545da7d5eSAndre Fischer         }
5676d44fc7SPavel Janík 	return PC_None;
5765908a7eSAndre Fischer     }
5865908a7eSAndre Fischer }
5965908a7eSAndre Fischer 
6065908a7eSAndre Fischer 
6165908a7eSAndre Fischer FocusManager::FocusManager (void)
6265908a7eSAndre Fischer     : maPanels(),
6365908a7eSAndre Fischer       maButtons(),
6465908a7eSAndre Fischer       mpTopLevelWindow(NULL)
6565908a7eSAndre Fischer {
6665908a7eSAndre Fischer }
6765908a7eSAndre Fischer 
6865908a7eSAndre Fischer 
6965908a7eSAndre Fischer 
7065908a7eSAndre Fischer 
7165908a7eSAndre Fischer FocusManager::~FocusManager (void)
7265908a7eSAndre Fischer {
7365908a7eSAndre Fischer     Clear();
7465908a7eSAndre Fischer }
7565908a7eSAndre Fischer 
7665908a7eSAndre Fischer 
7765908a7eSAndre Fischer 
7865908a7eSAndre Fischer 
7965908a7eSAndre Fischer void FocusManager::GrabFocus (void)
8065908a7eSAndre Fischer {
8165908a7eSAndre Fischer     if ( ! maPanels.empty())
8265908a7eSAndre Fischer         FocusPanel(0);
8365908a7eSAndre Fischer }
8465908a7eSAndre Fischer 
8565908a7eSAndre Fischer 
8665908a7eSAndre Fischer 
8765908a7eSAndre Fischer 
8865908a7eSAndre Fischer void FocusManager::Clear (void)
8965908a7eSAndre Fischer {
9065908a7eSAndre Fischer     ClearPanels();
9165908a7eSAndre Fischer     ClearButtons();
9265908a7eSAndre Fischer }
9365908a7eSAndre Fischer 
9465908a7eSAndre Fischer 
9565908a7eSAndre Fischer 
9665908a7eSAndre Fischer void FocusManager::ClearPanels (void)
9765908a7eSAndre Fischer {
9865908a7eSAndre Fischer     SetTopLevelWindow(NULL);
9965908a7eSAndre Fischer 
10065908a7eSAndre Fischer     ::std::vector<Panel*> aPanels;
10165908a7eSAndre Fischer     aPanels.swap(maPanels);
10265908a7eSAndre Fischer     for (::std::vector<Panel*>::iterator iPanel(aPanels.begin()),iEnd(aPanels.end());
10365908a7eSAndre Fischer          iPanel!=iEnd;
10465908a7eSAndre Fischer         ++iPanel)
10565908a7eSAndre Fischer     {
10665908a7eSAndre Fischer         UnregisterWindow(**iPanel);
10765908a7eSAndre Fischer         if ((*iPanel)->GetTitleBar() != NULL)
10865908a7eSAndre Fischer         {
10965908a7eSAndre Fischer             UnregisterWindow(*(*iPanel)->GetTitleBar());
11065908a7eSAndre Fischer             UnregisterWindow((*iPanel)->GetTitleBar()->GetToolBox());
11165908a7eSAndre Fischer         }
11265908a7eSAndre Fischer     }
11365908a7eSAndre Fischer }
11465908a7eSAndre Fischer 
11565908a7eSAndre Fischer 
11665908a7eSAndre Fischer 
11765908a7eSAndre Fischer 
11865908a7eSAndre Fischer void FocusManager::ClearButtons (void)
11965908a7eSAndre Fischer {
12065908a7eSAndre Fischer     ::std::vector<Window*> aButtons;
12165908a7eSAndre Fischer     for (::std::vector<Window*>::iterator iButton(aButtons.begin()),iEnd(aButtons.end());
12265908a7eSAndre Fischer          iButton!=iEnd;
12365908a7eSAndre Fischer         ++iButton)
12465908a7eSAndre Fischer     {
12565908a7eSAndre Fischer         UnregisterWindow(**iButton);
12665908a7eSAndre Fischer     }
12765908a7eSAndre Fischer }
12865908a7eSAndre Fischer 
12965908a7eSAndre Fischer 
13065908a7eSAndre Fischer 
13165908a7eSAndre Fischer 
13265908a7eSAndre Fischer void FocusManager::SetPanels (const SharedPanelContainer& rPanels)
13365908a7eSAndre Fischer {
13465908a7eSAndre Fischer     ClearPanels();
13565908a7eSAndre Fischer     for(SharedPanelContainer::const_iterator iPanel(rPanels.begin()),iEnd(rPanels.end());
13665908a7eSAndre Fischer         iPanel!=iEnd;
13765908a7eSAndre Fischer         ++iPanel)
13865908a7eSAndre Fischer     {
13965908a7eSAndre Fischer         RegisterWindow(**iPanel);
14065908a7eSAndre Fischer         if ((*iPanel)->GetTitleBar() != NULL)
14165908a7eSAndre Fischer         {
14265908a7eSAndre Fischer             RegisterWindow(*(*iPanel)->GetTitleBar());
14365908a7eSAndre Fischer             RegisterWindow((*iPanel)->GetTitleBar()->GetToolBox());
14465908a7eSAndre Fischer         }
14565908a7eSAndre Fischer         maPanels.push_back(iPanel->get());
14665908a7eSAndre Fischer     }
14765908a7eSAndre Fischer 
14865908a7eSAndre Fischer     RegisterTopLevelListener();
14965908a7eSAndre Fischer }
15065908a7eSAndre Fischer 
15165908a7eSAndre Fischer 
15265908a7eSAndre Fischer 
15365908a7eSAndre Fischer 
15465908a7eSAndre Fischer void FocusManager::SetButtons (const ::std::vector<Button*>& rButtons)
15565908a7eSAndre Fischer {
15665908a7eSAndre Fischer     ClearButtons();
15765908a7eSAndre Fischer     for (::std::vector<Button*>::const_iterator iButton(rButtons.begin()),iEnd(rButtons.end());
15865908a7eSAndre Fischer          iButton!=iEnd;
15965908a7eSAndre Fischer          ++iButton)
16065908a7eSAndre Fischer     {
16165908a7eSAndre Fischer         RegisterWindow(**iButton);
16265908a7eSAndre Fischer         maButtons.push_back(*iButton);
16365908a7eSAndre Fischer     }
16465908a7eSAndre Fischer }
16565908a7eSAndre Fischer 
16665908a7eSAndre Fischer 
16765908a7eSAndre Fischer 
16865908a7eSAndre Fischer 
16965908a7eSAndre Fischer void FocusManager::RegisterWindow (Window& rWindow)
17065908a7eSAndre Fischer {
17165908a7eSAndre Fischer     rWindow.AddEventListener(LINK(this, FocusManager, WindowEventListener));
17265908a7eSAndre Fischer }
17365908a7eSAndre Fischer 
17465908a7eSAndre Fischer 
17565908a7eSAndre Fischer 
17665908a7eSAndre Fischer 
17765908a7eSAndre Fischer void FocusManager::UnregisterWindow (Window& rWindow)
17865908a7eSAndre Fischer {
17965908a7eSAndre Fischer     rWindow.RemoveEventListener(LINK(this, FocusManager, WindowEventListener));
18065908a7eSAndre Fischer }
18165908a7eSAndre Fischer 
18265908a7eSAndre Fischer 
18365908a7eSAndre Fischer 
18465908a7eSAndre Fischer 
18565908a7eSAndre Fischer void FocusManager::RegisterTopLevelListener (void)
18665908a7eSAndre Fischer {
18765908a7eSAndre Fischer     if (maPanels.empty())
18865908a7eSAndre Fischer         return;
18965908a7eSAndre Fischer     Window* pWindow = maPanels.front();
19065908a7eSAndre Fischer     while (pWindow != NULL && pWindow->GetParent()!=NULL)
19165908a7eSAndre Fischer     {
19265908a7eSAndre Fischer         pWindow = pWindow->GetParent();
19365908a7eSAndre Fischer     }
19465908a7eSAndre Fischer     SetTopLevelWindow(pWindow);
19565908a7eSAndre Fischer }
19665908a7eSAndre Fischer 
19765908a7eSAndre Fischer 
19865908a7eSAndre Fischer 
19965908a7eSAndre Fischer 
20065908a7eSAndre Fischer void FocusManager::SetTopLevelWindow (Window* pWindow)
20165908a7eSAndre Fischer {
20265908a7eSAndre Fischer     if (mpTopLevelWindow != pWindow)
20365908a7eSAndre Fischer     {
20465908a7eSAndre Fischer         if (mpTopLevelWindow != NULL)
20565908a7eSAndre Fischer         {
20665908a7eSAndre Fischer             UnregisterWindow(*mpTopLevelWindow);
20765908a7eSAndre Fischer             mpTopLevelWindow->RemoveChildEventListener(LINK(this, FocusManager, WindowEventListener));
20865908a7eSAndre Fischer         }
20965908a7eSAndre Fischer         mpTopLevelWindow = pWindow;
21065908a7eSAndre Fischer         if (mpTopLevelWindow != NULL)
21165908a7eSAndre Fischer         {
21265908a7eSAndre Fischer             RegisterWindow(*mpTopLevelWindow);
21365908a7eSAndre Fischer             mpTopLevelWindow->AddChildEventListener(LINK(this, FocusManager, WindowEventListener));
21465908a7eSAndre Fischer         }
21565908a7eSAndre Fischer     }
21665908a7eSAndre Fischer }
21765908a7eSAndre Fischer 
21865908a7eSAndre Fischer 
21965908a7eSAndre Fischer 
22065908a7eSAndre Fischer 
22165908a7eSAndre Fischer sal_Int32 FocusManager::GetPanelIndex (const Window& rWindow) const
22265908a7eSAndre Fischer {
22365908a7eSAndre Fischer     for (sal_Int32 nIndex=0,nCount(maPanels.size()); nIndex<nCount; ++nIndex)
22465908a7eSAndre Fischer     {
22565908a7eSAndre Fischer         if (maPanels[nIndex] == &rWindow)
22665908a7eSAndre Fischer             return nIndex;
22765908a7eSAndre Fischer         TitleBar* pTitleBar = maPanels[nIndex]->GetTitleBar();
22865908a7eSAndre Fischer         if (pTitleBar == &rWindow)
22965908a7eSAndre Fischer             return nIndex;
23065908a7eSAndre Fischer         if (pTitleBar!=NULL && &pTitleBar->GetToolBox()==&rWindow)
23165908a7eSAndre Fischer             return nIndex;
23265908a7eSAndre Fischer     }
23365908a7eSAndre Fischer     return -1;
23465908a7eSAndre Fischer }
23565908a7eSAndre Fischer 
23665908a7eSAndre Fischer 
23765908a7eSAndre Fischer 
23865908a7eSAndre Fischer 
23965908a7eSAndre Fischer sal_Int32 FocusManager::GetButtonIndex (const Window& rWindow) const
24065908a7eSAndre Fischer {
24165908a7eSAndre Fischer     for (sal_Int32 nIndex=0,nCount(maButtons.size()); nIndex<nCount; ++nIndex)
24265908a7eSAndre Fischer         if (maButtons[nIndex] == &rWindow)
24365908a7eSAndre Fischer             return nIndex;
24465908a7eSAndre Fischer     return -1;
24565908a7eSAndre Fischer }
24665908a7eSAndre Fischer 
24765908a7eSAndre Fischer 
24865908a7eSAndre Fischer 
24965908a7eSAndre Fischer 
25065908a7eSAndre Fischer bool FocusManager::IsAnyPanelFocused (void) const
25165908a7eSAndre Fischer {
25265908a7eSAndre Fischer     for (::std::vector<Panel*>::const_iterator iPanel(maPanels.begin()),iEnd(maPanels.end());
25365908a7eSAndre Fischer          iPanel!=iEnd;
25465908a7eSAndre Fischer          ++iPanel)
25565908a7eSAndre Fischer     {
25665908a7eSAndre Fischer         if ((*iPanel)->HasFocus())
25765908a7eSAndre Fischer             return true;
25865908a7eSAndre Fischer         else if ((*iPanel)->HasChildPathFocus())
25965908a7eSAndre Fischer             return true;
26065908a7eSAndre Fischer     }
26165908a7eSAndre Fischer     return false;
26265908a7eSAndre Fischer }
26365908a7eSAndre Fischer 
26465908a7eSAndre Fischer 
26565908a7eSAndre Fischer 
26665908a7eSAndre Fischer 
26765908a7eSAndre Fischer bool FocusManager::IsAnyButtonFocused (void) const
26865908a7eSAndre Fischer {
26965908a7eSAndre Fischer     for (::std::vector<Button*>::const_iterator iButton(maButtons.begin()),iEnd(maButtons.end());
27065908a7eSAndre Fischer          iButton!=iEnd;
27165908a7eSAndre Fischer          ++iButton)
27265908a7eSAndre Fischer     {
27365908a7eSAndre Fischer         if ((*iButton)->HasFocus())
27465908a7eSAndre Fischer             return true;
27565908a7eSAndre Fischer     }
27665908a7eSAndre Fischer     return false;
27765908a7eSAndre Fischer }
27865908a7eSAndre Fischer 
27965908a7eSAndre Fischer 
28065908a7eSAndre Fischer 
28165908a7eSAndre Fischer 
28265908a7eSAndre Fischer void FocusManager::FocusPanel (const sal_Int32 nPanelIndex)
28365908a7eSAndre Fischer {
28465908a7eSAndre Fischer     Panel& rPanel (*maPanels[nPanelIndex]);
28565908a7eSAndre Fischer     TitleBar* pTitleBar = rPanel.GetTitleBar();
28665908a7eSAndre Fischer     if (pTitleBar!=NULL && pTitleBar->IsVisible())
28765908a7eSAndre Fischer     {
28865908a7eSAndre Fischer         rPanel.SetExpanded(true);
28965908a7eSAndre Fischer         pTitleBar->GrabFocus();
29065908a7eSAndre Fischer     }
29165908a7eSAndre Fischer     else
29265908a7eSAndre Fischer         FocusPanelContent(nPanelIndex);
29365908a7eSAndre Fischer }
29465908a7eSAndre Fischer 
29565908a7eSAndre Fischer 
29665908a7eSAndre Fischer 
29765908a7eSAndre Fischer 
29865908a7eSAndre Fischer void FocusManager::FocusPanelContent (const sal_Int32 nPanelIndex)
29965908a7eSAndre Fischer {
30065908a7eSAndre Fischer     Window* pWindow = VCLUnoHelper::GetWindow(maPanels[nPanelIndex]->GetElementWindow());
30165908a7eSAndre Fischer     if (pWindow != NULL)
30265908a7eSAndre Fischer         pWindow->GrabFocus();
30365908a7eSAndre Fischer }
30465908a7eSAndre Fischer 
30565908a7eSAndre Fischer 
30665908a7eSAndre Fischer 
30765908a7eSAndre Fischer 
30865908a7eSAndre Fischer void FocusManager::FocusButton (const sal_Int32 nButtonIndex)
30965908a7eSAndre Fischer {
31065908a7eSAndre Fischer     maButtons[nButtonIndex]->GrabFocus();
31165908a7eSAndre Fischer     maButtons[nButtonIndex]->Invalidate();
31265908a7eSAndre Fischer }
31365908a7eSAndre Fischer 
31465908a7eSAndre Fischer 
31565908a7eSAndre Fischer 
31665908a7eSAndre Fischer 
31765908a7eSAndre Fischer void FocusManager::ClickButton (const sal_Int32 nButtonIndex)
31865908a7eSAndre Fischer {
31965908a7eSAndre Fischer     maButtons[nButtonIndex]->Click();
32065908a7eSAndre Fischer     if (nButtonIndex > 0)
32165908a7eSAndre Fischer         if ( ! maPanels.empty())
32265908a7eSAndre Fischer             FocusPanel(0);
32365908a7eSAndre Fischer     maButtons[nButtonIndex]->GetParent()->Invalidate();
32465908a7eSAndre Fischer }
32565908a7eSAndre Fischer 
32665908a7eSAndre Fischer 
32765908a7eSAndre Fischer 
32865908a7eSAndre Fischer 
32965908a7eSAndre Fischer void FocusManager::RemoveWindow (Window& rWindow)
33065908a7eSAndre Fischer {
33165908a7eSAndre Fischer     ::std::vector<Panel*>::iterator iPanel (::std::find(maPanels.begin(), maPanels.end(), &rWindow));
33265908a7eSAndre Fischer     if (iPanel != maPanels.end())
33365908a7eSAndre Fischer     {
33465908a7eSAndre Fischer         UnregisterWindow(rWindow);
33565908a7eSAndre Fischer         if ((*iPanel)->GetTitleBar() != NULL)
33665908a7eSAndre Fischer         {
33765908a7eSAndre Fischer             UnregisterWindow(*(*iPanel)->GetTitleBar());
33865908a7eSAndre Fischer             UnregisterWindow((*iPanel)->GetTitleBar()->GetToolBox());
33965908a7eSAndre Fischer         }
34065908a7eSAndre Fischer         maPanels.erase(iPanel);
34165908a7eSAndre Fischer         return;
34265908a7eSAndre Fischer     }
34365908a7eSAndre Fischer 
34465908a7eSAndre Fischer     ::std::vector<Button*>::iterator iButton (::std::find(maButtons.begin(), maButtons.end(), &rWindow));
34565908a7eSAndre Fischer     if (iButton != maButtons.end())
34665908a7eSAndre Fischer     {
34765908a7eSAndre Fischer         UnregisterWindow(rWindow);
34865908a7eSAndre Fischer         maButtons.erase(iButton);
34965908a7eSAndre Fischer         return;
35065908a7eSAndre Fischer     }
35165908a7eSAndre Fischer }
35265908a7eSAndre Fischer 
35365908a7eSAndre Fischer 
35465908a7eSAndre Fischer 
35565908a7eSAndre Fischer 
35665908a7eSAndre Fischer bool FocusManager::MoveFocusInsidePanel (
35765908a7eSAndre Fischer     const sal_Int32 nPanelIndex,
35865908a7eSAndre Fischer     const sal_Int32 nDirection)
35965908a7eSAndre Fischer {
36065908a7eSAndre Fischer     Panel& rPanel (*maPanels[nPanelIndex]);
36165908a7eSAndre Fischer     switch (GetFocusedComponent(rPanel))
36265908a7eSAndre Fischer     {
36365908a7eSAndre Fischer         case  PC_TitleBar:
36465908a7eSAndre Fischer             if (nDirection > 0)
36565908a7eSAndre Fischer                 rPanel.GetTitleBar()->GetToolBox().GrabFocus();
36665908a7eSAndre Fischer             else
36765908a7eSAndre Fischer                 FocusPanelContent(nPanelIndex);
36865908a7eSAndre Fischer             return true;
36965908a7eSAndre Fischer 
37065908a7eSAndre Fischer         case PC_ToolBox:
37165908a7eSAndre Fischer             if (nDirection > 0)
37265908a7eSAndre Fischer                 FocusPanelContent(nPanelIndex);
37365908a7eSAndre Fischer             else
37465908a7eSAndre Fischer                 rPanel.GetTitleBar()->GrabFocus();
37565908a7eSAndre Fischer             return true;
37665908a7eSAndre Fischer 
37765908a7eSAndre Fischer         default:
37865908a7eSAndre Fischer             return false;
37965908a7eSAndre Fischer     }
38065908a7eSAndre Fischer }
38165908a7eSAndre Fischer 
38265908a7eSAndre Fischer 
38365908a7eSAndre Fischer 
38465908a7eSAndre Fischer 
38565908a7eSAndre Fischer long FocusManager::NotifyDockingWindowEvent (const KeyEvent& rKeyEvent)
38665908a7eSAndre Fischer {
38765908a7eSAndre Fischer     switch(rKeyEvent.GetKeyCode().GetCode())
38865908a7eSAndre Fischer     {
38965908a7eSAndre Fischer         case KEY_F6:
39065908a7eSAndre Fischer             if (rKeyEvent.GetKeyCode().IsShift())
39165908a7eSAndre Fischer             {
39265908a7eSAndre Fischer                 if (IsAnyButtonFocused())
39365908a7eSAndre Fischer                 {
39465908a7eSAndre Fischer                     FocusPanel(0);
39565908a7eSAndre Fischer                     return 1;
39665908a7eSAndre Fischer                 }
39765908a7eSAndre Fischer             }
39865908a7eSAndre Fischer             else
39965908a7eSAndre Fischer             {
40065908a7eSAndre Fischer                 if (IsAnyPanelFocused())
40165908a7eSAndre Fischer                 {
40265908a7eSAndre Fischer                     FocusButton(0);
40365908a7eSAndre Fischer                     return 1;
40465908a7eSAndre Fischer                 }
40565908a7eSAndre Fischer             }
40665908a7eSAndre Fischer             break;
40765908a7eSAndre Fischer     }
40865908a7eSAndre Fischer     return 0;
40965908a7eSAndre Fischer }
41065908a7eSAndre Fischer 
41165908a7eSAndre Fischer 
41265908a7eSAndre Fischer 
41365908a7eSAndre Fischer 
41465908a7eSAndre Fischer void FocusManager::HandleKeyEvent (
41565908a7eSAndre Fischer     const KeyCode& rKeyCode,
41665908a7eSAndre Fischer     const Window& rWindow)
41765908a7eSAndre Fischer {
41865908a7eSAndre Fischer     if (rKeyCode.GetModifier() != 0)
41965908a7eSAndre Fischer         return;
42065908a7eSAndre Fischer 
42165908a7eSAndre Fischer     const sal_Int32 nPanelIndex (GetPanelIndex(rWindow));
42276d44fc7SPavel Janík     // const bool bIsPanelTitleFocused (nPanelIndex>=0 && maPanels[nPanelIndex] != &rWindow);
42376d44fc7SPavel Janík     // const bool bIsPanelToolBoxFocused (nPanelIndex>=0 && maPanels[nPanelIndex] != &rWindow);
42465908a7eSAndre Fischer     sal_Int32 nButtonIndex (nPanelIndex==-1 ? GetButtonIndex(rWindow) : -1);
42565908a7eSAndre Fischer 
42665908a7eSAndre Fischer     switch (rKeyCode.GetCode())
42765908a7eSAndre Fischer     {
42865908a7eSAndre Fischer         case KEY_F6:
42965908a7eSAndre Fischer             if (nPanelIndex >= 0)
43065908a7eSAndre Fischer                 FocusButton(0);
43165908a7eSAndre Fischer             else
43265908a7eSAndre Fischer                 return;
43365908a7eSAndre Fischer             break;
43465908a7eSAndre Fischer 
43565908a7eSAndre Fischer         case KEY_SPACE:
43665908a7eSAndre Fischer             if (nPanelIndex >= 0)
43765908a7eSAndre Fischer             {
43865908a7eSAndre Fischer                 if (GetFocusedComponent(*maPanels[nPanelIndex]) == PC_TitleBar)
43965908a7eSAndre Fischer                 {
44065908a7eSAndre Fischer                     // Toggle the expansion state.
44165908a7eSAndre Fischer                     maPanels[nPanelIndex]->SetExpanded( ! maPanels[nPanelIndex]->IsExpanded());
44265908a7eSAndre Fischer                 }
44365908a7eSAndre Fischer             }
44465908a7eSAndre Fischer             else if (nButtonIndex >= 0)
44565908a7eSAndre Fischer             {
44665908a7eSAndre Fischer                 // Activate the button.
44765908a7eSAndre Fischer                 ClickButton(nButtonIndex);
44865908a7eSAndre Fischer             }
44965908a7eSAndre Fischer             return;
45065908a7eSAndre Fischer 
45165908a7eSAndre Fischer         case KEY_RETURN:
45265908a7eSAndre Fischer             if (nPanelIndex >= 0)
45365908a7eSAndre Fischer             {
45465908a7eSAndre Fischer                 if (GetFocusedComponent(*maPanels[nPanelIndex]) == PC_TitleBar)
45565908a7eSAndre Fischer                 {
45665908a7eSAndre Fischer                     // Enter the panel.
45765908a7eSAndre Fischer                     FocusPanelContent(nPanelIndex);
45865908a7eSAndre Fischer                 }
45965908a7eSAndre Fischer             }
46065908a7eSAndre Fischer             else if (nButtonIndex >= 0)
46165908a7eSAndre Fischer             {
46265908a7eSAndre Fischer                 // Activate the button.
46365908a7eSAndre Fischer                 ClickButton(nButtonIndex);
46465908a7eSAndre Fischer             }
46565908a7eSAndre Fischer             return;
46665908a7eSAndre Fischer 
46765908a7eSAndre Fischer         case KEY_TAB:
46865908a7eSAndre Fischer             if (nPanelIndex >= 0)
46965908a7eSAndre Fischer             {
47065908a7eSAndre Fischer                 if (rKeyCode.IsShift())
47165908a7eSAndre Fischer                     MoveFocusInsidePanel(nPanelIndex, -1);
47265908a7eSAndre Fischer                 else
47365908a7eSAndre Fischer                     MoveFocusInsidePanel(nPanelIndex, +1);
47465908a7eSAndre Fischer             }
47565908a7eSAndre Fischer             break;
47665908a7eSAndre Fischer 
47765908a7eSAndre Fischer         case KEY_LEFT:
47865908a7eSAndre Fischer         case KEY_UP:
47965908a7eSAndre Fischer             // Go to previous element in focus ring.
48065908a7eSAndre Fischer             if (nPanelIndex >= 0)
48165908a7eSAndre Fischer             {
48265908a7eSAndre Fischer                 FocusPanel((nPanelIndex + maPanels.size() - 1) % maPanels.size());
48365908a7eSAndre Fischer             }
48465908a7eSAndre Fischer             else if (nButtonIndex >= 0)
48565908a7eSAndre Fischer             {
48665908a7eSAndre Fischer                 FocusButton((nButtonIndex + maButtons.size() - 1) % maButtons.size());
48765908a7eSAndre Fischer             }
48865908a7eSAndre Fischer             break;
48965908a7eSAndre Fischer 
49065908a7eSAndre Fischer         case KEY_RIGHT:
49165908a7eSAndre Fischer         case KEY_DOWN:
49265908a7eSAndre Fischer             // Go to next element in focus ring.
49365908a7eSAndre Fischer             if (nPanelIndex >= 0)
49465908a7eSAndre Fischer             {
49565908a7eSAndre Fischer                 FocusPanel((nPanelIndex + 1) % maPanels.size());
49665908a7eSAndre Fischer             }
49765908a7eSAndre Fischer             else if (nButtonIndex >= 0)
49865908a7eSAndre Fischer             {
49965908a7eSAndre Fischer                 FocusButton((nButtonIndex + 1) % maButtons.size());
50065908a7eSAndre Fischer             }
50165908a7eSAndre Fischer             break;
50265908a7eSAndre Fischer     }
50365908a7eSAndre Fischer }
50465908a7eSAndre Fischer 
50565908a7eSAndre Fischer 
50665908a7eSAndre Fischer 
50765908a7eSAndre Fischer 
50865908a7eSAndre Fischer void FocusManager::HandleTopLevelEvent (VclWindowEvent& rEvent)
50965908a7eSAndre Fischer {
51065908a7eSAndre Fischer     switch (rEvent.GetId())
51165908a7eSAndre Fischer     {
51265908a7eSAndre Fischer         case VCLEVENT_WINDOW_KEYINPUT:
51365908a7eSAndre Fischer         {
51465908a7eSAndre Fischer             KeyEvent* pKeyEvent = static_cast<KeyEvent*>(rEvent.GetData());
51565908a7eSAndre Fischer             switch (pKeyEvent->GetKeyCode().GetCode())
51665908a7eSAndre Fischer             {
51765908a7eSAndre Fischer                 case KEY_F6:
51865908a7eSAndre Fischer                     OSL_TRACE("");
51965908a7eSAndre Fischer                     break;
52065908a7eSAndre Fischer             }
52165908a7eSAndre Fischer         }
52265908a7eSAndre Fischer     }
52365908a7eSAndre Fischer }
52465908a7eSAndre Fischer 
52565908a7eSAndre Fischer 
52665908a7eSAndre Fischer 
52765908a7eSAndre Fischer 
52865908a7eSAndre Fischer IMPL_LINK(FocusManager, WindowEventListener, VclSimpleEvent*, pEvent)
52965908a7eSAndre Fischer {
53065908a7eSAndre Fischer     if (pEvent == NULL)
53165908a7eSAndre Fischer         return 0;
53265908a7eSAndre Fischer 
53365908a7eSAndre Fischer     if ( ! pEvent->ISA(VclWindowEvent))
53465908a7eSAndre Fischer         return 0;
53565908a7eSAndre Fischer 
53665908a7eSAndre Fischer     VclWindowEvent* pWindowEvent = static_cast<VclWindowEvent*>(pEvent);
53765908a7eSAndre Fischer     Window* pSource = pWindowEvent->GetWindow();
53865908a7eSAndre Fischer     if (pSource == NULL)
53965908a7eSAndre Fischer         return 0;
54065908a7eSAndre Fischer 
54165908a7eSAndre Fischer     if (pSource == mpTopLevelWindow)
54265908a7eSAndre Fischer         HandleTopLevelEvent(*pWindowEvent);
54365908a7eSAndre Fischer     else
54465908a7eSAndre Fischer         switch (pWindowEvent->GetId())
54565908a7eSAndre Fischer         {
54665908a7eSAndre Fischer             case VCLEVENT_WINDOW_KEYINPUT:
54765908a7eSAndre Fischer             {
54865908a7eSAndre Fischer                 KeyEvent* pKeyEvent = static_cast<KeyEvent*>(pWindowEvent->GetData());
54965908a7eSAndre Fischer                 HandleKeyEvent(pKeyEvent->GetKeyCode(), *pSource);
55065908a7eSAndre Fischer                 return 1;
55165908a7eSAndre Fischer             }
55265908a7eSAndre Fischer 
55365908a7eSAndre Fischer             case VCLEVENT_OBJECT_DYING:
55465908a7eSAndre Fischer                 RemoveWindow(*pSource);
55565908a7eSAndre Fischer                 return 1;
55665908a7eSAndre Fischer 
55765908a7eSAndre Fischer             case VCLEVENT_WINDOW_GETFOCUS:
55865908a7eSAndre Fischer             case VCLEVENT_WINDOW_LOSEFOCUS:
55965908a7eSAndre Fischer                 pSource->Invalidate();
56065908a7eSAndre Fischer         }
56165908a7eSAndre Fischer     return 0;
56265908a7eSAndre Fischer }
56365908a7eSAndre Fischer 
56465908a7eSAndre Fischer 
56565908a7eSAndre Fischer 
56665908a7eSAndre Fischer } } // end of namespace sfx2::sidebar
567