preps for native widgets
authorca
Mon, 05 Apr 2004 18:46:11 +0200
changeset 4145 c1d5d9449460
parent 4144 42b7f6e01565
child 4146 4c46ae30bd64
preps for native widgets
WinWorkstation.st
--- a/WinWorkstation.st	Mon Apr 05 18:21:47 2004 +0200
+++ b/WinWorkstation.st	Mon Apr 05 18:46:11 2004 +0200
@@ -476,6 +476,7 @@
 # define RES_BMP_PRINTF(x)      /*{ if (__debug__) printf x;}*/
 # define TH_DPRINTF(x)          /*{ if (__debug__) printf x;}*/
 # define DPRINTF(x)             { if (__debug__) printf x;}
+# define NDPRINTF(x)            { if (__debugNative__) printf x;}
 # define DDPRINTF(x)            { if (__debug__ > 1) printf x;}
 # define EVENT_PRINTF(x)        { if (__debug__) printf x;}
 # define EVENT_PRINTF2(x)       { if (__debug__ > 1) printf x;}
@@ -489,6 +490,7 @@
 # define RES1PRINTF(x)          /* */
 # define TH_DPRINTF(x)          /* */
 # define DPRINTF(x)             /* */
+# define NDPRINTF(x)            /* */
 # define DDPRINTF(x)            /* */
 # define EVENT_PRINTF(x)        /* */
 # define EVENT_PRINTF2(x)       /* */
@@ -684,13 +686,19 @@
 static createWindowInfo *pendingCREATEWINDOWInfo = 0;
 static unsigned short pendingSequenceNr = INVALIDATED_CWI;
 
+#ifdef OLD
+# define GWL_LOCALINFO  0
+#else
+# define GWL_LOCALINFO  GWL_USERDATA
+#endif
+
 #define N_WINDOW_PRIVATE (sizeof(plocalWindowInfo))
 
 #define GETLOCALWINDOWINFOPTR(__hWnd__) \
-	((localWindowInfo *)GetWindowLong(__hWnd__, 0))
+	((localWindowInfo *)GetWindowLong(__hWnd__, GWL_LOCALINFO))
 
 #define SETLOCALWINDOWINFOPTR(__hWnd__,__ptr__) \
-	SetWindowLong(__hWnd__, 0 , (DWORD)__ptr__)
+	SetWindowLong(__hWnd__, GWL_LOCALINFO , (DWORD)__ptr__)
 
 #define SetWindow_Cursor(__hWnd__, __hCurs__) \
 	(GETLOCALWINDOWINFOPTR(__hWnd__) ? (GETLOCALWINDOWINFOPTR(__hWnd__)->hCursor = __hCurs__) : 0)
@@ -809,6 +817,7 @@
 static char *app_namePopup = "ST/X:Popup";
 static char *app_nameDialog = "ST/X:Dialog";
 static int __debug__ = 0;
+static int __debugNative__ = 0;
 static int __depth;
 static int __realDepth;
 static HWND __rootWin = NULL;
@@ -2544,7 +2553,10 @@
     }
 
     if (hWnd) {
-	isNative = GetWindow_flag(hWnd) & LI_NATIVEWIN;
+	isNative = (GetWindow_flag(hWnd) & LI_NATIVEWIN);
+	if (isNative) {
+	    NDPRINTF(("event for nativeWindow\n"));
+	}
     }
 
     /*
@@ -2581,6 +2593,13 @@
 			    cwi->errCode = GetLastError();
 			    fprintf(stderr, "WinWorkstation [info]: CreateWindow failed: %d (0x%x) [%d]\n",
 						cwi->errCode, cwi->errCode, __LINE__);
+			} else {
+			    SETLOCALWINDOWINFOPTR(cwi->newWinHandle, cwi->localWindowInfo);
+#ifdef DEBUG /* PARANOIA */
+			    if (GETLOCALWINDOWINFOPTR(cwi->newWinHandle) != cwi->localWindowInfo) {
+			       fprintf(stderr, "lI-Error\n");
+			    }
+#endif
 			}
 			ev = cwi->hCreateEvent;
 			if (ev) {
@@ -2628,16 +2647,22 @@
 
 	case WM_CREATE:
 	    {
+#ifdef SETLOCALINFO_IN_CREATE /* no longer */
+		localWindowInfo *lI;
+
 		CREATESTRUCT *lpcs = (LPCREATESTRUCT) lParam; // structure with creation data
 
-		EVENT_PRINTF(("WM_CREATE\n"));
-
-		SETLOCALWINDOWINFOPTR(hWnd, lpcs->lpCreateParams);
-#ifdef SUPERDEBUG
+		lI = lpcs->lpCreateParams;
+		EVENT_PRINTF(("WM_CREATE lI=%x\n", lI));
+
+		SETLOCALWINDOWINFOPTR(hWnd, lI);
+# ifdef SUPERDEBUG
 		if (GETLOCALWINDOWINFOPTR(hWnd) != lpcs->lpCreateParams) {
 		    PRINTF(("SETLOCALWINDOWINFOPTR ERROR\n"));
 		}
-#endif
+# endif /* SUPERDEBUG */
+#endif
+
 		*pDefault = 0;
 #ifdef COUNT_RESOURCES
 		__cnt_createWindows++;
@@ -2944,8 +2969,12 @@
 	case WM_ERASEBKGND:
 	    EVENT_PRINTF(("WM_ERASEBKGND\n"));
 	    if (isNative) {
+fprintf(stderr, "ignore ERASEBKGND for native\n");
 		return 0;
 	    }
+	    if (GetWindow_flag(hWnd) & LI_NATIVEWIN) {
+fprintf(stderr, "oops - isNative is 0 but flag is %x\n", GetWindow_flag(hWnd));
+	    }
 
 #ifndef PRE_21_NOV
 	    *pDefault = 0;
@@ -2970,21 +2999,25 @@
 	case WM_PAINT:
 	    EVENT_PRINTF(("WM_PAINT ********************* "));
 	    if (isNative) {
+fprintf(stderr, "ignore PAINT for native\n");
 		return 0;
 	    }
+	    if (GetWindow_flag(hWnd) & LI_NATIVEWIN) {
+fprintf(stderr, "oops - isNative is 0 but flag is %x\n", GetWindow_flag(hWnd));
+	    }
 
 #ifndef PRE_21_NOV
-	{   int n;
-
-	    n = __generateExposes( hWnd, NULL, WM_PAINT, 0 );
-
-	    if( n <= 0 ) {
-		* pDefault = 1;
-		return 0;
-	    }
-	    * pDefault = 0;
-	    return n;
-	}
+	    {   int n;
+
+		n = __generateExposes( hWnd, NULL, WM_PAINT, 0 );
+
+		if( n <= 0 ) {
+		    * pDefault = 1;
+		    return 0;
+		}
+		* pDefault = 0;
+		return n;
+	    }
 #else
 
 
@@ -4114,6 +4147,46 @@
 	    enqEvent(0, hWnd, message, wParam, 0, 0, 0, 0, EV_NOTIME);
 	    break;
 
+	/* native widget action */
+	case WM_COMMAND:
+	    if (lParam) {
+		DPRINTF(("COMMAND for widget\n"));
+		enqEvent(0, (HWND)(lParam), message, wParam, lParam, 0, 0, 0, EV_NOTIME);
+	    } else {
+		DPRINTF(("COMMAND for owner\n"));
+		enqEvent(0, hWnd, message, wParam, lParam, 0, 0, 0, EV_NOTIME);
+	    }
+	    break;
+
+	case WM_CTLCOLORMSGBOX:
+	    UNHANDLED_EVENT_PRINTF(("WM_CTLCOLORMSGBOX\n"));
+	    break;
+	case WM_CTLCOLOREDIT:
+	    UNHANDLED_EVENT_PRINTF(("WM_CTLCOLOREDIT\n"));
+	    break;
+	case WM_CTLCOLORLISTBOX:
+	    UNHANDLED_EVENT_PRINTF(("WM_CTLCOLORLISTBOX\n"));
+	    break;
+	case WM_CTLCOLORBTN:
+	    UNHANDLED_EVENT_PRINTF(("WM_CTLCOLORBTN\n"));
+	    break;
+	case WM_CTLCOLORDLG:
+	    UNHANDLED_EVENT_PRINTF(("WM_CTLCOLORDLG\n"));
+	    break;
+	case WM_CTLCOLORSTATIC:
+	    UNHANDLED_EVENT_PRINTF(("WM_CTLCOLORSTATIC\n"));
+	    break;
+	case WM_CTLCOLORSCROLLBAR:
+	    UNHANDLED_EVENT_PRINTF(("WM_CTLCOLORSCROLLBAR\n"));
+	    break;
+
+	case WM_GETICON:
+	    UNHANDLED_EVENT_PRINTF(("WM_GETICON\n"));
+	    break;
+	case WM_SETICON:
+	    UNHANDLED_EVENT_PRINTF(("WM_SETICON\n"));
+	    break;
+
 #if 0
 	case WM_NULL:
 	    EVENT_PRINTF(("WM_NULL\n"));
@@ -4251,10 +4324,6 @@
 	    EVENT_PRINTF(("WM_CONTEXTMENU\n"));
 	    break;
 
-	case WM_GETICON:
-	    EVENT_PRINTF(("WM_GETICON\n"));
-	    break;
-
 	case WM_SETICON:
 	    EVENT_PRINTF(("WM_SETICON\n"));
 	    break;
@@ -4274,7 +4343,7 @@
 #endif
 
 	default:
-	    UNHANDLED_EVENT_PRINTF(("WinWorkstat [info]: unhandled msg = %x\n", message));
+	    fprintf(stderr, "WinWorkstat [info] unhandled msg = %d 0x%x [%d]\n", message, message, __LINE__);
 	    break;
     }
     return 0;
@@ -4493,9 +4562,17 @@
 
 			    if (cwi->newWinHandle == NULL) {
 				cwi->errCode = GetLastError();
-				fprintf(stderr, "WinWorkstation [info]: CreateWindow failed: %d (0x%x) [%d]\n",
-						cwi->errCode, cwi->errCode, __LINE__);
+				fprintf(stderr, "WinWorkstation [info]: CreateWindow %s failed: %d (0x%x) [%d]\n",
+						cwi->className, cwi->errCode, cwi->errCode, __LINE__);
+			    } else {
+				SETLOCALWINDOWINFOPTR(cwi->newWinHandle, cwi->localWindowInfo);
+#ifdef DEBUG /* PARANOIA */
+				if (GETLOCALWINDOWINFOPTR(cwi->newWinHandle) != cwi->localWindowInfo) {
+				   fprintf(stderr, "lI-Error\n");
+				}
+#endif
 			    }
+
 			    ev = cwi->hCreateEvent;
 			    if (ev) {
 				SetEvent(ev);
@@ -5001,7 +5078,7 @@
     NativeWindowClassTable := IdentityDictionary new.
     NativeWindowClassTable at:#ScrollBar                put:'SCROLLBAR'.
     NativeWindowClassTable at:#HorizontalScrollBar      put:'SCROLLBAR'.
-    NativeWindowClassTable at:#BerticalScrollBar        put:'SCROLLBAR'.
+    NativeWindowClassTable at:#VerticalScrollBar        put:'SCROLLBAR'.
     NativeWindowClassTable at:#CheckBox                 put:'BUTTON'.
     NativeWindowClassTable at:#RadioButton              put:'BUTTON'.
     NativeWindowClassTable at:#Button                   put:'BUTTON'.
@@ -5885,6 +5962,13 @@
 %}
 !
 
+debugNative:aBoolean
+%{  /* NOCONTEXT */
+
+    __debugNative__ = (aBoolean == true) ? 1 : 0;
+%}
+!
+
 fontHandleCounts
     "for resource debugging only - will vanish"
 
@@ -7184,16 +7268,14 @@
 
     NativeWindows ifTrue:[
 	windowType := aView nativeWindowType.
-
-	"/ if it is already a string, take it as it is;
-	"/ otherwise, it must be a symbol and is used
-	"/ as a key into the nativeClass translation map.
-
-	windowType isString ifTrue:[
-	    windowClass := windowType
-	] ifFalse:[
-	    windowClass := NativeWindowClassTable at:windowType ifAbsent:nil
-	]
+	windowType notNil ifTrue:[
+	    "/ must be a symbol and is used
+	    "/ as a key into the nativeClass translation map.
+
+	    windowClass := NativeWindowClassTable at:windowType ifAbsent:windowType.
+	    "/ 'windowType: ' errorPrint. windowType errorPrintCR.
+	    "/ 'windowClass: ' errorPrint. windowClass errorPrintCR.
+	].
     ].
 
     moreArgs := Array new:20.
@@ -7481,7 +7563,8 @@
     HICON          xIcon = (HICON)0;
     ICONINFO       iconInfo;
     char *className;
-    char nameBuffer[256];
+    static char classNameBuffer[256];
+    static char windowNameBuffer[256];
     unsigned char fastBits[10000];
 
     xpos = __ArrayInstPtr(moreArgs)->a_element[0];
@@ -7625,7 +7708,7 @@
 #if 1
     if (__isString(windowClass) || __isSymbol(windowClass)) {
 	className = __stringVal(windowClass);
-	DPRINTF(("className: %s\n", className));
+	NDPRINTF(("className: %s\n", className));
     }
 #endif
 
@@ -7633,24 +7716,30 @@
 	if (__isInteger(wStyle)) {
 	    isNativeWindow = 1;
 	    winStyleBits |= __longIntVal(wStyle);
-	    DPRINTF(("winStyleBits: %x\n", winStyleBits));
+	    NDPRINTF(("winStyleBits: %x\n", winStyleBits));
 	} else {
 	    if (windowType == @symbol(RadioButton)) {
 		isNativeWindow = 1;
 		winStyleBits |= BS_RADIOBUTTON;
-		DPRINTF(("winStyleBits BS_RADIOBUTTON: %x\n", winStyleBits));
+		NDPRINTF(("RADIOBUTTON - winStyleBits BS_RADIOBUTTON: %x\n", winStyleBits));
 	    } else if (windowType == @symbol(CheckBox)) {
 		isNativeWindow = 1;
 		winStyleBits |= BS_CHECKBOX;
-		DPRINTF(("winStyleBits BS_CHECKBOX: %x\n", winStyleBits));
-	    } else if (windowType == @symbol(HorizontalScrollbar)) {
+		NDPRINTF(("CHECKBOX - winStyleBits BS_CHECKBOX: %x\n", winStyleBits));
+	    } else if (windowType == @symbol(HorizontalScrollBar)) {
 		isNativeWindow = 1;
 		winStyleBits |= SBS_HORZ;
-		DPRINTF(("winStyleBits SBS_HORZ: %x\n", winStyleBits));
+		className = "SCROLLBAR";
+		NDPRINTF(("SCROLLBAR - winStyleBits SBS_HORZ: %x\n", winStyleBits));
 	    } else if (windowType == @symbol(VerticalScrollBar)) {
 		isNativeWindow = 1;
 		winStyleBits |= SBS_VERT;
-		DPRINTF(("winStyleBits SBS_VERT: %x\n", winStyleBits));
+		className = "SCROLLBAR";
+		NDPRINTF(("SCROLLBAR - winStyleBits SBS_VERT: %x\n", winStyleBits));
+	    } else if (windowType == @symbol(Button)) {
+		isNativeWindow = 1;
+		className = "BUTTON";
+		NDPRINTF(("BUTTON\n", winStyleBits));
 	    }
 	}
     }
@@ -7830,6 +7919,7 @@
 	lI->flag |= LI_INPUTWIN;
     }
     if (isNativeWindow) {
+	NDPRINTF(("set native\n"));
 	lI->flag |= LI_NATIVEWIN;
     }
 
@@ -7848,7 +7938,9 @@
 	if (wStyle == @symbol(dialog)) {
 	    cwi.className = app_nameDialog;
 	} else {
-	    cwi.className = className;
+	    strncpy(classNameBuffer, className, sizeof(classNameBuffer));
+	    classNameBuffer[sizeof(classNameBuffer)-1] = 0;
+	    cwi.className = &classNameBuffer;
 	}
     }
 
@@ -7904,8 +7996,9 @@
 
     if (isTopWindow) {
 	if (__isString(wlabel) || __isSymbol(wlabel)) {
-	    strcpy(nameBuffer, (char *) __stringVal(wlabel));
-	    cwi.windowName = nameBuffer;
+	    strncpy(windowNameBuffer, (char *) __stringVal(wlabel), sizeof(windowNameBuffer));
+	    windowNameBuffer[ sizeof(windowNameBuffer)-1 ] = 0;
+	    cwi.windowName = windowNameBuffer;
 	    DPRINTF(("title = %s\n", cwi.windowName));
 	}
     }
@@ -7929,6 +8022,7 @@
     if (cwi.hCreateEvent == NULL) {
 	fprintf(stderr, "WinWorkstation [error]: oops - CreateEvent failed in CreateWindow: %d\n", GetLastError() );
 	cwi.sequenceNr = INVALIDATED_CWI;
+	free(lI);
 	RETURN ( nil );
     }
 #endif
@@ -8022,6 +8116,7 @@
     if (isTopWindow) {
 	BringWindowToTop(newWindowHandle);
     }
+    DragAcceptFiles(newWindowHandle, 1);
 
 #ifndef TOPWINDOWCLASS
     if (xIcon) {
@@ -9821,6 +9916,20 @@
     "Modified: / 28.4.1999 / 15:07:09 / cg"
 !
 
+nativeWidgetCommand:commandId view:aView
+    "forward a command event for some view.
+     (Button, CheckBox etc.)"
+
+    |sensor|
+
+    aView isNil ifTrue:[
+	"/ event arrived, after I destroyed it myself
+	^ self
+    ].
+    sensor := aView sensor.
+    sensor nativeWidgetCommand:commandId view:aView
+!
+
 configureX:x y:y width:w height:h view:aView
     "forward a configure for some view"
 
@@ -9857,6 +9966,14 @@
     "Modified: / 19.5.1999 / 23:37:17 / cg"
 !
 
+queryDropFiles:files view:view
+    "called if files are droped from window
+    "
+    Transcript showCR:'Drop files:'.
+    files do:[:f| Transcript showCR:('  ', f printString) ].
+!
+
+
 queryEndSession
     "system is about to be shut down.
      This is a speciality of windows.
@@ -9987,6 +10104,9 @@
     static struct inlineCache settingChg = _ILC0;
     static struct inlineCache qEndSess = _ILC0;
     static struct inlineCache powerDown = _ILC0;
+    static struct inlineCache command = _ILC2;
+
+    static struct inlineCache queryDrop = _ILC2;
 
     int x, y, w, h;
     int keyCode, modifiers, isDoubleClick = 0;
@@ -10074,17 +10194,32 @@
 
 	    case WM_DROPFILES:
 		{
-		  int i;
-		  char buf[MAXPATH];
-		  HDROP hDrop = (HDROP)ev->ev_wParam;
-		  int count = DragQueryFile(hDrop,0xffffffff,0,0);
-
-		  PRINTF((">>> WM_DROPFILES %d Files\n",count));
-		  for (i = 0;i < count;i++) {
-		      DragQueryFile(hDrop,i,buf,sizeof(buf));
-		      PRINTF(("Filename:%s\n",buf));
-		  }
-		  DragFinish(hDrop);
+		   HDROP hDrop = (HDROP) ev->ev_wParam;
+		   int   count = DragQueryFile( hDrop,0xffffffff,0,0 );
+
+		   if (count > 0) {
+		       OBJ  files;
+		       char buf[MAXPATH];
+		       int  i;
+
+		       files = __ARRAY_NEW_INT( count );
+
+		       for (i = 0;i < count;i++) {
+			   OBJ s;
+
+			   DragQueryFile(hDrop,i,buf,sizeof(buf));
+			   s = __MKSTRING(buf);
+			   __ArrayInstPtr(files)->a_element[i] = s;
+			   __STORE(files, s);
+		       }
+
+		       (*queryDrop.ilc_func)
+			   ( self
+			     , @symbol(queryDropFiles:view:)
+			     , nil, &queryDrop, files, theView
+			   );
+		    }
+		    DragFinish(hDrop);
 		}
 		break;
 
@@ -10766,6 +10901,12 @@
 		(*power.ilc_func)(self, @symbol(powerDown), nil, &power);
 	       break;
 #endif
+	    /* native widget action */
+	    case WM_COMMAND:
+		DPRINTF((">>> WM_COMMAND\n"));
+		(*command.ilc_func)(self, @symbol(nativeWidgetCommand:view:), nil, &command,
+				__MKSMALLINT(ev->ev_wParam), theView);
+	       break;
 
 	    default:
 		UNHANDLED_EVENT_PRINTF(("WinWorkstat [info]: >>> unhandled event: %x\n", ev->ev_message));
@@ -15838,7 +15979,7 @@
 !WinWorkstation class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/WinWorkstation.st,v 1.263 2004-04-05 13:57:56 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/WinWorkstation.st,v 1.264 2004-04-05 16:46:11 ca Exp $'
 ! !
 
 WinWorkstation initialize!