xwidget.h 3.62 KB
Newer Older
1 2
/* Support for embedding graphical components in a buffer.

Paul Eggert's avatar
Paul Eggert committed
3
Copyright (C) 2011-2019 Free Software Foundation, Inc.
4 5 6 7 8

This file is part of GNU Emacs.

GNU Emacs is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
9 10
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
11 12 13 14 15 16 17

GNU Emacs 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
18
along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
19 20 21 22

#ifndef XWIDGET_H_INCLUDED
#define XWIDGET_H_INCLUDED

Paul Eggert's avatar
Paul Eggert committed
23
#include "lisp.h"
24

Paul Eggert's avatar
Paul Eggert committed
25 26 27 28 29
struct glyph_matrix;
struct glyph_string;
struct xwidget;
struct xwidget_view;
struct window;
30

Paul Eggert's avatar
Paul Eggert committed
31 32
#ifdef HAVE_XWIDGETS
# include <gtk/gtk.h>
33

Paul Eggert's avatar
Paul Eggert committed
34 35
struct xwidget
{
36
  union vectorlike_header header;
37

Paul Eggert's avatar
Paul Eggert committed
38 39
  /* Auxiliary data.  */
  Lisp_Object plist;
40

Paul Eggert's avatar
Paul Eggert committed
41 42
  /* The widget type.  */
  Lisp_Object type;
43

Paul Eggert's avatar
Paul Eggert committed
44 45
  /* The buffer where the xwidget lives.  */
  Lisp_Object buffer;
46

Paul Eggert's avatar
Paul Eggert committed
47 48
  /* A title used for button labels, for instance.  */
  Lisp_Object title;
49

50 51
  /* Vector of currently executing scripts with callbacks.  */
  Lisp_Object script_callbacks;
52
  /* Here ends the Lisp part.  script_callbacks is the marker field.  */
53 54 55 56

  int height;
  int width;

Paul Eggert's avatar
Paul Eggert committed
57
  /* For offscreen widgets, unused if not osr.  */
58 59
  GtkWidget *widget_osr;
  GtkWidget *widgetwindow_osr;
Paul Eggert's avatar
Paul Eggert committed
60 61 62

  /* Kill silently if Emacs is exited.  */
  bool_bf kill_without_query : 1;
Paul Eggert's avatar
Paul Eggert committed
63
} GCALIGNED_STRUCT;
64 65 66

struct xwidget_view
{
67
  union vectorlike_header header;
68 69
  Lisp_Object model;
  Lisp_Object w;
70
  /* Here ends the lisp part.  "w" is the marker field.  */
Paul Eggert's avatar
Paul Eggert committed
71 72 73

  /* If touched by redisplay.  */
  bool redisplayed;
74

Paul Eggert's avatar
Paul Eggert committed
75 76
  /* The "live" instance isn't drawn.  */
  bool hidden;
77 78 79 80 81 82 83 84 85 86 87 88

  GtkWidget *widget;
  GtkWidget *widgetwindow;
  GtkWidget *emacswindow;
  int x;
  int y;
  int clip_right;
  int clip_bottom;
  int clip_top;
  int clip_left;

  long handler_id;
Paul Eggert's avatar
Paul Eggert committed
89
} GCALIGNED_STRUCT;
Paul Eggert's avatar
Paul Eggert committed
90
#endif
91

Paul Eggert's avatar
Paul Eggert committed
92
/* Test for xwidget pseudovector.  */
93
#define XWIDGETP(x) PSEUDOVECTORP (x, PVEC_XWIDGET)
Paul Eggert's avatar
Paul Eggert committed
94
#define XXWIDGET(a) (eassert (XWIDGETP (a)), \
95
		     XUNTAG (a, Lisp_Vectorlike, struct xwidget))
96 97 98 99

#define CHECK_XWIDGET(x) \
  CHECK_TYPE (XWIDGETP (x), Qxwidgetp, x)

Paul Eggert's avatar
Paul Eggert committed
100
/* Test for xwidget_view pseudovector.  */
101
#define XWIDGET_VIEW_P(x) PSEUDOVECTORP (x, PVEC_XWIDGET_VIEW)
Paul Eggert's avatar
Paul Eggert committed
102
#define XXWIDGET_VIEW(a) (eassert (XWIDGET_VIEW_P (a)), \
103
			  XUNTAG (a, Lisp_Vectorlike, struct xwidget_view))
104 105 106 107 108 109 110

#define CHECK_XWIDGET_VIEW(x) \
  CHECK_TYPE (XWIDGET_VIEW_P (x), Qxwidget_view_p, x)

#define XG_XWIDGET "emacs_xwidget"
#define XG_XWIDGET_VIEW "emacs_xwidget_view"

Paul Eggert's avatar
Paul Eggert committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
#ifdef HAVE_XWIDGETS
void syms_of_xwidget (void);
bool valid_xwidget_spec_p (Lisp_Object);
void xwidget_view_delete_all_in_window (struct window *);
void x_draw_xwidget_glyph_string (struct glyph_string *);
struct xwidget *lookup_xwidget (Lisp_Object spec);
void xwidget_end_redisplay (struct window *, struct glyph_matrix *);
void kill_buffer_xwidgets (Lisp_Object);
#else
INLINE_HEADER_BEGIN
INLINE void syms_of_xwidget (void) {}
INLINE bool valid_xwidget_spec_p (Lisp_Object obj) { return false; }
INLINE void xwidget_view_delete_all_in_window (struct window *w) {}
INLINE void x_draw_xwidget_glyph_string (struct glyph_string *s) { eassume (0); }
INLINE struct xwidget *lookup_xwidget (Lisp_Object obj) { eassume (0); }
INLINE void xwidget_end_redisplay (struct window *w, struct glyph_matrix *m) {}
INLINE void kill_buffer_xwidgets (Lisp_Object buf) {}
INLINE_HEADER_END
#endif

131
#endif /* XWIDGET_H_INCLUDED */