summaryrefslogtreecommitdiff
blob: 4e24e6f0d2118ae08657283ec099e437d7d96f2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
--- wlist.c.orig	Sat Apr 20 20:17:16 2002
+++ wlist.c	Sun Apr 21 14:12:06 2002
@@ -4,6 +4,8 @@
 
 #include "WINGsP.h"
 
+#include <X11/keysym.h>
+
 char *WMListDidScrollNotification = "WMListDidScrollNotification";
 char *WMListSelectionDidChangeNotification = "WMListSelectionDidChangeNotification";
 
@@ -42,6 +44,7 @@
         unsigned int redrawPending:1;
         unsigned int buttonPressed:1;
         unsigned int buttonWasPressed:1;
+	unsigned int focused:1;
     } flags;
 } List;
 
@@ -115,10 +118,10 @@
     lPtr->view->delegate = &_ListViewDelegate;
 
     WMCreateEventHandler(lPtr->view, ExposureMask|StructureNotifyMask
-                         |ClientMessageMask, handleEvents, lPtr);
+                         |FocusChangeMask|ClientMessageMask, handleEvents, lPtr);
 
     WMCreateEventHandler(lPtr->view, ButtonPressMask|ButtonReleaseMask
-                         |EnterWindowMask|LeaveWindowMask|ButtonMotionMask,
+                         |EnterWindowMask|LeaveWindowMask|ButtonMotionMask|KeyPressMask,
                          handleActionEvents, lPtr);
 
     lPtr->itemHeight = WMFontHeight(scrPtr->normalFont) + 1;
@@ -1011,6 +1014,11 @@
     int topItem = lPtr->topItem;
     static int lastClicked = -1, prevItem = -1;
 
+    /* for arrow keys handling */
+    char buffer[64];
+    KeySym ksym;
+    int count, row;
+
     CHECK_CLASS(data, WC_List);
 
     switch (event->type) {
@@ -1063,6 +1071,10 @@
     case ButtonPress:
         if (event->xbutton.x <= WMWidgetWidth(lPtr->vScroller))
             break;
+	/* need focus for keyboard events */
+	if (!lPtr->flags.focused);
+	    WMSetFocusToWidget(lPtr);
+
         if (event->xbutton.button == WINGsConfiguration.mouseWheelDown ||
             event->xbutton.button == WINGsConfiguration.mouseWheelUp) {
             int amount = 0;
@@ -1169,6 +1181,34 @@
             prevItem = tmp;
         }
         break;
+    case KeyPress:
+	/* handle arrow keys, space and return */
+	count = XLookupString(&event->xkey, buffer, 63, &ksym, NULL);
+	buffer[count] = '\0';
+	switch(ksym) {
+	case XK_Up:
+	   row = WMGetListSelectedItemRow(lPtr);
+	   WMSelectListItem(lPtr, row - 1);
+	   if (row <= topItem)
+	       scrollByAmount(lPtr, -1);
+	   break;
+	case XK_Down:
+	   row = WMGetListSelectedItemRow(lPtr);
+	   WMSelectListItem(lPtr, row + 1);
+	   if (row - topItem >= lPtr->fullFitLines)
+	       scrollByAmount(lPtr, 1);
+	   break;
+	case XK_space:
+	   if (lPtr->action)
+	       (*lPtr->action)(lPtr, lPtr->clientData);
+	   break;
+	case XK_Return:
+	   if (lPtr->doubleAction)
+	       (*lPtr->doubleAction)(lPtr, lPtr->clientData);
+	   break;  
+	}
+	break;
+
     }
     if (lPtr->topItem != topItem)
         WMPostNotificationName(WMListDidScrollNotification, lPtr, NULL);