Initial release of Maemo 5 port of gnuplot
[gnuplot] / src / term_api.h
1 /*
2  * $Id: term_api.h,v 1.59.2.1 2008/12/12 06:57:50 sfeam Exp $
3  */
4
5 /* GNUPLOT - term_api.h */
6
7 /*[
8  * Copyright 1999, 2004   Thomas Williams, Colin Kelley
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 #ifndef GNUPLOT_TERM_API_H
38 # define GNUPLOT_TERM_API_H
39
40 /* #if... / #include / #define collection: */
41
42 #include "syscfg.h"
43 #include "stdfn.h"
44 #include "gp_types.h"
45
46 #include "color.h"
47 #include "mousecmn.h"
48 #include "tables.h"
49
50 /* Constants that are interpreted by terminal driver routines */
51
52 /* Default line type is LT_BLACK; reset to this after changing colors */
53 #define LT_AXIS       (-1)
54 #define LT_BLACK      (-2)
55 #define LT_NODRAW     (-3)
56 #define LT_BACKGROUND (-4)
57 #define LT_UNDEFINED  (-5)
58 #define LT_COLORFROMCOLUMN  (-6)        /* Used by hidden3d code */
59 #define LT_DEFAULT    (-7)
60
61 /* Constant value passed to (term->text_angle)(ang) to generate vertical
62  * text. Current implementation has ang equal to rotation in degrees.
63  */
64 #define TEXT_VERTICAL (90)
65
66
67 /* Type definitions */
68
69 /* this order means we can use  x-(just*strlen(text)*t->h_char)/2 if
70  * term cannot justify
71  */
72 typedef enum JUSTIFY {
73     LEFT,
74     CENTRE,
75     RIGHT
76 } JUSTIFY;
77
78 /* we use a similar trick for vertical justification of multi-line labels */
79 typedef enum VERT_JUSTIFY {
80     JUST_TOP,
81     JUST_CENTRE,
82     JUST_BOT
83 } VERT_JUSTIFY;
84
85
86 typedef struct lp_style_type {  /* contains all Line and Point properties */
87     int     pointflag;          /* 0 if points not used, otherwise 1 */
88     int     l_type;
89     int     p_type;
90     double  l_width;
91     double  p_size;
92     TBOOLEAN use_palette;
93     struct t_colorspec pm3d_color;
94     /* ... more to come ? */
95 } lp_style_type;
96
97 #define DEFAULT_LP_STYLE_TYPE {0, -2, 0, 1.0, PTSZ_DEFAULT, FALSE, DEFAULT_COLORSPEC}
98
99 typedef enum e_arrow_head {
100         NOHEAD = 0,
101         END_HEAD = 1,
102         BACKHEAD = 2,
103         BOTH_HEADS = 3
104 } t_arrow_head;
105
106 extern const char *arrow_head_names[4];
107
108 typedef struct arrow_style_type {    /* contains all Arrow properties */
109     int layer;                       /* 0 = back, 1 = front */
110     struct lp_style_type lp_properties;
111     /* head options */
112     t_arrow_head head;               /* arrow head choice */
113     /* struct position headsize; */  /* x = length, y = angle [deg] */
114     double head_length;              /* length of head, 0 = default */
115     int head_lengthunit;             /* unit (x1, x2, screen, graph) */
116     double head_angle;               /* front angle / deg */
117     double head_backangle;           /* back angle / deg */
118     unsigned int head_filled;        /* filled heads: 0=not, 1=empty, 2=filled */
119     /* ... more to come ? */
120 } arrow_style_type;
121
122 /* Operations used by the terminal entry point term->layer(). */
123 typedef enum termlayer {
124         TERM_LAYER_RESET,
125         TERM_LAYER_BACKTEXT,
126         TERM_LAYER_FRONTTEXT,
127         TERM_LAYER_END_TEXT
128 } t_termlayer;
129
130 typedef struct fill_style_type {
131     int fillstyle;
132     int filldensity;
133     int fillpattern;
134     int border_linetype;
135 } fill_style_type;
136
137 typedef enum t_fillstyle { FS_EMPTY, FS_SOLID, FS_PATTERN, FS_DEFAULT }
138              t_fillstyle;
139 #define FS_OPAQUE (FS_SOLID + (100<<4))
140
141 #ifdef WITH_IMAGE
142 /* Color construction for an image, palette lookup or rgb components.
143  */
144 typedef enum t_imagecolor { IC_PALETTE, IC_RGB }
145              t_imagecolor;
146 #endif
147
148 /* values for the optional flags field - choose sensible defaults
149  * these aren't really very sensible names - multiplot attributes
150  * depend on whether stdout is redirected or not. Remember that
151  * the default is 0. Thus most drivers can do multiplot only if
152  * the output is redirected
153  */
154 #define TERM_CAN_MULTIPLOT    1  /* tested if stdout not redirected */
155 #define TERM_CANNOT_MULTIPLOT 2  /* tested if stdout is redirected  */
156 #define TERM_BINARY           4  /* open output file with "b"       */
157 #define TERM_INIT_ON_REPLOT   8  /* call term->init() on replot     */
158 #define TERM_IS_POSTSCRIPT   16  /* post, next, pslatex, etc        */
159 #define TERM_ENHANCED_TEXT   32  /* enhanced text mode is enabled   */
160 #define TERM_NO_OUTPUTFILE   64  /* terminal doesnt write to a file */
161 #define TERM_CAN_CLIP       128  /* terminal does its own clipping  */
162
163 /* The terminal interface structure --- heart of the terminal layer.
164  *
165  * It should go without saying that additional entries may be made
166  * only at the end of this structure. Any fields added must be
167  * optional - a value of 0 (or NULL pointer) means an older driver
168  * does not support that feature - gnuplot must still be able to
169  * function without that terminal feature
170  */
171
172 typedef struct TERMENTRY {
173     const char *name;
174 #ifdef WIN16
175     const char GPFAR description[80];  /* to make text go in FAR segment */
176 #else
177     const char *description;
178 #endif
179     unsigned int xmax,ymax,v_char,h_char,v_tic,h_tic;
180
181     void (*options) __PROTO((void));
182     void (*init) __PROTO((void));
183     void (*reset) __PROTO((void));
184     void (*text) __PROTO((void));
185     int (*scale) __PROTO((double, double));
186     void (*graphics) __PROTO((void));
187     void (*move) __PROTO((unsigned int, unsigned int));
188     void (*vector) __PROTO((unsigned int, unsigned int));
189     void (*linetype) __PROTO((int));
190     void (*put_text) __PROTO((unsigned int, unsigned int, const char*));
191     /* the following are optional. set term ensures they are not NULL */
192     int (*text_angle) __PROTO((int));
193     int (*justify_text) __PROTO((enum JUSTIFY));
194     void (*point) __PROTO((unsigned int, unsigned int, int));
195     void (*arrow) __PROTO((unsigned int, unsigned int, unsigned int, unsigned int, int));
196     int (*set_font) __PROTO((const char *font));
197     void (*pointsize) __PROTO((double)); /* change pointsize */
198     int flags;
199     void (*suspend) __PROTO((void)); /* called after one plot of multiplot */
200     void (*resume)  __PROTO((void)); /* called before plots of multiplot */
201     void (*fillbox) __PROTO((int, unsigned int, unsigned int, unsigned int, unsigned int)); /* clear in multiplot mode */
202     void (*linewidth) __PROTO((double linewidth));
203 #ifdef USE_MOUSE
204     int (*waitforinput) __PROTO((void));     /* used for mouse input */
205     void (*put_tmptext) __PROTO((int, const char []));   /* draws temporary text; int determines where: 0=statusline, 1,2: at corners of zoom box, with \r separating text above and below the point */
206     void (*set_ruler) __PROTO((int, int));    /* set ruler location; x<0 switches ruler off */
207     void (*set_cursor) __PROTO((int, int, int));   /* set cursor style and corner of rubber band */
208     void (*set_clipboard) __PROTO((const char[]));  /* write text into cut&paste buffer (clipboard) */
209 #endif
210     int (*make_palette) __PROTO((t_sm_palette *palette));
211     /* 1. if palette==NULL, then return nice/suitable
212        maximal number of colours supported by this terminal.
213        Returns 0 if it can make colours without palette (like
214        postscript).
215        2. if palette!=NULL, then allocate its own palette
216        return value is undefined
217        3. available: some negative values of max_colors for whatever
218        can be useful
219      */
220     void (*previous_palette) __PROTO((void));
221     /* release the palette that the above routine allocated and get
222        back the palette that was active before.
223        Some terminals, like displays, may draw parts of the figure
224        using their own palette. Those terminals that possess only
225        one palette for the whole plot don't need this routine.
226      */
227     void (*set_color) __PROTO((t_colorspec *));
228     /* EAM November 2004 - revised to take a pointer to struct rgb_color,
229        so that a palette gray value is not the only option for
230        specifying color.
231      */
232     void (*filled_polygon) __PROTO((int points, gpiPoint *corners));
233 #ifdef WITH_IMAGE
234     void (*image) __PROTO((unsigned, unsigned, coordval *, gpiPoint *, t_imagecolor));
235 #endif
236
237 /* Enhanced text mode driver call-backs */
238     void (*enhanced_open) __PROTO((char * fontname, double fontsize,
239                 double base, TBOOLEAN widthflag, TBOOLEAN showflag,
240                 int overprint));
241     void (*enhanced_flush) __PROTO((void));
242     void (*enhanced_writec) __PROTO((int c));
243
244 /* Driver-specific synchronization or other layering commands.
245  * Introduced as an alternative to the ugly sight of
246  * driver-specific code strewn about in the core routines.
247  * As of this point (July 2005) used only by pslatex.trm
248  */
249     void (*layer) __PROTO((t_termlayer));
250
251 /* Begin/End path control. 
252  * Needed by PostScript-like devices in order to join the endpoints of
253  * a polygon cleanly.
254  */
255     void (*path) __PROTO((int p));
256
257 } TERMENTRY;
258
259 #ifdef WIN16
260 # define termentry TERMENTRY far
261 #else
262 # define termentry TERMENTRY
263 #endif
264
265 enum set_encoding_id {
266    S_ENC_DEFAULT, S_ENC_ISO8859_1, S_ENC_ISO8859_2, S_ENC_ISO8859_15,
267    S_ENC_CP437, S_ENC_CP850, S_ENC_CP852, S_ENC_CP1250,
268    S_ENC_KOI8_R, S_ENC_KOI8_U, 
269    S_ENC_INVALID
270 };
271
272 /* HBB 20020225: this stuff used to be in a separate header, ipc.h,
273  * but I strongly disliked the way that was done */
274
275 /*
276  * There are the following types of interprocess communication from
277  * (gnupmdrv, gnuplot_x11) => gnuplot:
278  *      OS2_IPC  ... the OS/2 shared memory + event semaphores approach
279  *      PIPE_IPC ... communication by using bidirectional pipe
280  */
281
282
283 /*
284  * OS2_IPC: gnuplot's terminals communicate with it by shared memory + event
285  * semaphores => the code in gpexecute.c is used, and nothing more from here.
286  */
287
288 #ifdef PIPE_IPC
289
290 enum { IPC_BACK_UNUSABLE = -2, IPC_BACK_CLOSED = -1 };
291
292 /*
293  * Currently only used for PIPE_IPC, but in principle
294  * every term could use this file descriptor to write back
295  * commands to gnuplot.  Note, that terminals using this fd
296  * should set it to a negative value when closing. (joze)
297  */
298 /* HBB 20020225: currently not used anywhere outside term.c --> make
299  * it static */
300 /* extern int ipc_back_fd; */
301
302 # endif /* PIPE_IPC */
303
304 /* options handling */
305 enum { UNSET = -1, no = 0, yes = 1 };
306
307 /* Variables of term.c needed by other modules: */
308
309 /* the terminal info structure, being the heart of the whole module */
310 extern struct termentry *term;
311 /* Options string of the currently used terminal driver */
312 extern char term_options[];
313 /* access head length + angle without changing API */
314 extern int curr_arrow_headlength;
315 /* angle in degrees */
316 extern double curr_arrow_headangle;
317 extern double curr_arrow_headbackangle;
318 /* arrow head filled or not */
319 extern int curr_arrow_headfilled;
320
321 /* Current 'output' file: name and open filehandle */
322 extern char *outstr;
323 extern FILE *gpoutfile;
324
325 /* Output file where the PostScript output goes to.
326    In particular:
327         gppsfile == gpoutfile
328                 for 'set term': postscript, pstex
329         gppsfile == PSLATEX_auxfile
330                 for 'set term': pslatex
331         gppsfile == 0
332                 for all other terminals
333    It is non-zero for for the family of postscript terminals, thus making
334    this a unique check for postscript output (pm3d has some code optimized
335    for PS, for instance).
336 */
337 extern FILE *gppsfile;
338
339 extern TBOOLEAN multiplot;
340
341 /* 'set encoding' support: index of current encoding ... */
342 extern enum set_encoding_id encoding;
343 /* ... in table of encoding names: */
344 extern const char *encoding_names[];
345 /* parsing table for encodings */
346 extern const struct gen_table set_encoding_tbl[];
347
348 /* mouse module needs this */
349 extern TBOOLEAN term_initialised;
350
351 /* Support for enhanced text mode. */
352 extern char  enhanced_text[];
353 extern char *enhanced_cur_text;
354 extern double enhanced_fontscale;
355 /* give array size to allow the use of sizeof */
356 extern char enhanced_escape_format[16];
357 extern double enhanced_max_height, enhanced_min_height;
358 extern TBOOLEAN ignore_enhanced_text;
359
360
361 /* Prototypes of functions exported by term.c */
362
363 void term_set_output __PROTO((char *));
364 void term_initialise __PROTO((void));
365 void term_start_plot __PROTO((void));
366 void term_end_plot __PROTO((void));
367 void term_start_multiplot __PROTO((void));
368 void term_end_multiplot __PROTO((void));
369 /* void term_suspend __PROTO((void)); */
370 void term_reset __PROTO((void));
371 void term_apply_lp_properties __PROTO((struct lp_style_type *lp));
372 void term_check_multiplot_okay __PROTO((TBOOLEAN));
373
374 void write_multiline __PROTO((unsigned int, unsigned int, char *, JUSTIFY, VERT_JUSTIFY, int, const char *));
375 int estimate_strlen __PROTO((char *));
376 #if 0 /* UNUSED */
377 int term_count __PROTO((void));
378 #endif /* UNUSED */
379 void list_terms __PROTO((void));
380 struct termentry *set_term __PROTO((int));
381 void init_terminal __PROTO((void));
382 void test_term __PROTO((void));
383
384 /* Support for enhanced text mode. */
385 char *enhanced_recursion __PROTO((char *p, TBOOLEAN brace,
386                                          char *fontname, double fontsize,
387                                          double base, TBOOLEAN widthflag,
388                                          TBOOLEAN showflag, int overprint));
389 void enh_err_check __PROTO((const char *str));
390 /* note: c is char, but must be declared int due to K&R compatibility. */
391 void do_enh_writec __PROTO((int c));
392 /* flag: don't use enhanced output methods --- for output of
393  * filenames, which usually looks bad using subscripts */
394 void ignore_enhanced __PROTO((TBOOLEAN flag));
395
396 /* Simple-minded test that point is with drawable area */
397 TBOOLEAN on_page __PROTO((int x, int y));
398
399 #ifdef LINUXVGA
400 void LINUX_setup __PROTO((void));
401 #endif
402
403 #ifdef PC
404 void PC_setup __PROTO((void));
405 #endif
406
407 #ifdef VMS
408 void vms_reset();
409 #endif
410
411 #ifdef OS2
412 int PM_pause __PROTO((char *));
413 void PM_intc_cleanup __PROTO((void));
414 # ifdef USE_MOUSE
415 void PM_update_menu_items __PROTO((void));
416 void PM_set_gpPMmenu __PROTO((struct t_gpPMmenu * gpPMmenu));
417 # endif
418 #endif
419
420 /* in set.c (used in pm3d.c) */
421 void lp_use_properties __PROTO((struct lp_style_type *lp, int tag, int pointflag));
422
423 /* Wrappers for term->path() */
424 void newpath __PROTO((void));
425 void closepath __PROTO((void));
426
427 #endif /* GNUPLOT_TERM_API_H */