comparison src/gui-msw.c @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents de805c49cfc1
children 11054d720c21
comparison
equal deleted inserted replaced
411:12e008d41344 412:697ef44129c6
20 20
21 /* Synched up with: Not in FSF. */ 21 /* Synched up with: Not in FSF. */
22 22
23 #include <config.h> 23 #include <config.h>
24 #include "lisp.h" 24 #include "lisp.h"
25 #include "console-msw.h" 25 #include "gui.h"
26 #include "redisplay.h" 26 #include "redisplay.h"
27 #include "gui.h"
28 #include "glyphs.h"
29 #include "frame.h" 27 #include "frame.h"
30 #include "elhash.h" 28 #include "elhash.h"
31 #include "events.h" 29 #include "console-msw.h"
32 #include "buffer.h"
33 30
34 /* 31 /*
35 * Return value is Qt if we have dispatched the command, 32 * Return value is Qt if we have dispatched the command,
36 * or Qnil if id has not been mapped to a callback. 33 * or Qnil if id has not been mapped to a callback.
37 * Window procedure may try other targets to route the 34 * Window procedure may try other targets to route the
38 * command if we return nil 35 * command if we return nil
39 */ 36 */
40 Lisp_Object 37 Lisp_Object
41 mswindows_handle_gui_wm_command (struct frame* f, HWND ctrl, LPARAM id) 38 mswindows_handle_gui_wm_command (struct frame* f, HWND ctrl, WORD id)
42 { 39 {
43 /* Try to map the command id through the proper hash table */ 40 /* Try to map the command id through the proper hash table */
44 Lisp_Object callback, callback_ex, image_instance, frame, event; 41 Lisp_Object data, fn, arg, frame;
45 42
43 data = Fgethash (make_int (id),
44 FRAME_MSWINDOWS_WIDGET_HASH_TABLE (f), Qnil);
45
46 if (NILP (data) || UNBOUNDP (data))
47 return Qnil;
48
49 MARK_SUBWINDOWS_CHANGED;
50 /* Ok, this is our one. Enqueue it. */
51 get_gui_callback (data, &fn, &arg);
46 XSETFRAME (frame, f); 52 XSETFRAME (frame, f);
53 mswindows_enqueue_misc_user_event (frame, fn, arg);
47 54
48 /* #### make_int should assert that --kkm */
49 assert (XINT (make_int (id)) == id);
50
51 image_instance = Fgethash (make_int (id),
52 FRAME_MSWINDOWS_WIDGET_HASH_TABLE1 (f), Qnil);
53 callback = Fgethash (make_int (id),
54 FRAME_MSWINDOWS_WIDGET_HASH_TABLE2 (f), Qnil);
55 callback_ex = Fgethash (make_int (id),
56 FRAME_MSWINDOWS_WIDGET_HASH_TABLE3 (f), Qnil);
57
58 if (!NILP (callback_ex) && !UNBOUNDP (callback_ex))
59 {
60 event = Fmake_event (Qnil, Qnil);
61
62 XEVENT (event)->event_type = misc_user_event;
63 XEVENT (event)->channel = frame;
64 XEVENT (event)->timestamp = GetTickCount ();
65 XEVENT (event)->event.eval.function = Qeval;
66 XEVENT (event)->event.eval.object =
67 list4 (Qfuncall, callback_ex, image_instance, event);
68 }
69 else if (NILP (callback) || UNBOUNDP (callback))
70 return Qnil;
71 else
72 {
73 Lisp_Object fn, arg;
74
75 event = Fmake_event (Qnil, Qnil);
76
77 get_gui_callback (callback, &fn, &arg);
78 XEVENT (event)->event_type = misc_user_event;
79 XEVENT (event)->channel = frame;
80 XEVENT (event)->timestamp = GetTickCount ();
81 XEVENT (event)->event.eval.function = fn;
82 XEVENT (event)->event.eval.object = arg;
83 }
84
85 mswindows_enqueue_dispatch_event (event);
86 /* The result of this evaluation could cause other instances to change so
87 enqueue an update callback to check this. */
88 enqueue_magic_eval_event (update_widget_instances, frame);
89 return Qt; 55 return Qt;
90 } 56 }
91 57
92 DEFUN ("mswindows-shell-execute", Fmswindows_shell_execute, 2, 4, 0, /*
93 Get Windows to perform OPERATION on DOCUMENT.
94 This is a wrapper around the ShellExecute system function, which
95 invokes the application registered to handle OPERATION for DOCUMENT.
96 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be
97 nil for the default action), and DOCUMENT is typically the name of a
98 document file or URL, but can also be a program executable to run or
99 a directory to open in the Windows Explorer.
100
101 If DOCUMENT is a program executable, PARAMETERS can be a string
102 containing command line parameters, but otherwise should be nil.
103
104 SHOW-FLAG can be used to control whether the invoked application is hidden
105 or minimized. If SHOW-FLAG is nil, the application is displayed normally,
106 otherwise it is an integer representing a ShowWindow flag:
107
108 0 - start hidden
109 1 - start normally
110 3 - start maximized
111 6 - start minimized
112 */
113 (operation, document, parameters, show_flag))
114 {
115 /* Encode filename and current directory. */
116 Lisp_Object current_dir = Ffile_name_directory (document);
117 char* path = NULL;
118 char* doc = NULL;
119 Extbyte* f=0;
120 int ret;
121 struct gcpro gcpro1, gcpro2;
122
123 CHECK_STRING (document);
124
125 if (NILP (current_dir))
126 current_dir = current_buffer->directory;
127
128 GCPRO2 (current_dir, document);
129
130 /* Use mule and cygwin-safe APIs top get at file data. */
131 if (STRINGP (current_dir))
132 {
133 TO_EXTERNAL_FORMAT (LISP_STRING, current_dir,
134 C_STRING_ALLOCA, f,
135 Qfile_name);
136 #ifdef CYGWIN
137 CYGWIN_WIN32_PATH (f, path);
138 #else
139 path = f;
140 #endif
141 }
142
143 if (STRINGP (document))
144 {
145 TO_EXTERNAL_FORMAT (LISP_STRING, document,
146 C_STRING_ALLOCA, f,
147 Qfile_name);
148 #ifdef CYGWIN
149 CYGWIN_WIN32_PATH (f, doc);
150 #else
151 doc = f;
152 #endif
153 }
154
155 UNGCPRO;
156
157 ret = (int) ShellExecute (NULL,
158 (STRINGP (operation) ?
159 XSTRING_DATA (operation) : NULL),
160 doc,
161 (STRINGP (parameters) ?
162 XSTRING_DATA (parameters) : NULL),
163 path,
164 (INTP (show_flag) ?
165 XINT (show_flag) : SW_SHOWDEFAULT));
166
167 if (ret > 32)
168 return Qt;
169
170 if (ret == ERROR_FILE_NOT_FOUND)
171 signal_simple_error ("file not found", document);
172 else if (ret == ERROR_PATH_NOT_FOUND)
173 signal_simple_error ("path not found", current_dir);
174 else if (ret == ERROR_BAD_FORMAT)
175 signal_simple_error ("bad executable format", document);
176 else
177 error ("internal error");
178
179 return Qnil;
180 }
181
182 void
183 syms_of_gui_mswindows (void)
184 {
185 DEFSUBR (Fmswindows_shell_execute);
186 }