The R Project SVN R

Rev

Rev 87075 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4394 ripley 1
/*
2
 *  Internal include file
3
 *  ---------------------
4
 *  GraphApp internal functions (Windows version).
5
 *
6
 *  The type objptr is defined in this file to be an
7
 *  object pointer. This differs from the normal graphapp.h
8
 *  definition which makes an objptr a pointer to int.
9
 *  There are a few reasons for this:
10
 *  1. The graphapp.h file is platform independent,
11
 *     so making the basic object type an int pointer
12
 *     is platform-neutral.
13
 *  2. Thus the object type does not need to be defined in
14
 *     graphapp.h since this type includes platform-specific
15
 *     information.
16
 *  3. An int pointer facilitates data-hiding. No-one can
17
 *     poke around in the object data structure.
18
 *  4. Inside the library code we can treat all fonts, windows
19
 *     controls, cursors, etc as ordinary objects. There is
20
 *     no need for typecasting, so code size is reduced.
21
 */
86153 kalibera 22
 
23
 /* The above has been modified in R 4.4.0, so that the object pointer is a
24
    pointer to structure objinfo, in both internal and public interface, but
25
    the structure is incomplete in the public interface.  See also
26
    graphapp.h.
27
  */
4394 ripley 28
 
29
#ifndef _GRAPH_INT_H
30
#define _GRAPH_INT_H
31
 
32
/*
33
 *  Set DEBUG to 1 to produce object debugging, otherwise zero.
34
 */
35
#ifndef DEBUG
36
#define DEBUG 0
37
#endif
38
 
39
/*
40
 *  If compiling the whole library from graphapp.c, we
41
 *  define PROTECTED to be the storage class "static",
42
 *  hence optimising the library's symbol table by
43
 *  omitting the internal library function names.
44
 */
45
#ifdef _GRAPHAPP_
46
	#define PROTECTED static
47
#else
48
	#define PROTECTED
49
#endif
50
 
51
/*
52
 *  Type definitions.
53
 */
54
 
55
typedef struct callinfo  callinfo;
56
typedef struct objinfo   objinfo;
57
typedef objinfo *object;
58
 
21104 ripley 59
/* in w32api this needs to be before ga.h */
60
#ifndef __WINDOWS_H     /* prevent multiple includes */
61
#include <windows.h>
62
#endif
42578 ripley 63
#include <stdint.h> /* for intptr_t */
21104 ripley 64
 
4394 ripley 65
#ifndef __GA__VERSION__
66
#define objptr object
67
#include "ga.h"
68
#endif
69
 
70
/* extras */
71
rect getcliprect(void);
72
void setcliprect(rect r);
41793 ripley 73
PROTECTED void updatestatus(const char *text);
44201 ripley 74
PROTECTED font new_font_object(HFONT hf);
84952 kalibera 75
UINT default_font_charset(void);
4394 ripley 76
 
77
#include <stdio.h>
78
#include <stdlib.h>
79
#include <string.h>
80
#include <ctype.h>
81
#include <math.h>
82
 
83
 
84
#include <commdlg.h>
85
 
87075 kalibera 86
#ifdef __cplusplus
87
extern "C" {
88
#endif
89
 
4394 ripley 90
#ifdef __MWERKS__
45017 ripley 91
    /* Metrowerks Codewarrior Cross-Platform C/C++ Compiler */
4394 ripley 92
	#define COMPILER 32
93
#endif
94
 
95
#ifdef __MINGW32__
96
     #define COMPILER 32
42239 ripley 97
#ifndef WINVER
4394 ripley 98
     #define WINVER 0x0400
42239 ripley 99
#endif
4394 ripley 100
     #define PASS_ARGS 1
101
#ifndef WIN32
102
 #define WIN32
103
#endif
104
#else
105
  #define PASS_ARGS	1
106
#endif
107
 
108
 
109
#ifdef _MSC_VER
110
	/* Microsoft Visual C++ Compiler */
111
	#ifdef WIN32
112
		#define COMPILER 32
113
	#else
114
		#define COMPILER 16
115
	#endif
116
#endif
117
 
118
/*
119
 *  Set USE_NATIVE_LABELS to 1 for Windows text labels (never necessary).
120
 *  Set USE_NATIVE_TOGGLES to 1 for Windows checkboxes and radiobuttons.
121
 *  Set USE_NATIVE_BUTTONS to 1 for Windows buttons.
122
 */
123
 
124
#define USE_NATIVE_LABELS  0
125
#define USE_NATIVE_TOGGLES 1
126
#define USE_NATIVE_BUTTONS 1
127
 
128
#ifdef WINVER
129
  #if (WINVER <= 0x030a)
130
	#undef  USE_NATIVE_TOGGLES
131
	#define USE_NATIVE_TOGGLES 0
132
	#undef  USE_NATIVE_BUTTONS
133
	#define USE_NATIVE_BUTTONS 0
134
  #endif
135
#endif
136
 
137
#define USE_NATIVE_CONTROLS (USE_NATIVE_LABELS + USE_NATIVE_BUTTONS + USE_NATIVE_TOGGLES)
138
 
139
/*
140
 *  Check that certain words are defined.
141
 */
142
#ifdef COMPILER
143
   #ifndef __MINGW32__
144
	#ifndef _argc
145
		#define _argc __argc
146
	#endif
147
	#ifndef _argv
148
		#define _argv __argv
149
	#endif
150
  #endif
151
#endif /* special compiler definitions */
152
 
153
/*
154
 *  Object types.
155
 */
156
 
157
	#define BaseObject        0x4000
158
 
159
	#define Image8            0x0008
160
	#define Image32           0x0020
161
 
162
	#define ControlObject     0x1000
163
	#define WindowObject      0x1100
164
	#define BitmapObject      0x0200
165
	#define CursorObject      0x0400
166
	#define FontObject        0x0800
167
 
168
	#define UserObject        0x1080
169
	#define LabelObject       0x1001
170
	#define ButtonObject      0x1004
171
	#define CheckboxObject    0x1005
172
	#define RadioObject       0x1006
173
	#define ScrollbarObject   0x1008
174
	#define FieldObject       0x1011
175
	#define TextboxObject     0x1012
176
	#define ListboxObject     0x1020
177
	#define MultilistObject   0x1021
178
	#define DroplistObject    0x1022
179
	#define DropfieldObject   0x1023
13710 ripley 180
	#define ProgressbarObject 0x1024
4394 ripley 181
 
182
	#define MenubarObject     0x0041
183
	#define MenuObject        0x0042
184
	#define MenuitemObject    0x0048
185
 
186
	#define RadiogroupObject  0x2006
187
 
45017 ripley 188
	#define PrinterObject     0x0030
189
	#define MetafileObject    0x0050
4394 ripley 190
 
191
/*
192
 *  Object information structures.
193
 */
194
 
195
struct objinfo
196
{
45017 ripley 197
    int	kind;	/* what kind of object is it? */
198
    int	refcount; /* equals zero after del() */
199
    HANDLE	handle;	/* handle to associated Windows object */
200
    object  menubar,popup,toolbar;
201
    char    status[256];
202
    object	next;	/* next object in the list */
203
    object	prev;	/* previous object in the list */
204
    object	parent;	/* object's parent/container */
205
    object	child;	/* first born */
4394 ripley 206
 
45017 ripley 207
    actionfn die;	/* private object destructor */
4394 ripley 208
 
45017 ripley 209
    rect	rect;	/* rectangle size */
210
    int	depth;	/* pixel depth */
4394 ripley 211
 
45017 ripley 212
    drawstate drawstate; /* private drawstate */
213
    image	img;	/* associated image */
4394 ripley 214
 
45017 ripley 215
    int	id;	/* a unique id number */
216
    long	state;	/* enabled/visible/armed etc */
217
    long	flags;	/* kind of window/child control */
218
    void *	data;	/* data supplied by user */
219
    char *	text;	/* text associated with the object */
220
    rgb	fg;	/* foreground colour */
221
    rgb	bg;	/* background colour */
4394 ripley 222
 
45017 ripley 223
    actionfn action; /* button/checkbox action */
224
    actionfn dble ; /* listbox double-click action */
225
    intfn	hit;	/* menuitem/scrollbar action */
226
    int	value;	/* current argument to hit() */
227
    int	key;	/* menuitem key equivalent */
228
    int	shortcut; /* menu shortcut key */
229
    int	max;	/* scrollbar maximum value */
230
    int	size;	/* scrollbar page size */
231
    int	xmax;	/* scrollbar maximum value */
232
    int	xsize;	/* scrollbar page size */
4394 ripley 233
 
45017 ripley 234
    callinfo *call;	/* window/control call-backs */
235
    void *	extra;	/* for extra internal data */
236
    WNDPROC	winproc; /* control's normal event handler */
4394 ripley 237
 
45017 ripley 238
#if USE_NATIVE_CONTROLS
239
    HBRUSH  bgbrush; /* background brush */
240
#endif
51948 murdoch 241
    int caretwidth;  /* Caret (blinking cursor) is set here. caretwidth=0 for none, 
242
                        negative for not focussed */
243
    int caretheight;
244
    int caretshowing;
83479 kalibera 245
    int caretexists; /* A WinAPI caret has been created with CreateCaret */
246
    int caretx;      /* Coordinates are stored so that the WinAPI caret can */
247
    int carety;      /*   be re-created after the window re-gains focus */
83510 kalibera 248
 
249
    WNDPROC edit_winproc; /* edit control event handler for dropfield (combo box) */
45017 ripley 250
};
4394 ripley 251
 
252
struct callinfo
253
{
45017 ripley 254
    actionfn die;		/* user-defined destructor */
255
    actionfn close;		/* window close function */
4394 ripley 256
 
45017 ripley 257
    drawfn	redraw;		/* draw the window/control */
258
    drawfn	resize;		/* window/control was resized */
4394 ripley 259
 
45017 ripley 260
    keyfn	keydown;	/* normal key pressed */
261
    keyfn	keyaction;	/* function/arrow key pressed */
4394 ripley 262
 
45017 ripley 263
    mousefn	mousedown;	/* mouse button was clicked */
264
    mousefn	mouseup;	/* mouse button was released */
265
    mousefn	mousemove;	/* mouse was moved */
266
    mousefn	mousedrag;	/* mouse dragged (button is down) */
267
    mousefn	mouserepeat;	/* mouse-down timer auto repeat */
14086 ripley 268
 
45017 ripley 269
    dropfn drop;		/* drag-and-drop function */
43908 ripley 270
 
45017 ripley 271
    imfn    im;             /* input method function */
4394 ripley 272
 
45017 ripley 273
    actionfn focus;
274
};
4394 ripley 275
 
45017 ripley 276
 
4394 ripley 277
/*  Useful definitions.  */
278
 
5429 ripley 279
#undef min
280
#undef max
4394 ripley 281
#define min(a,b) (((a) < (b)) ? (a) : (b))
282
#define max(a,b) (((a) > (b)) ? (a) : (b))
283
 
284
#define MinMenuID  0x0100
285
#define MinChildID 0x6000
286
#define MinDocID   0xE000
287
 
88464 kalibera 288
PROTECTED LRESULT
289
sendmessage_unwind(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
4394 ripley 290
 
88464 kalibera 291
#define sendmessage(a,b,c,d) sendmessage_unwind((HWND)(a),(UINT)(b),(WPARAM)c,(LPARAM)d)
292
 
4394 ripley 293
/*
294
 *  Function prototypes.
295
 */
296
 
297
/* Array memory management. */
298
 
299
  #define create(type)  ( (type*) memalloc(sizeof(type)) )
300
  #define array(n,type) ( (type*) memalloc(n*sizeof(type)) )
301
  #define len(a)        ( memlength((char*)(a))/sizeof((a)[0]) )
302
  #define element(a,i)  ( (((i)<len(a)) && ((i)>=0)) ? (a)[i] : 0 )
303
  #define append(a,e)   ( *(char**)&(a)=memexpand((char*)(a),sizeof((a)[0])),\
304
				(a)[len(a)-1]=(e) )
305
  #define join(a,b)     ( *(char**)&(a)=memjoin((char*)(a),(char*)(b)) )
306
  #define discard(a)    ( memfree((char*)(a)), (a)=0 )
307
 
308
  char * memalloc(long size);
309
  void   memfree(char *a);
310
  long   memlength(char *a);
311
  char * memexpand(char *a, long extra);
312
  char * memjoin(char *a, char *b);
313
 
314
/* Module initialisation methods. */
315
 
316
  PROTECTED void  init_objects(void);
317
  PROTECTED void  init_events(void);
318
  PROTECTED void  init_contexts(void);
319
  PROTECTED void  init_menus(void);
320
  PROTECTED void  init_fonts(void);
321
  PROTECTED void  init_cursors(void);
322
 
323
  PROTECTED window  simple_window(void);
324
 
325
/* Module finaliser methods. */
326
 
327
  PROTECTED void  app_cleanup(void);
328
 
329
  PROTECTED void  finish_objects(void);
330
  PROTECTED void  finish_events(void);
331
  PROTECTED void  finish_contexts(void);
332
 
333
/* Object management. */
334
 
335
  PROTECTED object  new_object(int kind, HANDLE handle, object parent);
28991 murdoch 336
  PROTECTED object  tree_search(object top, HANDLE handle, int id, int key);
4394 ripley 337
  PROTECTED object  find_object(HANDLE handle, int id, int key);
338
  PROTECTED void    move_to_front(object obj);
339
  PROTECTED void    apply_to_list(object first, actionfn fn);
340
 
341
  #define find_by_handle(h) find_object(h, 0, 0)
342
  #define find_by_id(id)    find_object(0, id, 0)
28991 murdoch 343
  #define find_by_key(base, key)  tree_search(base, 0, 0, key)
4394 ripley 344
 
345
/* Object refcounts and deletion. */
346
 
347
  PROTECTED void  decrease_refcount(object obj);
348
  PROTECTED void  increase_refcount(object obj);
349
  PROTECTED void  protect_object(object obj);
350
  PROTECTED void  deletion_traversal(void);
351
 
352
/* Menu event management. */
353
 
354
  PROTECTED void  adjust_menu(WPARAM wParam);
355
  PROTECTED void  handle_menu_id(WPARAM wParam);
28991 murdoch 356
  PROTECTED int  handle_menu_key(WPARAM wParam);
4394 ripley 357
 
358
/* Control event management. */
359
 
360
  PROTECTED void   handle_control(HWND hwnd, UINT message);
83639 kalibera 361
  PROTECTED object find_next_valid_sibling(object obj);
362
  PROTECTED object find_prev_valid_sibling(object obj);
4394 ripley 363
 
28991 murdoch 364
/* Dialog event management */
365
 
366
  PROTECTED void handle_findreplace(HWND hwnd, LPFINDREPLACE pfr);
44201 ripley 367
  PROTECTED HWND get_modeless(void);
28991 murdoch 368
 
4394 ripley 369
/* Drawing context management. */
370
 
371
  PROTECTED void  add_context(object obj, HDC dc, HGDIOBJ old);
372
  PROTECTED HDC   get_context(object obj);
373
  PROTECTED void  remove_context(object obj);
374
  PROTECTED void  del_context(object obj);
375
  PROTECTED void  del_all_contexts(void);
376
 
377
  PROTECTED void  fix_brush(HDC dc, object obj, HBRUSH brush);
378
 
379
/* Window private functions. */
380
 
381
  PROTECTED rect  screen_coords(object obj);
382
  PROTECTED void  show_window(object obj);
383
  PROTECTED void  hide_window(object obj);
384
 
385
/* Image private functions. */
386
 
41793 ripley 387
  PROTECTED image   load_gif(const char *filename);
388
  PROTECTED void    save_gif(image img, const char *filename);
4394 ripley 389
 
390
  PROTECTED rgb  get_image_pixel(image img, int x, int y);
391
  PROTECTED rgb  get_monochrome_pixel(image img, int x, int y);
392
  PROTECTED rgb  get_grey_pixel(image img, int x, int y);
393
 
394
  PROTECTED int  has_transparent_pixels(image img);
395
 
396
/* Debugging functions. */
397
 
398
  #if DEBUG
399
  PROTECTED void    printimage(FILE *file, image img);
400
  PROTECTED void    print_object_list(void);
401
  #endif
402
 
403
/* String functions. */
404
 
41793 ripley 405
  char * new_string(const char *src);
406
  void   del_string(const char *str);
407
  long   string_length(const char *s);
408
  void   copy_string(char *dest, const char *src);
409
  int    compare_strings(const char *s1, const char *s2);
410
  const char * add_strings(const char *s1, const char *s2);
4394 ripley 411
  char * char_to_string(char ch);
412
  char * int_to_string(long i);
413
  char * float_to_string(float f);
414
 
41793 ripley 415
  PROTECTED int    string_diff(const char *s, const char *t);
416
  PROTECTED char * to_dos_string(const char *str);
417
  PROTECTED char * to_c_string(const char *str);
4394 ripley 418
 
419
/* New functions yet to be placed in the official header file */
420
 
421
 
422
/*
42529 ripley 423
 * variables used building R
424
 */
425
#ifdef GA_EXTERN
426
extern __declspec(dllimport) HWND hwndClient;
427
#else
428
extern HWND hwndClient;
429
#endif
430
 
431
 
432
/*
4394 ripley 433
 *  Library internal variables.
434
 */
435
 
42870 ripley 436
#if defined(R_DLL_BUILD)
437
  extern
438
#else
45017 ripley 439
  extern  __declspec(dllimport)
42870 ripley 440
#endif
45017 ripley 441
  unsigned int localeCP; /* from Defn.h */
4394 ripley 442
  extern int    app_initialised;
443
  extern char * app_name;
444
 
445
  extern HANDLE	this_instance;
446
  extern HANDLE	prev_instance;
447
 
42577 ripley 448
  LRESULT WINAPI app_win_proc (HWND, UINT, WPARAM, LPARAM);
449
  LRESULT WINAPI app_doc_proc (HWND, UINT, WPARAM, LPARAM);
450
  LRESULT WINAPI app_work_proc (HWND, UINT, WPARAM, LPARAM);
88464 kalibera 451
  LRESULT WINAPI app_control_procedure (HWND, UINT, WPARAM, LPARAM);
42239 ripley 452
  UINT WINAPI app_timer_procedure(HWND, UINT, UINT, DWORD);
453
  extern WNDPROC app_control_proc;
88464 kalibera 454
  LRESULT WINAPI edit_control_procedure (HWND, UINT, WPARAM, LPARAM);
83510 kalibera 455
  extern WNDPROC edit_control_proc;
4394 ripley 456
 
45017 ripley 457
  extern int	menus_active;
458
  extern int	active_windows;
42577 ripley 459
  extern intptr_t child_id;
4394 ripley 460
 
461
  extern window  current_window;
462
  extern menubar current_menubar;
463
  extern menu    current_menu;
464
 
465
  extern HACCEL	hAccel;
466
  extern HWND	hwndMain;
467
  extern HWND	hwndFrame;
468
  extern object MDIFrame;
469
  extern object MDIToolbar;
470
  extern HWND   MDIStatus;
471
  extern HDC      dc;
472
  extern HPEN     the_pen;
473
  extern HBRUSH   the_brush;
474
  extern COLORREF win_rgb;
475
 
476
  extern drawstruct app_drawstate;
477
 
478
  extern drawstate current;	/* global colour, font &c */
45017 ripley 479
  extern int	keystate;	/* state of Shift, Ctrl, Alt */
4394 ripley 480
 
45017 ripley 481
  static inline RECT *rect2RECT(rect *r) {return (RECT *)r;}
42585 ripley 482
 
4394 ripley 483
#ifdef __cplusplus
484
}
485
#endif
486
 
487
#endif /* GraphApp internal header file */