Project

General

Profile

keynav.diff

Vadim Gindin, 12/17/2015 03:32 PM

Download (13.3 KB)

View differences:

src/com/goldencode/p2j/ui/chui/ThinClient.java 2015-12-17 20:04:46 +0000
12764 12764
   {
12765 12765
      // get and check the focus - the widget in focus may be disabled
12766 12766
      Widget comp = UiUtils.getCurrentFocus();
12767
      if (comp != null && !comp.isEnabled())
12767
      // TODO: not sure if it is correct
12768
      if (comp != null && !comp.focusTraversable()/*!comp.isEnabled()*/)
12768 12769
      {
12769 12770
         comp = null;
12770 12771
      }
......
14925 14926
               // allowed
14926 14927
               if (inf != null &&
14927 14928
                   !(inf instanceof TopLevelWindow) &&
14928
                   !(inf.isEnabled() &&
14929
                   !(/* TODO check if it is correct instead of inf.isEnabled() &&*/
14930
                     inf.focusTraversable() &&
14929 14931
                     inf.isVisible() &&
14930 14932
                     (infFrame == null ||
14931 14933
                      infFrame.isVisible())))
......
15465 15467

  
15466 15468
      TriggerResult tr = null;
15467 15469
      Widget cur = UiUtils.getCurrentFocus();
15468
      if (cur != null && !cur.isEnabled())
15470
      // TODO uncomment: mouse disabled items are navigable even they are disabled 
15471
      if (cur != null && /*!cur.isEnabled() */ !cur.focusTraversable())
15469 15472
      {
15470 15473
         cur = null;
15471 15474
      }
......
15752 15755
            if (fire)
15753 15756
            {
15754 15757
               if (!src.isVisible() ||
15755
                   !src.isEnabled() ||
15758
                   !/*src.isEnabled()*/ src.focusTraversable() ||
15756 15759
                   (frame != null &&
15757 15760
                    !frame.isVisible()))
15758 15761
               {
......
15849 15852

  
15850 15853
               // ENTRY was accepted, set focus to source only if the widget
15851 15854
               // is still enabled, visible and within a nested trigger
15852
               if (src.isEnabled() &&
15855
               if (/* src.isEnabled() */ src.focusTraversable() &&
15853 15856
                   src.isVisible() &&
15854 15857
                   (frame == null ||
15855 15858
                    frame.isVisible()))
src/com/goldencode/p2j/ui/client/FocusManager.java 2015-12-04 20:43:18 +0000
208 208
            newFillIn.setInsertMode(ins);
209 209
         }
210 210
         else if (newFocus != oldFocus &&
211
                  (!oldFocus.isEnabled() || !oldFocus.isVisible()))
211
                  (/* !oldFocus.isEnabled()*/ !oldFocus.isFocusable() || !oldFocus.isVisible()))
212 212
         {
213 213
            if (oldFocus instanceof Editor)
214 214
            {
src/com/goldencode/p2j/ui/client/Menu.java 2015-12-08 20:40:30 +0000
24 24
import java.util.List;
25 25

  
26 26
import com.goldencode.p2j.ui.*;
27
import com.goldencode.p2j.ui.chui.ThinClient;
27 28
import com.goldencode.p2j.ui.client.event.*;
28 29
import com.goldencode.p2j.ui.client.event.listener.KeyListener;
29 30
import com.goldencode.p2j.ui.client.widget.*;
......
91 92
      if (!menu.isVisible())
92 93
      {
93 94
         menu.setVisible(true);
94
         menu.firstFocus();
95
         if (ThinClient.getInstance().isChui())
96
            menu.firstFocus();
95 97
      }
96 98

  
97 99
      menu.repaint();
src/com/goldencode/p2j/ui/client/MenuItem.java 2015-12-02 21:03:46 +0000
95 95
         // menu-items are focusable even in a closed sub-menu.
96 96
         // Implementation is the same as the parents implementation, 
97 97
         // except of the parent visibility check instead of its own.
98
         return (isEnabled() && parent().isVisible() && !hidden());         
98
         /* TODO: test if item really must be enabled. isEnabled() && */
99
         return (parent().isVisible() && !hidden());         
99 100
      }
100 101
      
101 102
      return  false;
src/com/goldencode/p2j/ui/client/SubMenu.java 2015-12-02 20:40:06 +0000
628 628
   /**
629 629
    * Sets initial focus on first traversable child.
630 630
    */
631
   private void setInitialFocus()
632
   {
633
      Widget<?> firstChild = null;
634
      for (Widget<?> w : widgets())
631
   protected void setInitialFocus()
632
   {
633
      Widget<O> firstChild = getFirstFocusableItem();     
634
      
635
      FocusManager.setInitialFocus(firstChild);
636
   }
637

  
638
   /**
639
    * Returns the first focusable child.
640
    * 
641
    * @return  focusable child.
642
    */
643
   protected Widget<O> getFirstFocusableItem()
644
   {
645
      Widget<O> firstChild = null;
646
      for (Widget<O> w : widgets())
635 647
      {
636 648
         if (w.focusTraversable())
637 649
         {
......
640 652
         }
641 653
      }
642 654
      
643
      FocusManager.setInitialFocus(firstChild);
655
      return firstChild;
644 656
   }
645 657
}
src/com/goldencode/p2j/ui/client/gui/MenuGuiImpl.java 2015-12-17 12:06:47 +0000
50 50
   /** Background color */
51 51
   private ColorRgb bgColor = null;
52 52
   
53
   /** Keyboard navigation mode: If <code>true</code> => mnemonics are drawn. */
53
   /** 
54
    * Keyboard navigation mode: If <code>true</code> => mnemonics are drawn.
55
    * This mode is intended only for MENUBAR. It activated using ALT key.
56
    */
54 57
   private boolean keyMode = false;
55 58
   
59
   /** Flag, indicating, that current operation is navigating and it called by key */ 
60
   private boolean keyNavigation = false;
61
   
56 62
   /**
57 63
    * Special constructor used to restore component using given configuration.
58 64
    * 
......
248 254
   }
249 255

  
250 256
   /**
257
    * Get keyboard navigation mode.
258
    * 
259
    * @return  <code>true</code> if keyboard navigation mode is on. 
260
    */
261
   public boolean isKeyNavigation()
262
   {
263
      return this.keyNavigation;
264
   }
265
   
266
   /**
267
    * Set keyboard navigation mode to specified value.
268
    * 
269
    * @param   keyNavigation
270
    *          <code>true</code> if keyboard navigation mode is on. 
271
    */
272
   public void setKeyNavigation(boolean keyNavigation)
273
   {
274
      this.keyNavigation = keyNavigation;
275
   }
276

  
277
   /**
251 278
    * Determine the mouse actions processed by this widget.
252 279
    * 
253 280
    * @return   See above.
......
436 463
         {
437 464
            // call repaint now, to re-draw all widgets bellow it
438 465
            repaint();
466
            setFocusInt(null);
439 467
            setVisible(false);
440 468
         }
441 469
      }
442 470
   }
443 471
   
444 472
   /**
473
    * Notification of a mouse exited event occurred for this widget.
474
    * 
475
    * @param    e
476
    *           The mouse event.
477
    */
478
   /*
479
   @Override
480
   public void mouseExited(MouseEvent e)
481
   {
482
      if (mouseEntered)
483
      {
484
         // reset the focus if it is not set to some neighbor 
485
         if (parent().focus() != null && parent().focus().getId().asInt() == this.getId().asInt())
486
         {
487
            parent().setFocus(null);
488
         }
489
      }
490
   }*/
491
   
492
   /**
445 493
    * Hide/show widget.
446 494
    * <p>
447 495
    * If the menu is being shown and not yet attached to a window, attached it to the default
......
521 569
   }
522 570
   
523 571
   /**
572
    * Process key event.
573
    *
574
    * @param   event
575
    *          Key event to process.
576
    */
577
   @Override
578
   public void processKeyEvent(KeyInput event)
579
   {
580
      int actionCode = event.actionCode();
581

  
582
      if (this.config().popupOnly && currentFocus() == null)
583
      {
584
         if (actionCode == Keyboard.KA_CURSOR_DOWN)
585
         {
586
            firstFocus();
587
         }
588
         else if (actionCode == Keyboard.KA_CURSOR_UP)
589
         {
590
            lastFocus();
591
         }
592

  
593
         Widget<GuiOutputManager> focused = currentFocus();
594
         if (focused != null)
595
         {
596
            EventManager.postEvent(new FocusEvent(focused, EventType.FOCUS_GAINED));
597
            repaint();
598
         }
599
         event.consume();
600
      }
601
      else
602
      {
603
         super.processKeyEvent(event);
604
      }
605
   }
606
   
607
   /**
608
    * Hide widget.
609
    */
610
   public void hide()
611
   {
612
      Widget<GuiOutputManager> focused = currentFocus();
613
      if (focused instanceof SubMenu)
614
      {
615
         ((SubMenu<?>) focused).hideBody(false);
616
      }
617
      
618
      setFocusInt(null);
619
      super.hide();
620
   }
621
   
622
   /**
524 623
    * Replace original version to take into account P2J specific behavior.
525 624
    * 
526 625
    * @param   includeNested
src/com/goldencode/p2j/ui/client/gui/MenuItemGuiImpl.java 2015-12-07 21:14:34 +0000
467 467
   }
468 468

  
469 469
   /**
470
    * Process key event.
471
    * 
472
    * @param   event
473
    *          Key event to process.
474
    */
475
   @Override
476
   public void processKeyEvent(KeyInput event)
477
   {
478
      int actionCode = event.actionCode();
479
      boolean keyNavigation = (actionCode == Keyboard.SE_ENTRY       ||
480
                               actionCode == Keyboard.KA_CURSOR_DOWN || 
481
                               actionCode == Keyboard.KA_CURSOR_UP   ||
482
                               actionCode == Keyboard.KA_CURSOR_LEFT ||
483
                               actionCode == Keyboard.KA_CURSOR_RIGHT);
484
                            
485
      parent(MenuGuiImpl.class).setKeyNavigation(keyNavigation);                            
486
      super.processKeyEvent(event);
487
   }
488
   
489
   /**
470 490
    * Notification of a mouse clicked event occurred for this widget.
471 491
    * 
472 492
    * @param    e
......
487 507
   @Override
488 508
   public void mouseEntered(MouseEvent e)
489 509
   {
510
      parent(MenuGuiImpl.class).setKeyNavigation(false);
490 511
      if (!mouseEntered && isEnabled() && !isRule() && !hasFocus())
491 512
      {
492 513
         requestFocus();
src/com/goldencode/p2j/ui/client/gui/SubMenuGuiImpl.java 2015-12-17 20:23:52 +0000
678 678
   }
679 679
   
680 680
   /**
681
    * Process key event.
682
    * 
683
    * @param   event
684
    *          Key event to process.
685
    */
686
   @Override
687
   public void processKeyEvent(KeyInput event)
688
   {
689
      int actionCode = event.actionCode();
690
      boolean keyNavigation = (actionCode == Keyboard.SE_ENTRY       ||
691
                               actionCode == Keyboard.KA_CURSOR_DOWN || 
692
                               actionCode == Keyboard.KA_CURSOR_UP   ||
693
                               actionCode == Keyboard.KA_CURSOR_LEFT ||
694
                               actionCode == Keyboard.KA_CURSOR_RIGHT);
695
                            
696
      parent(MenuGuiImpl.class).setKeyNavigation(keyNavigation);                            
697
      super.processKeyEvent(event);
698
   }
699
   
700
   /**
681 701
    * Notification of a mouse clicked event occurred for this widget.
682 702
    * 
683 703
    * @param    e
......
720 740
   @Override
721 741
   public void mouseEntered(MouseEvent e)
722 742
   {
743
      parent(MenuGuiImpl.class).setKeyNavigation(false);
723 744
      if (!mouseEntered && !hasFocus())
724 745
      {
725 746
         requestFocus();
......
908 929
   {
909 930
      if (!mouseEntered)
910 931
      {
911
         if (!Menu.isMenubarElement(this) && isEnabled())
932
         /* TODO: pop-up menu: when sub-menu become active using keyboard: don't show body.
933
          * That is why this block is commented.
934
          */  
935
         if ((!Menu.isMenubarElement(this)                  && 
936
              isEnabled()                                   && 
937
              !parent(MenuGuiImpl.class).isKeyNavigation()) || 
938
              pressed)
912 939
         {
913
            // and simulate ENTER key to select it
914
            KeyInput ki = new KeyInput(this, EventType.KEY_PRESSED, Keyboard.SE_MENU_DROP);
915
            EventManager.postEvent(ki);
940
            showBody();
916 941
         }
917 942
         
918 943
         mouseEntered = true;
919

  
920
         if (pressed)
921
         {
922
            config.displayed = true;
923
            showBody();
924
         }
925
         
926 944
         repaint();
927 945
      }
928 946

  
......
1161 1179
   }
1162 1180
   
1163 1181
   /**
1182
    * Sets initial focus on first traversable child.
1183
    */
1184
   @Override
1185
   protected void setInitialFocus()
1186
   {
1187
      Widget<GuiOutputManager> firstChild = getFirstFocusableItem();
1188
      
1189
      if (firstChild != null)
1190
      {
1191
         MenuGuiImpl.requestFocusWorker(firstChild);
1192
      }
1193
      
1194
      FocusManager.setInitialFocus(firstChild);
1195
   }
1196

  
1197
   /**
1164 1198
    * Draws rectangle around sub-menu title
1165 1199
    * 
1166 1200
    * @param   tDim
src/com/goldencode/p2j/ui/client/widget/AbstractContainer.java 2015-12-08 20:52:20 +0000
247 247
         Menu<O> popupMenu = (Menu<O>) current.screen().getRegistry().getComponent(popupMenuId);
248 248
         if (popupMenu.config() != null && popupMenu.config().visible)
249 249
         {
250
            return popupMenu.currentFocus();
250
            Widget<O> focus = popupMenu.currentFocus();
251
            return focus == null ? popupMenu : focus;
251 252
         }
252 253
      }
253 254