00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision$ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 00019 #ifndef MITKFOCUSMANAGER_H_HEADER_INCLUDED_C135A197 00020 #define MITKFOCUSMANAGER_H_HEADER_INCLUDED_C135A197 00021 00022 #include "mitkCommon.h" 00023 #include "mitkBaseRenderer.h" 00024 #include <vector> 00025 #include <itkEventObject.h> 00026 00027 namespace mitk { 00028 00029 //##Documentation 00030 //## @brief manages a list of BaseRenderer. 00031 //## 00032 //## A focuspointer can be set and read. 00033 //## GoToNext can be used to switch through the list. 00034 //## if the switch m_Loop is set to true, GetNext loops through the list; after 00035 //## the last it goes to the first. 00036 //## if it is not set, it returnes NULL if it steps behind the last Widget. 00037 //## @ingroup Interaction 00038 class MITK_CORE_EXPORT FocusManager : public itk::Object 00039 { 00040 public: 00041 mitkClassMacro(FocusManager, itk::Object); 00042 itkNewMacro(Self); 00043 00044 //##Documentation 00045 //##@brief Element, that can be focused and held here. 00046 //## 00047 //## has to be an itk-Objekct in order to use itk-Smartpointer! 00048 typedef mitk::BaseRenderer FocusElement; 00049 00050 typedef itk::WeakPointer<FocusElement> FocusElementWeakPointer; 00051 00052 typedef std::vector<FocusElementWeakPointer> FocusElementList; 00053 00054 typedef std::vector<FocusElementWeakPointer>::iterator FocusListIterator; 00055 00056 //##Documentation 00057 //## Destructor 00058 ~FocusManager(); 00059 00060 //##Documentation 00061 //## Adds the widget into the set of managed Widgets after the focused 00062 //## widget and sets the focus to the added one if the list was empty before 00063 bool AddElement(FocusElement* element); 00064 00065 //##Documentation 00066 //## removes the given widget from the list. 00067 //## true if found and removed, else false 00068 //## afterwards the focused widget is the one behind the deleted 00069 //## or if the deleted was the last, then the one before the deleted 00070 //## that way you can delete sequentialy from the back on or from front to back 00071 bool RemoveElement(FocusElement* element); 00072 00073 //##Documentation 00074 //## returns the focused Widget 00075 FocusElement* GetFocused() const; 00076 00077 //##Documentation 00078 //## searches the given Widget in List; 00079 //## if found, sets the focus to this widget and returns true 00080 bool SetFocused(FocusElement* element); 00081 00082 //##Documentation 00083 //## returns, if this focused widget points behind the end of the List 00084 bool IsLast(); 00085 00086 //##Documentation 00087 //## returns true, if the focused widget is the first in the list 00088 bool IsFirst(); 00089 00090 //##Documentation 00091 //## returns the first widget in list 00092 const FocusElement* GetFirst() const; 00093 00094 //##Documentation 00095 //## returns the last widget in list 00096 const FocusElement* GetLast() const; 00097 00098 //##Documentation 00099 //## sets the focus to the next in list 00100 //## loops the list, if switch loop is true 00101 //## returns true if successful, else false 00102 bool GoToNext(); 00103 00104 //##Documentation 00105 //## returns an iterator, that points to the 00106 //## beginning of the list 00107 //## no changes are made to the current focused element 00108 FocusListIterator GetIter(); 00109 00110 //##Documentation 00111 //## Sets the LoopMode. 00112 //## if set to true-> the one after the last is the first 00113 void SetLoop(bool loop); 00114 00115 friend class GlobalInteraction; 00116 protected: 00117 //##Documentation 00118 //## Constructor 00119 FocusManager(); 00120 00121 private: 00122 //##Documentation 00123 //## stores the Widgets 00124 FocusElementList m_FocusList; 00125 00126 //##Documentation 00127 //## holds the focused Widget 00128 itk::WeakPointer<FocusElement> m_FocElement; 00129 00130 //##Documentation 00131 //## switch which sets the LoopMode. 00132 //## if true, then the next after the last one is the first 00133 bool m_Loop; 00134 }; 00135 00136 //##Documentation 00137 //## @brief connect to this Event to get noticed when the focus changes 00138 itkEventMacro( FocusEvent , itk::AnyEvent ); 00139 00140 } // namespace mitk 00141 00142 00143 00144 #endif /* MITKFOCUSMANAGER_H_HEADER_INCLUDED_C135A197 */