~ubuntu-branches/ubuntu/quantal/texmacs/quantal

« back to all changes in this revision

Viewing changes to src/Plugins/X11/x_init.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Atsuhito KOHDA, Kamaraju Kusumanchi, kohda
  • Date: 2008-04-06 15:11:41 UTC
  • mfrom: (1.1.7 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080406151141-w0sg20jnv86mlt6f
Tags: 1:1.0.6.14-1
[Kamaraju Kusumanchi <kamaraju@gmail.com>]
* New upstream release
* 01_american.dpatch is updated
* Since thread support in guile-1.8 is now disabled, the segmentation faults
  should not arise anymore. More info at #439923. (Closes: #450499, #458685)
[kohda]
* This version fixed menu problem.  (Closes: #447083)
* Reverted orig.tar.gz to the upstream tarball.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/******************************************************************************
 
3
* MODULE     : x_init.cpp
 
4
* DESCRIPTION: Initialization of the X11 window manager
 
5
* COPYRIGHT  : (C) 1999  Joris van der Hoeven
 
6
*******************************************************************************
 
7
* This software falls under the GNU general public license and comes WITHOUT
 
8
* ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
 
9
* If you don't have this file, write to the Free Software Foundation, Inc.,
 
10
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
11
******************************************************************************/
 
12
 
 
13
#include "X11/x_window.hpp"
 
14
#include "language.hpp"
 
15
#include "font.hpp"
 
16
#include "analyze.hpp"
 
17
#include "dictionary.hpp"
 
18
#include "iterator.hpp"
 
19
#include "message.hpp"
 
20
#include <locale.h>
 
21
 
 
22
x_gui_rep* the_gui= NULL;
 
23
extern hashmap<Window,pointer> Window_to_window;
 
24
 
 
25
/******************************************************************************
 
26
* Set up colors
 
27
******************************************************************************/
 
28
 
 
29
bool true_color= false;
 
30
bool reverse_colors= false;
 
31
 
 
32
color black, white, red, green, blue;
 
33
color yellow, magenta, orange, brown, pink;
 
34
color light_grey, grey, dark_grey;
 
35
 
 
36
static int CSCALES= 4;
 
37
static int CFACTOR= 5;
 
38
static int GREYS  = 16;
 
39
static int CTOTAL = (CFACTOR*CFACTOR*CFACTOR+GREYS+1);
 
40
 
 
41
int
 
42
x_alloc_color (int r, int g, int b) {
 
43
  if (reverse_colors) {
 
44
    int m= min (r, min (g, b));
 
45
    int M= max (r, max (g, b));
 
46
    int t= (r + g + b) / 3;
 
47
    int tt= 65535 - t;
 
48
    double mu= 1.0;
 
49
    tt= 6 * tt / 7;
 
50
    if (M != m) {
 
51
      double lambda1= max (((double) (t - m)) / t,
 
52
                           ((double) (M - t)) / (65535 - t));
 
53
      double lambda2= max (((double) (t - m)) / tt,
 
54
                           ((double) (M - t)) / (65535 - tt));
 
55
      mu= lambda1 / lambda2;
 
56
    }
 
57
    r= (int) (tt + mu * (r - t) + 0.5);
 
58
    g= (int) (tt + mu * (g - t) + 0.5);
 
59
    b= (int) (tt + mu * (b - t) + 0.5);
 
60
  }
 
61
  if (true_color)
 
62
    return (r << 16) + (g << 8) + b;
 
63
 
 
64
  XColor col;
 
65
  col.red  = r;
 
66
  col.green= g;
 
67
  col.blue = b;
 
68
  if (!XAllocColor (the_gui->dpy, the_gui->cols, &col))
 
69
    cerr << "Warning: can't allocate color\n";
 
70
  return col.pixel;
 
71
}
 
72
 
 
73
void
 
74
x_init_color_map () {
 
75
  if (true_color) return;
 
76
 
 
77
  int i, r, g, b;
 
78
  the_gui->cmap= new color [CTOTAL];
 
79
 
 
80
  for (i=0; i<=GREYS; i++)
 
81
    the_gui->cmap[i]=
 
82
      x_alloc_color ((i*65535)/GREYS, (i*65535)/GREYS, (i*65535)/GREYS);
 
83
 
 
84
  for (r=0; r<=CSCALES; r++)
 
85
    for (g=0; g<=CSCALES; g++)
 
86
      for (b=0; b<=CSCALES; b++) {
 
87
        i= r*CFACTOR*CFACTOR+ g*CFACTOR+ b+ GREYS+ 1;
 
88
        the_gui->cmap[i]= x_alloc_color ((r*65535)/CSCALES,
 
89
                                         (g*65535)/CSCALES,
 
90
                                         (b*65535)/CSCALES);
 
91
      }
 
92
}
 
93
 
 
94
color
 
95
rgb_color (int r, int g, int b) {
 
96
  if (true_color) return (r << 16) + (g << 8) + b;
 
97
  else if ((r==g) && (g==b)) return (r*GREYS+ 128)/255;
 
98
  else {
 
99
    r= (r*CSCALES+ 128)/255;
 
100
    g= (g*CSCALES+ 128)/255;
 
101
    b= (b*CSCALES+ 128)/255;
 
102
    return r*CFACTOR*CFACTOR+ g*CFACTOR+ b+ GREYS+ 1;
 
103
  }
 
104
}
 
105
 
 
106
void
 
107
get_rgb_color (color col, int& r, int& g, int& b) {
 
108
  if (true_color) {
 
109
    r= (col >> 16) & 255;
 
110
    g= (col >> 8 ) & 255;
 
111
    b=  col        & 255;
 
112
  }
 
113
  else if (col <= GREYS) {
 
114
    r= (col*255)/GREYS;
 
115
    g= (col*255)/GREYS;
 
116
    b= (col*255)/GREYS;
 
117
  }
 
118
  else {
 
119
    int rr, gg, bb;
 
120
    col-= (GREYS+1);
 
121
    bb  = col % CFACTOR;
 
122
    gg  = (col/CFACTOR) % CFACTOR;
 
123
    rr  = (col/(CFACTOR*CFACTOR)) % CFACTOR;
 
124
    r   = (rr*255)/CSCALES;
 
125
    g   = (gg*255)/CSCALES;
 
126
    b   = (bb*255)/CSCALES;
 
127
  }
 
128
}
 
129
 
 
130
color
 
131
named_color (string s) {
 
132
  if ((N(s) == 4) && (s[0]=='#')) {
 
133
    int r= 17 * from_hexadecimal (s (1, 2));
 
134
    int g= 17 * from_hexadecimal (s (2, 3));
 
135
    int b= 17 * from_hexadecimal (s (3, 4));
 
136
    return rgb_color (r, g, b);
 
137
  }
 
138
  if ((N(s) == 7) && (s[0]=='#')) {
 
139
    int r= from_hexadecimal (s (1, 3));
 
140
    int g= from_hexadecimal (s (3, 5));
 
141
    int b= from_hexadecimal (s (5, 7));
 
142
    return rgb_color (r, g, b);
 
143
  }
 
144
  int pastel= (the_gui->depth>=16? 223: 191);
 
145
  if (s == "black")          return black;
 
146
  if (s == "white")          return white;
 
147
  if (s == "grey")           return grey;
 
148
  if (s == "red")            return red;
 
149
  if (s == "blue")           return blue;
 
150
  if (s == "yellow")         return yellow;
 
151
  if (s == "green")          return green;
 
152
  if (s == "magenta")        return magenta;
 
153
  if (s == "cyan")           return rgb_color (0, 255, 255);
 
154
  if (s == "orange")         return orange;
 
155
  if (s == "brown")          return brown;
 
156
  if (s == "pink")           return pink;
 
157
  if (s == "broken white")   return rgb_color (255, 255, pastel);
 
158
  if (s == "light grey")     return light_grey;
 
159
  if (s == "dark grey")      return dark_grey;
 
160
  if (s == "dark red")       return rgb_color (128, 0, 0);
 
161
  if (s == "dark blue")      return rgb_color (0, 0, 128);
 
162
  if (s == "dark yellow")    return rgb_color (128, 128, 0);
 
163
  if (s == "dark green")     return rgb_color (0, 128, 0);
 
164
  if (s == "dark magenta")   return rgb_color (128, 0, 128);
 
165
  if (s == "dark cyan")      return rgb_color (0, 128, 128);
 
166
  if (s == "dark orange")    return rgb_color (128, 64, 0);
 
167
  if (s == "dark brown")     return rgb_color (64, 16, 0);
 
168
  if (s == "pastel grey")    return rgb_color (pastel, pastel, pastel);
 
169
  if (s == "pastel red")     return rgb_color (255, pastel, pastel);
 
170
  if (s == "pastel blue")    return rgb_color (pastel, pastel, 255);
 
171
  if (s == "pastel yellow")  return rgb_color (255, 255, pastel);
 
172
  if (s == "pastel green")   return rgb_color (pastel, 255, pastel);
 
173
  if (s == "pastel magenta") return rgb_color (255, pastel, 255);
 
174
  if (s == "pastel cyan")    return rgb_color (pastel, 255, 255);
 
175
  if (s == "pastel orange")  return rgb_color (255, pastel, 2*pastel-255);
 
176
  if (s == "pastel brown")   return rgb_color (pastel, 2*pastel-255, 2*pastel-255);
 
177
  return black;
 
178
}
 
179
 
 
180
string
 
181
get_named_color (color c) {
 
182
  SI r, g, b;
 
183
  get_rgb_color (c, r, g, b);
 
184
  return "#" *
 
185
    as_hexadecimal (r, 2) *
 
186
    as_hexadecimal (g, 2) *
 
187
    as_hexadecimal (b, 2);
 
188
}
 
189
 
 
190
void
 
191
x_initialize_colors () {
 
192
  if (the_gui->depth >= 16) {
 
193
    CSCALES= 8;
 
194
    CFACTOR= 9;
 
195
    GREYS  = 256;
 
196
    CTOTAL = (CFACTOR*CFACTOR*CFACTOR+GREYS+1);
 
197
  }
 
198
 
 
199
  x_init_color_map ();
 
200
 
 
201
  black   = rgb_color (0, 0, 0);
 
202
  white   = rgb_color (255, 255, 255);
 
203
  red     = rgb_color (255, 0, 0);
 
204
  blue    = rgb_color (0, 0, 255);
 
205
  yellow  = rgb_color (255, 255, 0);
 
206
  green   = rgb_color (0, 255, 0);
 
207
  magenta = rgb_color (255, 0, 255);
 
208
  orange  = rgb_color (255, 128, 0);
 
209
  brown   = rgb_color (128, 32, 0);
 
210
  pink    = rgb_color (255, 128, 128);
 
211
 
 
212
  light_grey = rgb_color (208, 208, 208);
 
213
  grey       = rgb_color (184, 184, 184);
 
214
  dark_grey  = rgb_color (112, 112, 112);
 
215
}
 
216
 
 
217
/******************************************************************************
 
218
* Set up input method
 
219
******************************************************************************/
 
220
 
 
221
void
 
222
x_gui_rep::initialize_input_method () {
 
223
  im_ok= false;
 
224
  if (setlocale (LC_CTYPE, "") == NULL)
 
225
    cerr << "TeXmacs] Warning: locale could not be set\n";
 
226
  else {
 
227
    if (!XSetLocaleModifiers (""))
 
228
      cerr << "TeXmacs] Warning: could not set locale modifiers\n";
 
229
    if (XSupportsLocale () == False)
 
230
      cerr << "TeXmacs] Warning: locale is not supported\n";
 
231
    else if ((im = XOpenIM (dpy, NULL, NULL, NULL)) == NULL)
 
232
      cout << "TeXmacs] Warning: could not open input method\n";
 
233
    else im_ok= true;
 
234
  }
 
235
}
 
236
 
 
237
/******************************************************************************
 
238
* Get xmodmap
 
239
******************************************************************************/
 
240
 
 
241
#ifndef XK_ISO_Left_Tab
 
242
#define XK_ISO_Left_Tab 0xFE20
 
243
#endif
 
244
 
 
245
static XModifierKeymap* xmodmap;
 
246
static int        mod_n;
 
247
static KeyCode*   mod_k;
 
248
static array<int> mod_shift;
 
249
static array<int> mod_ctrl;
 
250
static array<int> mod_alt;
 
251
 
 
252
void
 
253
x_gui_rep::insert_keysym (array<int>& a, int i, int j) {
 
254
  int ks= XKeycodeToKeysym (dpy, mod_k[i*mod_n+j], 0);
 
255
  if (ks!=0) a << ks;
 
256
}
 
257
 
 
258
void
 
259
x_gui_rep::get_xmodmap () {
 
260
  int i;
 
261
  xmodmap= XGetModifierMapping (dpy);
 
262
  mod_n= xmodmap->max_keypermod;
 
263
  mod_k= xmodmap->modifiermap;
 
264
  for (i=0; i<mod_n; i++) {
 
265
    insert_keysym (mod_shift, 0, i);
 
266
    insert_keysym (mod_shift, 1, i);
 
267
    insert_keysym (mod_ctrl, 2, i);
 
268
    insert_keysym (mod_alt, 3, i);
 
269
  }
 
270
  XFreeModifiermap (xmodmap);
 
271
}
 
272
 
 
273
/******************************************************************************
 
274
* Set up keyboard
 
275
******************************************************************************/
 
276
 
 
277
void
 
278
x_gui_rep::map (int key, string s) {
 
279
  lower_key (key)= s;
 
280
  upper_key (key)= "S-" * s;
 
281
}
 
282
 
 
283
void
 
284
x_gui_rep::Map (int key, string s) {
 
285
  lower_key (key)= s;
 
286
  upper_key (key)= s;
 
287
}
 
288
 
 
289
void
 
290
x_gui_rep::initialize_keyboard_pointer () {
 
291
  // Latin characters
 
292
  Map (XK_a, "a");
 
293
  Map (XK_b, "b");
 
294
  Map (XK_c, "c");
 
295
  Map (XK_d, "d");
 
296
  Map (XK_e, "e");
 
297
  Map (XK_f, "f");
 
298
  Map (XK_g, "g");
 
299
  Map (XK_h, "h");
 
300
  Map (XK_i, "i");
 
301
  Map (XK_j, "j");
 
302
  Map (XK_k, "k");
 
303
  Map (XK_l, "l");
 
304
  Map (XK_m, "m");
 
305
  Map (XK_n, "n");
 
306
  Map (XK_o, "o");
 
307
  Map (XK_p, "p");
 
308
  Map (XK_q, "q");
 
309
  Map (XK_r, "r");
 
310
  Map (XK_s, "s");
 
311
  Map (XK_t, "t");
 
312
  Map (XK_u, "u");
 
313
  Map (XK_v, "v");
 
314
  Map (XK_w, "w");
 
315
  Map (XK_x, "x");
 
316
  Map (XK_y, "y");
 
317
  Map (XK_z, "z");
 
318
  Map (XK_A, "A");
 
319
  Map (XK_B, "B");
 
320
  Map (XK_C, "C");
 
321
  Map (XK_D, "D");
 
322
  Map (XK_E, "E");
 
323
  Map (XK_F, "F");
 
324
  Map (XK_G, "G");
 
325
  Map (XK_H, "H");
 
326
  Map (XK_I, "I");
 
327
  Map (XK_J, "J");
 
328
  Map (XK_K, "K");
 
329
  Map (XK_L, "L");
 
330
  Map (XK_M, "M");
 
331
  Map (XK_N, "N");
 
332
  Map (XK_O, "O");
 
333
  Map (XK_P, "P");
 
334
  Map (XK_Q, "Q");
 
335
  Map (XK_R, "R");
 
336
  Map (XK_S, "S");
 
337
  Map (XK_T, "T");
 
338
  Map (XK_U, "U");
 
339
  Map (XK_V, "V");
 
340
  Map (XK_W, "W");
 
341
  Map (XK_X, "X");
 
342
  Map (XK_Y, "Y");
 
343
  Map (XK_Z, "Z");
 
344
  Map (XK_0, "0");
 
345
  Map (XK_1, "1");
 
346
  Map (XK_2, "2");
 
347
  Map (XK_3, "3");
 
348
  Map (XK_4, "4");
 
349
  Map (XK_5, "5");
 
350
  Map (XK_6, "6");
 
351
  Map (XK_7, "7");
 
352
  Map (XK_8, "8");
 
353
  Map (XK_9, "9");
 
354
 
 
355
  // Cyrillic letters
 
356
  Map (XK_Cyrillic_a,   "\xe0");
 
357
  Map (XK_Cyrillic_be,  "\xe1");
 
358
  Map (XK_Cyrillic_ve,  "\xe2");
 
359
  Map (XK_Cyrillic_ghe, "\xe3");
 
360
  Map (XK_Cyrillic_de,  "\xe4");
 
361
  Map (XK_Cyrillic_ie,  "\xe5");
 
362
  Map (XK_Cyrillic_io,  "\xbc");
 
363
  Map (XK_Cyrillic_zhe, "\xe6");
 
364
  Map (XK_Cyrillic_ze,  "\xe7");
 
365
  Map (XK_Cyrillic_i,   "\xe8");
 
366
  Map (XK_Cyrillic_shorti,   "\xe9");
 
367
  Map (XK_Cyrillic_ka,  "\xea");
 
368
  Map (XK_Cyrillic_el,  "\xeb");
 
369
  Map (XK_Cyrillic_em,  "\xec");
 
370
  Map (XK_Cyrillic_en,  "\xed");
 
371
  Map (XK_Cyrillic_o,   "\xee");
 
372
  Map (XK_Cyrillic_pe,  "\xef");
 
373
  Map (XK_Cyrillic_er,  "\xf0");
 
374
  Map (XK_Cyrillic_es,  "\xf1");
 
375
  Map (XK_Cyrillic_te,  "\xf2");
 
376
  Map (XK_Cyrillic_u,   "\xf3");
 
377
  Map (XK_Cyrillic_ef,  "\xf4");
 
378
  Map (XK_Cyrillic_ha,  "\xf5");
 
379
  Map (XK_Cyrillic_tse, "\xf6");
 
380
  Map (XK_Cyrillic_che, "\xf7");
 
381
  Map (XK_Cyrillic_sha, "\xf8");
 
382
  Map (XK_Cyrillic_shcha,    "\xf9");
 
383
  Map (XK_Cyrillic_hardsign, "\xfa");
 
384
  Map (XK_Cyrillic_yeru,     "\xfb");
 
385
  Map (XK_Cyrillic_softsign, "\xfc");
 
386
  Map (XK_Cyrillic_e,   "\xfd");
 
387
  Map (XK_Cyrillic_yu,  "\xfe");
 
388
  Map (XK_Cyrillic_ya,  "\xff");
 
389
  Map (XK_Cyrillic_A,   "\xc0");
 
390
  Map (XK_Cyrillic_BE,  "\xc1");
 
391
  Map (XK_Cyrillic_VE,  "\xc2");
 
392
  Map (XK_Cyrillic_GHE, "\xc3");
 
393
  Map (XK_Cyrillic_DE,  "\xc4");
 
394
  Map (XK_Cyrillic_IE,  "\xc5");
 
395
  Map (XK_Cyrillic_IO,  "\x9c");
 
396
  Map (XK_Cyrillic_ZHE, "\xc6");
 
397
  Map (XK_Cyrillic_ZE,  "\xc7");
 
398
  Map (XK_Cyrillic_I,   "\xc8");
 
399
  Map (XK_Cyrillic_SHORTI,   "\xc9");
 
400
  Map (XK_Cyrillic_KA,  "\xca");
 
401
  Map (XK_Cyrillic_EL,  "\xcb");
 
402
  Map (XK_Cyrillic_EM,  "\xcc");
 
403
  Map (XK_Cyrillic_EN,  "\xcd");
 
404
  Map (XK_Cyrillic_O,   "\xce");
 
405
  Map (XK_Cyrillic_PE,  "\xcf");
 
406
  Map (XK_Cyrillic_ER,  "\xd0");
 
407
  Map (XK_Cyrillic_ES,  "\xd1");
 
408
  Map (XK_Cyrillic_TE,  "\xd2");
 
409
  Map (XK_Cyrillic_U,   "\xd3");
 
410
  Map (XK_Cyrillic_EF,  "\xd4");
 
411
  Map (XK_Cyrillic_HA,  "\xd5");
 
412
  Map (XK_Cyrillic_TSE, "\xd6");
 
413
  Map (XK_Cyrillic_CHE, "\xd7");
 
414
  Map (XK_Cyrillic_SHA, "\xd8");
 
415
  Map (XK_Cyrillic_SHCHA,    "\xd9");
 
416
  Map (XK_Cyrillic_HARDSIGN, "\xda");
 
417
  Map (XK_Cyrillic_YERU,     "\xdb");
 
418
  Map (XK_Cyrillic_SOFTSIGN, "\xdc");
 
419
  Map (XK_Cyrillic_E,   "\xdd");
 
420
  Map (XK_Cyrillic_YU,  "\xde");
 
421
  Map (XK_Cyrillic_YA,  "\xdf");
 
422
  
 
423
  //Ukrainian letters in T2A encoding
 
424
  Map (XK_Ukrainian_i,   "i"); // Fall back! 
 
425
  Map (XK_Ukrainian_I,   "I"); // Fall back!
 
426
  Map (XK_Ukrainian_yi,   "\xa8");
 
427
  Map (XK_Ukrainian_YI,   "\x88");
 
428
  Map (XK_Ukrainian_ie,   "\xb9");
 
429
  Map (XK_Ukrainian_IE,   "\x99");
 
430
  // Map (XK_Ukrainian_ghe_with_upturn,   "\xa0");
 
431
  // Map (XK_Ukrainian_GHE_WITH_UPTURN,   "\x80");
 
432
  Map (0x6ad,   "\xa0");
 
433
  Map (0x6bd,   "\x80");
 
434
 
 
435
  // Standard ASCII Symbols
 
436
  Map (XK_exclam, "!");
 
437
  Map (XK_quotedbl, "\x22");
 
438
  Map (XK_numbersign, "#");
 
439
  Map (XK_dollar, "$");
 
440
  Map (XK_percent, "%");
 
441
  Map (XK_ampersand, "&");
 
442
  Map (XK_apostrophe, "'");
 
443
  Map (XK_quoteright, "'");
 
444
  Map (XK_parenleft, "(");
 
445
  Map (XK_parenright, ")");
 
446
  Map (XK_asterisk, "*");
 
447
  Map (XK_plus, "+");
 
448
  Map (XK_comma, ",");
 
449
  Map (XK_minus, "-");
 
450
  Map (XK_period, ".");
 
451
  Map (XK_slash, "/");
 
452
  Map (XK_colon, ":");
 
453
  Map (XK_semicolon, ";");
 
454
  Map (XK_less, "<");
 
455
  Map (XK_equal, "=");
 
456
  Map (XK_greater, ">");
 
457
  Map (XK_question, "?");
 
458
  Map (XK_at, "@");
 
459
  Map (XK_bracketleft, "[");
 
460
  Map (XK_backslash, "\\");
 
461
  Map (XK_bracketright, "]");
 
462
  Map (XK_asciicircum, "^");
 
463
  Map (XK_underscore, "_");
 
464
  Map (XK_grave, "`");
 
465
  Map (XK_quoteleft, "`");
 
466
  Map (XK_braceleft, "{");
 
467
  Map (XK_bar, "|");
 
468
  Map (XK_braceright, "}");
 
469
  Map (XK_asciitilde, "~");
 
470
 
 
471
  // dead keys
 
472
  Map (0xFE50, "grave");
 
473
  Map (0xFE51, "acute");
 
474
  Map (0xFE52, "hat");
 
475
  Map (0xFE53, "tilde");
 
476
  Map (0xFE54, "macron");
 
477
  Map (0xFE55, "breve");
 
478
  Map (0xFE56, "abovedot");
 
479
  Map (0XFE57, "umlaut");
 
480
  Map (0xFE58, "abovering");
 
481
  Map (0xFE59, "doubleacute");
 
482
  Map (0xFE5A, "check");
 
483
  Map (0xFE5B, "cedilla");
 
484
  Map (0xFE5C, "ogonek");
 
485
  Map (0xFE5D, "iota");
 
486
  Map (0xFE5E, "voicedsound");
 
487
  Map (0xFE5F, "semivoicedsound");
 
488
  Map (0xFE60, "belowdot");
 
489
 
 
490
  // Extended symbols and accented characters
 
491
  Map (XK_nobreakspace, "varspace");
 
492
  Map (XK_exclamdown, "exclamdown");
 
493
  Map (XK_cent, "cent");
 
494
  Map (XK_sterling, "sterling");
 
495
  Map (XK_currency, "currency");
 
496
  Map (XK_yen, "yen");
 
497
  Map (XK_brokenbar, "brokenbar");
 
498
  Map (XK_section, "section");
 
499
  Map (XK_diaeresis, "umlaut");
 
500
  Map (XK_copyright, "copyright");
 
501
  Map (XK_ordfeminine, "ordfeminine");
 
502
  Map (XK_guillemotleft, "guillemotleft");
 
503
  Map (XK_notsign, "notsign");
 
504
  Map (XK_hyphen, "hyphen");
 
505
  Map (XK_registered, "registered");
 
506
  Map (XK_macron, "macron");
 
507
  Map (XK_degree, "degree");
 
508
  Map (XK_plusminus, "plusminus");
 
509
  Map (XK_twosuperior, "twosuperior");
 
510
  Map (XK_threesuperior, "threesuperior");
 
511
  Map (XK_acute, "acute");
 
512
  Map (XK_mu, "mu");
 
513
  Map (XK_paragraph, "paragraph");
 
514
  Map (XK_periodcentered, "periodcentered");
 
515
  Map (XK_cedilla, "cedilla");
 
516
  Map (XK_onesuperior, "onesuperior");
 
517
  Map (XK_masculine, "masculine");
 
518
  Map (XK_guillemotright, "guillemotright");
 
519
  Map (XK_onequarter, "onequarter");
 
520
  Map (XK_onehalf, "onehalf");
 
521
  Map (XK_threequarters, "threequarters");
 
522
  Map (XK_questiondown, "questiondown");
 
523
  Map (XK_multiply, "times");
 
524
  Map (XK_division, "div");
 
525
 
 
526
  Map (XK_Agrave, "\xc0");
 
527
  Map (XK_Aacute, "\xc1");
 
528
  Map (XK_Acircumflex, "\xc2");
 
529
  Map (XK_Atilde, "\xc3");
 
530
  Map (XK_Adiaeresis, "\xc4");
 
531
  Map (XK_Aring, "\xc5");
 
532
  Map (XK_AE, "\xc6");
 
533
  Map (XK_Ccedilla, "\xc7");
 
534
  Map (XK_Egrave, "\xc8");
 
535
  Map (XK_Eacute, "\xc9");
 
536
  Map (XK_Ecircumflex, "\xca");
 
537
  Map (XK_Ediaeresis, "\xcb");
 
538
  Map (XK_Igrave, "\xcc");
 
539
  Map (XK_Iacute, "\xcd");
 
540
  Map (XK_Icircumflex, "\xce");
 
541
  Map (XK_Idiaeresis, "\xcf");
 
542
  Map (XK_ETH, "\xd0");
 
543
  Map (XK_Eth, "\xd0");
 
544
  Map (XK_Ntilde, "\xd1");
 
545
  Map (XK_Ograve, "\xd2");
 
546
  Map (XK_Oacute, "\xd3");
 
547
  Map (XK_Ocircumflex, "\xd4");
 
548
  Map (XK_Otilde, "\xd5");
 
549
  Map (XK_Odiaeresis, "\xd6");
 
550
  Map (XK_OE, "\xd7");
 
551
  Map (XK_Ooblique, "\xd8");
 
552
  Map (XK_Ugrave, "\xd9");
 
553
  Map (XK_Uacute, "\xda");
 
554
  Map (XK_Ucircumflex, "\xdb");
 
555
  Map (XK_Udiaeresis, "\xdc");
 
556
  Map (XK_Yacute, "\xdd");
 
557
  Map (XK_THORN, "\xde");
 
558
  Map (XK_Thorn, "\xde");
 
559
  Map (XK_ssharp, "sz");
 
560
  Map (XK_agrave, "\xe0");
 
561
  Map (XK_aacute, "\xe1");
 
562
  Map (XK_acircumflex, "\xe2");
 
563
  Map (XK_atilde, "\xe3");
 
564
  Map (XK_adiaeresis, "\xe4");
 
565
  Map (XK_aring, "\xe5");
 
566
  Map (XK_ae, "\xe6");
 
567
  Map (XK_ccedilla, "\xe7");
 
568
  Map (XK_egrave, "\xe8");
 
569
  Map (XK_eacute, "\xe9");
 
570
  Map (XK_ecircumflex, "\xea");
 
571
  Map (XK_ediaeresis, "\xeb");
 
572
  Map (XK_igrave, "\xec");
 
573
  Map (XK_iacute, "\xed");
 
574
  Map (XK_icircumflex, "\xee");
 
575
  Map (XK_idiaeresis, "\xef");
 
576
  Map (XK_eth, "\xf0");
 
577
  Map (XK_ntilde, "\xf1");
 
578
  Map (XK_ograve, "\xf2");
 
579
  Map (XK_oacute, "\xf3");
 
580
  Map (XK_ocircumflex, "\xf4");
 
581
  Map (XK_otilde, "\xf5");
 
582
  Map (XK_odiaeresis, "\xf6");
 
583
  Map (XK_oe, "\xf7");
 
584
  Map (XK_oslash, "\xf8");
 
585
  Map (XK_ugrave, "\xf9");
 
586
  Map (XK_uacute, "\xfa");
 
587
  Map (XK_ucircumflex, "\xfb");
 
588
  Map (XK_udiaeresis, "\xfc");
 
589
  Map (XK_yacute, "\xfd");
 
590
  Map (XK_thorn, "\xfe");
 
591
  Map (XK_ydiaeresis, "\xff");
 
592
 
 
593
  // Symbols from iso-latin-2
 
594
  Map (XK_Aogonek, "\x81");
 
595
  Map (XK_breve, "breve");
 
596
  Map (XK_Lstroke, "\x8a");
 
597
  Map (XK_Lcaron, "\x89");
 
598
  Map (XK_Sacute, "\x91");
 
599
  Map (XK_Scaron, "\x92");
 
600
  Map (XK_Scedilla, "\x93");
 
601
  Map (XK_Tcaron, "\x94");
 
602
  Map (XK_Zacute, "\x99");
 
603
  Map (XK_Zcaron, "\x9a");
 
604
  Map (XK_Zabovedot, "\x9b");
 
605
  Map (XK_aogonek, "\xa1");
 
606
  Map (XK_ogonek, "ogonek");
 
607
  Map (XK_lstroke, "\xaa");
 
608
  Map (XK_lcaron, "\xa9");
 
609
  Map (XK_sacute, "\xb1");
 
610
  Map (XK_caron, "caron");
 
611
  Map (XK_scaron, "\xb2");
 
612
  Map (XK_scedilla, "\xb3");
 
613
  Map (XK_tcaron, "\xb4");
 
614
  Map (XK_zacute, "\xb9");
 
615
  Map (XK_doubleacute, "doubleacute");
 
616
  Map (XK_zcaron, "\xba");
 
617
  Map (XK_zabovedot, "\xbb");
 
618
  Map (XK_Racute, "\x8f");
 
619
  Map (XK_Abreve, "\x80");
 
620
  Map (XK_Lacute, "\x88");
 
621
  Map (XK_Cacute, "\x82");
 
622
  Map (XK_Ccaron, "\x83");
 
623
  Map (XK_Eogonek, "\x86");
 
624
  Map (XK_Ecaron, "\x85");
 
625
  Map (XK_Dcaron, "\x84");
 
626
  Map (XK_Dstroke, "\xd0");
 
627
  Map (XK_Nacute, "\x8b");
 
628
  Map (XK_Ncaron, "\x8c");
 
629
  Map (XK_Odoubleacute, "\x8e");
 
630
  Map (XK_Rcaron, "\x90");
 
631
  Map (XK_Uring, "\x97");
 
632
  Map (XK_Udoubleacute, "\x96");
 
633
  Map (XK_Tcedilla, "\x95");
 
634
  Map (XK_racute, "\xaf");
 
635
  Map (XK_abreve, "\xa0");
 
636
  Map (XK_lacute, "\xa8");
 
637
  Map (XK_cacute, "\xa2");
 
638
  Map (XK_ccaron, "\xa3");
 
639
  Map (XK_eogonek, "\xa6");
 
640
  Map (XK_ecaron, "\xa5");
 
641
  Map (XK_dcaron, "\xa4");
 
642
  Map (XK_dstroke, "\x9e");
 
643
  Map (XK_nacute, "\xab");
 
644
  Map (XK_ncaron, "\xac");
 
645
  Map (XK_odoubleacute, "\xae");
 
646
  Map (XK_udoubleacute, "\xb6");
 
647
  Map (XK_rcaron, "\xb0");
 
648
  Map (XK_uring, "\xb7");
 
649
  Map (XK_tcedilla, "\xb5");
 
650
  Map (XK_abovedot, "abovedot");
 
651
 
 
652
  // Special control keys
 
653
  Map (XK_Prior, "pageup");
 
654
  Map (XK_Next, "pagedown");
 
655
  Map (XK_Undo, "undo");
 
656
  Map (XK_Redo, "redo");
 
657
  Map (XK_Cancel, "cancel");
 
658
 
 
659
  // Control keys
 
660
  map (XK_space, "space");
 
661
  map (XK_Return, "return");
 
662
  map (XK_BackSpace, "backspace");
 
663
  map (XK_Delete, "delete");
 
664
  map (XK_Insert, "insert");
 
665
  map (XK_Tab, "tab");
 
666
  map (XK_ISO_Left_Tab, "tab");
 
667
  map (XK_Escape, "escape");
 
668
  map (XK_Left, "left");
 
669
  map (XK_Right, "right");
 
670
  map (XK_Up, "up");
 
671
  map (XK_Down, "down");
 
672
  map (XK_Page_Up, "pageup");
 
673
  map (XK_Page_Down, "pagedown");
 
674
  map (XK_Home, "home");
 
675
  map (XK_End, "end");
 
676
  map (XK_F1, "F1");
 
677
  map (XK_F2, "F2");
 
678
  map (XK_F3, "F3");
 
679
  map (XK_F4, "F4");
 
680
  map (XK_F5, "F5");
 
681
  map (XK_F6, "F6");
 
682
  map (XK_F7, "F7");
 
683
  map (XK_F8, "F8");
 
684
  map (XK_F9, "F9");
 
685
  map (XK_F10, "F10");
 
686
  map (XK_F11, "F11");
 
687
  map (XK_F12, "F12");
 
688
  // map (XK_Mode_switch, "modeswitch");
 
689
 
 
690
  // Keypad keys
 
691
  Map (XK_KP_Space, "K-space");
 
692
  Map (XK_KP_Enter, "K-return");
 
693
  Map (XK_KP_Delete, "K-delete");
 
694
  Map (XK_KP_Insert, "K-insert");
 
695
  Map (XK_KP_Tab, "K-tab");
 
696
  Map (XK_KP_Left, "K-left");
 
697
  Map (XK_KP_Right, "K-right");
 
698
  Map (XK_KP_Up, "K-up");
 
699
  Map (XK_KP_Down, "K-down");
 
700
  Map (XK_KP_Page_Up, "K-pageup");
 
701
  Map (XK_KP_Page_Down, "K-pagedown");
 
702
  Map (XK_KP_Home, "K-home");
 
703
  Map (XK_KP_Begin, "K-begin");
 
704
  Map (XK_KP_End, "K-end");
 
705
  Map (XK_KP_F1, "K-F1");
 
706
  Map (XK_KP_F2, "K-F2");
 
707
  Map (XK_KP_F3, "K-F3");
 
708
  Map (XK_KP_F4, "K-F4");
 
709
  Map (XK_KP_Equal, "K-=");
 
710
  Map (XK_KP_Multiply, "K-*");
 
711
  Map (XK_KP_Add, "K-+");
 
712
  Map (XK_KP_Subtract, "K--");
 
713
  Map (XK_KP_Decimal, "K-.");
 
714
  Map (XK_KP_Separator, "K-,");
 
715
  Map (XK_KP_Divide, "K-/");
 
716
  Map (XK_KP_0, "K-0");
 
717
  Map (XK_KP_1, "K-1");
 
718
  Map (XK_KP_2, "K-2");
 
719
  Map (XK_KP_3, "K-3");
 
720
  Map (XK_KP_4, "K-4");
 
721
  Map (XK_KP_5, "K-5");
 
722
  Map (XK_KP_6, "K-6");
 
723
  Map (XK_KP_7, "K-7");
 
724
  Map (XK_KP_8, "K-8");
 
725
  Map (XK_KP_9, "K-9");
 
726
 
 
727
  // For Sun keyboards
 
728
  Map (SunXK_FA_Grave, "grave");
 
729
  Map (SunXK_FA_Circum, "hat");
 
730
  Map (SunXK_FA_Tilde, "tilde");
 
731
  Map (SunXK_FA_Acute, "acute");
 
732
  Map (SunXK_FA_Diaeresis, "umlaut");
 
733
  Map (SunXK_FA_Cedilla, "cedilla");
 
734
  Map (SunXK_F36, "F11");
 
735
  Map (SunXK_F37, "F12");
 
736
  Map (SunXK_Copy, "copy");
 
737
  Map (SunXK_Paste, "paste");
 
738
  Map (SunXK_Cut, "cut");
 
739
  // Map (XK_L1, "stop");   On Sun, but conflicts with F11
 
740
  // Map (XK_L2, "again");  On Sun, but conflicts with F12
 
741
  Map (XK_L3, "props");
 
742
  Map (XK_L4, "undo");
 
743
  Map (XK_L5, "front");
 
744
  Map (XK_L6, "copy");
 
745
  Map (XK_L7, "open");
 
746
  Map (XK_L8, "paste");
 
747
  Map (XK_L9, "find");
 
748
  Map (XK_L10, "cut");
 
749
 
 
750
  // Miscellaneous
 
751
  Map (0x20ac, "euro");
 
752
}
 
753
 
 
754
/******************************************************************************
 
755
* Miscellaneous
 
756
******************************************************************************/
 
757
 
 
758
void
 
759
x_gui_rep::get_extents (SI& width, SI& height) {
 
760
  width = screen_width  * PIXEL;
 
761
  height= screen_height * PIXEL;
 
762
}
 
763
 
 
764
void
 
765
x_gui_rep::get_max_size (SI& width, SI& height) {
 
766
  width = 8000 * PIXEL;
 
767
  height= 6000 * PIXEL;
 
768
}
 
769
 
 
770
/******************************************************************************
 
771
* Main initialization
 
772
******************************************************************************/
 
773
 
 
774
x_gui_rep::x_gui_rep (int argc2, char** argv2):
 
775
  color_scale ((void*) NULL),
 
776
  character_bitmap (NULL), character_pixmap ((pointer) 0),
 
777
  xpm_bitmap (0), xpm_pixmap (0),
 
778
  lower_key (""), upper_key (""),
 
779
  selection (NULL), selection_t ("none"), selection_s ("")
 
780
{
 
781
  the_gui= this;
 
782
  if ((dpy= XOpenDisplay (NULL)) == NULL)
 
783
    fatal_error ("I failed to connect to Xserver", "x_gui_rep::x_gui_rep");
 
784
  // XSynchronize (dpy, true);
 
785
 
 
786
  XGCValues values;
 
787
  XVisualInfo visual;
 
788
 
 
789
  scr                = DefaultScreen (dpy);
 
790
  root               = RootWindow (dpy, scr);
 
791
  gc                 = XCreateGC (dpy, root, 0, &values);
 
792
  pixmap_gc          = XCreateGC (dpy, root, 0, &values);
 
793
  depth              = DefaultDepth (dpy, scr);
 
794
  screen_width       = DisplayWidth  (dpy, scr);
 
795
  screen_height      = DisplayHeight (dpy, scr);
 
796
  cols               = DefaultColormap (dpy, DefaultScreen (dpy));
 
797
  state              = 0;
 
798
  gswindow           = NULL;
 
799
  argc               = argc2;
 
800
  argv               = argv2;
 
801
  balloon_win        = NULL;
 
802
  interrupted        = false;
 
803
  interrupt_time     = texmacs_time ();
 
804
 
 
805
  if (XMatchVisualInfo (dpy, scr, depth, TrueColor, &visual) != 0) {
 
806
    if (visual.red_mask   == (255 << 16) &&
 
807
        visual.green_mask == (255 << 8) &&
 
808
        visual.blue_mask  == 255)
 
809
      true_color= true;
 
810
  }
 
811
 
 
812
  XSetGraphicsExposures (dpy, gc, true);
 
813
 
 
814
  //get_xmodmap ();
 
815
  x_initialize_colors ();
 
816
  initialize_input_method ();
 
817
  initialize_keyboard_pointer ();
 
818
  set_output_language (get_locale_language ());
 
819
  (void) default_font ();
 
820
}
 
821
 
 
822
x_gui_rep::~x_gui_rep () {
 
823
  if (im_ok) XCloseIM (im);
 
824
  clear_selection ("primary");
 
825
  XFreeGC (dpy, gc);
 
826
  XCloseDisplay (dpy);
 
827
  if (!true_color) delete[] cmap;
 
828
}
 
829
 
 
830
void
 
831
gui_open (int argc2, char** argv2) {
 
832
  if (the_gui != NULL)
 
833
    fatal_error ("gui already open", "gui_open");
 
834
  the_gui= new x_gui_rep (argc2, argv2);
 
835
}
 
836
 
 
837
void
 
838
gui_start_loop () {
 
839
  the_gui->event_loop ();
 
840
}
 
841
 
 
842
void
 
843
gui_close () {
 
844
  if (the_gui == NULL)
 
845
    fatal_error ("gui not yet open", "gui_close");
 
846
  delete the_gui;
 
847
  the_gui= NULL;
 
848
}
 
849
 
 
850
void
 
851
gui_root_extents (SI& width, SI& height) {
 
852
  the_gui->get_extents (width, height);
 
853
}
 
854
 
 
855
void
 
856
gui_maximal_extents (SI& width, SI& height) {
 
857
  the_gui->get_max_size (width, height);
 
858
}
 
859
 
 
860
void
 
861
gui_refresh () {
 
862
  iterator<Window> it= iterate (Window_to_window);
 
863
  while (it->busy()) {
 
864
    x_window win= (x_window) Window_to_window [it->next()];
 
865
    if (get_x_window (win->w) != NULL)
 
866
      send_update (win->w);
 
867
  }
 
868
}