| 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 |
*/
|
|
|
22 |
|
|
|
23 |
#ifndef _GRAPH_INT_H
|
|
|
24 |
#define _GRAPH_INT_H
|
|
|
25 |
|
|
|
26 |
/*
|
|
|
27 |
* Set DEBUG to 1 to produce object debugging, otherwise zero.
|
|
|
28 |
*/
|
|
|
29 |
#ifndef DEBUG
|
|
|
30 |
#define DEBUG 0
|
|
|
31 |
#endif
|
|
|
32 |
|
|
|
33 |
/*
|
|
|
34 |
* If compiling the whole library from graphapp.c, we
|
|
|
35 |
* define PROTECTED to be the storage class "static",
|
|
|
36 |
* hence optimising the library's symbol table by
|
|
|
37 |
* omitting the internal library function names.
|
|
|
38 |
*/
|
|
|
39 |
#ifdef _GRAPHAPP_
|
|
|
40 |
#define PROTECTED static
|
|
|
41 |
#else
|
|
|
42 |
#define PROTECTED
|
|
|
43 |
#endif
|
|
|
44 |
|
|
|
45 |
/*
|
|
|
46 |
* Type definitions.
|
|
|
47 |
*/
|
|
|
48 |
|
|
|
49 |
typedef struct callinfo callinfo;
|
|
|
50 |
typedef struct objinfo objinfo;
|
|
|
51 |
typedef objinfo *object;
|
|
|
52 |
|
| 21104 |
ripley |
53 |
/* in w32api this needs to be before ga.h */
|
|
|
54 |
#ifndef __WINDOWS_H /* prevent multiple includes */
|
|
|
55 |
#include <windows.h>
|
|
|
56 |
#endif
|
|
|
57 |
|
| 4394 |
ripley |
58 |
#ifndef __GA__VERSION__
|
|
|
59 |
#define objptr object
|
|
|
60 |
#include "ga.h"
|
|
|
61 |
#endif
|
|
|
62 |
|
|
|
63 |
/* extras */
|
|
|
64 |
rect getcliprect(void);
|
|
|
65 |
void setcliprect(rect r);
|
|
|
66 |
PROTECTED void updatestatus(char *text);
|
|
|
67 |
PROTECTED font new_font_object();
|
|
|
68 |
|
|
|
69 |
#ifdef __cplusplus
|
|
|
70 |
extern "C" {
|
|
|
71 |
#endif
|
|
|
72 |
|
|
|
73 |
#include <stdio.h>
|
|
|
74 |
#include <stdlib.h>
|
|
|
75 |
#include <string.h>
|
|
|
76 |
#include <ctype.h>
|
|
|
77 |
#include <math.h>
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
#include <commdlg.h>
|
|
|
81 |
|
|
|
82 |
#ifdef __MWERKS__
|
|
|
83 |
/* Metrowerks Codewarrior Cross-Platform C/C++ Compiler */
|
|
|
84 |
#define COMPILER 32
|
|
|
85 |
#endif
|
|
|
86 |
|
|
|
87 |
#ifdef __MINGW32__
|
|
|
88 |
#define COMPILER 32
|
|
|
89 |
#define WINVER 0x0400
|
|
|
90 |
#define PASS_ARGS 1
|
|
|
91 |
#ifndef WIN32
|
|
|
92 |
#define WIN32
|
|
|
93 |
#endif
|
|
|
94 |
#else
|
|
|
95 |
#define PASS_ARGS 1
|
|
|
96 |
#endif
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
#ifdef _MSC_VER
|
|
|
100 |
/* Microsoft Visual C++ Compiler */
|
|
|
101 |
#ifdef WIN32
|
|
|
102 |
#define COMPILER 32
|
|
|
103 |
#else
|
|
|
104 |
#define COMPILER 16
|
|
|
105 |
#endif
|
|
|
106 |
#endif
|
|
|
107 |
|
|
|
108 |
/*
|
|
|
109 |
* Set USE_NATIVE_LABELS to 1 for Windows text labels (never necessary).
|
|
|
110 |
* Set USE_NATIVE_TOGGLES to 1 for Windows checkboxes and radiobuttons.
|
|
|
111 |
* Set USE_NATIVE_BUTTONS to 1 for Windows buttons.
|
|
|
112 |
*/
|
|
|
113 |
|
|
|
114 |
#define USE_NATIVE_LABELS 0
|
|
|
115 |
#define USE_NATIVE_TOGGLES 1
|
|
|
116 |
#define USE_NATIVE_BUTTONS 1
|
|
|
117 |
|
|
|
118 |
#ifdef WINVER
|
|
|
119 |
#if (WINVER <= 0x030a)
|
|
|
120 |
#undef USE_NATIVE_TOGGLES
|
|
|
121 |
#define USE_NATIVE_TOGGLES 0
|
|
|
122 |
#undef USE_NATIVE_BUTTONS
|
|
|
123 |
#define USE_NATIVE_BUTTONS 0
|
|
|
124 |
#endif
|
|
|
125 |
#endif
|
|
|
126 |
|
|
|
127 |
#define USE_NATIVE_CONTROLS (USE_NATIVE_LABELS + USE_NATIVE_BUTTONS + USE_NATIVE_TOGGLES)
|
|
|
128 |
|
|
|
129 |
/*
|
|
|
130 |
* Check that certain words are defined.
|
|
|
131 |
*/
|
|
|
132 |
#ifdef COMPILER
|
|
|
133 |
#ifndef __MINGW32__
|
|
|
134 |
#ifndef _export
|
|
|
135 |
#define _export
|
|
|
136 |
#endif
|
|
|
137 |
#ifndef _argc
|
|
|
138 |
#define _argc __argc
|
|
|
139 |
#endif
|
|
|
140 |
#ifndef _argv
|
|
|
141 |
#define _argv __argv
|
|
|
142 |
#endif
|
|
|
143 |
#endif
|
|
|
144 |
#endif /* special compiler definitions */
|
|
|
145 |
|
|
|
146 |
/*
|
|
|
147 |
* Object types.
|
|
|
148 |
*/
|
|
|
149 |
|
|
|
150 |
#define BaseObject 0x4000
|
|
|
151 |
|
|
|
152 |
#define Image8 0x0008
|
|
|
153 |
#define Image32 0x0020
|
|
|
154 |
|
|
|
155 |
#define ControlObject 0x1000
|
|
|
156 |
#define WindowObject 0x1100
|
|
|
157 |
#define BitmapObject 0x0200
|
|
|
158 |
#define CursorObject 0x0400
|
|
|
159 |
#define FontObject 0x0800
|
|
|
160 |
|
|
|
161 |
#define UserObject 0x1080
|
|
|
162 |
#define LabelObject 0x1001
|
|
|
163 |
#define ButtonObject 0x1004
|
|
|
164 |
#define CheckboxObject 0x1005
|
|
|
165 |
#define RadioObject 0x1006
|
|
|
166 |
#define ScrollbarObject 0x1008
|
|
|
167 |
#define FieldObject 0x1011
|
|
|
168 |
#define TextboxObject 0x1012
|
|
|
169 |
#define ListboxObject 0x1020
|
|
|
170 |
#define MultilistObject 0x1021
|
|
|
171 |
#define DroplistObject 0x1022
|
|
|
172 |
#define DropfieldObject 0x1023
|
| 13710 |
ripley |
173 |
#define ProgressbarObject 0x1024
|
| 4394 |
ripley |
174 |
|
|
|
175 |
#define MenubarObject 0x0041
|
|
|
176 |
#define MenuObject 0x0042
|
|
|
177 |
#define MenuitemObject 0x0048
|
|
|
178 |
|
|
|
179 |
#define RadiogroupObject 0x2006
|
|
|
180 |
|
|
|
181 |
#define PrinterObject 0x0030
|
|
|
182 |
#define MetafileObject 0x0050
|
|
|
183 |
|
|
|
184 |
/*
|
|
|
185 |
* Object information structures.
|
|
|
186 |
*/
|
|
|
187 |
|
|
|
188 |
struct objinfo
|
|
|
189 |
{
|
|
|
190 |
int kind; /* what kind of object is it? */
|
|
|
191 |
int refcount; /* equals zero after del() */
|
|
|
192 |
HANDLE handle; /* handle to associated Windows object */
|
|
|
193 |
object menubar,popup,toolbar;
|
|
|
194 |
char status[256];
|
|
|
195 |
object next; /* next object in the list */
|
|
|
196 |
object prev; /* previous object in the list */
|
|
|
197 |
object parent; /* object's parent/container */
|
|
|
198 |
object child; /* first born */
|
|
|
199 |
|
|
|
200 |
actionfn die; /* private object destructor */
|
|
|
201 |
|
|
|
202 |
rect rect; /* rectangle size */
|
|
|
203 |
int depth; /* pixel depth */
|
|
|
204 |
|
|
|
205 |
drawstate drawstate; /* private drawstate */
|
|
|
206 |
image img; /* associated image */
|
|
|
207 |
|
|
|
208 |
int id; /* a unique id number */
|
|
|
209 |
long state; /* enabled/visible/armed etc */
|
|
|
210 |
long flags; /* kind of window/child control */
|
|
|
211 |
void * data; /* data supplied by user */
|
|
|
212 |
char * text; /* text associated with the object */
|
|
|
213 |
rgb fg; /* foreground colour */
|
|
|
214 |
rgb bg; /* background colour */
|
|
|
215 |
|
|
|
216 |
actionfn action; /* button/checkbox action */
|
|
|
217 |
intfn hit; /* menuitem/scrollbar action */
|
|
|
218 |
int value; /* current argument to hit() */
|
|
|
219 |
int key; /* menuitem key equivalent */
|
|
|
220 |
int shortcut; /* menu shortcut key */
|
|
|
221 |
int max; /* scrollbar maximum value */
|
|
|
222 |
int size; /* scrollbar page size */
|
| 7849 |
ripley |
223 |
int xmax; /* scrollbar maximum value */
|
|
|
224 |
int xsize; /* scrollbar page size */
|
| 4394 |
ripley |
225 |
|
|
|
226 |
callinfo *call; /* window/control call-backs */
|
|
|
227 |
void * extra; /* for extra internal data */
|
|
|
228 |
WNDPROC winproc; /* control's normal event handler */
|
|
|
229 |
|
|
|
230 |
#if USE_NATIVE_CONTROLS
|
|
|
231 |
HBRUSH bgbrush; /* background brush */
|
|
|
232 |
#endif
|
|
|
233 |
};
|
|
|
234 |
|
|
|
235 |
struct callinfo
|
|
|
236 |
{
|
|
|
237 |
actionfn die; /* user-defined destructor */
|
|
|
238 |
actionfn close; /* window close function */
|
|
|
239 |
|
|
|
240 |
drawfn redraw; /* draw the window/control */
|
|
|
241 |
drawfn resize; /* window/control was resized */
|
|
|
242 |
|
|
|
243 |
keyfn keydown; /* normal key pressed */
|
|
|
244 |
keyfn keyaction; /* function/arrow key pressed */
|
|
|
245 |
|
|
|
246 |
mousefn mousedown; /* mouse button was clicked */
|
|
|
247 |
mousefn mouseup; /* mouse button was released */
|
|
|
248 |
mousefn mousemove; /* mouse was moved */
|
|
|
249 |
mousefn mousedrag; /* mouse dragged (button is down) */
|
|
|
250 |
mousefn mouserepeat; /* mouse-down timer auto repeat */
|
| 14086 |
ripley |
251 |
|
|
|
252 |
dropfn drop; /* drag-and-drop function */
|
| 4394 |
ripley |
253 |
};
|
|
|
254 |
|
|
|
255 |
|
|
|
256 |
/* Useful definitions. */
|
|
|
257 |
|
| 5429 |
ripley |
258 |
#undef min
|
|
|
259 |
#undef max
|
| 4394 |
ripley |
260 |
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
|
|
261 |
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
|
|
262 |
|
|
|
263 |
#define MinMenuID 0x0100
|
|
|
264 |
#define MinChildID 0x6000
|
|
|
265 |
#define MinDocID 0xE000
|
|
|
266 |
|
|
|
267 |
#define sendmessage(a,b,c,d) SendMessage((HWND)(a),(UINT)(b),(WPARAM)c,(LPARAM)d)
|
|
|
268 |
|
|
|
269 |
/*
|
|
|
270 |
* Function prototypes.
|
|
|
271 |
*/
|
|
|
272 |
|
|
|
273 |
/* Array memory management. */
|
|
|
274 |
|
|
|
275 |
#define create(type) ( (type*) memalloc(sizeof(type)) )
|
|
|
276 |
#define array(n,type) ( (type*) memalloc(n*sizeof(type)) )
|
|
|
277 |
#define len(a) ( memlength((char*)(a))/sizeof((a)[0]) )
|
|
|
278 |
#define element(a,i) ( (((i)<len(a)) && ((i)>=0)) ? (a)[i] : 0 )
|
|
|
279 |
#define append(a,e) ( *(char**)&(a)=memexpand((char*)(a),sizeof((a)[0])),\
|
|
|
280 |
(a)[len(a)-1]=(e) )
|
|
|
281 |
#define join(a,b) ( *(char**)&(a)=memjoin((char*)(a),(char*)(b)) )
|
|
|
282 |
#define discard(a) ( memfree((char*)(a)), (a)=0 )
|
|
|
283 |
|
|
|
284 |
char * memalloc(long size);
|
|
|
285 |
void memfree(char *a);
|
|
|
286 |
long memlength(char *a);
|
|
|
287 |
char * memexpand(char *a, long extra);
|
|
|
288 |
char * memjoin(char *a, char *b);
|
|
|
289 |
|
|
|
290 |
/* Module initialisation methods. */
|
|
|
291 |
|
|
|
292 |
PROTECTED void init_objects(void);
|
|
|
293 |
PROTECTED void init_events(void);
|
|
|
294 |
PROTECTED void init_contexts(void);
|
|
|
295 |
PROTECTED void init_menus(void);
|
|
|
296 |
PROTECTED void init_fonts(void);
|
|
|
297 |
PROTECTED void init_cursors(void);
|
|
|
298 |
|
|
|
299 |
PROTECTED window simple_window(void);
|
|
|
300 |
|
|
|
301 |
/* Module finaliser methods. */
|
|
|
302 |
|
|
|
303 |
PROTECTED void app_cleanup(void);
|
|
|
304 |
|
|
|
305 |
PROTECTED void finish_objects(void);
|
|
|
306 |
PROTECTED void finish_events(void);
|
|
|
307 |
PROTECTED void finish_contexts(void);
|
|
|
308 |
|
|
|
309 |
/* Object management. */
|
|
|
310 |
|
|
|
311 |
PROTECTED object new_object(int kind, HANDLE handle, object parent);
|
|
|
312 |
PROTECTED object find_object(HANDLE handle, int id, int key);
|
|
|
313 |
PROTECTED void move_to_front(object obj);
|
|
|
314 |
PROTECTED void apply_to_list(object first, actionfn fn);
|
|
|
315 |
|
|
|
316 |
#define find_by_handle(h) find_object(h, 0, 0)
|
|
|
317 |
#define find_by_id(id) find_object(0, id, 0)
|
|
|
318 |
#define find_by_key(key) find_object(0, 0, key)
|
|
|
319 |
|
|
|
320 |
/* Object refcounts and deletion. */
|
|
|
321 |
|
|
|
322 |
PROTECTED void decrease_refcount(object obj);
|
|
|
323 |
PROTECTED void increase_refcount(object obj);
|
|
|
324 |
PROTECTED void protect_object(object obj);
|
|
|
325 |
PROTECTED void deletion_traversal(void);
|
|
|
326 |
|
|
|
327 |
/* Menu event management. */
|
|
|
328 |
|
|
|
329 |
PROTECTED void adjust_menu(WPARAM wParam);
|
|
|
330 |
PROTECTED void handle_menu_id(WPARAM wParam);
|
|
|
331 |
PROTECTED void handle_menu_key(WPARAM wParam);
|
|
|
332 |
|
|
|
333 |
/* Control event management. */
|
|
|
334 |
|
|
|
335 |
PROTECTED void handle_control(HWND hwnd, UINT message);
|
|
|
336 |
PROTECTED object find_valid_sibling(object obj);
|
|
|
337 |
|
|
|
338 |
/* Drawing context management. */
|
|
|
339 |
|
|
|
340 |
PROTECTED void add_context(object obj, HDC dc, HGDIOBJ old);
|
|
|
341 |
PROTECTED HDC get_context(object obj);
|
|
|
342 |
PROTECTED void remove_context(object obj);
|
|
|
343 |
PROTECTED void del_context(object obj);
|
|
|
344 |
PROTECTED void del_all_contexts(void);
|
|
|
345 |
|
|
|
346 |
PROTECTED void fix_brush(HDC dc, object obj, HBRUSH brush);
|
|
|
347 |
|
|
|
348 |
/* Window private functions. */
|
|
|
349 |
|
|
|
350 |
PROTECTED rect screen_coords(object obj);
|
|
|
351 |
PROTECTED void show_window(object obj);
|
|
|
352 |
PROTECTED void hide_window(object obj);
|
|
|
353 |
|
|
|
354 |
/* Image private functions. */
|
|
|
355 |
|
|
|
356 |
PROTECTED image load_gif(char *filename);
|
|
|
357 |
PROTECTED void save_gif(image img, char *filename);
|
|
|
358 |
|
|
|
359 |
PROTECTED rgb get_image_pixel(image img, int x, int y);
|
|
|
360 |
PROTECTED rgb get_monochrome_pixel(image img, int x, int y);
|
|
|
361 |
PROTECTED rgb get_grey_pixel(image img, int x, int y);
|
|
|
362 |
|
|
|
363 |
PROTECTED int has_transparent_pixels(image img);
|
|
|
364 |
|
|
|
365 |
/* Debugging functions. */
|
|
|
366 |
|
|
|
367 |
#if DEBUG
|
|
|
368 |
PROTECTED void printimage(FILE *file, image img);
|
|
|
369 |
PROTECTED void print_object_list(void);
|
|
|
370 |
#endif
|
|
|
371 |
|
|
|
372 |
/* String functions. */
|
|
|
373 |
|
|
|
374 |
char * new_string(char *src);
|
|
|
375 |
void del_string(char *str);
|
|
|
376 |
long string_length(char *s);
|
|
|
377 |
void copy_string(char *dest, char *src);
|
|
|
378 |
int compare_strings(char *s1, char *s2);
|
|
|
379 |
char * add_strings(char *s1, char *s2);
|
|
|
380 |
char * char_to_string(char ch);
|
|
|
381 |
char * int_to_string(long i);
|
|
|
382 |
char * float_to_string(float f);
|
|
|
383 |
|
|
|
384 |
PROTECTED int string_diff(char *s, char *t);
|
|
|
385 |
PROTECTED char * to_dos_string(char *str);
|
|
|
386 |
PROTECTED char * to_c_string(char *str);
|
|
|
387 |
|
|
|
388 |
/* New functions yet to be placed in the official header file */
|
|
|
389 |
|
|
|
390 |
|
|
|
391 |
/*
|
|
|
392 |
* Library internal variables.
|
|
|
393 |
*/
|
|
|
394 |
|
|
|
395 |
extern int app_initialised;
|
|
|
396 |
extern char * app_name;
|
|
|
397 |
|
|
|
398 |
extern HANDLE this_instance;
|
|
|
399 |
extern HANDLE prev_instance;
|
|
|
400 |
|
|
|
401 |
long FAR PASCAL _export app_win_proc (HWND, UINT, UINT, LONG);
|
|
|
402 |
long FAR PASCAL _export app_doc_proc (HWND, UINT, UINT, LONG);
|
|
|
403 |
long FAR PASCAL _export app_work_proc (HWND, UINT, UINT, LONG);
|
|
|
404 |
long FAR PASCAL _export app_control_procedure (HWND, UINT, UINT, LONG);
|
|
|
405 |
UINT FAR PASCAL _export app_timer_procedure(HWND, UINT, UINT, DWORD);
|
|
|
406 |
extern WNDPROC app_control_proc;
|
|
|
407 |
|
|
|
408 |
extern int menus_active;
|
|
|
409 |
extern int active_windows;
|
|
|
410 |
extern int child_id;
|
|
|
411 |
|
|
|
412 |
extern window current_window;
|
|
|
413 |
extern menubar current_menubar;
|
|
|
414 |
extern menu current_menu;
|
|
|
415 |
|
|
|
416 |
extern HACCEL hAccel;
|
|
|
417 |
extern HWND hwndMain;
|
|
|
418 |
extern HWND hwndClient;
|
|
|
419 |
extern HWND hwndFrame;
|
|
|
420 |
extern object MDIFrame;
|
|
|
421 |
extern object MDIToolbar;
|
|
|
422 |
extern HWND MDIStatus;
|
|
|
423 |
extern HDC dc;
|
|
|
424 |
extern HPEN the_pen;
|
|
|
425 |
extern HBRUSH the_brush;
|
|
|
426 |
extern COLORREF win_rgb;
|
|
|
427 |
|
|
|
428 |
extern drawstruct app_drawstate;
|
|
|
429 |
|
|
|
430 |
extern drawstate current; /* global colour, font &c */
|
|
|
431 |
extern int keystate; /* state of Shift, Ctrl, Alt */
|
|
|
432 |
|
|
|
433 |
#ifdef __cplusplus
|
|
|
434 |
}
|
|
|
435 |
#endif
|
|
|
436 |
|
|
|
437 |
#endif /* GraphApp internal header file */
|