Merge branch 'merges'
[sxemacs] / src / ui / X11 / balloon-x.c
1 /*
2    Copyright (c) 1997 Douglas Keller
3
4 This file is part of SXEmacs
5
6 SXEmacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 SXEmacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
18
19
20 /* Synched up with: Not in FSF. */
21
22 #include <config.h>
23 #include "lisp.h"
24
25 #include "ui/device.h"
26 #include "console-x.h"
27
28 #include "balloon_help.h"
29
30 /* #### start of hack */
31
32 static unsigned long
33 alloc_color(Display * dpy, const char *colorname, int light)
34 {
35         Colormap cmap = DEVICE_X_COLORMAP(XDEVICE(Vdefault_x_device));
36         unsigned long pixel = 0;
37         XColor color;
38
39         if (XParseColor(dpy, cmap, colorname, &color)
40             && XAllocColor(dpy, cmap, &color)) {
41                 pixel = color.pixel;
42         } else {
43                 if (light) {
44                         printf
45                             ("Warning: could not allocate color \"%s\", using \"white\"\n",
46                              colorname);
47                         pixel = alloc_color(dpy, "white", True);
48                 } else {
49                         printf
50                             ("Warning: could not allocate color \"%s\", using \"black\"\n",
51                              colorname);
52                         pixel = alloc_color(dpy, "black", True);
53                 }
54         }
55         return pixel;
56 }
57
58 static XFontStruct *open_font(Display * dpy, const char *font_name)
59 {
60         XFontStruct *fontStruct = NULL;
61
62         fontStruct = XLoadQueryFont(dpy, font_name ? font_name : "fixed");
63         if (fontStruct == NULL) {
64                 printf
65                     ("Warning: could not load font \"%s\", using \"fixed\".\n",
66                      font_name);
67                 fontStruct = XLoadQueryFont(dpy, "fixed");
68                 assert(fontStruct != NULL);
69         }
70         return fontStruct;
71 }
72
73 static void init(void)
74 {
75         static int init_p = 0;
76
77         if (!init_p) {
78                 Pixel fg, bg, shine, shadow;
79                 XFontStruct *font;
80                 Display *dpy = DEVICE_X_DISPLAY(XDEVICE(Vdefault_x_device));
81
82                 fg = alloc_color(dpy, "grey60", 1);
83                 bg = alloc_color(dpy, "black", 0);
84
85                 shine = alloc_color(dpy, "grey80", 1);
86                 shadow = alloc_color(dpy, "grey40", 0);
87
88                 font = open_font(dpy, "-adobe-helvetica-medium-r-normal--12-*");
89
90                 balloon_help_create(dpy, bg, fg, shine, shadow, font);
91                 init_p = 1;
92         }
93 }
94
95 /* #### end of hack */
96
97 DEFUN("show-balloon-help", Fshow_balloon_help, 1, 1, 0, /*
98 Show balloon help.
99 */
100       (string))
101 {
102         char *p;
103         CHECK_STRING(string);
104
105         p = (char *)XSTRING_DATA(string);
106
107         init();
108
109         balloon_help_show(p);
110
111         return Qnil;
112 }
113
114 DEFUN("hide-balloon-help", Fhide_balloon_help, 0, 0, 0, /*
115 Hide balloon help.
116 */
117       ())
118 {
119         init();
120
121         balloon_help_hide();
122
123         return Qnil;
124 }
125
126 DEFUN("balloon-help-move-to-pointer", Fballoon_help_move_to_pointer, 0, 0, 0,   /*
127 Move the balloon help to the place where the pointer currently
128 resides.
129 */
130       ())
131 {
132         init();
133
134         balloon_help_move_to_pointer();
135
136         return Qnil;
137 }
138 \f
139 /************************************************************************/
140 /*                              initialization                          */
141 /************************************************************************/
142
143 void syms_of_balloon_x(void)
144 {
145         DEFSUBR(Fshow_balloon_help);
146         DEFSUBR(Fhide_balloon_help);
147         DEFSUBR(Fballoon_help_move_to_pointer);
148 }
149
150 void vars_of_balloon_x(void)
151 {
152         Fprovide(intern("c-balloon-help"));
153 }