Initial release of Maemo 5 port of gnuplot
[gnuplot] / term / wxt.trm
1 /*
2  * $Id: wxt.trm,v 1.17 2006/09/15 14:09:36 tlecomte Exp $
3  */
4
5 /* GNUPLOT - wxt.trm */
6
7 /*[
8  * Copyright 2005,2006   Timothee Lecomte
9  *
10  * Permission to use, copy, and distribute this software and its
11  * documentation for any purpose with or without fee is hereby granted,
12  * provided that the above copyright notice appear in all copies and
13  * that both that copyright notice and this permission notice appear
14  * in supporting documentation.
15  *
16  * Permission to modify the software is granted, but not the right to
17  * distribute the complete modified source code.  Modifications are to
18  * be distributed as patches to the released version.  Permission to
19  * distribute binaries produced by compiling modified sources is granted,
20  * provided you
21  *   1. distribute the corresponding source modifications from the
22  *    released version in the form of a patch file along with the binaries,
23  *   2. add special version identification to distinguish your version
24  *    in addition to the base release version number,
25  *   3. provide your name and address as the primary contact for the
26  *    support of your modified version, and
27  *   4. retain our contact information in regard to use of the base
28  *    software.
29  * Permission to distribute the released version of the source code along
30  * with corresponding source modifications in the form of a patch file is
31  * granted with same provisions 2 through 4 for binary distributions.
32  *
33  * This software is provided "as is" without express or implied warranty
34  * to the extent permitted by applicable law.
35 ]*/
36
37 /* ------------------------------------------------------
38  * Here you will find the terminal table, filled
39  * with C++ functions defined in wxt_gui.cpp,
40  * where the wxWidgets terminal is mainly implemented.
41  * See wxt_gui.cpp for details about this terminal.
42  * ------------------------------------------------------*/
43
44 #ifdef TERM_REGISTER
45 register_term (wxt)
46 #endif
47
48 #ifdef TERM_PROTO
49 TERM_PUBLIC void wxt_options __PROTO ((void));
50 #endif /* TERM_PROTO */
51
52 #ifndef TERM_PROTO_ONLY
53
54 #ifdef TERM_BODY
55
56 #include "wxterminal/wxt_term.h"
57 /* for enhanced text mode */
58 #include "wxterminal/gp_cairo_term.h"
59
60 /* terminal state, defined extern in wxt_term.h */
61 int wxt_window_number = 0;
62 TBOOLEAN wxt_enhanced_enabled = FALSE;
63 int wxt_persist = UNSET;
64 int wxt_raise = UNSET;
65 int wxt_ctrl = UNSET;
66 /* default text font family: */
67 char wxt_set_fontname[MAX_ID_LEN + 1] = "";
68 /* default text size*/
69 int wxt_set_fontsize = 0;
70 /* window title */
71 char wxt_title[MAX_ID_LEN + 1] = "";
72
73 enum WXT_id {
74     WXT_FONT,
75     WXT_ENHANCED,
76     WXT_NOENHANCED,
77     WXT_PERSIST,
78     WXT_NOPERSIST,
79     WXT_RAISE,
80     WXT_NORAISE,
81     WXT_CTRL,
82     WXT_NOCTRL,
83     WXT_TITLE,
84     WXT_CLOSE,
85     WXT_OTHER
86 };
87
88 static struct gen_table wxt_opts[] = {
89     {"font",   WXT_FONT},
90     {"enh$anced", WXT_ENHANCED},
91     {"noenh$anced", WXT_NOENHANCED},
92     {"per$sist", WXT_PERSIST},
93     {"noper$sist", WXT_NOPERSIST},
94     {"rai$se", WXT_RAISE},
95     {"norai$se", WXT_NORAISE},
96     {"ct$rlq", WXT_CTRL},
97     {"noct$rlq", WXT_NOCTRL},
98     {"ti$tle", WXT_TITLE},
99     {"cl$ose", WXT_CLOSE},
100     {NULL, WXT_OTHER}
101 };
102
103
104 /* "Called when terminal type is selected. This procedure should parse options on the command line.
105 * A list of the currently selected options should be stored in term_options[],
106 * in a form suitable for use with the set term command.
107 * term_options[] is used by the save command.  Use options_null() if no options are available." */
108 TERM_PUBLIC void wxt_options()
109 {
110         struct value a;
111         char *s = NULL;
112         char *font_setting = NULL;
113         int sep;
114         TBOOLEAN duplication = FALSE;
115         TBOOLEAN set_enhanced = FALSE, set_font = FALSE;
116         TBOOLEAN set_persist = FALSE, set_number = FALSE;
117         TBOOLEAN set_raise = FALSE, set_ctrl = FALSE;
118         TBOOLEAN set_title = FALSE, set_close = FALSE;
119
120         while (!END_OF_COMMAND) {
121                 FPRINTF((stderr, "processing token\n"));
122                 switch (lookup_table(&wxt_opts[0], c_token)) {
123                 case WXT_FONT:
124                         c_token++;
125                         if (!(s = try_to_get_string()))
126                                 int_error(c_token,"font: expecting string");
127                         if (!(*s)) {
128                                 strcpy (wxt_set_fontname, "");
129                                 wxt_set_fontsize = 0;
130                         } else {
131                                 sep = strcspn(s,",");
132                                 if (sep > 0) {
133                                         strncpy(wxt_set_fontname, s, sep);
134                                         wxt_set_fontname[sep] = '\0';
135                                 }
136                                 if (s[sep] == ',')
137                                         sscanf(&(s[sep+1]), "%d", &wxt_set_fontsize);
138                         }
139                         font_setting = (char*) gp_alloc(strlen(s) + 1,"wxt font");
140                         strcpy(font_setting,s);
141                         free(s);
142                         if (set_font) duplication=TRUE;
143                         set_font = TRUE;
144                         break;
145                 case WXT_ENHANCED:
146                         c_token++;
147                         wxt_enhanced_enabled = TRUE;
148                         term->flags |= TERM_ENHANCED_TEXT;
149                         if (set_enhanced) duplication=TRUE;
150                         set_enhanced = TRUE;
151                         break;
152                 case WXT_NOENHANCED:
153                         c_token++;
154                         wxt_enhanced_enabled = FALSE;
155                         term->flags &= ~TERM_ENHANCED_TEXT;
156                         if (set_enhanced) duplication=TRUE;
157                         set_enhanced = TRUE;
158                         break;
159                 case WXT_PERSIST:
160                         c_token++;
161                         wxt_persist = yes;
162                         if (set_persist) duplication=TRUE;
163                         set_persist = TRUE;
164                         break;
165                 case WXT_NOPERSIST:
166                         c_token++;
167                         wxt_persist = no;
168                         if (set_persist) duplication=TRUE;
169                         set_persist = TRUE;
170                         break;
171                 case WXT_RAISE:
172                         c_token++;
173                         wxt_raise = yes;
174                         if (set_raise) duplication=TRUE;
175                         set_raise = TRUE;
176                         break;
177                 case WXT_NORAISE:
178                         c_token++;
179                         wxt_raise = no;
180                         if (set_raise) duplication=TRUE;
181                         set_raise = TRUE;
182                         break;
183                 case WXT_CTRL:
184                         c_token++;
185                         wxt_ctrl = yes;
186                         if (set_ctrl) duplication=TRUE;
187                         set_ctrl = TRUE;
188                         break;
189                 case WXT_NOCTRL:
190                         c_token++;
191                         wxt_ctrl = no;
192                         if (set_ctrl) duplication=TRUE;
193                         set_ctrl = TRUE;
194                         break;
195                 case WXT_TITLE:
196                         c_token++;
197                         if (!(s = try_to_get_string()))
198                                 int_error(c_token,"title: expecting string");
199                         if (*s)
200                                 strncpy(wxt_title, s, sizeof(wxt_title));
201                         free(s);
202                         if (set_title) duplication=TRUE;
203                         set_title = TRUE;
204                         break;
205                 case WXT_CLOSE:
206                         c_token++;
207                         if (set_close) duplication=TRUE;
208                         set_close = TRUE;
209                         break;
210                 case WXT_OTHER:
211                 default:
212                         wxt_window_number = (int) real(const_express(&a));
213                         if (set_number) duplication=TRUE;
214                         set_number = TRUE;
215                         /*int_error(c_token, "unrecognized terminal option");*/
216                         break;
217                 }
218
219                 if (duplication)
220                         int_error(c_token-1, "Duplicated or contradicting arguments in wxt term options.");
221         }
222
223         /* Save options back into options string in normalized format */
224         snprintf(term_options, sizeof(term_options)-strlen(term_options),
225                 "%d", wxt_window_number);
226
227         if (set_title) {
228                 strncat(term_options, " title \"", sizeof(term_options)-strlen(term_options));
229                 strncat(term_options, wxt_title, sizeof(term_options)-strlen(term_options));
230                 strncat(term_options, "\"", sizeof(term_options)-strlen(term_options));
231                 wxt_update_title(wxt_window_number);
232         }
233
234         if (set_enhanced)
235                 strncat(term_options,
236                         wxt_enhanced_enabled ? " enhanced" : " noenhanced",
237                         sizeof(term_options)-strlen(term_options));
238
239         if (set_font) {
240                 strncat(term_options, " font \"", sizeof(term_options)-strlen(term_options));
241                 strncat(term_options, font_setting, sizeof(term_options)-strlen(term_options));
242                 strncat(term_options, "\"", sizeof(term_options)-strlen(term_options));
243                 free(font_setting);
244         }
245
246         if (set_persist)
247                 strncat(term_options,
248                         (wxt_persist==yes) ? " persist" : " nopersist",
249                         sizeof(term_options)-strlen(term_options));
250
251         if (set_raise)
252                 strncat(term_options,
253                         (wxt_raise==yes) ? " raise" : " noraise",
254                         sizeof(term_options)-strlen(term_options));
255
256         if (set_ctrl)
257                 strncat(term_options,
258                         (wxt_ctrl==yes) ? " ctrl" : " noctrl",
259                         sizeof(term_options)-strlen(term_options));
260
261         if (set_close)
262                 wxt_close_terminal_window(wxt_window_number);
263 }
264 #endif /* TERM_BODY */
265
266 #ifdef TERM_TABLE
267 TERM_TABLE_START (wxt_driver)
268     "wxt", "wxWidgets cross-platform windowed terminal",
269     /* the following values are overriden by wxt_graphics */
270     1 /* xmax */ , 1 /* ymax */ , 1 /* vchar */ , 1 /* hchar */ ,
271     1 /* vtic */ , 1 /* htic */ ,
272     wxt_options, wxt_init, wxt_reset, wxt_text, null_scale, wxt_graphics,
273     wxt_move, wxt_vector, wxt_linetype, wxt_put_text,
274     wxt_text_angle, wxt_justify_text,
275     wxt_point, do_arrow, wxt_set_font,
276     wxt_pointsize, TERM_CAN_MULTIPLOT|TERM_NO_OUTPUTFILE,
277     wxt_text /* suspend */, 0 /* resume */, wxt_fillbox, wxt_linewidth
278 #ifdef USE_MOUSE
279     , wxt_waitforinput, wxt_put_tmptext, wxt_set_ruler, wxt_set_cursor, wxt_set_clipboard
280 #endif
281     , wxt_make_palette, 0 /* wxt_previous_palette */, wxt_set_color, wxt_filled_polygon
282 #ifdef WITH_IMAGE
283     , wxt_image
284 #endif
285     , gp_cairo_enhanced_open, gp_cairo_enhanced_flush, do_enh_writec
286 TERM_TABLE_END (wxt_driver)
287
288 #undef LAST_TERM
289 #define LAST_TERM wxt_driver
290
291 #endif /* TERM_TABLE */
292 #endif /* TERM_PROTO_ONLY */
293
294 #ifdef TERM_HELP
295 START_HELP(wxt)
296 "1 wxt",
297 "?set terminal wxt",
298 "?terminal wxt",
299 "?set term wxt",
300 "?term wxt",
301 "?wxt",
302 " The `wxt` terminal device generates output in a separate window. The window",
303 " is created by the wxWidgets library, where the 'wxt' comes from. The actual",
304 " drawing is done via cairo, a 2D graphics library, and pango, a library for",
305 " laying out and rendering text.",
306 "",
307 " Syntax:",
308 "         set term wxt {<n>}",
309 "                      {{no}enhanced}",
310 "                      {font <font>}",
311 "                      {title \"title\"}",
312 "                      {{no}persist}",
313 "                      {{no}raise}",
314 "                      {{no}ctrl}",
315 "                      {close}",
316 "",
317 " Multiple plot windows are supported: `set terminal wxt <n>` directs the",
318 " output to plot window number n.",
319 "",
320 " The default window title is based on the window number. This title can also",
321 " be specified with the keyword \"title\".",
322 "",
323 " Plot windows remain open even when the `gnuplot` driver is changed to a",
324 " different device.  A plot window can be closed by pressing the letter 'q'",
325 " while that window has input focus, by choosing `close` from a window",
326 " manager menu, or with `set term wxt <n> close`.",
327 "",
328 " When you resize a window, the plot is immediately scaled to fit in the",
329 " new size of the window. Unlike other interactive terminals, the `wxt`",
330 " terminal scales the whole plot, including fonts and linewidths, and keeps",
331 " its global aspect ratio constant, leaving an empty space painted in gray.",
332 " If you type `replot`, click the `replot` icon in the terminal toolbar or",
333 " type a new `plot` command, the new plot will completely fit in the window",
334 " and the font size and the linewidths will be reset to their defaults.",
335 "",
336 " The active plot window (the one selected by `set term wxt <n>`) is",
337 " interactive. Its behaviour is shared with other terminal types. See `mouse`",
338 " for details. It also has some extra icons, which are supposed to be",
339 " self-explanatory.",
340 "",
341 " This terminal supports an enhanced text mode, which allows font and other",
342 " formatting commands (subscripts, superscripts, etc.) to be embedded in labels",
343 " and other text strings. The enhanced text mode syntax is shared with other",
344 " gnuplot terminal types. See `enhanced` for more details.",
345 "",
346 " <font> is in the format \"FontFace,FontSize\", i.e. the face and the size",
347 " comma-separated in a single string. FontFace is a usual font face name, such",
348 " as \'Arial\'. If you do not provide FontFace, the wxt terminal will use",
349 " \'Sans\'. FontSize is the font size, in points. If you do not provide it,",
350 " the wxt terminal will use a size of 10 points.",
351 "    For example :",
352 "       set term wxt font \"Arial,12\"",
353 "       set term wxt font \"Arial\" # to change the font face only",
354 "       set term wxt font \",12\" # to change the font size only",
355 "       set term wxt font \"\" # to reset the font name and size",
356 "",
357 " The fonts are retrieved from the usual fonts subsystems. Under Windows,",
358 " those fonts are to be found and configured in the entry \"Fonts\" of the",
359 " control panel. Under UNIX, they are handled by \"fontconfig\".",
360 "",
361 " Pango, the library used to layout the text, is based on utf-8. Thus, the wxt",
362 " terminal has to convert from your encoding to utf-8. The default input",
363 " encoding is based on your \'locale\'. If you want to use another encoding,",
364 " make sure gnuplot knows which one you are using. See `encoding` for more",
365 " details.",
366 "",
367 " Pango may give unexpected results with fonts that do not respect the unicode",
368 " mapping. With the Symbol font, for example, the wxt terminal will use the map",
369 " provided by http://www.unicode.org/ to translate character codes to unicode.",
370 " Pango will do its best to find a font containing this character, looking for",
371 " your Symbol font, or other fonts with a broad unicode coverage, like the",
372 " DejaVu fonts. Note that \"the Symbol font\" is to be understood as the Adobe",
373 " Symbol font, distributed with Acrobat Reader as \"SY______.PFB\".",
374 " Alternatively, the OpenSymbol font, distributed with OpenOffice.org as",
375 " \"opens___.ttf\", offers the same characters. Microsoft has distributed a",
376 " Symbol font (\"symbol.ttf\"), but it has a different character set with",
377 " several missing or moved mathematic characters. If you experience problems",
378 " with your default setup (if the demo enhancedtext.dem is not displayed",
379 " properly for example), you probably have to install one of the Adobe or",
380 " OpenOffice Symbol fonts, and remove the Microsoft one.",
381 " Other non-conform fonts, such as \"wingdings\" have been observed working.",
382 "",
383 " The rendering of the plot can be altered with a dialog available from the",
384 " toolbar. To obtain the best output possible, the rendering involves three",
385 " mechanisms : antialiasing, oversampling and hinting.",
386 " Antialiasing allows to display non-horizontal and non-vertical lines",
387 " smoother.",
388 " Oversampling combined with antialiasing provides subpixel accuracy,",
389 " so that gnuplot can draw a line from non-integer coordinates. This avoids",
390 " wobbling effects on diagonal lines ('plot x' for example).",
391 " Hinting avoids the blur on horizontal and vertical lines caused by",
392 " oversampling. The terminal will snap these lines to integer coordinates so",
393 " that a one-pixel-wide line will actually be drawn on one and only one pixel.",
394 "",
395 " By default, the window is raised to the top of your desktop when a plot is",
396 " drawn. This can be controlled with the keyword \"raise\".",
397 " The keyword \"persist\" will prevent gnuplot from exiting before you",
398 " explicitely close all the plot windows.",
399 " Finally, by default the key <space> raises the gnuplot console window, and",
400 " 'q' closes the plot window. The keyword \"ctrl\" allows you to replace those",
401 " bindings by <ctrl>+<space> and <ctrl>+'q', respectively.",
402 " These three keywords (raise, persist and ctrl) can also be set and remembered",
403 " between sessions through the configuration dialog."
404 END_HELP(wxt)
405 #endif /* TERM_HELP */