1 /* Definitions and headers for GTK widgets. 2 3 Copyright (C) 2003-2021 Free Software Foundation, Inc. 4 5 This file is part of GNU Emacs. 6 7 GNU Emacs is free software: you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation, either version 3 of the License, or (at 10 your option) any later version. 11 12 GNU Emacs is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 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 #ifndef GTKUTIL_H 21 #define GTKUTIL_H 22 23 24 #ifdef USE_GTK 25 26 #include <gtk/gtk.h> 27 #include "../lwlib/lwlib-widget.h" 28 #ifdef HAVE_PGTK 29 #include "pgtkterm.h" 30 #define EVENT GdkEvent 31 #else 32 #include "xterm.h" 33 #define EVENT XEvent 34 #endif 35 36 /* Minimum and maximum values used for GTK scroll bars */ 37 38 #define XG_SB_MIN 1 39 #define XG_SB_MAX 10000000 40 #define XG_SB_RANGE (XG_SB_MAX-XG_SB_MIN) 41 #define YG_SB_MIN 1 42 #define YG_SB_MAX 10000000 43 #define YG_SB_RANGE (YG_SB_MAX-YG_SB_MIN) 44 45 /* Key for data that is valid for menus and scroll bars in a frame */ 46 #define XG_FRAME_DATA "emacs_frame" 47 48 /* Key for data that menu items hold. */ 49 #define XG_ITEM_DATA "emacs_menuitem" 50 51 /* This is a list node in a generic list implementation. */ 52 typedef struct xg_list_node_ 53 { 54 struct xg_list_node_ *prev; 55 struct xg_list_node_ *next; 56 } xg_list_node; 57 58 /* This structure is the callback data that is shared for menu items. 59 We need to keep it separate from the frame structure due to 60 detachable menus. The data in the frame structure is only valid while 61 the menu is popped up. This structure is kept around as long as 62 the menu is. */ 63 typedef struct xg_menu_cb_data_ 64 { 65 xg_list_node ptrs; 66 67 struct frame *f; 68 Lisp_Object menu_bar_vector; 69 int menu_bar_items_used; 70 GCallback highlight_cb; 71 int ref_count; 72 } xg_menu_cb_data; 73 74 /* This structure holds callback information for each individual menu item. */ 75 typedef struct xg_menu_item_cb_data_ 76 { 77 xg_list_node ptrs; 78 79 gulong select_id; 80 Lisp_Object help; 81 gpointer call_data; 82 xg_menu_cb_data *cl_data; 83 84 } xg_menu_item_cb_data; 85 86 extern bool xg_uses_old_file_dialog (void); 87 88 extern char *xg_get_file_name (struct frame *f, 89 char *prompt, 90 char *default_filename, 91 bool mustmatch_p, 92 bool only_dir_p); 93 94 extern Lisp_Object xg_get_font (struct frame *f, const char *); 95 96 extern GtkWidget *xg_create_widget (const char *type, 97 const char *name, 98 struct frame *f, 99 struct _widget_value *val, 100 GCallback select_cb, 101 GCallback deactivate_cb, 102 GCallback highlight_cb); 103 104 extern void xg_modify_menubar_widgets (GtkWidget *menubar, 105 struct frame *f, 106 struct _widget_value *val, 107 bool deep_p, 108 GCallback select_cb, 109 GCallback deactivate_cb, 110 GCallback highlight_cb); 111 112 extern void xg_update_frame_menubar (struct frame *f); 113 114 extern bool xg_event_is_for_menubar (struct frame *, const EVENT *); 115 116 extern ptrdiff_t xg_get_scroll_id_for_window (Display *dpy, Window wid); 117 118 extern void xg_create_scroll_bar (struct frame *f, 119 struct scroll_bar *bar, 120 GCallback scroll_callback, 121 GCallback end_callback, 122 const char *scroll_bar_name); 123 extern void xg_create_horizontal_scroll_bar (struct frame *f, 124 struct scroll_bar *bar, 125 GCallback scroll_callback, 126 GCallback end_callback, 127 const char *scroll_bar_name); 128 extern void xg_remove_scroll_bar (struct frame *f, ptrdiff_t scrollbar_id); 129 130 extern void xg_update_scrollbar_pos (struct frame *f, 131 ptrdiff_t scrollbar_id, 132 int top, 133 int left, 134 int width, 135 int height); 136 extern void xg_update_horizontal_scrollbar_pos (struct frame *f, 137 ptrdiff_t scrollbar_id, 138 int top, 139 int left, 140 int width, 141 int height); 142 143 extern void xg_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar, 144 int portion, 145 int position, 146 int whole); 147 extern void xg_set_toolkit_horizontal_scroll_bar_thumb (struct scroll_bar *bar, 148 int portion, 149 int position, 150 int whole); 151 extern bool xg_event_is_for_scrollbar (struct frame *, const EVENT *); 152 extern int xg_get_default_scrollbar_width (struct frame *f); 153 extern int xg_get_default_scrollbar_height (struct frame *f); 154 155 extern void update_frame_tool_bar (struct frame *f); 156 extern void free_frame_tool_bar (struct frame *f); 157 extern void xg_change_toolbar_position (struct frame *f, Lisp_Object pos); 158 159 extern void xg_frame_resized (struct frame *f, 160 int pixelwidth, 161 int pixelheight); 162 extern void xg_frame_set_char_size (struct frame *f, int width, int height); 163 extern GtkWidget * xg_win_to_widget (Display *dpy, Window wdesc); 164 165 extern int xg_get_scale (struct frame *f); 166 #ifndef HAVE_PGTK 167 extern void xg_display_open (char *display_name, Display **dpy); 168 extern void xg_display_close (Display *dpy); 169 extern GdkCursor * xg_create_default_cursor (Display *dpy); 170 #else 171 extern void xg_display_open (char *display_name, GdkDisplay **dpy); 172 extern void xg_display_close (GdkDisplay *gdpy); 173 extern GdkCursor * xg_create_default_cursor (GdkDisplay *gdpy); 174 #endif 175 176 extern bool xg_create_frame_widgets (struct frame *f); 177 extern void xg_free_frame_widgets (struct frame *f); 178 extern void xg_set_background_color (struct frame *f, unsigned long bg); 179 extern bool xg_check_special_colors (struct frame *f, 180 const char *color_name, 181 Emacs_Color *color); 182 #ifdef HAVE_PGTK 183 extern void xg_create_frame_outer_widgets (struct frame *f); 184 #endif 185 186 #ifndef HAVE_PGTK 187 extern void xg_set_frame_icon (struct frame *f, 188 Pixmap icon_pixmap, 189 Pixmap icon_mask); 190 #endif 191 192 extern void xg_set_undecorated (struct frame *f, Lisp_Object undecorated); 193 extern void xg_frame_restack (struct frame *f1, struct frame *f2, bool above); 194 extern void xg_set_skip_taskbar (struct frame *f, Lisp_Object skip_taskbar); 195 extern void xg_set_no_focus_on_map (struct frame *f, Lisp_Object no_focus_on_map); 196 extern void xg_set_no_accept_focus (struct frame *f, Lisp_Object no_accept_focus); 197 extern void xg_set_override_redirect (struct frame *f, Lisp_Object override_redirect); 198 199 extern bool xg_prepare_tooltip (struct frame *f, 200 Lisp_Object string, 201 int *width, 202 int *height); 203 #ifndef HAVE_PGTK 204 extern void xg_show_tooltip (struct frame *f, int root_x, int root_y); 205 #else 206 extern void xg_show_tooltip (struct frame *f, Lisp_Object string); 207 #endif 208 extern bool xg_hide_tooltip (struct frame *f); 209 210 #ifdef USE_CAIRO 211 extern void xg_page_setup_dialog (void); 212 extern Lisp_Object xg_get_page_setup (void); 213 extern void xg_print_frames_dialog (Lisp_Object); 214 #endif 215 216 #if defined HAVE_GTK3 && defined HAVE_XINPUT2 217 extern bool xg_is_menu_window (Display *dpy, Window); 218 #endif 219 220 /* Mark all callback data that are Lisp_object:s during GC. */ 221 extern void xg_mark_data (void); 222 223 /* Initialize GTK specific parts. */ 224 extern void xg_initialize (void); 225 226 /* Setting scrollbar values invokes the callback. Use this variable 227 to indicate that the callback should do nothing. */ 228 extern bool xg_ignore_gtk_scrollbar; 229 230 extern bool xg_gtk_initialized; 231 232 #endif /* USE_GTK */ 233 #endif /* GTKUTIL_H */ 234