Project

General

Profile

1223.diff

Vadim Gindin, 12/23/2015 07:15 AM

Download (13.9 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-23 11:35:22 +0000
208 208
            newFillIn.setInsertMode(ins);
209 209
         }
210 210
         else if (newFocus != oldFocus &&
211
                  (!oldFocus.isEnabled() || !oldFocus.isVisible()))
211
                  (/* !oldFocus.isEnabled()*/ !oldFocus.focusTraversable() || !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-23 11:23:51 +0000
540 540
   @Override
541 541
   public boolean focusTraversable()
542 542
   {
543
      // The same as AbstractWidget.focusTraversable().
543
      // The same as AbstractWidget.focusTraversable() except isEnabled().
544 544
      // children focusability doesn't affect sub-menu focusability.
545
      return isVisible() && isEnabled() && !hidden();
545
      return isVisible() && !hidden();
546 546
   }
547 547
   
548 548
   /**
......
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-23 11:31:13 +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
      }
......
521 549
   }
522 550
   
523 551
   /**
552
    * Process key event.
553
    *
554
    * @param   event
555
    *          Key event to process.
556
    */
557
   @Override
558
   public void processKeyEvent(KeyInput event)
559
   {
560
      int actionCode = event.actionCode();
561

  
562
      if (this.config().popupOnly && currentFocus() == null)
563
      {
564
         if (actionCode == Keyboard.KA_CURSOR_DOWN)
565
         {
566
            firstFocus();
567
         }
568
         else if (actionCode == Keyboard.KA_CURSOR_UP)
569
         {
570
            lastFocus();
571
         }
572

  
573
         Widget<GuiOutputManager> focused = currentFocus();
574
         if (focused != null)
575
         {
576
            EventManager.postEvent(new FocusEvent(focused, EventType.FOCUS_GAINED));
577
            repaint();
578
         }
579
         event.consume();
580
      }
581
      else
582
      {
583
         super.processKeyEvent(event);
584
      }
585
   }
586
   
587
   /**
588
    * Hide widget.
589
    */
590
   public void hide()
591
   {
592
      Widget<GuiOutputManager> focused = currentFocus();
593
      if (focused instanceof SubMenu)
594
      {
595
         ((SubMenu<?>) focused).hideBody(false);
596
      }
597
      
598
      setFocusInt(null);
599
      super.hide();
600
   }
601
   
602
   /**
524 603
    * Replace original version to take into account P2J specific behavior.
525 604
    * 
526 605
    * @param   includeNested
src/com/goldencode/p2j/ui/client/gui/MenuItemGuiImpl.java 2015-12-23 11:30:37 +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
   {
490
      if (!mouseEntered && isEnabled() && !isRule() && !hasFocus())
510
      parent(MenuGuiImpl.class).setKeyNavigation(false);
511
      if (!mouseEntered && !isRule() && !hasFocus())
491 512
      {
492 513
         requestFocus();
493 514
      }
src/com/goldencode/p2j/ui/client/gui/SubMenuGuiImpl.java 2015-12-21 12:59:19 +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

  
......
1145 1163
   protected void setSubmenusPressed(boolean pressed, boolean recursive)
1146 1164
   {
1147 1165
      this.pressed = pressed;
1166
      
1148 1167
      this.setFocusInt(null);
1149 1168
      
1150 1169
      if (recursive)
......
1153 1172
         {
1154 1173
            if (w instanceof SubMenuGuiImpl)
1155 1174
            {
1156
               ((SubMenuGuiImpl) w).pressed = pressed;
1157
               ((SubMenuGuiImpl) w).config.displayed = pressed;
1175
               SubMenuGuiImpl childSm = (SubMenuGuiImpl) w;
1176
               
1177
               childSm.pressed = pressed;
1178

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

  
1201
   /**
1164 1202
    * Draws rectangle around sub-menu title
1165 1203
    * 
1166 1204
    * @param   tDim
......
1200 1238
            gd.fillRect(2, 2, c.widthToNative(maxItemWidth) - 5, tDim.height - 5);
1201 1239
         } 
1202 1240
      }
1241
      
1242
      System.out.println(config().title + " ME=" + mouseEntered + ", focus=" + hasFocus());
1203 1243
   }
1204 1244
   
1205 1245
   /**
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