134
|
1 #include <config.h>
|
|
2 #include "lisp.h"
|
|
3
|
|
4 #include "device.h"
|
|
5 #include "console-x.h"
|
|
6
|
|
7 #include "balloon_help.h"
|
|
8
|
|
9 /* ### start of hack */
|
|
10
|
|
11 static unsigned long alloc_color( Display* dpy, const char* colorname, int light )
|
|
12 {
|
|
13 Colormap cmap = DefaultColormap( dpy, DefaultScreen(dpy) );
|
|
14 unsigned long pixel = 0;
|
|
15 XColor color;
|
|
16
|
|
17 if( XParseColor(dpy, cmap, colorname, &color) && XAllocColor(dpy, cmap, &color) )
|
|
18 {
|
|
19 pixel = color.pixel;
|
|
20 }
|
|
21 else
|
|
22 {
|
|
23 if( light )
|
|
24 {
|
|
25 printf("Warning: could not allocate color \"%s\", using \"white\"\n", colorname);
|
|
26 pixel = alloc_color( dpy, "white", True );
|
|
27 }
|
|
28 else
|
|
29 {
|
|
30 printf("Warning: could not allocate color \"%s\", using \"black\"\n", colorname);
|
|
31 pixel = alloc_color( dpy, "black", True );
|
|
32 }
|
|
33 }
|
|
34 return pixel;
|
|
35 }
|
|
36
|
|
37 static XFontStruct* open_font( Display* dpy, const char* font_name )
|
|
38 {
|
|
39 XFontStruct* fontStruct = NULL;
|
|
40
|
|
41 fontStruct = XLoadQueryFont( dpy, font_name ? font_name : "fixed" );
|
|
42 if( fontStruct == NULL )
|
|
43 {
|
|
44 printf("Warning: could not load font \"%s\", using \"fixed\".\n", font_name);
|
|
45 fontStruct = XLoadQueryFont( dpy, "fixed" );
|
|
46 assert( fontStruct != NULL );
|
|
47 }
|
|
48 return fontStruct;
|
|
49 }
|
|
50
|
|
51 static void init( void )
|
|
52 {
|
|
53 static int init;
|
|
54
|
|
55 if( !init )
|
|
56 {
|
|
57 Pixel fg, bg, shine, shadow;
|
|
58 XFontStruct* font;
|
|
59 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (Vdefault_x_device));
|
|
60
|
|
61 fg = alloc_color( dpy, "grey60", 1 );
|
|
62 bg = alloc_color( dpy, "black", 0 );
|
|
63
|
|
64 shine = alloc_color( dpy, "grey80", 1 );
|
|
65 shadow = alloc_color( dpy, "grey40", 0 );
|
|
66
|
|
67 font = open_font( dpy, "-adobe-helvetica-medium-r-normal--12-*" );
|
|
68
|
|
69 balloon_help_create( dpy, bg, fg, shine, shadow, font );
|
|
70 init = 1;
|
|
71 }
|
|
72 }
|
|
73
|
|
74 /* ### end of hack */
|
|
75
|
|
76 DEFUN( "show-balloon-help", Fshow_balloon_help, 1, 1, 0, /*
|
|
77 Show balloon help.
|
|
78 */
|
|
79 (string))
|
|
80 {
|
|
81 char *p;
|
|
82 CHECK_STRING (string);
|
|
83
|
|
84 p = (char *) XSTRING_DATA (string);
|
|
85
|
|
86 init();
|
|
87
|
|
88 balloon_help_show( p );
|
|
89
|
|
90 return Qnil;
|
|
91 }
|
|
92
|
|
93 DEFUN( "hide-balloon-help", Fhide_balloon_help, 0, 0, 0, /*
|
|
94 Hide balloon help.
|
|
95 */
|
|
96 ())
|
|
97 {
|
|
98 init();
|
|
99
|
|
100 balloon_help_hide();
|
|
101
|
|
102 return Qnil;
|
|
103 }
|
|
104
|
|
105 DEFUN( "balloon-help-move-to-pointer", Fballoon_help_move_to_pointer, 0, 0, 0, /*
|
|
106 Hide balloon help.
|
|
107 */
|
|
108 ())
|
|
109 {
|
|
110 init();
|
|
111
|
|
112 balloon_help_move_to_pointer();
|
|
113
|
|
114 return Qnil;
|
|
115 }
|
|
116
|
|
117
|
|
118
|
|
119 /************************************************************************/
|
|
120 /* initialization */
|
|
121 /************************************************************************/
|
|
122
|
|
123 void
|
|
124 syms_of_balloon_x (void)
|
|
125 {
|
|
126 DEFSUBR( Fshow_balloon_help );
|
|
127 DEFSUBR( Fhide_balloon_help );
|
|
128 DEFSUBR( Fballoon_help_move_to_pointer );
|
|
129 }
|
|
130
|
|
131 void
|
|
132 vars_of_balloon_x (void)
|
|
133 {
|
|
134 Fprovide (intern ("balloon-help"));
|
|
135 }
|