+ if (UNBOUNDP (mswindows_handle_wm_initmenupopup (
+ (HMENU) wParam,
+ XFRAME (mswindows_find_frame (hwnd)))))
+ SendMessage (hwnd, WM_CANCELMODE, 0, 0);
+ }
+ break;
+
+#endif /* HAVE_MENUBARS */
+
+ case WM_COMMAND:
+ {
+ WORD id = LOWORD (wParam);
+ WORD nid = HIWORD (wParam);
+ HWND cid = (HWND)lParam;
+ frame = XFRAME (mswindows_find_frame (hwnd));
+
+#ifdef HAVE_TOOLBARS
+ if (!NILP (mswindows_handle_toolbar_wm_command (frame, cid, id)))
+ break;
+#endif
+ /* widgets in a buffer only eval a callback for suitable events.*/
+ switch (nid)
+ {
+ case BN_CLICKED:
+ case EN_CHANGE:
+ case CBN_EDITCHANGE:
+ case CBN_SELCHANGE:
+ if (!NILP (mswindows_handle_gui_wm_command (frame, cid, id)))
+ return 0;
+ }
+ /* menubars always must come last since the hashtables do not
+ always exist*/
+#ifdef HAVE_MENUBARS
+ if (!NILP (mswindows_handle_wm_command (frame, id)))
+ break;
+#endif
+
+ return DefWindowProc (hwnd, message_, wParam, lParam);
+ /* Bite me - a spurious command. This used to not be able to
+ happen but with the introduction of widgets its now
+ possible. */
+ }
+ break;
+
+ case WM_CTLCOLORBTN:
+ case WM_CTLCOLORLISTBOX:
+ case WM_CTLCOLOREDIT:
+ case WM_CTLCOLORSTATIC:
+ case WM_CTLCOLORSCROLLBAR:
+ {
+ /* if we get an opportunity to paint a widget then do so if
+ there is an appropriate face */
+ HWND crtlwnd = (HWND)lParam;
+ LONG ii = GetWindowLong (crtlwnd, GWL_USERDATA);
+ if (ii)
+ {
+ Lisp_Object image_instance;
+ VOID_TO_LISP (image_instance, ii);
+ if (IMAGE_INSTANCEP (image_instance)
+ &&
+ IMAGE_INSTANCE_TYPE_P (image_instance, IMAGE_WIDGET))
+ {
+ /* set colors for the buttons */
+ HDC hdc = (HDC)wParam;
+ if (last_widget_brushed != ii)
+ {
+ if (widget_brush)
+ DeleteObject (widget_brush);
+ widget_brush = CreateSolidBrush
+ (COLOR_INSTANCE_MSWINDOWS_COLOR
+ (XCOLOR_INSTANCE
+ (FACE_BACKGROUND
+ (XIMAGE_INSTANCE_WIDGET_FACE (image_instance),
+ XIMAGE_INSTANCE_FRAME (image_instance)))));
+ }
+ last_widget_brushed = ii;
+ SetTextColor
+ (hdc,
+ COLOR_INSTANCE_MSWINDOWS_COLOR
+ (XCOLOR_INSTANCE
+ (FACE_FOREGROUND
+ (XIMAGE_INSTANCE_WIDGET_FACE (image_instance),
+ XIMAGE_INSTANCE_FRAME (image_instance)))));
+ SetBkMode (hdc, OPAQUE);
+ SetBkColor
+ (hdc,
+ COLOR_INSTANCE_MSWINDOWS_COLOR
+ (XCOLOR_INSTANCE
+ (FACE_BACKGROUND
+ (XIMAGE_INSTANCE_WIDGET_FACE (image_instance),
+ XIMAGE_INSTANCE_FRAME (image_instance)))));
+ return (LRESULT)widget_brush;
+ }
+ }
+ }
+ goto defproc;
+
+#ifdef HAVE_DRAGNDROP
+ case WM_DROPFILES: /* implementation ripped-off from event-Xt.c */
+ {
+ UINT filecount, i, len;
+ POINT point;
+ char* filename;
+ char* fname;
+
+ Lisp_Object l_dndlist = Qnil, l_item = Qnil;
+ struct gcpro gcpro1, gcpro2, gcpro3;
+
+ emacs_event = Fmake_event (Qnil, Qnil);
+ event = XEVENT(emacs_event);
+
+ GCPRO3 (emacs_event, l_dndlist, l_item);
+
+ if (!DragQueryPoint ((HDROP) wParam, &point))
+ point.x = point.y = -1; /* outside client area */
+
+ event->event_type = misc_user_event;
+ event->channel = mswindows_find_frame(hwnd);
+ event->timestamp = GetMessageTime();
+ event->event.misc.button = 1; /* #### Should try harder */
+ event->event.misc.modifiers = mswindows_modifier_state (NULL,
+ (DWORD) -1, 0);
+ event->event.misc.x = point.x;
+ event->event.misc.y = point.y;
+ event->event.misc.function = Qdragdrop_drop_dispatch;
+
+ filecount = DragQueryFile ((HDROP) wParam, 0xffffffff, NULL, 0);
+ for (i=0; i<filecount; i++)
+ {
+ len = DragQueryFile ((HDROP) wParam, i, NULL, 0);
+ /* The URLs that we make here aren't correct according to section
+ * 3.10 of rfc1738 because they're missing the //<host>/ part and
+ * because they may contain reserved characters. But that's OK -
+ * they just need to be good enough to keep dragdrop.el happy. */
+ fname = (char *)xmalloc (len+1);
+ DragQueryFile ((HANDLE) wParam, i, fname, len+1);
+
+ /* May be a shell link aka "shortcut" - replace fname if so */
+#if !(defined(CYGWIN) || defined(MINGW))
+ /* cygwin doesn't define this COM stuff */
+ if (!stricmp (fname + strlen (fname) - 4, ".LNK"))
+ {
+ IShellLink* psl;
+
+ if (CoCreateInstance (&CLSID_ShellLink, NULL,
+ CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl) == S_OK)
+ {
+ IPersistFile* ppf;
+
+ if (psl->lpVtbl->QueryInterface (psl, &IID_IPersistFile,
+ &ppf) == S_OK)
+ {
+ OLECHAR wsz[PATH_MAX];
+ WIN32_FIND_DATA wfd;
+ LPSTR resolved = (char *) xmalloc (PATH_MAX+1);
+
+ MultiByteToWideChar (CP_ACP,0, fname, -1, wsz, PATH_MAX);
+
+ if ((ppf->lpVtbl->Load (ppf, wsz, STGM_READ) == S_OK) &&
+ (psl->lpVtbl->GetPath (psl, resolved, PATH_MAX,
+ &wfd, 0)==S_OK))
+ {
+ xfree (fname);
+ fname = resolved;
+ len = strlen (fname);
+ }
+
+ ppf->lpVtbl->Release (ppf);
+ }
+
+ psl->lpVtbl->Release (psl);
+ }
+ }
+#endif
+
+#ifdef CYGWIN
+ filename = xmalloc (cygwin_win32_to_posix_path_list_buf_size (fname) + 5);
+ strcpy (filename, "file:");
+ cygwin_win32_to_posix_path_list (fname, filename+5);