1 /*
2  *  GraphApp
3  *  --------
4  *  Common cross-platform graphics application routines.
5  *  Version 2.4 (c) Lachlan Patrick 1996-1998.
6  *  This header file is designed to be platform-independent.
7  *
8  *  Copyright 2006-8	The R Foundation
9  *  Copyright 2013-20	The R Core Team
10  *
11  */
12 
13 /*
14  *  Common cross-platform graphics routines library.
15  */
16 
17 #ifndef _GRAPHAPP_H
18 #define _GRAPHAPP_H	240
19 
20 /*
21  *  Assume C declarations for C++
22  */
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif /* begin normal C declarations */
27 
28 /*
29  *  Definition of some constants.
30  */
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 
35 #ifndef Pi
36 #define Pi 3.14159265359
37 #endif
38 
39 /*
40  *  Types.
41  */
42 
43 typedef unsigned char GAbyte;
44 
45 #ifndef objptr
46   typedef struct { int kind; } gui_obj;
47   typedef gui_obj * objptr;
48 #endif
49 
50 typedef unsigned long rgb;    /* red-green-blue colour value */
51 
52 typedef objptr font;          /* font of certain size and style */
53 typedef objptr cursor;        /* mouse cursor shape */
54 
55 typedef objptr drawing;       /* bitmap, window or control */
56 
57 typedef drawing bitmap;       /* platform-specific bitmap */
58 typedef drawing window;       /* on-screen window */
59 typedef drawing control;      /* buttons, text-fields, scrollbars */
60 
61 typedef control label;        /* text label */
62 typedef control button;       /* push button */
63 typedef control checkbox;     /* check-box */
64 typedef control radiobutton;  /* radio button */
65 typedef control radiogroup;   /* group of radio buttons */
66 typedef control field;        /* one-line text field */
67 typedef control textbox;      /* multi-line text box */
68 typedef control scrollbar;    /* scroll-bar */
69 typedef control listbox;      /* list of text */
70 typedef control progressbar;  /* progress bar */
71 
72 typedef control menubar;      /* contains menus */
73 typedef control menu;         /* pull-down menu contains menuitems */
74 typedef control menuitem;     /* a single item in a pull-down menu */
75 
76 /*
77  *  Structures.
78  */
79 
80 typedef struct point point;
81 typedef struct rect rect;
82 typedef struct drawstruct drawstruct;
83 typedef struct drawstruct *drawstate;
84 typedef struct imagedata imagedata;
85 typedef struct imagedata *image;
86 
87 struct point
88 {
89     int x, y;
90 };
91 
92 struct rect
93 {
94     int x, y;		/* top-left point inside rect */
95     int width, height;	/* width and height of rect */
96 };
97 
98 struct drawstruct
99 {
100     drawing	dest;
101     rgb	hue;
102     int	mode;
103     point	p;
104     int	linewidth;
105     font	fnt;
106     cursor	crsr;
107 };
108 
109 struct imagedata {
110     int     depth;
111     int     width;
112     int     height;
113     int     cmapsize;
114     rgb *   cmap;
115     GAbyte *  pixels;
116 };
117 
118 /*
119  *  Call-backs.
120  */
121 
122 typedef void (*voidfn)(void);
123 typedef void (*timerfn)(void *data);
124 typedef void (*actionfn)(control c);
125 typedef void (*drawfn)(control c, rect r);
126 typedef void (*mousefn)(control c, int buttons, point xy);
127 typedef void (*intfn)(control c, int argument);
128 typedef void (*keyfn)(control c, int key);
129 typedef void (*menufn)(menuitem m);
130 typedef void (*scrollfn)(scrollbar s, int position);
131 typedef void (*dropfn)(control c, char *data);
132 typedef void (*imfn)(control c, font *f, point *xy);
133 
134 /*
135  *  Mouse buttons state (bit-fields).
136  */
137 
138 #define NoButton	0x0000
139 #define LeftButton	0x0001
140 #define MiddleButton	0x0002
141 #define RightButton	0x0004
142 
143 /*
144  *  ANSI character codes.
145  */
146 
147 #define BELL	0x07
148 #define BKSP	0x08
149 #define VTAB	0x0B
150 #define FF	0x0C
151 #define ESC	0x1B
152 
153 /*
154  *  Edit-key codes.
155  */
156 
157 #define INS	0x2041
158 #define DEL	0x2326
159 #define HOME	0x21B8
160 #define END	0x2198
161 #define PGUP	0x21DE
162 #define PGDN	0x21DF
163 #define ENTER	0x2324
164 
165 /*
166  *  Cursor-key codes.
167  */
168 
169 #define LEFT	0x2190
170 #define UP	0x2191
171 #define RIGHT	0x2192
172 #define DOWN	0x2193
173 
174 /*
175  *  Function-key codes.
176  */
177 
178 #define F1	0x276C
179 #define F2	0x276D
180 #define F3	0x276E
181 #define F4	0x276F
182 #define F5	0x2770
183 #define F6	0x2771
184 #define F7	0x2772
185 #define F8	0x2773
186 #define F9	0x2774
187 #define F10	0x2775
188 
189 /*
190  *  Redefined functions.
191  */
192 #define REDEFINE_FUNC_NAMES
193 #define addpt      GA_addpt
194 #define subpt      GA_subpt
195 #define equalpt    GA_equalpt
196 #define newmenu    GA_newmenu
197 #define newcontrol GA_newcontrol
198 #define newwindow  GA_newwindow
199 /* #define gettext    GA_gettext */
200 #define settext    GA_settext
201 
202 #define R_REMAP
203 #ifdef R_REMAP
204 #define BringToTop		GA_BringToTop
205 #define GetCurrentWinPos	GA_GetCurrentWinPos
206 #define activatecontrol		GA_activatecontrol
207 #define add_context		GAI_add_context
208 #define add_strings		GA_add_strings
209 #define addstatusbar		GA_addstatusbar
210 #define addto		GA_addto
211 #define addtooltip		GA_addtooltip
212 #define adjust_menu		GAI_adjust_menu
213 #define app_cleanup		GA_appcleanup
214 #define apperror		GA_apperror
215 #define apply_to_list		GAI_apply_to_list
216 #define askUserPass		GA_askUserPass
217 #define askcdstring		GA_askcdstring
218 #define askchangedir		GA_askchangedir
219 #define askfilename		GA_askfilename
220 #define askfilenames		GA_askfilenames
221 #define askfilenamewithdir	GA_askfilenamewithdir
222 #define askfilesave		GA_askfilesave
223 #define askfilesavewithdir	GA_askfilesavewithdir
224 #define askok		GA_askok
225 #define askokcancel		GA_askokcancel
226 #define askpassword		GA_askpassword
227 #define askstring		GA_askstring
228 #define askyesno		GA_askyesno
229 #define askyesnocancel		GA_askyesnocancel
230 #define bitblt		GA_bitblt
231 #define bitmaptoimage		GA_bitmaptoimage
232 #define bottomleft		GA_bottomleft
233 #define bottomright		GA_bottomright
234 #define brighter		GA_brighter
235 #define changelistbox		GA_changelistbox
236 #define changescrollbar		GA_changescrollbar
237 #define char_to_string		GAI_char_to_string
238 #define check		GA_check
239 #define checklimittext		GA_checklimittext
240 #define clear		GA_clear
241 #define cleartext		GA_cleartext
242 #define clipboardhastext		GA_clipboardhastext
243 #define clipr		GA_clipr
244 #define compare_strings		GAI_compare_strings
245 #define convert32to8		GA_convert32to8
246 #define convert8to32		GA_convert8to32
247 #define copy_string		GAI_copy_string
248 #define copydrawstate		GA_copydrawstate
249 #define copyimage		GA_copyimage
250 #define copyrect		GA_copyrect
251 #define copystringtoclipboard		GA_copystringtoclipboard
252 #define copytext		GA_copytext
253 #define copytoclipboard		GA_copytoclipboard
254 #define countFilenames		GA_countFilenames
255 #define createbitmap		GA_createbitmap
256 #define createcursor		GA_createcursor
257 #define currentcursor		GA_currentcursor
258 #define currentdrawing		GA_currentdrawing
259 #define currentfont		GA_currentfont
260 #define currentlinewidth		GA_currentlinewidth
261 #define currentmode		GA_currentmode
262 #define currentpoint		GA_currentpoint
263 #define currentrgb		GA_currentrgb
264 #define currenttime		GA_currenttime
265 #define cuttext		GA_cuttext
266 #define darker		GA_darker
267 #define decrease_refcount	GAI_decrease_refcount
268 #define del_all_contexts	GAI_del_all_contexts
269 #define del_context		GAI_del_context
270 #define del_string		GAI_del_string
271 #define delay		GA_delay
272 #define deletion_traversal	GAI_deletion_traversal
273 #define delimage		GA_delimage
274 #define delobj		GA_delobj
275 #define delstatusbar		GA_delstatusbar
276 #define deviceheight		GA_deviceheight
277 #define deviceheightmm		GA_deviceheightmm
278 #define devicepixelsx		GA_devicepixelsx
279 #define devicepixelsy		GA_devicepixelsy
280 #define devicewidth		GA_devicewidth
281 #define devicewidthmm		GA_devicewidthmm
282 #define dialog_bg		GA_dialog_bg
283 #define disable		GA_disable
284 #define divpt		GA_divpt
285 #define doevent		GA_doevent
286 #define draw		GA_draw
287 #define drawall		GA_drawall
288 #define drawarc		GA_drawarc
289 #define drawbrighter		GA_drawbrighter
290 #define drawdarker		GA_drawdarker
291 #define drawellipse		GA_drawellipse
292 #define drawgreyscale		GA_drawgreyscale
293 #define drawimage		GA_drawimage
294 #define drawline		GA_drawline
295 #define drawmonochrome		GA_drawmonochrome
296 #define drawpoint		GA_drawpoint
297 #define drawpolygon		GA_drawpolygon
298 #define drawrect		GA_drawrect
299 #define drawroundrect		GA_drawroundrect
300 #define drawstr		GA_drawstr
301 #define drawtext		GA_drawtext
302 #define drawto		GA_drawto
303 #define enable		GA_enable
304 #define equalr		GA_equalr
305 #define execapp		GA_execapp
306 #define exitapp		GA_exitapp
307 #define fillarc		GA_fillarc
308 #define fillellipse		GA_fillellipse
309 #define fillpolygon		GA_fillpolygon
310 #define fillrect		GA_fillrect
311 #define fillroundrect		GA_fillroundrect
312 #define find_object		GAI_find_object
313 #define find_valid_sibling	GAI_find_valid_sibling
314 #define finddialog		GA_finddialog
315 #define finish_contexts		GAI_finish_contexts
316 #define finish_events		GAI_finish_events
317 #define finish_objects		GAI_finish_objects
318 #define fix_brush		GAI_fix_brush
319 #define flashcontrol		GA_flashcontrol
320 #define float_to_string		GAI_float_to_string
321 #define fontascent		GA_fontascent
322 #define fontdescent		GA_fontdescent
323 #define fontheight		GA_fontheight
324 #define fontwidth		GA_fontwidth
325 #define gabeep		GA_gabeep
326 #define gamainloop		GA_gamainloop
327 #define gbitblt		GA_gbitblt
328 #define gchangemenubar		GA_gchangemenubar
329 #define gchangepopup		GA_gchangepopup
330 #define gchangescrollbar		GA_gchangescrollbar
331 #define gcharmetric		GA_gcharmetric
332 #define gcopy		GA_gcopy
333 #define gcopyalpha		GA_gcopyalpha
334 #define gdrawellipse		GA_gdrawellipse
335 #define gdrawline		GA_gdrawline
336 #define gdrawpolyline		GA_gdrawpolyline
337 #define gdrawrect		GA_gdrawrect
338 #define gdrawstr		GA_gdrawstr
339 #define gdrawstr1		GA_gdrawstr1
340 #define gdrawwcs		GA_gdrawwcs
341 #define getHandle		GA_getHandle
342 #define getSysFontSize		GA_getSysFontSize
343 #define get_context		GAI_get_context
344 #define get_grey_pixel		GAI_get_grey_pixel
345 #define get_image_pixel		GAI_get_image_pixel
346 #define get_modeless		GAI_get_modeless
347 #define get_monochrome_pixel	GAI_get_monochrome_pixel
348 #define getbackground		GA_getbackground
349 #define getbitmapdata		GA_getbitmapdata
350 #define getbitmapdata2		GA_getbitmapdata2
351 #define getcliprect		GA_getcliprect
352 #define getcurrentline		GA_getcurrentline
353 #define getdata		GA_getdata
354 #define getforeground		GA_getforeground
355 #define getkeystate		GA_getkeystate
356 #define getlimittext		GA_getlimittext
357 #define getlinelength		GA_getlinelength
358 #define getlistitem		GA_getlistitem
359 #define getpalette		GA_getpalette
360 #define getpalettesize		GA_getpalettesize
361 #define getpastelength		GA_getpastelength
362 #define getpixel		GA_getpixel
363 #define getpixels		GA_getpixels
364 #define getseltext		GA_getseltext
365 #define getstringfromclipboard		GA_getstringfromclipboard
366 #define gettextfont		GA_gettextfont
367 #define getvalue		GA_getvalue
368 #define gfillellipse		GA_gfillellipse
369 #define gfillpolygon		GA_gfillpolygon
370 #define gfillrect		GA_gfillrect
371 #define ggetcliprect		GA_ggetcliprect
372 #define ggetkeystate		GA_ggetkeystate
373 #define ggetmodified		GA_ggetmodified
374 #define ggetpixel		GA_ggetpixel
375 #define ghasfixedwidth		GA_ghasfixedwidth
376 #define ginvert		GA_ginvert
377 #define gmenubar		GA_gmenubar
378 #define gnewfont		GA_gnewfont
379 #define gnewfont2		GA_gnewfont2
380 #define goldfillellipse		GA_goldfillellipse
381 #define gpopup		GA_gpopup
382 #define gprintf		GA_gprintf
383 #define growr		GA_growr
384 #define gscroll		GA_gscroll
385 #define gsetcliprect		GA_gsetcliprect
386 #define gsetcursor		GA_gsetcursor
387 #define gsetpolyfillmode	GA_gsetpolyfillmode
388 #define gsetmodified		GA_gsetmodified
389 #define gsetpixel		GA_gsetpixel
390 #define gstrrect		GA_gstrrect
391 #define gstrsize		GA_gstrsize
392 #define gstrwidth		GA_gstrwidth
393 #define gwcharmetric		GA_gwcharmetric
394 #define gwcswidth		GA_gwcswidth
395 #define gwdrawstr1		GA_gwdrawstr1
396 #define handle_control		GAI_handle_control
397 #define handle_findreplace	GAI_handle_findreplace
398 #define handle_menu_id		GAI_handle_menu_id
399 #define handle_menu_key		GAI_handle_menu_key
400 #define has_transparent_pixels	GAI_has_transparent_pixels
401 #define hide			GA_hide
402 #define hide_window		GAI_hide_window
403 #define highlight		GA_highlight
404 #define imagedepth		GA_imagedepth
405 #define imageheight		GA_imageheight
406 #define imagetobitmap		GA_imagetobitmap
407 #define imagewidth		GA_imagewidth
408 #define increase_refcount	GAI_increase_refcount
409 #define init_contexts		GAI_init_contexts
410 #define init_cursors		GAI_init_cursors
411 #define init_events		GAI_init_events
412 #define init_fonts		GAI_init_fonts
413 #define init_menus		GAI_init_menus
414 #define init_objects		GAI_init_objects
415 #define initapp			GA_initapp
416 #define inserttext		GA_inserttext
417 #define insetr			GA_insetr
418 #define int_to_string		GAI_int_to_string
419 #define invertrect		GA_invertrect
420 #define isTopmost		GA_isTopmost
421 #define ischecked		GA_ischecked
422 #define isenabled		GA_isenabled
423 #define ishighlighted		GA_ishighlighted
424 #define isiconic		GA_isiconic
425 #define ismdi			GA_ismdi
426 #define isselected		GA_isselected
427 #define isUnicodeWindow		GA_isUnicodeWindow
428 #define isvisible		GA_isvisible
429 #define lineto			GA_lineto
430 #define load_gif		GAI_load_gif
431 #define loadbitmap		GA_loadbitmap
432 #define loadcursor		GA_loadcursor
433 #define loadimage		GA_loadimage
434 #define memalloc		GAI_memalloc
435 #define memexpand		GAI_memexpand
436 #define memfree		GAI_memfree
437 #define memjoin		GAI_memjoin
438 #define memlength		GAI_memlength
439 #define memrealloc		GAI_memrealloc
440 #define midpt		GA_midpt
441 #define modeless_active		GA_modeless_active
442 #define move_to_front		GAI_move_to_front
443 #define moveto		GA_moveto
444 #define mulpt		GA_mulpt
445 #define myAppendMenu		GA_myAppendMenu
446 #define myGetSysColor		GA_myGetSysColor
447 #define myMessageBox		GA_myMessageBox
448 #define nametorgb		GA_nametorgb
449 #define new_font_object		GA_new_font_object
450 #define new_object		GAI_new_object
451 #define new_string		GAI_new_string
452 #define newbitmap		GA_newbitmap
453 #define newbutton		GA_newbutton
454 #define newcheckbox		GA_newcheckbox
455 #define newcursor		GA_newcursor
456 #define newdrawing		GA_newdrawing
457 #define newdropfield		GA_newdropfield
458 #define newdroplist		GA_newdroplist
459 #define newfield		GA_newfield
460 #define newfield_no_border		GA_newfield_no_border
461 #define newfont		GA_newfont
462 #define newimage		GA_newimage
463 #define newimagebutton		GA_newimagebutton
464 #define newimagecheckbox		GA_newimagecheckbox
465 #define newlabel		GA_newlabel
466 #define newlistbox		GA_newlistbox
467 #define newmdimenu		GA_newmdimenu
468 #define newmenubar		GA_newmenubar
469 #define newmenuitem		GA_newmenuitem
470 #define newmetafile		GA_newmetafile
471 #define newmultilist		GA_newmultilist
472 #define newpassword		GA_newpassword
473 #define newpicture		GA_newpicture
474 #define newpoint		GA_newpoint
475 #define newpopup		GA_newpopup
476 #define newprinter		GA_newprinter
477 #define newprogressbar		GA_newprogressbar
478 #define newradiobutton		GA_newradiobutton
479 #define newradiogroup		GA_newradiogroup
480 #define newrect		GA_newrect
481 #define newrichtextarea		GA_newrichtextarea
482 #define newscrollbar		GA_newscrollbar
483 #define newsubmenu		GA_newsubmenu
484 #define newtextarea		GA_newtextarea
485 #define newtextbox		GA_newtextbox
486 #define newtoolbar		GA_newtoolbar
487 #define newtoolbutton		GA_newtoolbutton
488 #define nextpage		GA_nextpage
489 #define objdepth		GA_objdepth
490 #define objheight		GA_objheight
491 #define objrect		GA_objrect
492 #define objwidth		GA_objwidth
493 #define oldfillellipse		GA_oldfillellipse
494 #define parentwindow		GA_parentwindow
495 #define pastetext		GA_pastetext
496 #define peekevent		GA_peekevent
497 #define protect_object		GAI_protect_object
498 #define ptinr		GA_ptinr
499 #define raddpt		GA_raddpt
500 #define rcanon		GA_rcanon
501 #define rcenter		GA_rcenter
502 #define rdiv		GA_rdiv
503 #define redraw		GA_redraw
504 #define remove_context		GAI_remove_context
505 #define remove_menu_item	GA_remove_menu_item
506 #define replacedialog		GA_replacedialog
507 #define resetdrawstate		GA_resetdrawstate
508 #define resize			GA_resize
509 #define restoredrawstate	GA_restoredrawstate
510 #define rgbtoname		GA_rgbtoname
511 #define rgbtonum		GA_rgbtonum
512 #define rinr		GA_rinr
513 #define rmove		GA_rmove
514 #define rmul		GA_rmul
515 #define rpt		GA_rpt
516 #define rsubpt		GA_rsubpt
517 #define rxr		GA_rxr
518 #define save_gif		GAI_save_gif
519 #define saveimage		GA_saveimage
520 #define scaleimage		GA_scaleimage
521 #define screen_coords		GA_screen_coords
522 #define scrollcaret		GA_scrollcaret
523 #define scrollrect		GA_scrollrect
524 #define scrolltext		GA_scrolltext
525 #define selecttext		GA_selecttext
526 #define selecttextex		GA_selecttextex
527 #define setaction		GA_setaction
528 #define setbackground		GA_setbackground
529 #define setbitmapdata		GA_setbitmapdata
530 #define setcaret		GA_setcaret
531 #define setcliprect		GA_setcliprect
532 #define setclose		GA_setclose
533 #define setcursor		GA_setcursor
534 #define setdata		GA_setdata
535 #define setdel		GA_setdel
536 #define setdrawmode		GA_setdrawmode
537 #define setdrawstate		GA_setdrawstate
538 #define setdrop		GA_setdrop
539 #define setfont		GA_setfont
540 #define setforeground		GA_setforeground
541 #define sethit		GA_sethit
542 #define setimage		GA_setimage
543 #define setim		GA_setim
544 #define setkeyaction		GA_setkeyaction
545 #define setkeydown		GA_setkeydown
546 #define setlimittext		GA_setlimittext
547 #define setlinewidth		GA_setlinewidth
548 #define setlistitem		GA_setlistitem
549 #define setmousedown		GA_setmousedown
550 #define setmousedrag		GA_setmousedrag
551 #define setmousemove		GA_setmousemove
552 #define setmouserepeat		GA_setmouserepeat
553 #define setmousetimer		GA_setmousetimer
554 #define setmouseup		GA_setmouseup
555 #define setonfocus		GA_setonfocus
556 #define setpalette		GA_setpalette
557 #define setpixel		GA_setpixel
558 #define setpixels		GA_setpixels
559 #define setprogressbar		GA_setprogressbar
560 #define setprogressbarrange		GA_setprogressbarrange
561 #define setredraw		GA_setredraw
562 #define setresize		GA_setresize
563 #define setrgb		GA_setrgb
564 #define setstatus		GA_setstatus
565 #define settextfont		GA_settextfont
566 #define settimer		GA_settimer
567 #define settimerfn		GA_settimerfn
568 #define setuserfilter		GA_setuserfilter
569 #define setvalue		GA_setvalue
570 #define show		GA_show
571 #define showcaret	GA_showcaret
572 #define show_window		GAI_show_window
573 #define simple_window		GAI_simple_window
574 #define sortpalette		GA_sortpalette
575 #define startgraphapp		GA_startgraphapp
576 #define stepprogressbar		GA_stepprogressbar
577 #define string_diff		GAI_string_diff
578 #define string_length		GAI_string_length
579 #define strrect		GA_strrect
580 #define strsize		GA_strsize
581 #define strwidth		GA_strwidth
582 #define textheight		GA_textheight
583 #define textselection		GA_textselection
584 #define textselectionex		GA_textselectionex
585 #define texturerect		GA_texturerect
586 #define to_c_string		GAI_to_c_string
587 #define to_dos_string		GAI_to_dos_string
588 #define toolbar_hide		GA_toolbar_hide
589 #define toolbar_show		GA_toolbar_show
590 #define topleft		GA_topleft
591 #define topright		GA_topright
592 #define tree_search		GA_tree_search
593 #define uncheck		GA_uncheck
594 #define undotext		GA_undotext
595 #define unhighlight		GA_unhighlight
596 #define updatestatus		GA_updatestatus
597 #define waitevent		GA_waitevent
598 
599 #define ColorName		GA_ColorName
600 #define Courier			GA_Courier
601 #define FixedFont		GA_FixedFont
602 #define Helvetica		GA_Helvetica
603 #define MDIFrame		GA_MDIFrame
604 #define MDIStatus		GA_MDIStatus
605 #define MDIToolbar		GA_MDIToolbar
606 #define SystemFont		GA_SystemFont
607 #define Times			GA_Times
608 #define TopmostDialogs		GA_TopmostDialogs
609 #define active_windows		GAI_active_windows
610 #define app_control_proc	GAI_app_control_proc
611 #define app_control_procedure	GAI_app_control_procedure
612 #define app_doc_proc		GAI_app_doc_proc
613 #define app_drawstate		GAI_app_drawstate
614 #define app_initialised		GAI_app_initialised
615 #define app_name		GAI_app_name
616 #define app_timer_proc		GAI_app_timer_proc
617 #define app_timer_procedure	GAI_app_timer_procedure
618 #define app_win_proc		GAI_app_win_proc
619 #define app_work_proc		GAI_app_work_proc
620 #define child_id		GAI_child_id
621 #define current			GAI_current
622 #define current_menu		GAI_current_menu
623 #define current_menubar		GAI_current_menubar
624 #define current_window		GAI_current_window
625 #define dc			GAI_dc
626 #define hAccel			GAI_hAccel
627 #define hwndClient		GAI_hwndClient
628 #define hwndFrame		GAI_hwndFrame
629 #define hwndMain		GAI_hwndMain
630 #define is_NT			GA_isNT
631 #define keystate		GAI_keystate
632 #define menus_active		GAI_menus_active
633 #define prev_instance		GAI_prev_instance
634 #define the_brush		GAI_the_brush
635 #define the_pen			GAI_the_pen
636 #define this_instance		GAI_this_instance
637 #define win_rgb			GAI_win_rgb
638 
639 #define ArrowCursor		GA_ArrowCursor
640 #define BlankCursor		GA_BlankCursor
641 #define CaretCursor		GA_CaretCursor
642 #define CrossCursor		GA_CrossCursor
643 #define HandCursor		GA_HandCursor
644 #define TextCursor		GA_TextCursor
645 #define WatchCursor		GA_WatchCursor
646 
647 #define cam_image		GA_cam_image
648 #define color_image		GA_color_image
649 #define console1_image		GA_console1_image
650 #define console_image		GA_console_image
651 #define copy1_image		GA_copy1_image
652 #define copy_image		GA_copy_image
653 #define copypaste_image		GA_copypaste_image
654 #define cut_image		GA_cut_image
655 #define erase_image		GA_erase_image
656 #define help_image		GA_help_image
657 #define open1_image		GA_open1_image
658 #define open_image		GA_open_image
659 #define paste1_image		GA_paste1_image
660 #define paste_image		GA_paste_image
661 #define print_image		GA_print_image
662 #define save_image		GA_save_image
663 #define stop_image		GA_stop_image
664 #endif
665 
666 /*
667  *  General functions.
668  */
669 
670 int	initapp(int argc, char *argv[]);
671 void	exitapp(void);
672 
673 void	drawall(void);
674 int	peekevent(void);
675 void	waitevent(void);
676 int	doevent(void);
677 void	mainloop(void);
678 
679 int	execapp(char *cmd);
680 
681 /*void	beep(void);*/
682 
683 /*
684  *  Point and rectangle arithmetic.
685  */
686 
687 point	newpoint(int x, int y);
688 rect	newrect(int left, int top, int width, int height);
689 rect	rpt(point min, point max);
690 
691 #define pt(x,y)         newpoint((x),(y))
692 #define rect(x,y,w,h)   newrect((x),(y),(w),(h))
693 
694 point	topleft(rect r);
695 point	bottomright(rect r);
696 point	topright(rect r);
697 point	bottomleft(rect r);
698 
699 point	addpt(point p1, point p2);
700 point	subpt(point p1, point p2);
701 point	midpt(point p1, point p2);
702 point	mulpt(point p1, int i);
703 point	divpt(point p1, int i);
704 rect	rmove(rect r, point p);
705 rect	raddpt(rect r, point p);
706 rect	rsubpt(rect r, point p);
707 rect	rmul(rect r, int i);
708 rect	rdiv(rect r, int i);
709 rect	growr(rect r, int w, int h);
710 rect	insetr(rect r, int i);
711 rect	rcenter(rect r1, rect r2);
712 int	ptinr(point p, rect r);
713 int	rinr(rect r1, rect r2);
714 int	rxr(rect r1, rect r2);
715 int	equalpt(point p1, point p2);
716 int	equalr(rect r1, rect r2);
717 rect	clipr(rect r1, rect r2);
718 rect	rcanon(rect r);
719 
720 /*
721  *  Colour functions and constants.
722  */
723 
724 #define	rgb(r,g,b)    ((((rgb)r)<<16)|(((rgb)g)<<8)|((rgb)b))
725 #define getalpha(col) (((col)>>24)&0x00FFUL)
726 #define getred(col)   (((col)>>16)&0x00FFUL)
727 #define getgreen(col) (((col)>>8)&0x00FFUL)
728 #define getblue(col)  ((col)&0x00FFUL)
729 
730 void	setrgb(rgb c);
731 #define	setcolor(c)  setrgb(c)
732 #define	setcolour(c) setrgb(c)
733 
734 /* changed to avoid clashes with w32api 2.0 */
735 #define gaRed		0x00FF0000UL
736 #define gaGreen		0x0000FF00UL
737 #define gaBlue		0x000000FFUL
738 
739 
740 #define Transparent     0xFFFFFFFFUL
741 
742 #define Black		0x00000000UL
743 #define White		0x00FFFFFFUL
744 #define Yellow		0x00FFFF00UL
745 #define Magenta		0x00FF00FFUL
746 #define Cyan		0x0000FFFFUL
747 
748 #define Grey		0x00808080UL
749 #define Gray		0x00808080UL
750 #define LightGrey	0x00C0C0C0UL
751 #define LightGray	0x00C0C0C0UL
752 #define DarkGrey	0x00404040UL
753 #define DarkGray	0x00404040UL
754 
755 #define DarkBlue	0x00000080UL
756 #define DarkGreen	0x00008000UL
757 #define DarkRed		0x008B0000UL/* changed to match rgb */
758 #define LightBlue	0x0080C0FFUL
759 #define LightGreen	0x0080FF80UL
760 #define LightRed	0x00FFC0FFUL
761 #define Pink		0x00FFAFAFUL
762 #define Brown		0x00603000UL
763 #define Orange		0x00FF8000UL
764 #define Purple		0x00C000FFUL
765 #define Lime		0x0080FF00UL
766 
767 /*
768  *  Context functions for bitmaps, windows, controls.
769  */
770 
771 void	addto(control dest);
772 void	drawto(drawing dest);
773 void	setlinewidth(int width);
774 
775 /*
776  *  Transfer modes for drawing operations, S=source, D=destination.
777  *  The modes are arranged so that, for example, (~D)|S == notDorS.
778  */
779 
780 void	setdrawmode(int mode);
781 
782 #define Zeros	 0x00
783 #define DnorS	 0x01
784 #define DandnotS 0x02
785 #define notS	 0x03
786 #define notDandS 0x04
787 #define notD	 0x05
788 #define DxorS	 0x06
789 #define DnandS	 0x07
790 #define DandS	 0x08
791 #define DxnorS	 0x09
792 #define D	 0x0A
793 #define DornotS	 0x0B
794 #define S	 0x0C
795 #define notDorS	 0x0D
796 #define DorS	 0x0E
797 #define Ones	 0x0F
798 
799 /*
800  *  Drawing functions.
801  */
802 
803 void	bitblt(drawing dest, drawing src, point dp, rect sr, int mode);
804 
805 void	scrollrect(point dp, rect sr);
806 void	copyrect(drawing src, point dp, rect sr);
807 void	texturerect(drawing src, rect r);
808 void	invertrect(rect r);
809 
810 rgb	getpixel(point p);
811 void	setpixel(point p, rgb c);
812 
813 /*
814  *  Drawing using the current colour.
815  */
816 
817 void	moveto(point p);
818 void	lineto(point p);
819 
820 void	drawpoint(point p);
821 void	drawline(point p1, point p2);
822 void	drawrect(rect r);
823 void	fillrect(rect r);
824 void	drawarc(rect r, int start_angle, int end_angle);
825 void	fillarc(rect r, int start_angle, int end_angle);
826 void	drawellipse(rect r);
827 void	fillellipse(rect r);
828 void	drawroundrect(rect r);
829 void	fillroundrect(rect r);
830 void	drawpolygon(point *p, int n);
831 void	fillpolygon(point *p, int n);
832 
833 /*
834  *  Drawing text, selecting fonts.
835  */
836 
837 font	newfont(const char *name, int style, int size);
838 void	setfont(font f);
839 
840 int	fontwidth(font f);
841 int	fontheight(font f);
842 int	fontascent(font f);
843 int	fontdescent(font f);
844 
845 #define	getascent(f)	fontascent(f)
846 #define	getdescent(f)	fontdescent(f)
847 
848 int	strwidth(font f, const char *s);
849 point	strsize(font f, const char *s);
850 rect	strrect(font f, const char *s);
851 
852 int	drawstr(point p, const char *str);
853 int	textheight(int width, const char *text);
854 const char *drawtext(rect r, int alignment, const char *text);
855 int	gprintf(const char *fmt, ...);
856 
857 /*
858  *  Text styles and alignments.
859  */
860 
861 #define Plain		0x0000
862 #define Bold		0x0001
863 #define Italic		0x0002
864 #define BoldItalic	0x0003
865 #define SansSerif	0x0004
866 #define FixedWidth	0x0008
867 #define Wide		0x0010
868 #define Narrow		0x0020
869 
870 #define AlignTop        0x0000
871 #define AlignBottom     0x0100
872 #define VJustify        0x0200
873 #define VCenter         0x0400
874 #define VCentre         0x0400
875 #define AlignLeft       0x0000
876 #define AlignRight      0x1000
877 #define Justify	        0x2000
878 #define Center	        0x4000
879 #define Centre          0x4000
880 #define AlignCenter     0x4000
881 #define AlignCentre     0x4000
882 #define Underline       0x0800
883 
884 /*
885  *  Find the current state of drawing.
886  */
887 
888 drawing	currentdrawing(void);
889 rgb	currentrgb(void);
890 #define	currentcolor() currentrgb()
891 #define	currentcolour() currentrgb()
892 int	currentmode(void);
893 point	currentpoint(void);
894 int	currentlinewidth(void);
895 font	currentfont(void);
896 cursor	currentcursor(void);
897 
898 /*
899  *  Find current keyboard state.
900  */
901 
902 int	getkeystate(void);
903 
904 #define AltKey	0x0001
905 #define CmdKey	0x0001
906 #define CtrlKey		0x0002
907 #define OptionKey	0x0002
908 #define ShiftKey	0x0004
909 
910 /*
911  *  Bitmaps.
912  */
913 
914 bitmap	newbitmap(int width, int height, int depth);
915 bitmap	loadbitmap(const char *name);
916 bitmap	imagetobitmap(image img);
917 bitmap	createbitmap(int width, int height, int depth, GAbyte *data);
918 void	setbitmapdata(bitmap b, GAbyte data[]);
919 void	getbitmapdata(bitmap b, GAbyte data[]);
920 void	getbitmapdata2(bitmap b, GAbyte **data);
921 
922 /*
923  *  Images.
924  */
925 
926 image	newimage(int width, int height, int depth);
927 image	copyimage(image img);
928 void	delimage(image img);
929 
930 int     imagedepth(image img);
931 int     imagewidth(image img);
932 int     imageheight(image img);
933 
934 void	setpixels(image img, GAbyte pixels[]);
935 GAbyte *	getpixels(image img);
936 
937 void	setpalette(image img, int length, rgb cmap[]);
938 rgb *	getpalette(image img);
939 int	getpalettesize(image img);
940 
941 image	scaleimage(image src, rect dr, rect sr);
942 image	convert32to8(image img);
943 image	convert8to32(image img);
944 void	sortpalette(image img);
945 
946 image	loadimage(const char *filename);
947 void	saveimage(image img, const char *filename);
948 
949 void	drawimage(image img, rect dr, rect sr);
950 void	drawmonochrome(image img, rect dr, rect sr);
951 void	drawgreyscale(image img, rect dr, rect sr);
952 #define drawgrayscale drawgreyscale
953 void	drawdarker(image img, rect dr, rect sr);
954 void	drawbrighter(image img, rect dr, rect sr);
955 
956 /*
957  *  Windows.
958  */
959 
960 window	newwindow(const char *name, rect r, long flags);
961 void	show(window w);
962 void	hide(window w);
963 rect    GetCurrentWinPos(window obj);
964 
965 /*
966  *  Window creation flags.
967  */
968 
969 #define SimpleWindow	0x00000000L
970 
971 #define Menubar		0x00000010L
972 #define Titlebar	0x00000020L
973 #define Closebox	0x00000040L
974 #define Resize		0x00000080L
975 #define Maximize	0x00000100L
976 #define Minimize	0x00000200L
977 #define HScrollbar	0x00000400L
978 #define VScrollbar	0x00000800L
979 #define CanvasSize	0x00200000L
980 
981 #define Modal		0x00001000L
982 #define Floating	0x00002000L
983 #define Centered	0x00004000L
984 #define Centred		0x00004000L
985 
986 #define Workspace	0x00010000L
987 #define Document	0x00020000L
988 #define ChildWindow	0x00040000L
989 
990 #define TrackMouse	0x00080000L
991 
992 #define UsePalette	0x00100000L
993 #define UseUnicode	0x00200000L
994 
995 #define StandardWindow	(Titlebar|Closebox|Resize|Maximize|Minimize)
996 
997 /*
998  *  Functions which work for bitmaps, windows and controls.
999  */
1000 
1001 int	objdepth(objptr obj);
1002 rect	objrect(objptr obj);
1003 int	objwidth(objptr obj);
1004 int	objheight(objptr obj);
1005 void	delobj(objptr obj);
1006 
1007 #define	getdepth(obj)	objdepth((objptr)(obj))
1008 #define	getrect(obj)	objrect((objptr)(obj))
1009 #define	getwidth(obj)	objwidth((objptr)(obj))
1010 #define	getheight(obj)	objheight((objptr)(obj))
1011 #define	del(obj)	delobj((objptr)(obj))
1012 
1013 /*
1014  *  Setting window and control callback functions.
1015  */
1016 
1017 void	setaction(control c, actionfn fn);
1018 void	sethit(control c, intfn fn);
1019 void	setdel(control c, actionfn fn);
1020 void	setclose(control c, actionfn fn);
1021 
1022 void	setredraw(control c, drawfn fn);
1023 void	setresize(control c, drawfn fn);
1024 
1025 void	setkeydown(control c, keyfn fn);
1026 void	setkeyaction(control c, keyfn fn);
1027 
1028 void	setmousedown(control c, mousefn fn);
1029 void	setmousedrag(control c, mousefn fn);
1030 void	setmouseup(control c, mousefn fn);
1031 void	setmousemove(control c, mousefn fn);
1032 void	setmouserepeat(control c, mousefn fn);
1033 
1034 void	setdrop(control c, dropfn fn);
1035 
1036 void	setonfocus(control c, actionfn fn);
1037 
1038 void    setim(control c, imfn fn);
1039 
1040 /*
1041  *  Using windows and controls.
1042  */
1043 
1044 void	clear(control c);
1045 void	draw(control c);
1046 void	redraw(control c);
1047 void	resize(control c, rect r);
1048 
1049 void	show(control c);
1050 void	hide(control c);
1051 int	isvisible(control c);
1052 
1053 void	enable(control c);
1054 void	disable(control c);
1055 int	isenabled(control c);
1056 
1057 void	check(control c);
1058 void	uncheck(control c);
1059 int	ischecked(control c);
1060 
1061 void	highlight(control c);
1062 void	unhighlight(control c);
1063 int	ishighlighted(control c);
1064 
1065 void	flashcontrol(control c);
1066 void	activatecontrol(control c);
1067 
1068 /*
1069  *  Changing the state of a control.
1070  */
1071 
1072 void	settext(control c, const char *newtext);
1073 char *	GA_gettext(control c);
1074 #define setname(c,newname) settext(c,newname)
1075 #define getname(c) GA_gettext(c)
1076 
1077 void	settextfont(control c, font f);
1078 font	gettextfont(control c);
1079 
1080 void	setforeground(control c, rgb fg);
1081 rgb	getforeground(control c);
1082 void	setbackground(control c, rgb bg);
1083 rgb	getbackground(control c);
1084 
1085 void	setvalue(control c, int value);
1086 int	getvalue(control c);
1087 void	setdata(control c, void *data);
1088 void *	getdata(control c);
1089 
1090 window	parentwindow(control c);
1091 
1092 /*
1093  *  Control states.
1094  */
1095 
1096 #define GA_Visible	0x0001L
1097 #define GA_Enabled	0x0002L
1098 #define GA_Checked	0x0004L
1099 #define GA_Highlighted	0x0008L
1100 #define GA_Armed	0x0010L
1101 #define GA_Focus	0x0020L
1102 
1103 /*
1104  *  Create buttons, scrollbars, controls etc on the current window.
1105  */
1106 
1107 control	  newcontrol(const char *text, rect r);
1108 
1109 drawing	  newdrawing(rect r, drawfn fn);
1110 drawing	  newpicture(image img, rect r);
1111 
1112 button	  newbutton(const char *text, rect r, actionfn fn);
1113 button	  newimagebutton(image img, rect r, actionfn fn);
1114 void	  setimage(control c, image img);
1115 
1116 checkbox  newcheckbox(const char *text, rect r, actionfn fn);
1117 checkbox  newimagecheckbox(image img, rect r, actionfn fn);
1118 
1119 radiobutton newradiobutton(const char *text, rect r, actionfn fn);
1120 radiogroup  newradiogroup(void);
1121 
1122 scrollbar newscrollbar(rect r, int max, int pagesize, scrollfn fn);
1123 void	  changescrollbar(scrollbar s, int where, int max, int size);
1124 
1125 label	  newlabel(const char *text, rect r, int alignment);
1126 field	  newfield(const char *text, rect r);
1127 field	  newpassword(const char *text, rect r);
1128 textbox	  newtextbox(const char *text, rect r);
1129 textbox	  newtextarea(const char *text, rect r);
1130 textbox	  newrichtextarea(const char *text, rect r);
1131 
1132 listbox	  newlistbox(const char *list[], rect r, scrollfn fn, actionfn dble);
1133 listbox	  newdroplist(const char *list[], rect r, scrollfn fn);
1134 listbox	  newdropfield(const char *list[], rect r, scrollfn fn);
1135 listbox	  newmultilist(const char *list[], rect r, scrollfn fn, actionfn dble);
1136 int	  isselected(listbox b, int index);
1137 void	  setlistitem(listbox b, int index);
1138 int	  getlistitem(listbox b);
1139 void	  changelistbox(listbox b, const char *new_list[]);
1140 
1141 progressbar newprogressbar(rect r, int pmin, int pmax, int incr, int smooth);
1142 void setprogressbar(progressbar obj, int n);
1143 void stepprogressbar(progressbar obj, int n);
1144 void setprogressbarrange(progressbar obj, int pbmin, int pbmax);
1145 
1146 
1147 menubar	  newmenubar(actionfn adjust_menus);
1148 menu	  newsubmenu(menu parent, const char *name);
1149 menu	  newmenu(const char *name);
1150 menuitem  newmenuitem(const char *name, int key, menufn fn);
1151 
1152 /*
1153  *  Text editing functions.
1154  */
1155 
1156 void  undotext(textbox t);
1157 void  cuttext(textbox t);
1158 void  copytext(textbox t);
1159 void  cleartext(textbox t);
1160 void  pastetext(textbox t);
1161 void  inserttext(textbox t, const char *text);
1162 void  selecttext(textbox t, long start, long end);
1163 void  textselection(textbox t, long *start, long *end);
1164 
1165 /*
1166  *  Dialogs.
1167  */
1168 
1169 #define YES    1
1170 #define NO    -1
1171 #define CANCEL 0
1172 
1173 void	apperror(const char *errstr);
1174 void	askok(const char *info);
1175 int	askokcancel(const char *question);
1176 int	askyesno(const char *question);
1177 int	askyesnocancel(const char *question);
1178 char *	askstring(const char *question, const char *default_string);
1179 char *	askpassword(const char *question, const char *default_string);
1180 char *	askfilename(const char *title, const char *default_name);
1181 char *  askfilenamewithdir(const char *title, const char *default_name, const char *dir);
1182 char *	askfilesave(const char *title, const char *default_name);
1183 char *	askUserPass(const char *title);
1184 
1185 /*
1186  *  Time functions.
1187  */
1188 
1189 int	settimer(unsigned millisec);
1190 void	settimerfn(timerfn timeout, void *data);
1191 int	setmousetimer(unsigned millisec);
1192 void	delay(unsigned millisec);
1193 long	currenttime(void);
1194 
1195 /*
1196  *  Cursors.
1197  */
1198 
1199 cursor	newcursor(point hotspot, image img);
1200 cursor	createcursor(point offset, GAbyte *white_mask, GAbyte *black_shape);
1201 cursor	loadcursor(const char *name);
1202 void	setcursor(cursor c);
1203 
1204 /*
1205  *  Change the drawing state.
1206  */
1207 
1208 drawstate copydrawstate(void);
1209 void	setdrawstate(drawstate saved_state);
1210 void	restoredrawstate(drawstate saved_state);
1211 void	resetdrawstate(void);
1212 
1213 /*
1214  *  Caret-related functions.
1215  */
1216 
1217 void 	setcaret(control c, int x, int y, int width, int height);
1218 void	showcaret(control c, int showing);
1219 
1220 /*
1221  *  Library supplied variables.
1222  */
1223 
1224 #include <R_ext/libextern.h>
1225 #undef LibExtern
1226 #ifdef GA_DLL_BUILD
1227 # define LibExtern extern
1228 #else
1229 # define LibExtern extern LibImport
1230 #endif
1231 
1232 LibExtern font		FixedFont;	/* fixed-width font */
1233 LibExtern cursor	ArrowCursor;	/* normal arrow cursor */
1234 LibExtern cursor	BlankCursor;	/* invisible cursor */
1235 LibExtern cursor	WatchCursor;	/* wait for the computer */
1236 LibExtern cursor	CaretCursor;	/* insert text */
1237 LibExtern cursor	TextCursor;	/* insert text */
1238 LibExtern cursor	HandCursor;	/* hand pointer */
1239 LibExtern cursor	CrossCursor;	/* cross pointer */
1240 LibExtern font		SystemFont;	/* system font */
1241 LibExtern font		Times;	/* times roman font (serif) */
1242 LibExtern font		Helvetica;	/* helvetica font (sans serif) */
1243 LibExtern font		Courier;	/* courier font (fixed width) */
1244 
1245 #undef LibExtern
1246 #undef extern
1247 
1248 #ifdef __cplusplus
1249 }
1250 #endif /* end normal C declarations */
1251 
1252 
1253 #ifdef __cplusplus
1254 
1255 /* begin C++ declarations */
1256 
1257 /*
1258  *  Point and rectangle arithmetic.
1259  */
1260 
1261 inline point operator +  (point p, point p2)  {p.x+=p2.x; p.y+=p2.y; return p;}
1262 inline point operator -  (point p, point p2)  {p.x-=p2.x; p.y-=p2.y; return p;}
1263 inline point operator += (point& p, point p2) {p.x+=p2.x; p.y+=p2.y; return p;}
1264 inline point operator -= (point& p, point p2) {p.x-=p2.x; p.y-=p2.y; return p;}
1265 
1266 inline rect operator +  (rect r, point p)  {r.x+=p.x; r.y+=p.y; return r;}
1267 inline rect operator -  (rect r, point p)  {r.x-=p.x; r.y-=p.y; return r;}
1268 inline rect operator += (rect& r, point p) {r.x+=p.x; r.y+=p.y; return r;}
1269 inline rect operator -= (rect& r, point p) {r.x-=p.x; r.y-=p.y; return r;}
1270 
1271 inline rect operator +  (rect r, int i)    {return insetr(r,-i);}
1272 inline rect operator -  (rect r, int i)    {return insetr(r,i);}
1273 inline rect operator ++ (rect& r)          {return r=insetr(r,-1);}
1274 inline rect operator -- (rect& r)          {return r=insetr(r,1);}
1275 inline rect operator += (rect& r, int i)   {return r=insetr(r,-i);}
1276 inline rect operator -= (rect& r, int i)   {return r=insetr(r,i);}
1277 
1278 inline int operator == (point p1, point p2) {return equalpt(p1,p2);}
1279 inline int operator == (rect r1, rect r2)   {return equalr(r1,r2);}
1280 inline int operator != (point p1, point p2) {return !equalpt(p1,p2);}
1281 inline int operator != (rect r1, rect r2)   {return !equalr(r1,r2);}
1282 
1283 #endif /* end C++ declarations */
1284 
1285 #endif /* Common cross-platform graphics library. */
1286