annotate src/gui-msw.c @ 404:2f8bb876ab1d r21-2-32

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