annotate src/gui-msw.c @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents bbff43aa5eb7
children a86b2b5e0111
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
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
39 mswindows_handle_gui_wm_command (struct frame* f, HWND ctrl, DWORD 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
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
53 MARK_SUBWINDOWS_STATE_CHANGED;
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
54 /* Ok, this is our one. Enqueue it. */
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
55 get_gui_callback (data, &fn, &arg);
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
56 XSETFRAME (frame, f);
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
57 mswindows_enqueue_misc_user_event (frame, fn, arg);
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
58
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
59 return Qt;
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
60 }
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents:
diff changeset
61
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
62 DEFUN ("mswindows-shell-execute", Fmswindows_shell_execute, 2, 4, 0, /*
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
63 Get Windows to perform OPERATION on DOCUMENT.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
64 This is a wrapper around the ShellExecute system function, which
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
65 invokes the application registered to handle OPERATION for DOCUMENT.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
66 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
67 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
68 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
69 a directory to open in the Windows Explorer.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
70
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
71 If DOCUMENT is a program executable, PARAMETERS can be a string
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
72 containing command line parameters, but otherwise should be nil.
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 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
75 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
76 otherwise it is an integer representing a ShowWindow flag:
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
77
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
78 0 - start hidden
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
79 1 - start normally
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
80 3 - start maximized
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
81 6 - start minimized
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
82 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
83 (operation, document, parameters, show_flag))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
84 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
85 /* Encode filename and current directory. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
86 Lisp_Object current_dir = Ffile_name_directory (document);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
87 char* path = NULL;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
88 char* doc = NULL;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
89 Extbyte* f=0;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
90 int ret;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
91 struct gcpro gcpro1, gcpro2;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
92
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
93 CHECK_STRING (document);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
94
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
95 /* Just get the filename if we were given it. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
96 document = Ffile_name_nondirectory (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);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
121 doc = f;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
122 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
123
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
124 UNGCPRO;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
125
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
126 ret = (int) ShellExecute (NULL,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
127 (STRINGP (operation) ?
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
128 XSTRING_DATA (operation) : NULL),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
129 doc,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
130 (STRINGP (parameters) ?
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
131 XSTRING_DATA (parameters) : NULL),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
132 path,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
133 (INTP (show_flag) ?
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
134 XINT (show_flag) : SW_SHOWDEFAULT));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
135
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
136 if (ret > 32)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
137 return Qt;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
138
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
139 if (ret == ERROR_FILE_NOT_FOUND || ret == SE_ERR_FNF)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
140 signal_simple_error ("file not found", document);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
141 else if (ret == ERROR_PATH_NOT_FOUND || ret == SE_ERR_PNF)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
142 signal_simple_error ("path not found", current_dir);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
143 else if (ret == ERROR_BAD_FORMAT)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
144 signal_simple_error ("bad executable format", document);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
145 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
146 error ("internal error");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
147
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
148 return Qnil;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
149 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
150
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
151 void
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
152 syms_of_gui_mswindows (void)
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 DEFSUBR (Fmswindows_shell_execute);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
155 }