annotate src/menubar-msw.c @ 665:fdefd0186b75

[xemacs-hg @ 2001-09-20 06:28:42 by ben] The great integral types renaming. The purpose of this is to rationalize the names used for various integral types, so that they match their intended uses and follow consist conventions, and eliminate types that were not semantically different from each other. The conventions are: -- All integral types that measure quantities of anything are signed. Some people disagree vociferously with this, but their arguments are mostly theoretical, and are vastly outweighed by the practical headaches of mixing signed and unsigned values, and more importantly by the far increased likelihood of inadvertent bugs: Because of the broken "viral" nature of unsigned quantities in C (operations involving mixed signed/unsigned are done unsigned, when exactly the opposite is nearly always wanted), even a single error in declaring a quantity unsigned that should be signed, or even the even more subtle error of comparing signed and unsigned values and forgetting the necessary cast, can be catastrophic, as comparisons will yield wrong results. -Wsign-compare is turned on specifically to catch this, but this tends to result in a great number of warnings when mixing signed and unsigned, and the casts are annoying. More has been written on this elsewhere. -- All such quantity types just mentioned boil down to EMACS_INT, which is 32 bits on 32-bit machines and 64 bits on 64-bit machines. This is guaranteed to be the same size as Lisp objects of type `int', and (as far as I can tell) of size_t (unsigned!) and ssize_t. The only type below that is not an EMACS_INT is Hashcode, which is an unsigned value of the same size as EMACS_INT. -- Type names should be relatively short (no more than 10 characters or so), with the first letter capitalized and no underscores if they can at all be avoided. -- "count" == a zero-based measurement of some quantity. Includes sizes, offsets, and indexes. -- "bpos" == a one-based measurement of a position in a buffer. "Charbpos" and "Bytebpos" count text in the buffer, rather than bytes in memory; thus Bytebpos does not directly correspond to the memory representation. Use "Membpos" for this. -- "Char" refers to internal-format characters, not to the C type "char", which is really a byte. -- For the actual name changes, see the script below. I ran the following script to do the conversion. (NOTE: This script is idempotent. You can safely run it multiple times and it will not screw up previous results -- in fact, it will do nothing if nothing has changed. Thus, it can be run repeatedly as necessary to handle patches coming in from old workspaces, or old branches.) There are two tags, just before and just after the change: `pre-integral-type-rename' and `post-integral-type-rename'. When merging code from the main trunk into a branch, the best thing to do is first merge up to `pre-integral-type-rename', then apply the script and associated changes, then merge from `post-integral-type-change' to the present. (Alternatively, just do the merging in one operation; but you may then have a lot of conflicts needing to be resolved by hand.) Script `fixtypes.sh' follows: ----------------------------------- cut ------------------------------------ files="*.[ch] s/*.h m/*.h config.h.in ../configure.in Makefile.in.in ../lib-src/*.[ch] ../lwlib/*.[ch]" gr Memory_Count Bytecount $files gr Lstream_Data_Count Bytecount $files gr Element_Count Elemcount $files gr Hash_Code Hashcode $files gr extcount bytecount $files gr bufpos charbpos $files gr bytind bytebpos $files gr memind membpos $files gr bufbyte intbyte $files gr Extcount Bytecount $files gr Bufpos Charbpos $files gr Bytind Bytebpos $files gr Memind Membpos $files gr Bufbyte Intbyte $files gr EXTCOUNT BYTECOUNT $files gr BUFPOS CHARBPOS $files gr BYTIND BYTEBPOS $files gr MEMIND MEMBPOS $files gr BUFBYTE INTBYTE $files gr MEMORY_COUNT BYTECOUNT $files gr LSTREAM_DATA_COUNT BYTECOUNT $files gr ELEMENT_COUNT ELEMCOUNT $files gr HASH_CODE HASHCODE $files ----------------------------------- cut ------------------------------------ `fixtypes.sh' is a Bourne-shell script; it uses 'gr': ----------------------------------- cut ------------------------------------ #!/bin/sh # Usage is like this: # gr FROM TO FILES ... # globally replace FROM with TO in FILES. FROM and TO are regular expressions. # backup files are stored in the `backup' directory. from="$1" to="$2" shift 2 echo ${1+"$@"} | xargs global-replace "s/$from/$to/g" ----------------------------------- cut ------------------------------------ `gr' in turn uses a Perl script to do its real work, `global-replace', which follows: ----------------------------------- cut ------------------------------------ : #-*- Perl -*- ### global-modify --- modify the contents of a file by a Perl expression ## Copyright (C) 1999 Martin Buchholz. ## Copyright (C) 2001 Ben Wing. ## Authors: Martin Buchholz <martin@xemacs.org>, Ben Wing <ben@xemacs.org> ## Maintainer: Ben Wing <ben@xemacs.org> ## Current Version: 1.0, May 5, 2001 # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with XEmacs; see the file COPYING. If not, write to the Free # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. eval 'exec perl -w -S $0 ${1+"$@"}' if 0; use strict; use FileHandle; use Carp; use Getopt::Long; use File::Basename; (my $myName = $0) =~ s@.*/@@; my $usage=" Usage: $myName [--help] [--backup-dir=DIR] [--line-mode] [--hunk-mode] PERLEXPR FILE ... Globally modify a file, either line by line or in one big hunk. Typical usage is like this: [with GNU print, GNU xargs: guaranteed to handle spaces, quotes, etc. in file names] find . -name '*.[ch]' -print0 | xargs -0 $0 's/\bCONST\b/const/g'\n [with non-GNU print, xargs] find . -name '*.[ch]' -print | xargs $0 's/\bCONST\b/const/g'\n The file is read in, either line by line (with --line-mode specified) or in one big hunk (with --hunk-mode specified; it's the default), and the Perl expression is then evalled with \$_ set to the line or hunk of text, including the terminating newline if there is one. It should destructively modify the value there, storing the changed result in \$_. Files in which any modifications are made are backed up to the directory specified using --backup-dir, or to `backup' by default. To disable this, use --backup-dir= with no argument. Hunk mode is the default because it is MUCH MUCH faster than line-by-line. Use line-by-line only when it matters, e.g. you want to do a replacement only once per line (the default without the `g' argument). Conversely, when using hunk mode, *ALWAYS* use `g'; otherwise, you will only make one replacement in the entire file! "; my %options = (); $Getopt::Long::ignorecase = 0; &GetOptions ( \%options, 'help', 'backup-dir=s', 'line-mode', 'hunk-mode', ); die $usage if $options{"help"} or @ARGV <= 1; my $code = shift; die $usage if grep (-d || ! -w, @ARGV); sub SafeOpen { open ((my $fh = new FileHandle), $_[0]); confess "Can't open $_[0]: $!" if ! defined $fh; return $fh; } sub SafeClose { close $_[0] or confess "Can't close $_[0]: $!"; } sub FileContents { my $fh = SafeOpen ("< $_[0]"); my $olddollarslash = $/; local $/ = undef; my $contents = <$fh>; $/ = $olddollarslash; return $contents; } sub WriteStringToFile { my $fh = SafeOpen ("> $_[0]"); binmode $fh; print $fh $_[1] or confess "$_[0]: $!\n"; SafeClose $fh; } foreach my $file (@ARGV) { my $changed_p = 0; my $new_contents = ""; if ($options{"line-mode"}) { my $fh = SafeOpen $file; while (<$fh>) { my $save_line = $_; eval $code; $changed_p = 1 if $save_line ne $_; $new_contents .= $_; } } else { my $orig_contents = $_ = FileContents $file; eval $code; if ($_ ne $orig_contents) { $changed_p = 1; $new_contents = $_; } } if ($changed_p) { my $backdir = $options{"backup-dir"}; $backdir = "backup" if !defined ($backdir); if ($backdir) { my ($name, $path, $suffix) = fileparse ($file, ""); my $backfulldir = $path . $backdir; my $backfile = "$backfulldir/$name"; mkdir $backfulldir, 0755 unless -d $backfulldir; print "modifying $file (original saved in $backfile)\n"; rename $file, $backfile; } WriteStringToFile ($file, $new_contents); } } ----------------------------------- cut ------------------------------------ In addition to those programs, I needed to fix up a few other things, particularly relating to the duplicate definitions of types, now that some types merged with others. Specifically: 1. in lisp.h, removed duplicate declarations of Bytecount. The changed code should now look like this: (In each code snippet below, the first and last lines are the same as the original, as are all lines outside of those lines. That allows you to locate the section to be replaced, and replace the stuff in that section, verifying that there isn't anything new added that would need to be kept.) --------------------------------- snip ------------------------------------- /* Counts of bytes or chars */ typedef EMACS_INT Bytecount; typedef EMACS_INT Charcount; /* Counts of elements */ typedef EMACS_INT Elemcount; /* Hash codes */ typedef unsigned long Hashcode; /* ------------------------ dynamic arrays ------------------- */ --------------------------------- snip ------------------------------------- 2. in lstream.h, removed duplicate declaration of Bytecount. Rewrote the comment about this type. The changed code should now look like this: --------------------------------- snip ------------------------------------- #endif /* The have been some arguments over the what the type should be that specifies a count of bytes in a data block to be written out or read in, using Lstream_read(), Lstream_write(), and related functions. Originally it was long, which worked fine; Martin "corrected" these to size_t and ssize_t on the grounds that this is theoretically cleaner and is in keeping with the C standards. Unfortunately, this practice is horribly error-prone due to design flaws in the way that mixed signed/unsigned arithmetic happens. In fact, by doing this change, Martin introduced a subtle but fatal error that caused the operation of sending large mail messages to the SMTP server under Windows to fail. By putting all values back to be signed, avoiding any signed/unsigned mixing, the bug immediately went away. The type then in use was Lstream_Data_Count, so that it be reverted cleanly if a vote came to that. Now it is Bytecount. Some earlier comments about why the type must be signed: This MUST BE SIGNED, since it also is used in functions that return the number of bytes actually read to or written from in an operation, and these functions can return -1 to signal error. Note that the standard Unix read() and write() functions define the count going in as a size_t, which is UNSIGNED, and the count going out as an ssize_t, which is SIGNED. This is a horrible design flaw. Not only is it highly likely to lead to logic errors when a -1 gets interpreted as a large positive number, but operations are bound to fail in all sorts of horrible ways when a number in the upper-half of the size_t range is passed in -- this number is unrepresentable as an ssize_t, so code that checks to see how many bytes are actually written (which is mandatory if you are dealing with certain types of devices) will get completely screwed up. --ben */ typedef enum lstream_buffering --------------------------------- snip ------------------------------------- 3. in dumper.c, there are four places, all inside of switch() statements, where XD_BYTECOUNT appears twice as a case tag. In each case, the two case blocks contain identical code, and you should *REMOVE THE SECOND* and leave the first.
author ben
date Thu, 20 Sep 2001 06:31:11 +0000
parents b39c14581166
children a307f9a2021d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Implements an elisp-programmable menubar -- Win32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1993, 1994 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4 Copyright (C) 1997 Kirill M. Katsnelson <kkm@kis.ru>.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5 Copyright (C) 2000 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 /* Synched up with: Not in FSF. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 /* Author:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 Initially written by kkm 12/24/97,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 peeking into and copying stuff from menubar-x.c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 /* Algorithm for handling menus is as follows. When window's menubar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 * is created, current-menubar is not traversed in depth. Rather, only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 * top level items, both items and pulldowns, are added to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 * menubar. Each pulldown is initially empty. When a pulldown is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 * selected and about to open, corresponding element of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 * current-menubar is found, and the newly open pulldown is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 * populated. This is made again in the same non-recursive manner.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 * This algorithm uses hash tables to find out element of the menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 * descriptor list given menu handle. The key is an opaque ptr data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 * type, keeping menu handle, and the value is a list of strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 * representing the path from the root of the menu to the item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 * descriptor. Each frame has an associated hash table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 * Leaf items are assigned a unique id based on item's hash. When an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 * item is selected, Windows sends back the id. Unfortunately, only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 * low 16 bit of the ID are sent, and there's no way to get the 32-bit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 * value. Yes, Win32 is just a different set of bugs than X! Aside
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 * from this blame, another hashing mechanism is required to map menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 * ids to commands (which are actually Lisp_Object's). This mapping is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 * performed in the same hash table, as the lifetime of both maps is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 * exactly the same. This is unambigous, as menu handles are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 * represented by lisp opaques, while command ids are by lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 * integers. The additional advantage for this is that command forms
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 * are automatically GC-protected, which is important because these
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 * may be transient forms generated by :filter functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 * The hash table is not allowed to grow too much; it is pruned
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 * whenever this is safe to do. This is done by re-creating the menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 * bar, and clearing and refilling the hash table from scratch.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 * Popup menus are handled identically to pulldowns. A static hash
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 * table is used for popup menus, and lookup is made not in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 * current-menubar but in a lisp form supplied to the `popup'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 * function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 * Another Windows weirdness is that there's no way to tell that a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 * popup has been dismissed without making selection. We need to know
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 * that to cleanup the popup menu hash table, but this is not honestly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 * doable using *documented* sequence of messages. Sticking to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 * particular knowledge is bad because this may break in Windows NT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 * 5.0, or Windows 98, or other future version. Instead, I allow the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 * hash tables to hang around, and not clear them, unless WM_COMMAND is
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
74 * received. This is worth some memory but more safe. Hacks welcome,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 * anyways!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 #include "commands.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 #include "console-msw.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 #include "elhash.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 #include "events.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 #include "frame.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 #include "gui.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 #include "menubar.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 #include "menubar-msw.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 #include "opaque.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 #include "window.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 /* #### */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
96 #define REPLACE_ME_WITH_GLOBAL_VARIABLE_WHICH_CONTROLS_RIGHT_FLUSH 0
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 #define EMPTY_ITEM_ID ((UINT)LISP_TO_VOID (Qunbound))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 #define EMPTY_ITEM_NAME "(empty)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 /* Current menu (bar or popup) descriptor. gcpro'ed */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 static Lisp_Object current_menudesc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 /* Current menubar or popup hash table. gcpro'ed */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 static Lisp_Object current_hash_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 /* This is used to allocate unique ids to menu items.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 Items ids are in MENU_ITEM_ID_MIN to MENU_ITEM_ID_MAX.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 Allocation checks that the item is not already in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 the TOP_LEVEL_MENU */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 /* #### defines go to gui-msw.h, as the range is shared with toolbars
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 (If only toolbars will be implemented as common controls) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 #define MENU_ITEM_ID_MIN 0x8000
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 #define MENU_ITEM_ID_MAX 0xFFFF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 #define MENU_ITEM_ID_BITS(x) (((x) & 0x7FFF) | 0x8000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 static HMENU top_level_menu;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 /*
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
120 * Translate (in place) X accelerator syntax to win32 accelerator syntax.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
121 * Return new length.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
122 * len = number of bytes (not including zero terminator).
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
123 * maxlen = size of buffer.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
124 * accel = (Emchar*) to receive the accelerator character
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
125 * or NULL to suppress accelerators in the menu or dialog item.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
126 *
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
127 * %% is replaced with %
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
128 * if accel is NULL:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
129 * %_ is removed.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
130 * if accel is non-NULL:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
131 * %_ is replaced with &.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
132 * The accelerator character is passed back in *accel.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
133 * (If there is no accelerator, it will be added on the first character.)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
134 *
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
135 * We assume and maintain zero-termination. To be absolutely sure
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
136 * of not hitting an error, maxlen should be >= 2*len + 3.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
137 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
138 Bytecount
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
139 mswindows_translate_menu_or_dialog_item (Intbyte *item, Bytecount len,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
140 Bytecount maxlen, Emchar *accel,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
141 Lisp_Object error_name)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
142 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
143 Intbyte *ptr;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
144
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
145 if (accel)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
146 *accel = '\0';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
147
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
148 /* Escape '&' as '&&' */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
149 ptr = item;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
150 while ((ptr = (Intbyte *) memchr (ptr, '&', len - (ptr - item))) != NULL)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
151 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
152 if (len + 2 > maxlen)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
153 invalid_argument ("Menu item produces too long displayable string",
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
154 error_name);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
155 memmove (ptr + 1, ptr, (len - (ptr - item)) + 1);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
156 len++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
157 ptr += 2;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
158 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
159
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
160 /* Replace XEmacs accelerator '%_' with Windows accelerator '&'
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
161 and `%%' with `%'. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
162 ptr = item;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
163 while ((ptr = (Intbyte *) memchr (ptr, '%', len - (ptr - item))) != NULL)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
164 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
165 if (*(ptr + 1) == '_')
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
166 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
167 if (accel)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
168 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
169 *ptr = '&';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
170 if (!*accel)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
171 /* #### urk ! We need a reference translation table for
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
172 case changes that aren't buffer-specific. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
173 *accel = DOWNCASE (current_buffer, charptr_emchar (ptr + 2));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
174 memmove (ptr + 1, ptr + 2, len - (ptr - item + 2) + 1);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
175 len--;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
176 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
177 else /* Skip accelerator */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
178 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
179 memmove (ptr, ptr + 2, len - (ptr - item + 2) + 1);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
180 len-=2;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
181 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
182 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
183 else if (*(ptr + 1) == '%')
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
184 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
185 memmove (ptr + 1, ptr + 2, len - (ptr - item + 2) + 1);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
186 len--;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
187 ptr++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
188 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
189 else /* % on its own - shouldn't happen */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
190 ptr++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
191 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
192
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
193 if (accel && !*accel)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
194 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
195 /* Force a default accelerator */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
196 if (len + 2 > maxlen)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
197 invalid_argument ("Menu item produces too long displayable string",
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
198 error_name);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
199 ptr = item;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
200 memmove (ptr + 1, ptr, len + 1);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
201 /* #### urk ! We need a reference translation table for
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
202 case changes that aren't buffer-specific. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
203 *accel = DOWNCASE (current_buffer, charptr_emchar (ptr + 1));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
204 *ptr = '&';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
205
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
206 len++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
207 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
208
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
209 return len;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
210 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
211
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
212 /*
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 * This returns Windows-style menu item string:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 * "Left Flush\tRight Flush"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
216
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
217 /* #### This is junk. Need correct handling of sizes. Use a Intbyte_dynarr,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
218 not a static buffer. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 static char*
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
220 displayable_menu_item (Lisp_Object gui_item, int bar_p, Emchar *accel)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 {
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 593
diff changeset
222 Bytecount ll;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
223
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 /* We construct the name in a static buffer. That's fine, because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 menu items longer than 128 chars are probably programming errors,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 and better be caught than displayed! */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
227
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 static char buf[MAX_MENUITEM_LENGTH+2];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 /* Left flush part of the string */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 ll = gui_item_display_flush_left (gui_item, buf, MAX_MENUITEM_LENGTH);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
233 ll = mswindows_translate_menu_or_dialog_item ((Intbyte *) buf, ll,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
234 MAX_MENUITEM_LENGTH, accel,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
235 XGUI_ITEM (gui_item)->name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 /* Right flush part, unless we're at the top-level where it's not allowed */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 if (!bar_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 {
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 593
diff changeset
240 Bytecount lr;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
241
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 assert (MAX_MENUITEM_LENGTH > ll + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 lr = gui_item_display_flush_right (gui_item, buf + ll + 1,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 MAX_MENUITEM_LENGTH - ll - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 if (lr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 buf [ll] = '\t';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 return buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 * hmenu_to_lisp_object() returns an opaque ptr given menu handle.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 hmenu_to_lisp_object (HMENU hmenu)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 return make_opaque_ptr (hmenu);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 * Allocation tries a hash based on item's path and name first. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 * almost guarantees that the same item will override its old value in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 * the hash table rather than abandon it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 allocate_menu_item_id (Lisp_Object path, Lisp_Object name, Lisp_Object suffix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 UINT id = MENU_ITEM_ID_BITS (HASH3 (internal_hash (path, 0),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 internal_hash (name, 0),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 internal_hash (suffix, 0)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 do {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 id = MENU_ITEM_ID_BITS (id + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 } while (GetMenuState (top_level_menu, id, MF_BYCOMMAND) != 0xFFFFFFFF);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 return make_int (id);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 static HMENU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 create_empty_popup_menu (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 return CreatePopupMenu ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 empty_menu (HMENU menu, int add_empty_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 while (DeleteMenu (menu, 0, MF_BYPOSITION));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 if (add_empty_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 AppendMenu (menu, MF_STRING | MF_GRAYED, EMPTY_ITEM_ID, EMPTY_ITEM_NAME);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 * The idea of checksumming is that we must hash minimal object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 * which is necessarily changes when the item changes. For separator
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 * this is a constant, for grey strings and submenus these are hashes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 * of names, since submenus are unpopulated until opened so always
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 * equal otherwise. For items, this is a full hash value of a callback,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 * because a callback may me a form which can be changed only somewhere
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 * in depth.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 static unsigned long
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 checksum_menu_item (Lisp_Object item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 if (STRINGP (item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 /* Separator or unselectable text - hash as a string + 13 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 if (separator_string_p (XSTRING_DATA (item)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 return 13;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 return internal_hash (item, 0) + 13;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 else if (CONSP (item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 /* Submenu - hash by its string name + 0 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 return internal_hash (XCAR(item), 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 else if (VECTORP (item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 /* An ordinary item - hash its name and callback form. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 return HASH2 (internal_hash (XVECTOR_DATA(item)[0], 0),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 internal_hash (XVECTOR_DATA(item)[1], 0));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
323
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 /* An error - will be caught later */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 populate_menu_add_item (HMENU menu, Lisp_Object path,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 Lisp_Object hash_tab, Lisp_Object item,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
331 Lisp_Object *accel_list,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 int flush_right, int bar_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 MENUITEMINFO item_info;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
335 UINT oldflags = MF_BYPOSITION;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
336 UINT olduidnewitem = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
337 LPCTSTR oldlpnewitem = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 item_info.cbSize = sizeof (item_info);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 item_info.fMask = MIIM_TYPE | MIIM_STATE | MIIM_ID;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 item_info.fState = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 item_info.wID = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 item_info.fType = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 if (STRINGP (item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 /* Separator or unselectable text */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 if (separator_string_p (XSTRING_DATA (item)))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
349 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
350 item_info.fType = MFT_SEPARATOR;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
351 oldflags |= MF_SEPARATOR;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
352 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 item_info.fType = MFT_STRING;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 item_info.fState = MFS_DISABLED;
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 563
diff changeset
357 /* !!#### mule-bogosity, fixed in my mule ws */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 563
diff changeset
358 item_info.dwTypeData = (Extbyte *) XSTRING_DATA (item);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
359 oldflags |= MF_STRING | MF_DISABLED;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
360 oldlpnewitem = item_info.dwTypeData;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 else if (CONSP (item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 /* Submenu */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 HMENU submenu;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 Lisp_Object gui_item = allocate_gui_item ();
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
368 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
369 struct gcpro gcpro1, gcpro2, gcpro3;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
370 Emchar accel;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
372 GCPRO3 (gui_item, path, *accel_list);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 menu_parse_submenu_keywords (item, gui_item);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 if (!STRINGP (pgui_item->name))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
377 invalid_argument ("Menu name (first element) must be a string",
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
378 item);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 if (!gui_item_included_p (gui_item, Vmenubar_configuration))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
381 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
382 UNGCPRO;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
383 goto done;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
384 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 if (!gui_item_active_p (gui_item))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
387 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
388 item_info.fState = MFS_GRAYED;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
389 oldflags |= MF_GRAYED;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
390 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 /* Temptation is to put 'else' right here. Although, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 displayed item won't have an arrow indicating that it is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 popup. So we go ahead a little bit more and create a popup */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
394 submenu = create_empty_popup_menu ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 item_info.fMask |= MIIM_SUBMENU;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
397 item_info.dwTypeData = displayable_menu_item (gui_item, bar_p, &accel);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 item_info.hSubMenu = submenu;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
399 olduidnewitem = (UINT) submenu;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
400 oldlpnewitem = item_info.dwTypeData;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
401 oldflags |= MF_POPUP;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
402
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
403 if (accel && bar_p)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
404 *accel_list = Fcons (make_char (accel), *accel_list);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 if (!(item_info.fState & MFS_GRAYED))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 /* Now add the full submenu path as a value to the hash table,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 keyed by menu handle */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 if (NILP(path))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 path = list1 (pgui_item->name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 Lisp_Object arg[2];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 arg[0] = path;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 arg[1] = list1 (pgui_item->name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 path = Fappend (2, arg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 Fputhash (hmenu_to_lisp_object (submenu), path, hash_tab);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
422 UNGCPRO;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
423 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 else if (VECTORP (item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 /* An ordinary item */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 Lisp_Object style, id;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 Lisp_Object gui_item = gui_parse_item_keywords (item);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
429 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
430 struct gcpro gcpro1, gcpro2;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
431 Emchar accel;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
433 GCPRO2 (gui_item, *accel_list);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 if (!gui_item_included_p (gui_item, Vmenubar_configuration))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
436 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
437 UNGCPRO;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
438 goto done;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
439 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
440
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
441 if (!STRINGP (pgui_item->name))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
442 pgui_item->name = Feval (pgui_item->name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 if (!gui_item_active_p (gui_item))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
445 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
446 item_info.fState = MFS_GRAYED;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
447 oldflags = MF_GRAYED;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
448 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 style = (NILP (pgui_item->selected) || NILP (Feval (pgui_item->selected))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 ? Qnil : pgui_item->style);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 if (EQ (style, Qradio))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 item_info.fType |= MFT_RADIOCHECK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 item_info.fState |= MFS_CHECKED;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
457 oldflags |= MF_CHECKED; /* Can't support radio-button checkmarks
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
458 under 3.51 */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 else if (EQ (style, Qtoggle))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 item_info.fState |= MFS_CHECKED;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
463 oldflags |= MF_CHECKED;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 id = allocate_menu_item_id (path, pgui_item->name,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 pgui_item->suffix);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 Fputhash (id, pgui_item->callback, hash_tab);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
470 item_info.wID = (UINT) XINT (id);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 item_info.fType |= MFT_STRING;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
472 item_info.dwTypeData = displayable_menu_item (gui_item, bar_p, &accel);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
473 olduidnewitem = item_info.wID;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
474 oldflags |= MF_STRING;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
475 oldlpnewitem = item_info.dwTypeData;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
477 if (accel && bar_p)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
478 *accel_list = Fcons (make_char (accel), *accel_list);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
479
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
480 UNGCPRO;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
483 sferror ("Malformed menu item descriptor", item);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 if (flush_right)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
486 item_info.fType |= MFT_RIGHTJUSTIFY; /* can't support in 3.51 */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
488 if (xInsertMenuItemA)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
489 xInsertMenuItemA (menu, UINT_MAX, TRUE, &item_info);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
490 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
491 InsertMenu (menu, UINT_MAX, oldflags, olduidnewitem, oldlpnewitem);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
492
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
493 done:;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
494 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 * This function is called from populate_menu and checksum_menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 * When called to populate, MENU is a menu handle, PATH is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 * list of strings representing menu path from root to this submenu,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 * DESCRIPTOR is a menu descriptor, HASH_TAB is a hash table associated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 * with root menu, BAR_P indicates whether this called for a menubar or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 * a popup, and POPULATE_P is non-zero. Return value must be ignored.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 * When called to checksum, DESCRIPTOR has the same meaning, POPULATE_P
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 * is zero, PATH must be Qnil, and the rest of parameters is ignored.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 * Return value is the menu checksum.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 static unsigned long
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 populate_or_checksum_helper (HMENU menu, Lisp_Object path, Lisp_Object desc,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 Lisp_Object hash_tab, int bar_p, int populate_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 Lisp_Object item_desc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 int deep_p, flush_right;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
513 struct gcpro gcpro1, gcpro2, gcpro3;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 unsigned long checksum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 Lisp_Object gui_item = allocate_gui_item ();
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
516 Lisp_Object accel_list = Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
517 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
518
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
519 GCPRO3 (gui_item, accel_list, desc);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 /* We are sometimes called with the menubar unchanged, and with changed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 right flush. We have to update the menubar in this case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 so account for the compliance setting in the hash value */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
524 checksum = REPLACE_ME_WITH_GLOBAL_VARIABLE_WHICH_CONTROLS_RIGHT_FLUSH;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 /* Will initially contain only "(empty)" */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 if (populate_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 empty_menu (menu, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 /* PATH set to nil indicates top-level popup or menubar */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 deep_p = !NILP (path);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 /* Fetch keywords prepending the item list */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 desc = menu_parse_submenu_keywords (desc, gui_item);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 /* Check that menu name is specified when expected */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 if (NILP (pgui_item->name) && deep_p)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
538 sferror ("Menu must have a name", desc);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 /* Apply filter if specified */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 if (!NILP (pgui_item->filter))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 desc = call1 (pgui_item->filter, desc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 /* Loop thru the desc's CDR and add items for each entry */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 flush_right = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 EXTERNAL_LIST_LOOP (item_desc, desc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 if (NILP (XCAR (item_desc)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 /* Do not flush right menubar items when MS style compliant */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
551 if (bar_p && !REPLACE_ME_WITH_GLOBAL_VARIABLE_WHICH_CONTROLS_RIGHT_FLUSH)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 flush_right = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 if (!populate_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 checksum = HASH2 (checksum, LISP_HASH (Qnil));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 else if (populate_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 populate_menu_add_item (menu, path, hash_tab,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
558 XCAR (item_desc), &accel_list,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
559 flush_right, bar_p);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 checksum = HASH2 (checksum,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 checksum_menu_item (XCAR (item_desc)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
564
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 if (populate_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 /* Remove the "(empty)" item, if there are other ones */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 if (GetMenuItemCount (menu) > 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 RemoveMenu (menu, EMPTY_ITEM_ID, MF_BYCOMMAND);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 /* Add the header to the popup, if told so. The same as in X - an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 insensitive item, and a separator (Seems to me, there were
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
573 two separators in X... In Windows this looks ugly, anyways.) */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
574 if (!bar_p && !deep_p && popup_menu_titles && !NILP (pgui_item->name))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 CHECK_STRING (pgui_item->name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 InsertMenu (menu, 0, MF_BYPOSITION | MF_STRING | MF_DISABLED,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
578 0, displayable_menu_item (gui_item, bar_p, NULL));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 InsertMenu (menu, 1, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
580 if (xSetMenuDefaultItem) /* not in NT 3.5x */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
581 xSetMenuDefaultItem (menu, 0, MF_BYPOSITION);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
584
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
585 if (bar_p)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
586 Fputhash (Qt, accel_list, hash_tab);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
587
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
588 UNGCPRO;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 return checksum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 populate_menu (HMENU menu, Lisp_Object path, Lisp_Object desc,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
594 Lisp_Object hash_tab, int bar_p)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 populate_or_checksum_helper (menu, path, desc, hash_tab, bar_p, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 static unsigned long
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 checksum_menu (Lisp_Object desc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 return populate_or_checksum_helper (NULL, Qnil, desc, Qunbound, 0, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 static void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
606 update_frame_menubar_maybe (struct frame *f)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 HMENU menubar = GetMenu (FRAME_MSWINDOWS_HANDLE (f));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 struct window *w = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 Lisp_Object desc = (!NILP (w->menubar_visible_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 ? symbol_value_in_buffer (Qcurrent_menubar, w->buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 : Qnil);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
613 struct gcpro gcpro1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
614
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
615 GCPRO1 (desc); /* it's safest to do this, just in case some filter
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
616 or something changes the value of current-menubar */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 top_level_menu = menubar;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 if (NILP (desc) && menubar != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 /* Menubar has gone */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
623 FRAME_MSWINDOWS_MENU_HASH_TABLE (f) = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 SetMenu (FRAME_MSWINDOWS_HANDLE (f), NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 DestroyMenu (menubar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 DrawMenuBar (FRAME_MSWINDOWS_HANDLE (f));
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
627 UNGCPRO;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 if (!NILP (desc) && menubar == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 /* Menubar has appeared */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 menubar = CreateMenu ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 goto populate;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 if (NILP (desc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 /* We did not have the bar and are not going to */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
641 UNGCPRO;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 /* Now we bail out if the menubar has not changed */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
646 if (FRAME_MSWINDOWS_MENU_CHECKSUM (f) == checksum_menu (desc))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
647 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
648 UNGCPRO;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
649 return;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
650 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 populate:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 /* Come with empty hash table */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
654 if (NILP (FRAME_MSWINDOWS_MENU_HASH_TABLE (f)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
655 FRAME_MSWINDOWS_MENU_HASH_TABLE (f) =
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 make_lisp_hash_table (50, HASH_TABLE_NON_WEAK, HASH_TABLE_EQUAL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 else
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
658 Fclrhash (FRAME_MSWINDOWS_MENU_HASH_TABLE (f));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 Fputhash (hmenu_to_lisp_object (menubar), Qnil,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
661 FRAME_MSWINDOWS_MENU_HASH_TABLE (f));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 populate_menu (menubar, Qnil, desc,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
663 FRAME_MSWINDOWS_MENU_HASH_TABLE (f), 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 SetMenu (FRAME_MSWINDOWS_HANDLE (f), menubar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 DrawMenuBar (FRAME_MSWINDOWS_HANDLE (f));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
667 FRAME_MSWINDOWS_MENU_CHECKSUM (f) = checksum_menu (desc);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
668
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
669 UNGCPRO;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 prune_menubar (struct frame *f)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 HMENU menubar = GetMenu (FRAME_MSWINDOWS_HANDLE (f));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 Lisp_Object desc = current_frame_menubar (f);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
677 struct gcpro gcpro1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
678
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 if (menubar == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 /* #### If a filter function has set desc to Qnil, this abort()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 triggers. To resolve, we must prevent filters explicitly from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 mangling with the active menu. In apply_filter probably?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 Is copy-tree on the whole menu too expensive? */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
686 if (NILP (desc))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 /* abort(); */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
690 GCPRO1 (desc); /* just to be safe -- see above */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 /* We do the trick by removing all items and re-populating top level */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 empty_menu (menubar, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
694 assert (HASH_TABLEP (FRAME_MSWINDOWS_MENU_HASH_TABLE (f)));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
695 Fclrhash (FRAME_MSWINDOWS_MENU_HASH_TABLE (f));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 Fputhash (hmenu_to_lisp_object (menubar), Qnil,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
698 FRAME_MSWINDOWS_MENU_HASH_TABLE (f));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
699 populate_menu (menubar, Qnil, desc,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
700 FRAME_MSWINDOWS_MENU_HASH_TABLE (f), 1);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
701 UNGCPRO;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 * This is called when cleanup is possible. It is better not to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 * clean things up at all than do it too early!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 menu_cleanup (struct frame *f)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 current_menudesc = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 current_hash_table = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 prune_menubar (f);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
716
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
717 int
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
718 mswindows_char_is_accelerator (struct frame *f, Emchar ch)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
719 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
720 Lisp_Object hash = FRAME_MSWINDOWS_MENU_HASH_TABLE (f);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
721
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
722 if (NILP (hash))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
723 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
724 /* !!#### not Mule-ized */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
725 return !NILP (memq_no_quit (make_char (tolower (ch)),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
726 Fgethash (Qt, hash, Qnil)));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
727 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
728
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 /*------------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 /* Message handlers */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 /*------------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 static Lisp_Object
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
734 unsafe_handle_wm_initmenupopup_1 (HMENU menu, struct frame *f)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 /* This function can call lisp, beat dogs and stick chewing gum to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 everything! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 Lisp_Object path, desc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 struct gcpro gcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 /* Find which guy is going to explode */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 path = Fgethash (hmenu_to_lisp_object (menu), current_hash_table, Qunbound);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 assert (!UNBOUNDP (path));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 #ifdef DEBUG_XEMACS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 /* Allow to continue in a debugger after assert - not so fatal */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 if (UNBOUNDP (path))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
748 signal_error (Qinternal_error, "internal menu error", Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 /* Now find a desc chunk for it. If none, then probably menu open
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 hook has played too much games around stuff */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 desc = Fmenu_find_real_submenu (current_menudesc, path);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 if (NILP (desc))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
755 invalid_state ("This menu does not exist any more", path);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 /* Now, stuff it */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 /* DESC may be generated by filter, so we have to gcpro it */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 GCPRO1 (desc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 populate_menu (menu, path, desc, current_hash_table, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 return Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 static Lisp_Object
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
766 unsafe_handle_wm_initmenu_1 (struct frame *f)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 /* This function can call lisp */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 /* NOTE: This is called for the bar only, WM_INITMENU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 for popups is filtered out */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 /* #### - this menubar update mechanism is expensively anti-social and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 the activate-menubar-hook is now mostly obsolete. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 /* We simply ignore return value. In any case, we construct the bar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 on the fly */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 run_hook (Qactivate_menubar_hook);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 update_frame_menubar_maybe (f);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 current_menudesc = current_frame_menubar (f);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
783 current_hash_table = FRAME_MSWINDOWS_MENU_HASH_TABLE (f);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 assert (HASH_TABLEP (current_hash_table));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 return Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 * Return value is Qt if we have dispatched the command,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 * or Qnil if id has not been mapped to a callback.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 * Window procedure may try other targets to route the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 * command if we return nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 Lisp_Object
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
796 mswindows_handle_wm_command (struct frame *f, WORD id)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 /* Try to map the command id through the proper hash table */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 Lisp_Object data, fn, arg, frame;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 struct gcpro gcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 if (NILP (current_hash_table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 data = Fgethash (make_int (id), current_hash_table, Qunbound);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 if (UNBOUNDP (data))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 menu_cleanup (f);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 /* Need to gcpro because the hash table may get destroyed by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 menu_cleanup(), and will not gcpro the data any more */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 GCPRO1 (data);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 menu_cleanup (f);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 /* Ok, this is our one. Enqueue it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 get_gui_callback (data, &fn, &arg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 XSETFRAME (frame, f);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 /* this used to call mswindows_enqueue_misc_user_event but that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 breaks customize because the misc_event gets eval'ed in some
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
823 circumstances. Don't change it back unless you can fix the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 customize problem also.*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 enqueue_misc_user_event (frame, fn, arg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 UNGCPRO; /* data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 return Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 /*------------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 /* Message handling proxies */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 /*------------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 static HMENU wm_initmenu_menu;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
838 static struct frame *wm_initmenu_frame;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 unsafe_handle_wm_initmenupopup (Lisp_Object u_n_u_s_e_d)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 return unsafe_handle_wm_initmenupopup_1 (wm_initmenu_menu, wm_initmenu_frame);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 unsafe_handle_wm_initmenu (Lisp_Object u_n_u_s_e_d)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 return unsafe_handle_wm_initmenu_1 (wm_initmenu_frame);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 Lisp_Object
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
853 mswindows_handle_wm_initmenupopup (HMENU hmenu, struct frame *frm)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 /* We cannot pass hmenu as a lisp object. Use static var */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 wm_initmenu_menu = hmenu;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 wm_initmenu_frame = frm;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 return mswindows_protect_modal_loop (unsafe_handle_wm_initmenupopup, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 Lisp_Object
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
862 mswindows_handle_wm_initmenu (HMENU hmenu, struct frame *f)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 /* Handle only frame menubar, ignore if from popup or system menu */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
865 if (GetMenu (FRAME_MSWINDOWS_HANDLE (f)) == hmenu)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 wm_initmenu_frame = f;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 return mswindows_protect_modal_loop (unsafe_handle_wm_initmenu, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 return Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 /*------------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 /* Methods */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 /*------------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 static void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
879 mswindows_update_frame_menubars (struct frame *f)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 update_frame_menubar_maybe (f);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 static void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
885 mswindows_free_frame_menubars (struct frame *f)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
887 FRAME_MSWINDOWS_MENU_HASH_TABLE (f) = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 mswindows_popup_menu (Lisp_Object menu_desc, Lisp_Object event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 struct frame *f = selected_frame ();
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
894 Lisp_Event *eev = NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 HMENU menu;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 POINT pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 int ok;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
898 struct gcpro gcpro1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
899
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
900 GCPRO1 (menu_desc); /* to be safe -- see above */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 if (!NILP (event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 CHECK_LIVE_EVENT (event);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 eev = XEVENT (event);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 if (eev->event_type != button_press_event
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 && eev->event_type != button_release_event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 wrong_type_argument (Qmouse_event_p, event);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 else if (!NILP (Vthis_command_keys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 /* if an event wasn't passed, use the last event of the event sequence
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 currently being executed, if that event is a mouse event */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 eev = XEVENT (Vthis_command_keys); /* last event first */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 if (eev->event_type != button_press_event
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 && eev->event_type != button_release_event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 eev = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 /* Default is to put the menu at the point (10, 10) in frame */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 if (eev)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 pt.x = eev->event.button.x;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 pt.y = eev->event.button.y;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 ClientToScreen (FRAME_MSWINDOWS_HANDLE (f), &pt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 pt.x = pt.y = 10;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 if (SYMBOLP (menu_desc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 menu_desc = Fsymbol_value (menu_desc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 CHECK_CONS (menu_desc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 CHECK_STRING (XCAR (menu_desc));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 current_menudesc = menu_desc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 current_hash_table =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 make_lisp_hash_table (10, HASH_TABLE_NON_WEAK, HASH_TABLE_EQUAL);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
938 menu = create_empty_popup_menu ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 Fputhash (hmenu_to_lisp_object (menu), Qnil, current_hash_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 top_level_menu = menu;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
941
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 /* see comments in menubar-x.c */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 if (zmacs_regions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 zmacs_region_stays = 1;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
945
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 ok = TrackPopupMenu (menu,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 pt.x, pt.y, 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 FRAME_MSWINDOWS_HANDLE (f), NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 DestroyMenu (menu);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 /* Signal a signal if caught by Track...() modal loop */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 mswindows_unmodalize_signal_maybe ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 /* This is probably the only real reason for failure */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
957 if (!ok)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
958 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
959 menu_cleanup (f);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
960 invalid_operation ("Cannot track popup menu while in menu",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 442
diff changeset
961 menu_desc);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
962 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
963 UNGCPRO;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 /*------------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 /* Initialization */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 /*------------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 syms_of_menubar_mswindows (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 console_type_create_menubar_mswindows (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 CONSOLE_HAS_METHOD (mswindows, update_frame_menubars);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 CONSOLE_HAS_METHOD (mswindows, free_frame_menubars);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 CONSOLE_HAS_METHOD (mswindows, popup_menu);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 vars_of_menubar_mswindows (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 current_menudesc = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 current_hash_table = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 staticpro (&current_menudesc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 staticpro (&current_hash_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 }