=== modified file 'src/com/goldencode/p2j/ui/chui/ThinClient.java'
--- src/com/goldencode/p2j/ui/chui/ThinClient.java	2015-12-03 13:53:36 +0000
+++ src/com/goldencode/p2j/ui/chui/ThinClient.java	2015-12-17 20:04:46 +0000
@@ -12764,7 +12764,8 @@
    {
       // get and check the focus - the widget in focus may be disabled
       Widget comp = UiUtils.getCurrentFocus();
-      if (comp != null && !comp.isEnabled())
+      // TODO: not sure if it is correct
+      if (comp != null && !comp.focusTraversable()/*!comp.isEnabled()*/)
       {
          comp = null;
       }
@@ -14925,7 +14926,8 @@
                // allowed
                if (inf != null &&
                    !(inf instanceof TopLevelWindow) &&
-                   !(inf.isEnabled() &&
+                   !(/* TODO check if it is correct instead of inf.isEnabled() &&*/
+                     inf.focusTraversable() &&
                      inf.isVisible() &&
                      (infFrame == null ||
                       infFrame.isVisible())))
@@ -15465,7 +15467,8 @@
 
       TriggerResult tr = null;
       Widget cur = UiUtils.getCurrentFocus();
-      if (cur != null && !cur.isEnabled())
+      // TODO uncomment: mouse disabled items are navigable even they are disabled 
+      if (cur != null && /*!cur.isEnabled() */ !cur.focusTraversable())
       {
          cur = null;
       }
@@ -15752,7 +15755,7 @@
             if (fire)
             {
                if (!src.isVisible() ||
-                   !src.isEnabled() ||
+                   !/*src.isEnabled()*/ src.focusTraversable() ||
                    (frame != null &&
                     !frame.isVisible()))
                {
@@ -15849,7 +15852,7 @@
 
                // ENTRY was accepted, set focus to source only if the widget
                // is still enabled, visible and within a nested trigger
-               if (src.isEnabled() &&
+               if (/* src.isEnabled() */ src.focusTraversable() &&
                    src.isVisible() &&
                    (frame == null ||
                     frame.isVisible()))

=== modified file 'src/com/goldencode/p2j/ui/client/FocusManager.java'
--- src/com/goldencode/p2j/ui/client/FocusManager.java	2015-11-27 18:25:44 +0000
+++ src/com/goldencode/p2j/ui/client/FocusManager.java	2015-12-23 11:35:22 +0000
@@ -208,7 +208,7 @@
             newFillIn.setInsertMode(ins);
          }
          else if (newFocus != oldFocus &&
-                  (!oldFocus.isEnabled() || !oldFocus.isVisible()))
+                  (/* !oldFocus.isEnabled()*/ !oldFocus.focusTraversable() || !oldFocus.isVisible()))
          {
             if (oldFocus instanceof Editor)
             {

=== modified file 'src/com/goldencode/p2j/ui/client/Menu.java'
--- src/com/goldencode/p2j/ui/client/Menu.java	2015-10-30 07:32:16 +0000
+++ src/com/goldencode/p2j/ui/client/Menu.java	2015-12-08 20:40:30 +0000
@@ -24,6 +24,7 @@
 import java.util.List;
 
 import com.goldencode.p2j.ui.*;
+import com.goldencode.p2j.ui.chui.ThinClient;
 import com.goldencode.p2j.ui.client.event.*;
 import com.goldencode.p2j.ui.client.event.listener.KeyListener;
 import com.goldencode.p2j.ui.client.widget.*;
@@ -91,7 +92,8 @@
       if (!menu.isVisible())
       {
          menu.setVisible(true);
-         menu.firstFocus();
+         if (ThinClient.getInstance().isChui())
+            menu.firstFocus();
       }
 
       menu.repaint();

=== modified file 'src/com/goldencode/p2j/ui/client/MenuItem.java'
--- src/com/goldencode/p2j/ui/client/MenuItem.java	2015-09-23 19:08:25 +0000
+++ src/com/goldencode/p2j/ui/client/MenuItem.java	2015-12-02 21:03:46 +0000
@@ -95,7 +95,8 @@
          // menu-items are focusable even in a closed sub-menu.
          // Implementation is the same as the parents implementation, 
          // except of the parent visibility check instead of its own.
-         return (isEnabled() && parent().isVisible() && !hidden());         
+         /* TODO: test if item really must be enabled. isEnabled() && */
+         return (parent().isVisible() && !hidden());         
       }
       
       return  false;

=== modified file 'src/com/goldencode/p2j/ui/client/SubMenu.java'
--- src/com/goldencode/p2j/ui/client/SubMenu.java	2015-11-05 12:37:19 +0000
+++ src/com/goldencode/p2j/ui/client/SubMenu.java	2015-12-23 11:23:51 +0000
@@ -540,9 +540,9 @@
    @Override
    public boolean focusTraversable()
    {
-      // The same as AbstractWidget.focusTraversable().
+      // The same as AbstractWidget.focusTraversable() except isEnabled().
       // children focusability doesn't affect sub-menu focusability.
-      return isVisible() && isEnabled() && !hidden();
+      return isVisible() && !hidden();
    }
    
    /**
@@ -628,10 +628,22 @@
    /**
     * Sets initial focus on first traversable child.
     */
-   private void setInitialFocus()
-   {
-      Widget<?> firstChild = null;
-      for (Widget<?> w : widgets())
+   protected void setInitialFocus()
+   {
+      Widget<O> firstChild = getFirstFocusableItem();     
+      
+      FocusManager.setInitialFocus(firstChild);
+   }
+
+   /**
+    * Returns the first focusable child.
+    * 
+    * @return  focusable child.
+    */
+   protected Widget<O> getFirstFocusableItem()
+   {
+      Widget<O> firstChild = null;
+      for (Widget<O> w : widgets())
       {
          if (w.focusTraversable())
          {
@@ -640,6 +652,6 @@
          }
       }
       
-      FocusManager.setInitialFocus(firstChild);
+      return firstChild;
    }
 }

=== modified file 'src/com/goldencode/p2j/ui/client/gui/MenuGuiImpl.java'
--- src/com/goldencode/p2j/ui/client/gui/MenuGuiImpl.java	2015-11-05 12:37:19 +0000
+++ src/com/goldencode/p2j/ui/client/gui/MenuGuiImpl.java	2015-12-23 11:31:13 +0000
@@ -50,9 +50,15 @@
    /** Background color */
    private ColorRgb bgColor = null;
    
-   /** Keyboard navigation mode: If <code>true</code> => mnemonics are drawn. */
+   /** 
+    * Keyboard navigation mode: If <code>true</code> => mnemonics are drawn.
+    * This mode is intended only for MENUBAR. It activated using ALT key.
+    */
    private boolean keyMode = false;
    
+   /** Flag, indicating, that current operation is navigating and it called by key */ 
+   private boolean keyNavigation = false;
+   
    /**
     * Special constructor used to restore component using given configuration.
     * 
@@ -248,6 +254,27 @@
    }
 
    /**
+    * Get keyboard navigation mode.
+    * 
+    * @return  <code>true</code> if keyboard navigation mode is on. 
+    */
+   public boolean isKeyNavigation()
+   {
+      return this.keyNavigation;
+   }
+   
+   /**
+    * Set keyboard navigation mode to specified value.
+    * 
+    * @param   keyNavigation
+    *          <code>true</code> if keyboard navigation mode is on. 
+    */
+   public void setKeyNavigation(boolean keyNavigation)
+   {
+      this.keyNavigation = keyNavigation;
+   }
+
+   /**
     * Determine the mouse actions processed by this widget.
     * 
     * @return   See above.
@@ -436,6 +463,7 @@
          {
             // call repaint now, to re-draw all widgets bellow it
             repaint();
+            setFocusInt(null);
             setVisible(false);
          }
       }
@@ -521,6 +549,57 @@
    }
    
    /**
+    * Process key event.
+    *
+    * @param   event
+    *          Key event to process.
+    */
+   @Override
+   public void processKeyEvent(KeyInput event)
+   {
+      int actionCode = event.actionCode();
+
+      if (this.config().popupOnly && currentFocus() == null)
+      {
+         if (actionCode == Keyboard.KA_CURSOR_DOWN)
+         {
+            firstFocus();
+         }
+         else if (actionCode == Keyboard.KA_CURSOR_UP)
+         {
+            lastFocus();
+         }
+
+         Widget<GuiOutputManager> focused = currentFocus();
+         if (focused != null)
+         {
+            EventManager.postEvent(new FocusEvent(focused, EventType.FOCUS_GAINED));
+            repaint();
+         }
+         event.consume();
+      }
+      else
+      {
+         super.processKeyEvent(event);
+      }
+   }
+   
+   /**
+    * Hide widget.
+    */
+   public void hide()
+   {
+      Widget<GuiOutputManager> focused = currentFocus();
+      if (focused instanceof SubMenu)
+      {
+         ((SubMenu<?>) focused).hideBody(false);
+      }
+      
+      setFocusInt(null);
+      super.hide();
+   }
+   
+   /**
     * Replace original version to take into account P2J specific behavior.
     * 
     * @param   includeNested

=== modified file 'src/com/goldencode/p2j/ui/client/gui/MenuItemGuiImpl.java'
--- src/com/goldencode/p2j/ui/client/gui/MenuItemGuiImpl.java	2015-11-12 16:04:40 +0000
+++ src/com/goldencode/p2j/ui/client/gui/MenuItemGuiImpl.java	2015-12-23 11:30:37 +0000
@@ -467,6 +467,26 @@
    }
 
    /**
+    * Process key event.
+    * 
+    * @param   event
+    *          Key event to process.
+    */
+   @Override
+   public void processKeyEvent(KeyInput event)
+   {
+      int actionCode = event.actionCode();
+      boolean keyNavigation = (actionCode == Keyboard.SE_ENTRY       ||
+                               actionCode == Keyboard.KA_CURSOR_DOWN || 
+                               actionCode == Keyboard.KA_CURSOR_UP   ||
+                               actionCode == Keyboard.KA_CURSOR_LEFT ||
+                               actionCode == Keyboard.KA_CURSOR_RIGHT);
+                            
+      parent(MenuGuiImpl.class).setKeyNavigation(keyNavigation);                            
+      super.processKeyEvent(event);
+   }
+   
+   /**
     * Notification of a mouse clicked event occurred for this widget.
     * 
     * @param    e
@@ -487,7 +507,8 @@
    @Override
    public void mouseEntered(MouseEvent e)
    {
-      if (!mouseEntered && isEnabled() && !isRule() && !hasFocus())
+      parent(MenuGuiImpl.class).setKeyNavigation(false);
+      if (!mouseEntered && !isRule() && !hasFocus())
       {
          requestFocus();
       }

=== modified file 'src/com/goldencode/p2j/ui/client/gui/SubMenuGuiImpl.java'
--- src/com/goldencode/p2j/ui/client/gui/SubMenuGuiImpl.java	2015-11-27 18:25:44 +0000
+++ src/com/goldencode/p2j/ui/client/gui/SubMenuGuiImpl.java	2015-12-21 12:59:19 +0000
@@ -678,6 +678,26 @@
    }
    
    /**
+    * Process key event.
+    * 
+    * @param   event
+    *          Key event to process.
+    */
+   @Override
+   public void processKeyEvent(KeyInput event)
+   {
+      int actionCode = event.actionCode();
+      boolean keyNavigation = (actionCode == Keyboard.SE_ENTRY       ||
+                               actionCode == Keyboard.KA_CURSOR_DOWN || 
+                               actionCode == Keyboard.KA_CURSOR_UP   ||
+                               actionCode == Keyboard.KA_CURSOR_LEFT ||
+                               actionCode == Keyboard.KA_CURSOR_RIGHT);
+                            
+      parent(MenuGuiImpl.class).setKeyNavigation(keyNavigation);                            
+      super.processKeyEvent(event);
+   }
+   
+   /**
     * Notification of a mouse clicked event occurred for this widget.
     * 
     * @param    e
@@ -720,6 +740,7 @@
    @Override
    public void mouseEntered(MouseEvent e)
    {
+      parent(MenuGuiImpl.class).setKeyNavigation(false);
       if (!mouseEntered && !hasFocus())
       {
          requestFocus();
@@ -908,21 +929,18 @@
    {
       if (!mouseEntered)
       {
-         if (!Menu.isMenubarElement(this) && isEnabled())
+         /* TODO: pop-up menu: when sub-menu become active using keyboard: don't show body.
+          * That is why this block is commented.
+          */  
+         if ((!Menu.isMenubarElement(this)                  && 
+              isEnabled()                                   && 
+              !parent(MenuGuiImpl.class).isKeyNavigation()) || 
+              pressed)
          {
-            // and simulate ENTER key to select it
-            KeyInput ki = new KeyInput(this, EventType.KEY_PRESSED, Keyboard.SE_MENU_DROP);
-            EventManager.postEvent(ki);
+            showBody();
          }
          
          mouseEntered = true;
-
-         if (pressed)
-         {
-            config.displayed = true;
-            showBody();
-         }
-         
          repaint();
       }
 
@@ -1145,6 +1163,7 @@
    protected void setSubmenusPressed(boolean pressed, boolean recursive)
    {
       this.pressed = pressed;
+      
       this.setFocusInt(null);
       
       if (recursive)
@@ -1153,14 +1172,33 @@
          {
             if (w instanceof SubMenuGuiImpl)
             {
-               ((SubMenuGuiImpl) w).pressed = pressed;
-               ((SubMenuGuiImpl) w).config.displayed = pressed;
+               SubMenuGuiImpl childSm = (SubMenuGuiImpl) w;
+               
+               childSm.pressed = pressed;
+
+               childSm.config.displayed = pressed;
             }
          }
       }
    }
    
    /**
+    * Sets initial focus on first traversable child.
+    */
+   @Override
+   protected void setInitialFocus()
+   {
+      Widget<GuiOutputManager> firstChild = getFirstFocusableItem();
+      
+      if (firstChild != null)
+      {
+         MenuGuiImpl.requestFocusWorker(firstChild);
+      }
+      
+      FocusManager.setInitialFocus(firstChild);
+   }
+
+   /**
     * Draws rectangle around sub-menu title
     * 
     * @param   tDim
@@ -1200,6 +1238,8 @@
             gd.fillRect(2, 2, c.widthToNative(maxItemWidth) - 5, tDim.height - 5);
          } 
       }
+      
+      System.out.println(config().title + " ME=" + mouseEntered + ", focus=" + hasFocus());
    }
    
    /**

=== modified file 'src/com/goldencode/p2j/ui/client/widget/AbstractContainer.java'
--- src/com/goldencode/p2j/ui/client/widget/AbstractContainer.java	2015-11-23 20:38:12 +0000
+++ src/com/goldencode/p2j/ui/client/widget/AbstractContainer.java	2015-12-08 20:52:20 +0000
@@ -247,7 +247,8 @@
          Menu<O> popupMenu = (Menu<O>) current.screen().getRegistry().getComponent(popupMenuId);
          if (popupMenu.config() != null && popupMenu.config().visible)
          {
-            return popupMenu.currentFocus();
+            Widget<O> focus = popupMenu.currentFocus();
+            return focus == null ? popupMenu : focus;
          }
       }
       

