The R Project SVN R

Rev

Rev 4394 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4394 Rev 9184
1
/*
1
/*
2
 * GraphApp - Cross-Platform Graphics Programming Library.
2
 * GraphApp - Cross-Platform Graphics Programming Library.
3
 *
3
 *
4
 * File: init.c -- library initialisation code.
4
 * File: init.c -- library initialisation code.
5
 * Platform: Windows  Version: 2.23  Date: 1997/09/09
5
 * Platform: Windows  Version: 2.23  Date: 1997/09/09
6
 *
6
 *
7
 * Version: 1.00  Changes: Original version by Lachlan Patrick.
7
 * Version: 1.00  Changes: Original version by Lachlan Patrick.
8
 * Version: 2.00  Changes: New object class system.
8
 * Version: 2.00  Changes: New object class system.
9
 * Version: 2.20  Changes: Added EasyWin support in Borland C.
9
 * Version: 2.20  Changes: Added EasyWin support in Borland C.
10
 * Version: 2.22  Changes: Now main doesn't use environ pointer.
10
 * Version: 2.22  Changes: Now main doesn't use environ pointer.
11
 */
11
 */
12
 
12
 
13
/* Copyright (C) 1993-1998 Lachlan Patrick
13
/* Copyright (C) 1993-1998 Lachlan Patrick
14
 
14
 
15
   This file is part of GraphApp, a cross-platform C graphics library.
15
   This file is part of GraphApp, a cross-platform C graphics library.
16
 
16
 
17
   GraphApp is free software; you can redistribute it and/or modify it
17
   GraphApp is free software; you can redistribute it and/or modify it
18
   under the terms of the GNU Library General Public License.
18
   under the terms of the GNU Library General Public License.
19
   GraphApp is distributed in the hope that it will be useful, but
19
   GraphApp is distributed in the hope that it will be useful, but
20
   WITHOUT ANY WARRANTY.
20
   WITHOUT ANY WARRANTY.
21
 
21
 
22
   See the file COPYLIB.TXT for details.
22
   See the file COPYLIB.TXT for details.
23
*/
23
*/
24
 
24
 
25
#include "internal.h"
25
#include "internal.h"
26
 
26
 
27
/*
27
/*
28
 *  Windows implementation globals.
28
 *  Windows implementation globals.
29
 */
29
 */
30
 
30
 
31
	PROTECTED char * app_name = "GraphApp";
31
	PROTECTED char * app_name = "GraphApp";
32
	PROTECTED int    app_initialised = 0;
32
	PROTECTED int    app_initialised = 0;
33
	PROTECTED HANDLE this_instance = 0;
33
	PROTECTED HANDLE this_instance = 0;
34
	PROTECTED HANDLE prev_instance = 0;
34
	PROTECTED HANDLE prev_instance = 0;
35
	PROTECTED int    cmd_show = 1;
35
	PROTECTED int    cmd_show = 1;
36
 
36
 
37
/*
37
/*
38
 *  Functions defined in this file.
38
 *  Functions defined in this file.
39
 */
39
 */
40
	static void setappname(char *title);
40
	static void setappname(char *title);
41
	static void getappname(HANDLE Instance);
41
	static void getappname(HANDLE Instance);
42
 
42
 
43
	int initapp(int argc, char **argv);
43
	int initapp(int argc, char **argv);
44
	void exitapp(void);
44
	void exitapp(void);
45
	void gabeep(void);
45
	void gabeep(void);
46
 
46
 
47
/*
47
/*
48
 *  Initialise application. Returns zero on failure.
48
 *  Initialise application. Returns zero on failure.
49
 */
49
 */
50
int initapp(int argc, char **argv)
50
int initapp(int argc, char **argv)
51
{
51
{
52
	if (! app_initialised)
52
	if (! app_initialised)
53
	{
53
	{
54
		app_initialised = 1;
54
		app_initialised = 1;
55
 
55
 
56
		init_objects();
56
		init_objects();
57
		init_events();
57
		init_events();
58
		init_fonts();
58
		init_fonts();
59
		init_cursors();
59
		init_cursors();
60
		init_contexts();
60
		init_contexts();
61
		init_menus();
61
		init_menus();
62
	}
62
	}
63
	return (argc < 1) ? 1 : argc;
63
	return (argc < 1) ? 1 : argc;
64
}
64
}
65
 
65
 
66
/*
66
/*
67
 *  This function releases all GDI objects.
67
 *  This function releases all GDI objects.
68
 */
68
 */
69
PROTECTED
69
PROTECTED
70
void app_cleanup(void)
70
void app_cleanup(void)
71
{
71
{
72
	if (app_initialised) {
72
	if (app_initialised) {
73
		app_initialised = 0;
73
		app_initialised = 0;
74
		finish_contexts();
74
		finish_contexts();
75
		finish_objects();
75
		finish_objects();
76
		finish_events();
76
		finish_events();
77
	}
77
	}
78
}
78
}
79
 
79
 
80
/*
80
/*
81
 *  Standard quit application function.
81
 *  Standard quit application function.
82
 *  This function releases all GDI objects and terminates the program.
82
 *  This function releases all GDI objects and terminates the program.
83
 *  It can be called at any time from within a program, or at the end,
83
 *  It can be called at any time from within a program, or at the end,
84
 *  or else it will be called if all windows are closed.
84
 *  or else it will be called if all windows are closed.
85
 */
85
 */
86
void exitapp(void)
86
void exitapp(void)
87
{
87
{
88
	app_cleanup();
88
	app_cleanup();
89
	active_windows = 0;
89
	active_windows = 0;
90
	exit(0);
90
	exit(0);
91
}
91
}
92
 
92
 
93
/*
93
/*
94
 *  Run an application program:
94
 *  Run an application program:
95
 */
95
 */
96
int execapp(char *app)
96
int execapp(char *app)
97
{
97
{
98
	#ifdef __MSDOS__
98
	#ifdef __MSDOS__
99
		if (WinExec(app, SW_SHOW) < 32)
99
		if (WinExec(app, SW_SHOW) < 32)
100
			return 0;
100
			return 0;
101
	#else
101
	#else
102
		if (system(app) != 0)
102
		if (system(app) != 0)
103
			return 0;
103
			return 0;
104
	#endif
104
	#endif
105
	return 1;
105
	return 1;
106
}
106
}
107
 
107
 
108
 
108
 
109
 
109
 
110
/*
110
/*
111
 *  Beep the speaker:
111
 *  Play error sound
112
 */
112
 */
113
void gabeep(void)
113
void gabeep(void)
114
{
114
{
115
	MessageBeep(-1);
115
	MessageBeep(MB_ICONASTERISK);
116
}
116
}
117
 
117
 
118
/*
118
/*
119
 *  Take a name like "PROG.EXE" and set app_name to be "Prog".
119
 *  Take a name like "PROG.EXE" and set app_name to be "Prog".
120
 */
120
 */
121
static void setappname(char *title)
121
static void setappname(char *title)
122
{
122
{
123
	int len;
123
	int len;
124
	char c;
124
	char c;
125
 
125
 
126
	if (title[0] == '\0')
126
	if (title[0] == '\0')
127
		return;
127
		return;
128
	for (len=1; (c=title[len]) != '\0'; len++)
128
	for (len=1; (c=title[len]) != '\0'; len++)
129
		title[len] = tolower(c);
129
		title[len] = tolower(c);
130
	if ((len-=4)<0)
130
	if ((len-=4)<0)
131
		len = 0;
131
		len = 0;
132
	if (! string_diff(title+len, ".exe"))
132
	if (! string_diff(title+len, ".exe"))
133
		title[len] = '\0';
133
		title[len] = '\0';
134
 
134
 
135
	app_name = new_string(title);
135
	app_name = new_string(title);
136
}
136
}
137
 
137
 
138
/*
138
/*
139
 *  Find out what the application is called.
139
 *  Find out what the application is called.
140
 */
140
 */
141
static void getappname(HANDLE Instance)
141
static void getappname(HANDLE Instance)
142
{
142
{
143
	char exename[120];
143
	char exename[120];
144
	char title[120];
144
	char title[120];
145
 
145
 
146
	/* find out executable name */
146
	/* find out executable name */
147
	GetModuleFileName(Instance, exename, sizeof(exename));
147
	GetModuleFileName(Instance, exename, sizeof(exename));
148
	GetFileTitle(exename, title, sizeof(title));
148
	GetFileTitle(exename, title, sizeof(title));
149
	setappname(title);
149
	setappname(title);
150
}
150
}
151
 
151
 
152
/*
152
/*
153
 *  Special function for making printf work on Windows systems.
153
 *  Special function for making printf work on Windows systems.
154
 *  This function is never called, it merely tricks the compiler into
154
 *  This function is never called, it merely tricks the compiler into
155
 *  including printf and scanf support.
155
 *  including printf and scanf support.
156
 */
156
 */
157
void app_init_printf(void)
157
void app_init_printf(void)
158
{
158
{
159
 	#ifdef __BORLANDC__
159
 	#ifdef __BORLANDC__
160
 		#if __BORLANDC__ <= 0x410
160
 		#if __BORLANDC__ <= 0x410
161
 		_InitEasyWin();
161
 		_InitEasyWin();
162
 		#endif
162
 		#endif
163
 	#else
163
 	#else
164
 	printf(" ");
164
 	printf(" ");
165
 	#endif
165
 	#endif
166
}
166
}
167
 
167
 
168
/*
168
/*
169
 *  The main Windows entry point is the WinMain function.
169
 *  The main Windows entry point is the WinMain function.
170
 */
170
 */
171
 
171
 
172
 
172
 
173
 
173
 
174
void startgraphapp(HINSTANCE Instance, HINSTANCE PrevInstance, int CmdShow)
174
void startgraphapp(HINSTANCE Instance, HINSTANCE PrevInstance, int CmdShow)
175
{
175
{
176
 	/*
176
 	/*
177
	 *  Save some variables for later.
177
	 *  Save some variables for later.
178
	 */
178
	 */
179
	this_instance = Instance;
179
	this_instance = Instance;
180
	prev_instance = PrevInstance;
180
	prev_instance = PrevInstance;
181
	cmd_show = CmdShow;
181
	cmd_show = CmdShow;
182
 
182
 
183
	/*
183
	/*
184
	 *  Initialise the graphical interface.
184
	 *  Initialise the graphical interface.
185
	 */
185
	 */
186
	initapp(0, NULL);
186
	initapp(0, NULL);
187
	getappname(Instance);
187
	getappname(Instance);
188
}
188
}
189
 
189