XEmacs 21.2.32 "Kastor & Polydeukes".
[chise/xemacs-chise.git.1] / src / gui-msw.c
1 /* mswindows GUI code. (menubars, scrollbars, toolbars, dialogs)
2    Copyright (C) 1998 Andy Piper.
3
4 This file is part of XEmacs.
5
6 XEmacs is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
10
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with XEmacs; see the file COPYING.  If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20
21 /* Synched up with: Not in FSF. */
22
23 #include <config.h>
24 #include "lisp.h"
25 #include "gui.h"
26 #include "redisplay.h"
27 #include "frame.h"
28 #include "elhash.h"
29 #include "console-msw.h"
30 #include "buffer.h"
31
32 /*
33  * Return value is Qt if we have dispatched the command,
34  * or Qnil if id has not been mapped to a callback.
35  * Window procedure may try other targets to route the
36  * command if we return nil
37  */
38 Lisp_Object
39 mswindows_handle_gui_wm_command (struct frame* f, HWND ctrl, LPARAM id)
40 {
41   /* Try to map the command id through the proper hash table */
42   Lisp_Object data, fn, arg, frame;
43
44   /* #### make_int should assert that --kkm */
45   assert (XINT (make_int (id)) == id);
46
47   data = Fgethash (make_int (id), 
48                    FRAME_MSWINDOWS_WIDGET_HASH_TABLE (f), Qnil);
49   
50   if (NILP (data) || UNBOUNDP (data))
51     return Qnil;
52
53   /* Ok, this is our one. Enqueue it. */
54   get_gui_callback (data, &fn, &arg);
55   XSETFRAME (frame, f);
56   mswindows_enqueue_misc_user_event (frame, fn, arg);
57   /* The result of this evaluation could cause other instances to change so 
58      enqueue an update callback to check this. */
59   mswindows_enqueue_misc_user_event (frame, Qeval, 
60                                      list2 (Qupdate_widget_instances, frame));
61
62   return Qt;
63 }
64
65 DEFUN ("mswindows-shell-execute", Fmswindows_shell_execute, 2, 4, 0, /*
66 Get Windows to perform OPERATION on DOCUMENT.
67 This is a wrapper around the ShellExecute system function, which
68 invokes the application registered to handle OPERATION for DOCUMENT.
69 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be
70 nil for the default action), and DOCUMENT is typically the name of a
71 document file or URL, but can also be a program executable to run or
72 a directory to open in the Windows Explorer.
73
74 If DOCUMENT is a program executable, PARAMETERS can be a string
75 containing command line parameters, but otherwise should be nil.
76
77 SHOW-FLAG can be used to control whether the invoked application is hidden
78 or minimized.  If SHOW-FLAG is nil, the application is displayed normally,
79 otherwise it is an integer representing a ShowWindow flag:
80
81   0 - start hidden
82   1 - start normally
83   3 - start maximized
84   6 - start minimized
85 */
86        (operation, document, parameters, show_flag))
87 {
88   /* Encode filename and current directory.  */
89   Lisp_Object current_dir = Ffile_name_directory (document);
90   char* path = NULL;
91   char* doc = NULL;
92   Extbyte* f=0;
93   int ret;
94   struct gcpro gcpro1, gcpro2;
95
96   CHECK_STRING (document);
97
98   if (NILP (current_dir))
99     current_dir = current_buffer->directory;
100
101   GCPRO2 (current_dir, document);
102
103   /* Use mule and cygwin-safe APIs top get at file data. */
104   if (STRINGP (current_dir))
105     {
106       TO_EXTERNAL_FORMAT (LISP_STRING, current_dir,
107                           C_STRING_ALLOCA, f,
108                           Qfile_name);
109 #ifdef __CYGWIN32__
110       CYGWIN_WIN32_PATH (f, path);
111 #else
112       path = f;
113 #endif
114     }
115
116   if (STRINGP (document))
117     {
118       TO_EXTERNAL_FORMAT (LISP_STRING, document,
119                           C_STRING_ALLOCA, f,
120                           Qfile_name);
121 #ifdef __CYGWIN32__
122       CYGWIN_WIN32_PATH (f, doc);
123 #else
124       doc = f;
125 #endif
126     }
127
128   UNGCPRO;
129
130   ret = (int) ShellExecute (NULL,
131                             (STRINGP (operation) ?
132                              XSTRING_DATA (operation) : NULL),
133                             doc, 
134                             (STRINGP (parameters) ?
135                              XSTRING_DATA (parameters) : NULL),
136                             path,
137                             (INTP (show_flag) ?
138                              XINT (show_flag) : SW_SHOWDEFAULT));
139
140   if (ret > 32)
141     return Qt;
142   
143   if (ret == ERROR_FILE_NOT_FOUND)
144     signal_simple_error ("file not found", document);
145   else if (ret == ERROR_PATH_NOT_FOUND)
146     signal_simple_error ("path not found", current_dir);
147   else if (ret == ERROR_BAD_FORMAT)
148     signal_simple_error ("bad executable format", document);
149   else
150     error ("internal error");
151
152   return Qnil;
153 }
154
155 void
156 syms_of_gui_mswindows (void)
157 {
158   DEFSUBR (Fmswindows_shell_execute);
159 }