Index: /branches/gui/src/lib/event/event_def.h
===================================================================
--- /branches/gui/src/lib/event/event_def.h	(revision 7902)
+++ /branches/gui/src/lib/event/event_def.h	(revision 7903)
@@ -30,4 +30,5 @@
   EV_VIDEO_RESIZE,
 
+  EV_LEAVE_STATE,
   EV_MAIN_QUIT,
 
Index: /branches/gui/src/lib/event/event_handler.cc
===================================================================
--- /branches/gui/src/lib/event/event_handler.cc	(revision 7902)
+++ /branches/gui/src/lib/event/event_handler.cc	(revision 7903)
@@ -93,4 +93,7 @@
 void EventHandler::setState(elState state)
 {
+  if (state == this->state)
+    return;
+
   /// When Changing the State, all the keys will be released.
   /// This is done by sending each eventListener, that still
@@ -107,9 +110,17 @@
       if (unlikely(this->bUNICODE[this->state]))
         ev.x = i;
-      this->dispachEvent( ev );
-    }
-  }
-
+      this->dispachEvent(this->state, ev );
+    }
+  }
+
+  // switching to the new State.
+  elState oldState = this->state;
   this->state = state;
+
+  // in the End the Corresponding handler will be notified.
+  Event stateSwitchEvent;
+  stateSwitchEvent.type = EV_LEAVE_STATE;
+  this->dispachEvent(oldState, stateSwitchEvent);
+
   SDL_EnableUNICODE(this->bUNICODE[state]);
 };
@@ -388,5 +399,5 @@
         break;
     }
-    this->dispachEvent(ev);
+    this->dispachEvent(this->state, ev);
   }
 }
@@ -397,18 +408,17 @@
  * @param event the Event to dispach.
  */
-void EventHandler::dispachEvent(const Event& event) const
+void EventHandler::dispachEvent(elState state, const Event& event) const
 {
   /* small debug routine: shows all events dispatched by the event handler */
   PRINT(4)("\n==========================| EventHandler::process () |===\n");
-  PRINT(4)("=  Got Event nr %i, for state %i\n", event.type, this->state);
+  PRINT(4)("=  Got Event nr %i, for state %i\n", event.type, state);
 
   /// setting a temporary state in case of an EventListener's process changes the state.
-  elState currentState = this->state;
-  for (unsigned int i = 0; i < this->listeners[currentState][event.type].size(); i++)
+  for (unsigned int i = 0; i < this->listeners[state][event.type].size(); i++)
   {
     PRINT(4)("=  Event dispatcher msg: This event has been consumed\n");
-    PRINT(4)("=  Got Event nr %i, for state %i %s::%s\n", event.type, currentState, this->listeners[this->state][event.type][i]->getClassName(), this->listeners[currentState][event.type][i]->getName());
+    PRINT(4)("=  Got Event nr %i, for state %i %s::%s\n", event.type, state, this->listeners[state][event.type][i]->getClassName(), this->listeners[state][event.type][i]->getName());
     PRINT(4)("=======================================================\n");
-    this->listeners[currentState][event.type][i]->process(event);
+    this->listeners[state][event.type][i]->process(event);
   }
   /*    else
Index: /branches/gui/src/lib/event/event_handler.h
===================================================================
--- /branches/gui/src/lib/event/event_handler.h	(revision 7902)
+++ /branches/gui/src/lib/event/event_handler.h	(revision 7903)
@@ -47,5 +47,5 @@
 
   void process() const;
-  void dispachEvent(const Event& event) const;
+  void dispachEvent(elState state, const Event& event) const;
 
   static int eventFilter(const SDL_Event *event);
Index: /branches/gui/src/lib/gui/gl_gui/glgui_handler.cc
===================================================================
--- /branches/gui/src/lib/gui/gl_gui/glgui_handler.cc	(revision 7902)
+++ /branches/gui/src/lib/gui/gl_gui/glgui_handler.cc	(revision 7903)
@@ -95,21 +95,27 @@
   void GLGuiHandler::process(const Event &event)
   {
-    if (event.type == EV_MOUSE_BUTTON_LEFT)
+    switch (event.type)
     {
+      case  EV_MOUSE_BUTTON_LEFT:
+        if (GLGuiWidget::focused() != NULL)
+        {
+          if (event.bPressed)
+          {
+            if (GLGuiWidget::focused()->clickable())
+              GLGuiWidget::focused()->click();
+          }
+          else
+          {
+            if (GLGuiWidget::focused()->clickable())
+              GLGuiWidget::focused()->release();
+          }
+        }
+        break;
+      case EV_LEAVE_STATE:
+        if (GLGuiWidget::focused() != NULL)
+          GLGuiWidget::focused()->breakFocus();
+    }
 
-      if (GLGuiWidget::focused() != NULL)
-      {
-        if (event.bPressed)
-        {
-          if (GLGuiWidget::focused()->clickable())
-          GLGuiWidget::focused()->click();
-        }
-        else
-        {
-          if (GLGuiWidget::focused()->clickable())
-            GLGuiWidget::focused()->release();
-        }
-      }
-    }
+
 
     if (GLGuiWidget::focused())
@@ -118,9 +124,11 @@
     }
 
+
+
   }
 
   void GLGuiHandler::draw()
   {
-//    GLGuiMainWidget::getInstance()->draw2D(E2D_LAYER_TOP);
+    //    GLGuiMainWidget::getInstance()->draw2D(E2D_LAYER_TOP);
   }
 
Index: /branches/gui/src/lib/gui/gl_gui/glgui_widget.cc
===================================================================
--- /branches/gui/src/lib/gui/gl_gui/glgui_widget.cc	(revision 7902)
+++ /branches/gui/src/lib/gui/gl_gui/glgui_widget.cc	(revision 7903)
@@ -77,4 +77,6 @@
   void GLGuiWidget::giveFocus()
   {
+    if (GLGuiWidget::focused() != NULL)
+      GLGuiWidget::focused()->breakFocus();
     GLGuiWidget::_focused = this;
     this->receivedFocus();
@@ -83,7 +85,10 @@
   void GLGuiWidget::breakFocus()
   {
-    GLGuiWidget::_focused = NULL;
-    this->_pushed = false;
-    this->removedFocus();
+    if (GLGuiWidget::_focused == this)
+    {
+      GLGuiWidget::_focused = NULL;
+      this->_pushed = false;
+      this->removedFocus();
+    }
   };
 
