Enlightenment CVS committal

Author  : kwo
Project : e16
Module  : e

Dir     : e16/e/src


Modified Files:
        E.h events.c evhandlers.c menus.c 


Log Message:
Enable navigating the menus with the keyboard.
===================================================================
RCS file: /cvsroot/enlightenment/e16/e/src/E.h,v
retrieving revision 1.258
retrieving revision 1.259
diff -u -3 -r1.258 -r1.259
--- E.h 1 May 2004 22:49:25 -0000       1.258
+++ E.h 2 May 2004 19:28:56 -0000       1.259
@@ -2024,6 +2024,7 @@
 void                EventShow(const XEvent * ev);
 
 /* evhandlers.c */
+void                HandleKeyPress(XEvent * ev);
 void                HandleMouseDown(XEvent * ev);
 void                HandleMouseUp(XEvent * ev);
 void                HandleMotion(XEvent * ev);
@@ -2118,7 +2119,6 @@
 EWin               *FindEwinByDecoration(Window win);
 Button             *FindButton(Window win);
 ActionClass        *FindActionClass(Window win);
-Menu               *FindMenuItem(Window win, MenuItem ** mi);
 Menu               *FindMenu(Window win);
 EWin               *FindEwinByMenu(Menu * m);
 Group             **ListWinGroups(EWin * ewin, char group_select, int *num);
@@ -2374,6 +2374,7 @@
 void                MenuHideMasker(void);
 void                MenusDestroyLoaded(void);
 void                MenusHideByWindow(Window win);
+int                 MenusEventKeyPress(XEvent * ev);
 int                 MenusEventMouseDown(XEvent * ev);
 int                 MenusEventMouseUp(XEvent * ev);
 int                 MenusEventMouseIn(XEvent * ev);
===================================================================
RCS file: /cvsroot/enlightenment/e16/e/src/events.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -3 -r1.65 -r1.66
--- events.c    28 Apr 2004 22:18:55 -0000      1.65
+++ events.c    2 May 2004 19:28:57 -0000       1.66
@@ -132,7 +132,7 @@
    switch (ev->type)
      {
      case KeyPress:            /*  2 */
-       DialogEventKeyPress(ev);
+       HandleKeyPress(ev);
        break;
      case KeyRelease:          /*  3 */
        break;
===================================================================
RCS file: /cvsroot/enlightenment/e16/e/src/evhandlers.c,v
retrieving revision 1.162
retrieving revision 1.163
diff -u -3 -r1.162 -r1.163
--- evhandlers.c        21 Apr 2004 20:50:33 -0000      1.162
+++ evhandlers.c        2 May 2004 19:28:57 -0000       1.163
@@ -92,6 +92,21 @@
       DoIn("TOOLTIP_TIMEOUT", Conf.tooltips.delay, ToolTipTimeout, 0, NULL);
 }
 
+void
+HandleKeyPress(XEvent * ev)
+{
+   EDBUG(5, "HandleKeyPress");
+
+   if (DialogEventKeyPress(ev))
+      goto done;
+
+   if (MenusEventKeyPress(ev))
+      goto done;
+
+ done:
+   EDBUG_RETURN_;
+}
+
 static void
 ButtonProxySendEvent(XEvent * ev)
 {
===================================================================
RCS file: /cvsroot/enlightenment/e16/e/src/menus.c,v
retrieving revision 1.126
retrieving revision 1.127
diff -u -3 -r1.126 -r1.127
--- menus.c     1 May 2004 22:49:25 -0000       1.126
+++ menus.c     2 May 2004 19:28:57 -0000       1.127
@@ -24,6 +24,7 @@
 #include "E.h"
 #include <sys/stat.h>
 #include <errno.h>
+#include <X11/keysym.h>
 
 static void         MenuRedraw(Menu * m);
 static void         MenuDrawItem(Menu * m, MenuItem * mi, char shape);
@@ -32,7 +33,10 @@
 static void         FillFlatFileMenu(Menu * m, MenuStyle * ms, char *name,
                                     char *file, Menu * parent);
 
-Menu               *
+static Menu        *active_menu = NULL;
+static MenuItem    *active_item = NULL;
+
+static Menu        *
 FindMenuItem(Window win, MenuItem ** mi)
 {
    Menu               *menu = NULL;
@@ -158,6 +162,12 @@
 static void
 MenuEwinClose(EWin * ewin)
 {
+   if (ewin->menu == active_menu)
+     {
+       XUngrabKeyboard(disp, CurrentTime);
+       active_menu = NULL;
+       active_item = NULL;
+     }
    ewin->menu = NULL;
 }
 
@@ -371,6 +381,12 @@
    }
 
    m->shown = 1;
+   if (Mode.cur_menu_depth == 0)
+     {
+       XSync(disp, False);
+       XGrabKeyboard(disp, m->win, True, GrabModeAsync, GrabModeAsync,
+                     CurrentTime);
+     }
 
    EDBUG_RETURN_;
 }
@@ -955,6 +971,18 @@
    if ((shape) && (m->style->use_item_bg))
       PropagateShapes(m->win);
 
+   if (mi->state == STATE_HILITED)
+     {
+       active_item = mi;
+       if (active_menu != m)
+         {
+            active_menu = m;
+            XUngrabKeyboard(disp, CurrentTime);
+            XGrabKeyboard(disp, m->win, True, GrabModeAsync, GrabModeAsync,
+                          CurrentTime);
+         }
+     }
+
    Mode.queue_up = pq;
    EDBUG_RETURN_;
 }
@@ -2290,6 +2318,9 @@
    Mode.cur_menu_depth = 0;
    Mode.cur_menu_mode = 0;
    clickmenu = 0;
+
+   /* This shouldn't be necessary but... */
+   XUngrabPointer(disp, CurrentTime);
 }
 
 Window
@@ -2302,6 +2333,96 @@
  * Menu event handlers
  */
 
+static MenuItem    *
+MenuFindNextItem(Menu * m, MenuItem * mi, int inc)
+{
+   int                 i;
+
+   for (i = 0; i < m->num; i++)
+      if (m->items[i] == mi)
+       {
+          i = (i + inc + m->num) % m->num;
+          return m->items[i];
+       }
+
+   return NULL;
+}
+
+static MenuItem    *
+MenuFindParentItem(Menu * m)
+{
+   int                 i;
+   Menu               *mp;
+
+   mp = m->parent;
+   if (mp == NULL)
+      return NULL;
+
+   for (i = 0; i < mp->num; i++)
+      if (mp->items[i]->child == m)
+        return mp->items[i];
+
+   return NULL;
+}
+
+int
+MenusEventKeyPress(XEvent * ev)
+{
+   Window              win = ev->xkey.window;
+   KeySym              key;
+   Menu               *m;
+   MenuItem           *mi;
+
+   m = FindMenu(win);
+   if (m == NULL)
+      return 0;
+
+   m = active_menu;
+   mi = active_item;
+
+   key = XLookupKeysym(&ev->xkey, 0);
+   switch (key)
+     {
+     case XK_Escape:
+       MenusHide();
+       break;
+     case XK_Down:
+       mi = MenuFindNextItem(m, mi, 1);
+       goto check_warp;
+     case XK_Up:
+       mi = MenuFindNextItem(m, mi, -1);
+       goto check_warp;
+     case XK_Left:
+       mi = MenuFindParentItem(m);
+       m = m->parent;
+       goto check_menu;
+     case XK_Right:
+       m = mi->child;
+       if (!m || m->num <= 0)
+          break;
+       mi = m->items[0];
+       goto check_menu;
+      check_menu:
+       if (!m)
+          break;
+       goto check_warp;
+      check_warp:
+       if (!mi)
+          break;
+       XWarpPointer(disp, None, mi->win, 0, 0, 0, 0, mi->text_w / 2,
+                    mi->text_h / 2);
+       break;
+     case XK_Return:
+       if (!mi->act_id)
+          break;
+       MenusHide();
+       ActionsCall(mi->act_id, NULL, mi->params);
+       break;
+     }
+
+   return 1;
+}
+
 int
 MenusEventMouseDown(XEvent * ev)
 {
@@ -2455,10 +2576,13 @@
                 ewin2->border->border.top);
        RaiseEwin(ewin2);
        ShowEwin(ewin2);
+
        if (Conf.menuslide)
           UnShadeEwin(ewin2);
+
        if (Mode.cur_menu[Mode.cur_menu_depth - 1] != data->mi->child)
           Mode.cur_menu[Mode.cur_menu_depth++] = data->mi->child;
+
        if (Conf.menusonscreen)
          {
             EWin               *menus[256];
@@ -2508,9 +2632,7 @@
    Window              win = ev->xcrossing.window;
    Menu               *m;
    MenuItem           *mi;
-   int                 i;
-
-   int                 j;
+   int                 i, j;
 
    m = FindMenuItem(win, &mi);
    if (m == NULL)
@@ -2550,6 +2672,7 @@
      {
        EWin               *ewin;
 
+       mi->child->parent = m;
        ewin = FindEwinByMenu(m);
        if (ewin)
          {




-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE. 
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to