1*7a32b0c8SAndre Fischer /************************************************************** 2*7a32b0c8SAndre Fischer * 3*7a32b0c8SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 4*7a32b0c8SAndre Fischer * or more contributor license agreements. See the NOTICE file 5*7a32b0c8SAndre Fischer * distributed with this work for additional information 6*7a32b0c8SAndre Fischer * regarding copyright ownership. The ASF licenses this file 7*7a32b0c8SAndre Fischer * to you under the Apache License, Version 2.0 (the 8*7a32b0c8SAndre Fischer * "License"); you may not use this file except in compliance 9*7a32b0c8SAndre Fischer * with the License. You may obtain a copy of the License at 10*7a32b0c8SAndre Fischer * 11*7a32b0c8SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 12*7a32b0c8SAndre Fischer * 13*7a32b0c8SAndre Fischer * Unless required by applicable law or agreed to in writing, 14*7a32b0c8SAndre Fischer * software distributed under the License is distributed on an 15*7a32b0c8SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*7a32b0c8SAndre Fischer * KIND, either express or implied. See the License for the 17*7a32b0c8SAndre Fischer * specific language governing permissions and limitations 18*7a32b0c8SAndre Fischer * under the License. 19*7a32b0c8SAndre Fischer * 20*7a32b0c8SAndre Fischer *************************************************************/ 21*7a32b0c8SAndre Fischer 22*7a32b0c8SAndre Fischer 23*7a32b0c8SAndre Fischer 24*7a32b0c8SAndre Fischer #ifndef SD_TOOLPANEL_FOCUS_MANAGER_HXX 25*7a32b0c8SAndre Fischer #define SD_TOOLPANEL_FOCUS_MANAGER_HXX 26*7a32b0c8SAndre Fischer 27*7a32b0c8SAndre Fischer #include <tools/link.hxx> 28*7a32b0c8SAndre Fischer 29*7a32b0c8SAndre Fischer #include <memory> 30*7a32b0c8SAndre Fischer 31*7a32b0c8SAndre Fischer class KeyCode; 32*7a32b0c8SAndre Fischer class VclSimpleEvent; 33*7a32b0c8SAndre Fischer class Window; 34*7a32b0c8SAndre Fischer 35*7a32b0c8SAndre Fischer namespace sd { namespace toolpanel { 36*7a32b0c8SAndre Fischer 37*7a32b0c8SAndre Fischer /** On certain key presses the focus is moved from one window to another. 38*7a32b0c8SAndre Fischer For this to work every window that wants its focus managed has to 39*7a32b0c8SAndre Fischer register or be registered and tell where to put the focus on what key 40*7a32b0c8SAndre Fischer press. 41*7a32b0c8SAndre Fischer */ 42*7a32b0c8SAndre Fischer class FocusManager 43*7a32b0c8SAndre Fischer { 44*7a32b0c8SAndre Fischer public: 45*7a32b0c8SAndre Fischer /** Return an instance of the focus manager. 46*7a32b0c8SAndre Fischer */ 47*7a32b0c8SAndre Fischer static FocusManager& Instance (void); 48*7a32b0c8SAndre Fischer 49*7a32b0c8SAndre Fischer /** Register a link from one window to another so that any time the 50*7a32b0c8SAndre Fischer specified key is pressed while the source window is focused, the 51*7a32b0c8SAndre Fischer focus is transferred to the target window. 52*7a32b0c8SAndre Fischer @param pSource 53*7a32b0c8SAndre Fischer The window from which the focus will be transferred. 54*7a32b0c8SAndre Fischer @param pTarget 55*7a32b0c8SAndre Fischer The window to which the focus will be transferred. 56*7a32b0c8SAndre Fischer @param rKey 57*7a32b0c8SAndre Fischer The key for which the focus is transferred from the source 58*7a32b0c8SAndre Fischer window to the target window. 59*7a32b0c8SAndre Fischer */ 60*7a32b0c8SAndre Fischer void RegisterLink ( 61*7a32b0c8SAndre Fischer ::Window* pSource, 62*7a32b0c8SAndre Fischer ::Window* pTarget, 63*7a32b0c8SAndre Fischer const KeyCode& rKey); 64*7a32b0c8SAndre Fischer 65*7a32b0c8SAndre Fischer /** Register a link that will move the focus from the source window to 66*7a32b0c8SAndre Fischer the target window when the source window is focused and KEY_ESCAPE 67*7a32b0c8SAndre Fischer is pressed. 68*7a32b0c8SAndre Fischer @param pSource 69*7a32b0c8SAndre Fischer The window from which the focus will be transferred. 70*7a32b0c8SAndre Fischer @param pTarget 71*7a32b0c8SAndre Fischer The window to which the focus will be transferred. 72*7a32b0c8SAndre Fischer */ 73*7a32b0c8SAndre Fischer void RegisterUpLink (::Window* pSource, ::Window* pTarget); 74*7a32b0c8SAndre Fischer 75*7a32b0c8SAndre Fischer /** Register a link that will move the focus from the source window to 76*7a32b0c8SAndre Fischer the target window when the source window is focused and KEY_RETURN 77*7a32b0c8SAndre Fischer is pressed. 78*7a32b0c8SAndre Fischer @param pSource 79*7a32b0c8SAndre Fischer The window from which the focus will be transferred. 80*7a32b0c8SAndre Fischer @param pTarget 81*7a32b0c8SAndre Fischer The window to which the focus will be transferred. 82*7a32b0c8SAndre Fischer */ 83*7a32b0c8SAndre Fischer void RegisterDownLink (::Window* pSource, ::Window* pTarget); 84*7a32b0c8SAndre Fischer 85*7a32b0c8SAndre Fischer /** Remove all links from the source window to the target window. When 86*7a32b0c8SAndre Fischer there are links from the target window to the source window then 87*7a32b0c8SAndre Fischer these are not touced. 88*7a32b0c8SAndre Fischer */ 89*7a32b0c8SAndre Fischer void RemoveLinks ( 90*7a32b0c8SAndre Fischer ::Window* pSource, 91*7a32b0c8SAndre Fischer ::Window* pTarget); 92*7a32b0c8SAndre Fischer 93*7a32b0c8SAndre Fischer /** Let the focus manager transfer the focus from the specified source 94*7a32b0c8SAndre Fischer window to a target window that is determined according the the 95*7a32b0c8SAndre Fischer registered links and the given key code. 96*7a32b0c8SAndre Fischer When there is no rule for this combination of source window and key 97*7a32b0c8SAndre Fischer code then the focus stays where it is. 98*7a32b0c8SAndre Fischer */ 99*7a32b0c8SAndre Fischer bool TransferFocus (::Window* pSource, const KeyCode& rCode); 100*7a32b0c8SAndre Fischer 101*7a32b0c8SAndre Fischer private: 102*7a32b0c8SAndre Fischer class LinkMap; 103*7a32b0c8SAndre Fischer ::std::auto_ptr<LinkMap> mpLinks; 104*7a32b0c8SAndre Fischer 105*7a32b0c8SAndre Fischer FocusManager (void); 106*7a32b0c8SAndre Fischer ~FocusManager (void); 107*7a32b0c8SAndre Fischer 108*7a32b0c8SAndre Fischer /** Clear the list of focus transfer links. This removes all window 109*7a32b0c8SAndre Fischer listeners. 110*7a32b0c8SAndre Fischer */ 111*7a32b0c8SAndre Fischer void Clear (void); 112*7a32b0c8SAndre Fischer 113*7a32b0c8SAndre Fischer /** Remove all links from or to the given window. 114*7a32b0c8SAndre Fischer */ 115*7a32b0c8SAndre Fischer void RemoveLinks (::Window* pWindow); 116*7a32b0c8SAndre Fischer 117*7a32b0c8SAndre Fischer /** Unregister as event listener from the given window when there are no 118*7a32b0c8SAndre Fischer links from this window anymore. 119*7a32b0c8SAndre Fischer */ 120*7a32b0c8SAndre Fischer void RemoveUnusedEventListener (::Window* pWindow); 121*7a32b0c8SAndre Fischer 122*7a32b0c8SAndre Fischer /** Listen for key events and on KEY_RETURN go down and on 123*7a32b0c8SAndre Fischer KEY_ESCAPE go up. 124*7a32b0c8SAndre Fischer */ 125*7a32b0c8SAndre Fischer DECL_LINK(WindowEventListener, VclSimpleEvent*); 126*7a32b0c8SAndre Fischer }; 127*7a32b0c8SAndre Fischer 128*7a32b0c8SAndre Fischer } } // end of namespace ::sd::toolpanel 129*7a32b0c8SAndre Fischer 130*7a32b0c8SAndre Fischer #endif 131