diff os2/dw.c @ 61:4a02842f8074

Added shift-tab and up/down/left/right button support. And added missing checkbox fix for windows.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 05 Dec 2001 06:03:49 +0000
parents 61869769c050
children 2be5174bdb5d
line wrap: on
line diff
--- a/os2/dw.c	Thu Nov 29 15:10:39 2001 +0000
+++ b/os2/dw.c	Wed Dec 05 06:03:49 2001 +0000
@@ -439,6 +439,178 @@
 	return 0;
 }
 
+int _focus_check_box_back(Box *box, HWND handle, int start, HWND defaultitem)
+{
+	int z;
+	static HWND lasthwnd, firsthwnd;
+    static int finish_searching;
+
+	/* Start is 2 when we have cycled completely and
+	 * need to set the focus to the last widget we found
+	 * that was valid.
+	 */
+	if(start == 2)
+	{
+		if(lasthwnd)
+			WinSetFocus(HWND_DESKTOP, lasthwnd);
+		return 0;
+	}
+
+	/* Start is 1 when we are entering the function
+	 * for the first time, it is zero when entering
+	 * the function recursively.
+	 */
+	if(start == 1)
+	{
+		lasthwnd = handle;
+		finish_searching = 0;
+		firsthwnd = 0;
+	}
+
+	/* Vertical boxes are inverted on OS/2 */
+	if(box->type == BOXVERT)
+	{
+		for(z=box->count-1;z>-1;z--)
+		{
+			if(box->items[z].type == TYPEBOX)
+			{
+				Box *thisbox = WinQueryWindowPtr(box->items[z].hwnd, QWP_USER);
+
+				if(thisbox && _focus_check_box_back(thisbox, handle, start == 3 ? 3 : 0, defaultitem))
+					return 1;
+			}
+			else
+			{
+				if(box->items[z].hwnd == handle)
+				{
+					if(lasthwnd == handle && firsthwnd)
+						WinSetFocus(HWND_DESKTOP, firsthwnd);
+					else if(lasthwnd == handle && !firsthwnd)
+						finish_searching = 1;
+					else
+						WinSetFocus(HWND_DESKTOP, lasthwnd);
+
+					/* If we aren't looking for the last handle,
+					 * return immediately.
+					 */
+					if(!finish_searching)
+						return 1;
+				}
+				if(_validate_focus(box->items[z].hwnd))
+				{
+					/* Start is 3 when we are looking for the
+					 * first valid item in the layout.
+					 */
+					if(start == 3)
+					{
+						if(!defaultitem || (defaultitem && defaultitem == box->items[z].hwnd))
+						{
+							WinSetFocus(HWND_DESKTOP, box->items[z].hwnd);
+							return 1;
+						}
+					}
+
+					if(!firsthwnd)
+						firsthwnd = box->items[z].hwnd;
+
+					lasthwnd = box->items[z].hwnd;
+				}
+				else
+				{
+					char tmpbuf[100] = "";
+
+					WinQueryClassName(box->items[z].hwnd, 99, tmpbuf);
+					if(strncmp(tmpbuf, "#40", 3)==0) /* Notebook */
+					{
+						Box *notebox;
+						HWND page = (HWND)WinSendMsg(box->items[z].hwnd, BKM_QUERYPAGEWINDOWHWND,
+													 (MPARAM)dw_notebook_page_query(box->items[z].hwnd), 0);
+
+						if(page)
+						{
+							notebox = (Box *)WinQueryWindowPtr(page, QWP_USER);
+
+							if(notebox && _focus_check_box_back(notebox, handle, start == 3 ? 3 : 0, defaultitem))
+								return 1;
+						}
+					}
+				}
+			}
+		}
+	}
+	else
+	{
+		for(z=0;z<box->count;z++)
+		{
+			if(box->items[z].type == TYPEBOX)
+			{
+				Box *thisbox = WinQueryWindowPtr(box->items[z].hwnd, QWP_USER);
+
+				if(thisbox && _focus_check_box_back(thisbox, handle, start == 3 ? 3 : 0, defaultitem))
+					return 1;
+			}
+			else
+			{
+				if(box->items[z].hwnd == handle)
+				{
+					if(lasthwnd == handle && firsthwnd)
+						WinSetFocus(HWND_DESKTOP, firsthwnd);
+					else if(lasthwnd == handle && !firsthwnd)
+						finish_searching = 1;
+					else
+						WinSetFocus(HWND_DESKTOP, lasthwnd);
+
+					/* If we aren't looking for the last handle,
+					 * return immediately.
+					 */
+					if(!finish_searching)
+						return 1;
+				}
+				if(_validate_focus(box->items[z].hwnd))
+				{
+					/* Start is 3 when we are looking for the
+					 * first valid item in the layout.
+					 */
+					if(start == 3)
+					{
+						if(!defaultitem || (defaultitem && defaultitem == box->items[z].hwnd))
+						{
+							WinSetFocus(HWND_DESKTOP, box->items[z].hwnd);
+							return 1;
+						}
+					}
+
+					if(!firsthwnd)
+						firsthwnd = box->items[z].hwnd;
+
+					lasthwnd = box->items[z].hwnd;
+				}
+				else
+				{
+					char tmpbuf[100] = "";
+
+					WinQueryClassName(box->items[z].hwnd, 99, tmpbuf);
+					if(strncmp(tmpbuf, "#40", 3)==0) /* Notebook */
+					{
+						Box *notebox;
+						HWND page = (HWND)WinSendMsg(box->items[z].hwnd, BKM_QUERYPAGEWINDOWHWND,
+													 (MPARAM)dw_notebook_page_query(box->items[z].hwnd), 0);
+
+						if(page)
+						{
+							notebox = (Box *)WinQueryWindowPtr(page, QWP_USER);
+
+							if(notebox && _focus_check_box_back(notebox, handle, start == 3 ? 3 : 0, defaultitem))
+								return 1;
+						}
+					}
+				}
+			}
+		}
+	}
+	return 0;
+}
+
 /* This function finds the first widget in the
  * layout and moves the current focus to it.
  */
@@ -485,6 +657,33 @@
 	}
 }
 
+/* This function finds the current widget in the
+ * layout and moves the current focus to the next item.
+ */
+void _shift_focus_back(HWND handle)
+{
+	Box *thisbox;
+	HWND box, lastbox = WinQueryWindow(handle, QW_PARENT);
+
+	/* Find the toplevel window */
+	while((box = WinQueryWindow(lastbox, QW_PARENT)) > 0x80000001)
+	{
+		lastbox = box;
+	}
+
+	box = WinWindowFromID(lastbox, FID_CLIENT);
+	if(box)
+		thisbox = WinQueryWindowPtr(box, QWP_USER);
+    else
+		thisbox = WinQueryWindowPtr(lastbox, QWP_USER);
+
+	if(thisbox)
+	{
+		if(_focus_check_box_back(thisbox, handle, 1, 0)  == 0)
+			_focus_check_box_back(thisbox, handle, 2, 0);
+	}
+}
+
 /* ResetWindow:
  *         Resizes window to the exact same size to trigger
  *         recalculation of frame.
@@ -1330,7 +1529,10 @@
 	case WM_CHAR:
 		if(SHORT1FROMMP(mp2) == '\t')
 		{
-			_shift_focus(hWnd);
+			if(CHARMSG(&msg)->fs & KC_SHIFT)
+				_shift_focus_back(hWnd);
+			else
+				_shift_focus(hWnd);
 			return FALSE;
 		}
 		else if(SHORT1FROMMP(mp2) == '\r' && blah && blah->clickdefault)
@@ -1361,7 +1563,10 @@
 	case WM_CHAR:
 		if(SHORT1FROMMP(mp2) == '\t')
 		{
-			_shift_focus(hWnd);
+			if(CHARMSG(&msg)->fs & KC_SHIFT)
+				_shift_focus_back(hWnd);
+			else
+				_shift_focus(hWnd);
 			return FALSE;
 		}
 		else if(SHORT1FROMMP(mp2) == '\r' && blah && blah->clickdefault)
@@ -1986,7 +2191,10 @@
 	case WM_CHAR:
 		if(SHORT1FROMMP(mp2) == '\t')
 		{
-			_shift_focus(hWnd);
+			if(CHARMSG(&msg)->fs & KC_SHIFT)
+				_shift_focus_back(hWnd);
+			else
+				_shift_focus(hWnd);
 			return FALSE;
 		}
 		break;
@@ -2410,8 +2618,21 @@
 #endif
 			if(SHORT1FROMMP(mp2) == '\t')
 			{
+				if(CHARMSG(&msg)->fs & KC_SHIFT)
+					_shift_focus_back(hwnd);
+				else
+					_shift_focus(hwnd);
+				WinSendMsg(hwnd, BM_SETDEFAULT, 0, 0);
+				return FALSE;
+			}
+			else if(!(CHARMSG(&msg)->fs & KC_KEYUP) && (CHARMSG(&msg)->vkey == VK_LEFT || CHARMSG(&msg)->vkey == VK_UP))
+			{
+				_shift_focus_back(hwnd);
+				return FALSE;
+			}
+			else if(!(CHARMSG(&msg)->fs & KC_KEYUP) && (CHARMSG(&msg)->vkey == VK_RIGHT || CHARMSG(&msg)->vkey == VK_DOWN))
+			{
 				_shift_focus(hwnd);
-				WinSendMsg(hwnd, BM_SETDEFAULT, 0, 0);
 				return FALSE;
 			}
 		}
@@ -2429,7 +2650,6 @@
 		if(!*bubble->bubbletext)
 			break;
 
-
 		if(hwndBubble)
 		{
 			WinDestroyWindow(hwndBubble);