emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: UI issue: inactive menu entries and icons


From: YAMAMOTO Mitsuharu
Subject: Re: UI issue: inactive menu entries and icons
Date: Sat, 30 Dec 2006 15:49:14 +0900
User-agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (Shijō) APEL/10.6 Emacs/22.0.92 (sparc-sun-solaris2.8) MULE/5.0 (SAKAKI)

>>>>> On Wed, 27 Dec 2006 18:24:55 +0100, Jan Djärv <address@hidden> said:

> I agree, but it is very hard (impossible?) to do in some toolkits.
> For example, inactive usually means that no events whatsoever are
> generated for those icons/buttons.  Things like Enter and Leave
> events that are used to determine what tooltip to show.

This reminds me that help echo strings for menu items are not
shown in any fashion on Mac Carbon.  As showing tooltip looks
really weird (and requires not-too-small change, I guess) on this
environment, they are shown in the echo area regardless of the
value of show-help-function by the patch below.  Fortunately,
targeting an inactive menu item also generates some event.

If there's no problem with this, I'll install it later (not now,
because I'm out of my usual development environment).

                                     YAMAMOTO Mitsuharu
                                address@hidden

Index: src/macmenu.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/macmenu.c,v
retrieving revision 1.48
diff -c -p -r1.48 macmenu.c
*** src/macmenu.c       14 Nov 2006 08:22:04 -0000      1.48
--- src/macmenu.c       30 Dec 2006 06:32:10 -0000
*************** update_submenu_strings (first_wv)
*** 1450,1455 ****
--- 1450,1535 ----
  }
  
  
+ #if TARGET_API_MAC_CARBON
+ extern Lisp_Object Vshow_help_function;
+ 
+ static Lisp_Object
+ restore_show_help_function (old_show_help_function)
+      Lisp_Object old_show_help_function;
+ {
+   Vshow_help_function = old_show_help_function;
+ 
+   return Qnil;
+ }
+ 
+ static pascal OSStatus
+ menu_target_item_handler (next_handler, event, data)
+      EventHandlerCallRef next_handler;
+      EventRef event;
+      void *data;
+ {
+   OSStatus err, result;
+   MenuRef menu;
+   MenuItemIndex menu_item;
+   Lisp_Object help;
+ #ifdef MAC_OS8
+   GrafPtr port;
+ #endif
+   int specpdl_count = SPECPDL_INDEX ();
+ 
+   result = CallNextEventHandler (next_handler, event);
+ 
+   err = GetEventParameter (event, kEventParamDirectObject, typeMenuRef,
+                          NULL, sizeof (MenuRef), NULL, &menu);
+   if (err == noErr)
+     err = GetEventParameter (event, kEventParamMenuItemIndex,
+                            typeMenuItemIndex, NULL,
+                            sizeof (MenuItemIndex), NULL, &menu_item);
+   if (err == noErr)
+     err = GetMenuItemProperty (menu, menu_item,
+                              MAC_EMACS_CREATOR_CODE, 'help',
+                              sizeof (Lisp_Object), NULL, &help);
+   if (err != noErr)
+     help = Qnil;
+ 
+   /* Temporarily bind Vshow_help_function to Qnil because we don't
+      want tooltips during menu tracking.  */
+   record_unwind_protect (restore_show_help_function, Vshow_help_function);
+   Vshow_help_function = Qnil;
+ #ifdef MAC_OS8
+   GetPort (&port);
+ #endif
+   show_help_echo (help, Qnil, Qnil, Qnil, 1);
+ #ifdef MAC_OS8
+   SetPort (port);
+ #endif
+   unbind_to (specpdl_count, Qnil);
+ 
+   return err == noErr ? noErr : result;
+ }
+ #endif
+ 
+ OSStatus
+ install_menu_target_item_handler (window)
+      WindowPtr window;
+ {
+   OSStatus err = noErr;
+ #if TARGET_API_MAC_CARBON
+   static const EventTypeSpec specs[] =
+     {{kEventClassMenu, kEventMenuTargetItem}};
+   static EventHandlerUPP menu_target_item_handlerUPP = NULL;
+ 
+   if (menu_target_item_handlerUPP == NULL)
+     menu_target_item_handlerUPP =
+       NewEventHandlerUPP (menu_target_item_handler);
+ 
+   err = InstallWindowEventHandler (window, menu_target_item_handlerUPP,
+                                  GetEventTypeCount (specs), specs,
+                                  NULL, NULL);
+ #endif
+   return err;
+ }
+ 
  /* Event handler function that pops down a menu on C-g.  We can only pop
     down menus if CancelMenuTracking is present (OSX 10.3 or later).  */
  
*************** add_menu_item (menu, pos, wv)
*** 2485,2490 ****
--- 2565,2574 ----
          EnableMenuItem (menu, pos);
        else
          DisableMenuItem (menu, pos);
+ 
+       if (STRINGP (wv->help))
+       SetMenuItemProperty (menu, pos, MAC_EMACS_CREATOR_CODE, 'help',
+                            sizeof (Lisp_Object), &wv->help);
  #else  /* ! TARGET_API_MAC_CARBON */
        item_name[sizeof (item_name) - 1] = '\0';
        strncpy (item_name, wv->name, sizeof (item_name) - 1);
Index: src/macterm.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/macterm.c,v
retrieving revision 1.199
diff -c -p -r1.199 macterm.c
*** src/macterm.c       15 Dec 2006 08:05:35 -0000      1.199
--- src/macterm.c       30 Dec 2006 06:32:11 -0000
*************** void remove_drag_handler P_ ((WindowRef)
*** 8746,8751 ****
--- 8746,8755 ----
  extern void init_service_handler ();
  static Lisp_Object Qservice, Qpaste, Qperform;
  #endif
+ 
+ /* Showing help echo string during menu tracking  */ 
+ extern OSStatus install_menu_target_item_handler P_ ((WindowPtr));
+ 
  /* Window Event Handler */
  static pascal OSStatus mac_handle_window_event (EventHandlerCallRef,
                                                EventRef, void *);
*************** install_window_handler (window)
*** 10168,10173 ****
--- 10172,10179 ----
  #endif
    if (err == noErr)
      err = install_drag_handler (window);
+   if (err == noErr)
+     err = install_menu_target_item_handler (window);
  
    return err;
  }
Index: src/macterm.h
===================================================================
RCS file: /cvsroot/emacs/emacs/src/macterm.h,v
retrieving revision 1.50
diff -c -p -r1.50 macterm.h
*** src/macterm.h       15 Dec 2006 08:05:42 -0000      1.50
--- src/macterm.h       30 Dec 2006 06:32:11 -0000
*************** struct scroll_bar {
*** 531,536 ****
--- 531,541 ----
  #define HOURGLASS_HEIGHT 16
  
  /* Some constants that are used locally.  */
+ /* Creator code for Emacs on Mac OS.  */
+ enum {
+   MAC_EMACS_CREATOR_CODE      = 'EMAx'
+ };
+ 
  /* Apple event descriptor types */
  enum {
    TYPE_FILE_NAME              = 'fNam'




reply via email to

[Prev in Thread] Current Thread [Next in Thread]