/* Menu support for GNU Emacs on the for Mac OS.
- Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU Emacs.
#include "charset.h"
#include "coding.h"
-#ifdef MAC_OSX
-#undef mktime
-#undef DEBUG
-#undef Z
-#undef free
-#undef malloc
-#undef realloc
-/* Macros max and min defined in lisp.h conflict with those in
- precompiled header Carbon.h. */
-#undef max
-#undef min
-#undef init_process
-#include <Carbon/Carbon.h>
-#undef Z
-#define Z (current_buffer->text->z)
-#undef free
-#define free unexec_free
-#undef malloc
-#define malloc unexec_malloc
-#undef realloc
-#define realloc unexec_realloc
-#undef min
-#define min(a, b) ((a) < (b) ? (a) : (b))
-#undef max
-#define max(a, b) ((a) > (b) ? (a) : (b))
-#undef init_process
-#define init_process emacs_init_process
-#else /* not MAC_OSX */
+#ifndef MAC_OSX
#include <MacTypes.h>
#include <Menus.h>
#include <QuickDraw.h>
typedef struct _widget_value
{
/* name of widget */
+ Lisp_Object lname;
char* name;
/* value (meaning depend on widget type) */
char* value;
/* keyboard equivalent. no implications for XtTranslations */
+ Lisp_Object lkey;
char* key;
/* Help string or nil if none.
GC finds this string through the frame's menu_bar_vector
extern Lisp_Object Qmenu_bar_update_hook;
+#if TARGET_API_MAC_CARBON
+#define ENCODE_MENU_STRING(str) ENCODE_UTF_8 (str)
+#else
+#define ENCODE_MENU_STRING(str) ENCODE_SYSTEM (str)
+#endif
+
void set_frame_menubar ();
static void push_menu_item P_ ((Lisp_Object, Lisp_Object, Lisp_Object,
CHECK_LIVE_WINDOW (window);
f = XFRAME (WINDOW_FRAME (XWINDOW (window)));
- xpos = (FONT_WIDTH (FRAME_FONT (f))
- * XFASTINT (XWINDOW (window)->left));
- ypos = (FRAME_LINE_HEIGHT (f)
- * XFASTINT (XWINDOW (window)->top));
+ xpos = WINDOW_LEFT_EDGE_X (XWINDOW (window));
+ ypos = WINDOW_TOP_EDGE_Y (XWINDOW (window));
}
else
/* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME,
int j;
struct input_event buf;
Lisp_Object frame;
+ EVENT_INIT (buf);
XSETFRAME (frame, f);
buf.kind = MENU_BAR_EVENT;
save_wv->next = wv;
else
first_wv->contents = wv;
- wv->name = pane_string;
- /* Ignore the @ that means "separate pane".
- This is a kludge, but this isn't worth more time. */
- if (!NILP (prefix) && wv->name[0] == '@')
- wv->name++;
- wv->value = 0;
+ wv->lname = pane_name;
+ /* Set value to 1 so update_submenu_strings can handle '@' */
+ wv->value = (char *)1;
wv->enabled = 1;
wv->button_type = BUTTON_TYPE_NONE;
wv->help = Qnil;
#ifndef HAVE_MULTILINGUAL_MENU
if (STRING_MULTIBYTE (item_name))
{
- item_name = ENCODE_SYSTEM (item_name);
+ item_name = ENCODE_MENU_STRING (item_name);
AREF (menu_items, i + MENU_ITEMS_ITEM_NAME) = item_name;
}
if (STRINGP (descrip) && STRING_MULTIBYTE (descrip))
{
- descrip = ENCODE_SYSTEM (descrip);
+ descrip = ENCODE_MENU_STRING (descrip);
AREF (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY) = descrip;
}
#endif /* not HAVE_MULTILINGUAL_MENU */
else
save_wv->contents = wv;
- wv->name = (char *) SDATA (item_name);
+ wv->lname = item_name;
if (!NILP (descrip))
- wv->key = (char *) SDATA (descrip);
+ wv->lkey = descrip;
wv->value = 0;
/* The EMACS_INT cast avoids a warning. There's no problem
as long as pointers have enough bits to hold small integers. */
return first_wv;
}
+/* Walk through the widget_value tree starting at FIRST_WV and update
+ the char * pointers from the corresponding lisp values.
+ We do this after building the whole tree, since GC may happen while the
+ tree is constructed, and small strings are relocated. So we must wait
+ until no GC can happen before storing pointers into lisp values. */
+static void
+update_submenu_strings (first_wv)
+ widget_value *first_wv;
+{
+ widget_value *wv;
+
+ for (wv = first_wv; wv; wv = wv->next)
+ {
+ if (STRINGP (wv->lname))
+ {
+ wv->name = SDATA (wv->lname);
+
+ /* Ignore the @ that means "separate pane".
+ This is a kludge, but this isn't worth more time. */
+ if (wv->value == (char *)1)
+ {
+ if (wv->name[0] == '@')
+ wv->name++;
+ wv->value = 0;
+ }
+ }
+
+ if (STRINGP (wv->lkey))
+ wv->key = SDATA (wv->lkey);
+
+ if (wv->contents)
+ update_submenu_strings (wv->contents);
+ }
+}
+
\f
/* Set the contents of the menubar widgets of frame F.
The argument FIRST_TIME is currently ignored;
items = FRAME_MENU_BAR_ITEMS (f);
- inhibit_garbage_collection ();
-
/* Save the frame's previous menu bar contents data. */
if (previous_menu_items_used)
bcopy (XVECTOR (f->menu_bar_vector)->contents, previous_items,
for (i = 0; i < previous_menu_items_used; i++)
if (menu_items_used == i
- || (!Fequal (previous_items[i], XVECTOR (menu_items)->contents[i])))
+ || (NILP (Fequal (previous_items[i],
+ XVECTOR (menu_items)->contents[i]))))
break;
if (i == menu_items_used && i == previous_menu_items_used && i != 0)
{
if (NILP (string))
break;
wv->name = (char *) SDATA (string);
+ update_submenu_strings (wv->contents);
wv = wv->next;
}
#ifndef HAVE_MULTILINGUAL_MENU
if (STRINGP (item_name) && STRING_MULTIBYTE (item_name))
{
- item_name = ENCODE_SYSTEM (item_name);
+ item_name = ENCODE_MENU_STRING (item_name);
AREF (menu_items, i + MENU_ITEMS_ITEM_NAME) = item_name;
}
if (STRINGP (descrip) && STRING_MULTIBYTE (descrip))
{
- descrip = ENCODE_SYSTEM (descrip);
+ descrip = ENCODE_MENU_STRING (descrip);
AREF (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY) = descrip;
}
#endif /* not HAVE_MULTILINGUAL_MENU */
#ifndef HAVE_MULTILINGUAL_MENU
if (STRING_MULTIBYTE (title))
- title = ENCODE_SYSTEM (title);
+ title = ENCODE_MENU_STRING (title);
#endif
wv_title->name = (char *) SDATA (title);
wv_title->enabled = TRUE;
pos.h = x;
pos.v = y;
-#if TARGET_API_MAC_CARBON
- SetPort (GetWindowPort (FRAME_MAC_WINDOW (f)));
-#else
- SetPort (FRAME_MAC_WINDOW (f));
-#endif
+ SetPortWindowPort (FRAME_MAC_WINDOW (f));
LocalToGlobal (&pos);
/* Get the refcon to find the correct item*/
if (menu_item_selection)
{
- menu = GetMenuHandle (HiWord (menu_item_choice));
- if (menu) {
- GetMenuItemRefCon (menu, menu_item_selection, &refcon);
+ MenuHandle sel_menu = GetMenuHandle (HiWord (menu_item_choice));
+ if (sel_menu) {
+ GetMenuItemRefCon (sel_menu, menu_item_selection, &refcon);
}
}
discard_mouse_events ();
#endif
+ /* Must reset this manually because the button release event is not
+ passed to Emacs event loop. */
+ FRAME_MAC_DISPLAY_INFO (f)->grabbed = 0;
+
/* Free the widget_value objects we used to specify the
contents. */
free_menubar_widget_value_tree (first_wv);
{
int i = MIN_POPUP_SUBMENU_ID;
MenuHandle submenu = GetMenuHandle (i);
- while (menu != NULL)
+ while (submenu != NULL)
{
DeleteMenu (i);
- DisposeMenu (menu);
- menu = GetMenuHandle (++i);
+ DisposeMenu (submenu);
+ submenu = GetMenuHandle (++i);
}
}
window_ptr = GetNewCWindow (DIALOG_WINDOW_RESOURCE, NULL, (WindowPtr) -1);
-#if TARGET_API_MAC_CARBON
- SetPort (GetWindowPort (window_ptr));
-#else
- SetPort (window_ptr);
-#endif
+ SetPortWindowPort (window_ptr);
TextFont (0);
/* Left and right margins in the dialog are 13 pixels each.*/
SizeWindow (window_ptr, dialog_width, 78, 0);
ShowWindow (window_ptr);
-#if TARGET_API_MAC_CARBON
- SetPort (GetWindowPort (window_ptr));
-#else
- SetPort (window_ptr);
-#endif
+ SetPortWindowPort (window_ptr);
TextFont (0);
int force_disable)
{
Str255 item_name;
- int pos, i;
+ int pos;
if (name_is_separator (wv->name))
AppendMenu (menu, "\p-");
strncat (item_name, wv->key, 255);
}
item_name[255] = 0;
+#if TARGET_API_MAC_CARBON
+ {
+ CFStringRef string = cfstring_create_with_utf8_cstring (item_name);
+
+ SetMenuItemTextWithCFString (menu, pos, string);
+ CFRelease (string);
+ }
+#else
c2pstr (item_name);
SetMenuItemText (menu, pos, item_name);
+#endif
if (wv->enabled && !force_disable)
#if TARGET_API_MAC_CARBON
else
SetItemMark (menu, pos, noMark);
}
- }
- SetMenuItemRefCon (menu, pos, (UInt32) wv->call_data);
+ SetMenuItemRefCon (menu, pos, (UInt32) wv->call_data);
+ }
if (submenu != NULL)
SetMenuItemHierarchicalID (menu, pos, submenu);
defsubr (&Sx_popup_dialog);
#endif
}
+
+/* arch-tag: 40b2c6c7-b8a9-4a49-b930-1b2707184cce
+ (do not change this comment) */