view lwlib/lwlib-Xlw.c @ 74984:21f28d10d73a

Merge from gnus--rel--5.10 Patches applied: * gnus--rel--5.10 (patch 179-183) - Update from CVS 2006-12-25 Daiki Ueno <ueno@unixuser.org> * lisp/pgg-def.el (pgg-passphrase-coding-system): Default to nil instead of locale-coding-system. * lisp/pgg-gpg.el (pgg-gpg-process-region): Encode passphrase with eol-type LF. 2006-12-29 Jouni K. Sepp,Ad(Bnen <jks@iki.fi> * lisp/gnus/nnimap.el (nnimap-expunge-search-string): Mention nnimap-search-uids-not-since-is-evil in docstring. 2006-12-28 Reiner Steib <Reiner.Steib@gmx.de> * lisp/gnus/spam.el: Revert to make-obsolete-variable because define-obsolete-variable-alias is not supported in Emacs 21. 2006-12-28 Daiki Ueno <ueno@unixuser.org> * lisp/gnus/gnus-sum.el (gnus-summary-next-article): Make sure we are in the summary buffer. 2006-12-27 Reiner Steib <Reiner.Steib@gmx.de> * lisp/gnus/spam.el (spam-ifile-path, spam-ifile-database-path) (spam-bogofilter-path): Use define-obsolete-variable-alias instead of make-obsolete-variable. 2006-12-26 Reiner Steib <Reiner.Steib@gmx.de> * lisp/gnus/message.el (message-make-fqdn): Fix comment. (message-bogus-system-names): Add ".local". * lisp/gnus/spam.el (spam-ifile-path, spam-ifile-program) (spam-ifile-database-path, spam-ifile-database) (spam-bogofilter-path, spam-bogofilter-program): Rename variables. Don't use "path" inappropriately. (spam-spamoracle-database, spam-get-ifile-database-parameter): Fix doc strings. (spam-check-ifile, spam-ifile-register-with-ifile) (spam-check-bogofilter, spam-bogofilter-register-with-bogofilter): Use new variable names. * lisp/gnus/gnus-art.el (gnus-treat-display-x-face, gnus-treat-display-face) (gnus-treat-display-smileys): Simplify using gnus-image-type-available-p. * lisp/gnus/gnus-ems.el (gnus-image-type-available-p): Use display-images-p if available. 2006-12-22 Katsumi Yamaoka <yamaoka@jpl.org> * lisp/gnus/nnrss.el (nnrss-fetch): Replace buffer's contents with the decoded one after turning on the buffer's multibyteness instead of decoding them directly in the unibyte buffer that causes unexpected conversion in Emacs 23 (unicode). 2006-12-29 Reiner Steib <Reiner.Steib@gmx.de> * man/gnus.texi (Customizing Articles): Add index entries for all gnus-treat-* variables. 2006-12-29 Jouni K. Sepp,Ad(Bnen <jks@iki.fi> * man/gnus.texi (IMAP): Fix incorrect explanation of nnimap-search-uids-not-since-is-evil in documentation for nnimap-expunge-search-string. 2006-12-27 Reiner Steib <Reiner.Steib@gmx.de> * man/gnus.texi (ifile spam filtering): Rename spam-ifile-database-path to spam-ifile-database. 2006-12-26 Reiner Steib <Reiner.Steib@gmx.de> * man/gnus.texi (Spam Package Configuration Examples): Don't encourage to rebind C-s. 2006-12-26 Jouni K. Sepp,Ad(Bnen <jks@iki.fi> * man/gnus.texi (Group Parameters, Group Maintenance, Topic Commands) (Mail Group Commands, Expiring Mail, IMAP): Add index entries for "expiring mail". (IMAP): Document nnimap-search-uids-not-since-is-evil and nnimap-nov-is-evil. Revision: emacs@sv.gnu.org/emacs--devo--0--patch-576
author Miles Bader <miles@gnu.org>
date Sat, 30 Dec 2006 15:34:42 +0000
parents e8a3fb527b77
children 6be52bf115d4 c5406394f567
line wrap: on
line source

/* The lwlib interface to "xlwmenu" menus.
   Copyright (C) 1992 Lucid, Inc.
   Copyright (C) 1994, 2000, 2001, 2002, 2003, 2004,
                 2005, 2006 Free Software Foundation, Inc.

This file is part of the Lucid Widget Library.

The Lucid Widget Library 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 1, or (at your option)
any later version.

The Lucid Widget Library 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 GNU Emacs; see the file COPYING.  If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.  */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "lisp.h"

#include "lwlib-Xlw.h"
#include <X11/StringDefs.h>
#include <X11/IntrinsicP.h>
#include <X11/ObjectP.h>
#include <X11/CompositeP.h>
#include <X11/Shell.h>
#include "xlwmenu.h"

#if 0

#include <stdio.h>

/* Print the complete X resource name of widget WIDGET to stderr.
   This is sometimes handy to have available.  */

void
x_print_complete_resource_name (widget)
     Widget widget;
{
  int i;
  String names[100];

  for (i = 0; i < 100 && widget != NULL; ++i)
    {
      names[i] = XtName (widget);
      widget = XtParent (widget);
    }

  for (--i; i >= 1; --i)
    fprintf (stderr, "%s.", names[i]);
  fprintf (stderr, "%s\n", names[0]);
}

#endif /* 0 */


/* Menu callbacks */

/* Callback XtNhighlightCallback for Lucid menus.  W is the menu
   widget, CLIENT_DATA contains a pointer to the widget_instance
   for the menu, CALL_DATA contains a pointer to the widget_value
   structure for the highlighted menu item.  The latter may be null
   if there isn't any highlighted menu item.  */

static void
highlight_hook (w, client_data, call_data)
     Widget w;
     XtPointer client_data;
     XtPointer call_data;
{
  widget_instance *instance = (widget_instance *) client_data;

  if (instance->info->highlight_cb
      && !w->core.being_destroyed)
    instance->info->highlight_cb (w, instance->info->id, call_data);
}

static void
pre_hook (w, client_data, call_data)
     Widget w;
     XtPointer client_data;
     XtPointer call_data;
{
  widget_instance* instance = (widget_instance*)client_data;
  widget_value* val;

  if (w->core.being_destroyed)
    return;

  val = lw_get_widget_value_for_widget (instance, w);
  if (instance->info->pre_activate_cb)
    instance->info->pre_activate_cb (w, instance->info->id,
				     val ? val->call_data : NULL);
}

static void
pick_hook (w, client_data, call_data)
     Widget w;
     XtPointer client_data;
     XtPointer call_data;
{
  widget_instance* instance = (widget_instance*)client_data;
  widget_value* contents_val = (widget_value*)call_data;
  widget_value* widget_val;
  XtPointer widget_arg;

  if (w->core.being_destroyed)
    return;

  if (instance->info->selection_cb && contents_val && contents_val->enabled
      && !contents_val->contents)
    instance->info->selection_cb (w, instance->info->id,
				  contents_val->call_data);

  widget_val = lw_get_widget_value_for_widget (instance, w);
  widget_arg = widget_val ? widget_val->call_data : NULL;
  if (instance->info->post_activate_cb)
    instance->info->post_activate_cb (w, instance->info->id, widget_arg);

}

/* creation functions */

static Widget
xlw_create_menubar (instance)
     widget_instance* instance;
{
  Widget widget;
  Arg al[5];
  int ac = 0;

  XtSetArg (al[ac], XtNmenu, instance->info->val); ac++;
#ifdef emacs
  XtSetArg (al[ac], XtNshowGrip, 0); ac++;
  XtSetArg (al[ac], XtNresizeToPreferred, 1); ac++;
  XtSetArg (al[ac], XtNallowResize, 1); ac++;
#endif

  /* This used to use XtVaCreateWidget, but an old Xt version
     has a bug in XtVaCreateWidget that frees instance->info->name.  */
  widget
    = XtCreateWidget (instance->info->name, xlwMenuWidgetClass,
		      instance->parent, al, ac);

  XtAddCallback (widget, XtNopen, pre_hook, (XtPointer)instance);
  XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
  XtAddCallback (widget, XtNhighlightCallback, highlight_hook,
		 (XtPointer)instance);
  return widget;
}

static Widget
xlw_create_popup_menu (instance)
     widget_instance* instance;
{
  Widget popup_shell
    = XtCreatePopupShell (instance->info->name, overrideShellWidgetClass,
			  instance->parent, NULL, 0);

  Widget widget;
  Arg al[2];
  int ac = 0;

  XtSetArg (al[ac], XtNmenu, instance->info->val); ac++;
  XtSetArg (al[ac], XtNhorizontal, False); ac++;

  /* This used to use XtVaManagedCreateWidget, but an old Xt version
     has a bug in XtVaManagedCreateWidget that frees instance->info->name.  */
  widget
    = XtCreateManagedWidget ("popup", xlwMenuWidgetClass,
			     popup_shell, al, ac);

  XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
  XtAddCallback (widget, XtNhighlightCallback, highlight_hook,
		 (XtPointer)instance);

  return popup_shell;
}

widget_creation_entry
xlw_creation_table [] =
{
  {"menubar", xlw_create_menubar},
  {"popup", xlw_create_popup_menu},
  {NULL, NULL}
};

Boolean
lw_lucid_widget_p (widget)
     Widget widget;
{
  WidgetClass the_class = XtClass (widget);

  if (the_class == xlwMenuWidgetClass)
    return True;
  if (the_class == overrideShellWidgetClass)
    return (XtClass (((CompositeWidget)widget)->composite.children [0])
	    == xlwMenuWidgetClass);
  return False;
}

void
#ifdef PROTOTYPES
xlw_update_one_widget (widget_instance* instance, Widget widget,
		       widget_value* val, Boolean deep_p)
#else
xlw_update_one_widget (instance, widget, val, deep_p)
     widget_instance* instance;
     Widget widget;
     widget_value* val;
     Boolean deep_p;
#endif
{
  Arg al[1];

  /* This used to use XtVaSetValues, but some old Xt versions
     that have a bug in XtVaCreateWidget might have it here too.  */
  XtSetArg (al[0], XtNmenu, instance->info->val);

  XtSetValues (widget, al, 1);
}

void
xlw_update_one_value (instance, widget, val)
     widget_instance* instance;
     Widget widget;
     widget_value* val;
{
  return;
}

void
#ifdef PROTOTYPES
xlw_pop_instance (widget_instance* instance, Boolean up)
#else
xlw_pop_instance (instance, up)
     widget_instance* instance;
     Boolean up;
#endif
{
}

void
xlw_popup_menu (widget, event)
     Widget widget;
     XEvent *event;
{
  XlwMenuWidget mw;

  if (!XtIsShell (widget))
    return;

  mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];

  if (event)
    XtCallActionProc ((Widget) mw, "start", event, NULL, 0);
  else
    {
      XEvent dummy;
      XButtonPressedEvent *bd = &dummy.xbutton;

      bd->type = ButtonPress;
      bd->serial = 0;
      bd->send_event = 0;
      bd->display = XtDisplay (widget);
      bd->window = XtWindow (XtParent (widget));
      bd->time = CurrentTime;
      bd->button = 0;
      XQueryPointer (bd->display, bd->window, &bd->root,
		     &bd->subwindow, &bd->x_root, &bd->y_root,
		     &bd->x, &bd->y, &bd->state);

      XtCallActionProc ((Widget) mw, "start", &dummy, NULL, 0);
    }
}

/* Destruction of instances */
void
xlw_destroy_instance (instance)
     widget_instance* instance;
{
  if (instance->widget)
    XtDestroyWidget (instance->widget);
}

/* arch-tag: 541e3912-477d-406e-9bf2-dbf2b7ff8c3b
   (do not change this comment) */