The R Project SVN R

Rev

Rev 43328 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 43328 Rev 45017
Line 26... Line 26...
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 = NULL;
33
PROTECTED HANDLE this_instance = NULL;
34
	PROTECTED HANDLE prev_instance = NULL;
34
PROTECTED HANDLE prev_instance = NULL;
35
 
35
 
36
/*
36
/*
37
 *  Functions defined in this file.
37
 *  Functions defined in this file.
38
 */
38
 */
39
	static void setappname(char *title);
39
static void setappname(char *title);
40
	static void getappname(HANDLE Instance);
40
static void getappname(HANDLE Instance);
41
 
41
 
42
	int initapp(int argc, char **argv);
42
int initapp(int argc, char **argv);
43
	void exitapp(void);
43
void exitapp(void);
44
	void gabeep(void);
44
void gabeep(void);
45
 
45
 
46
/*
46
/*
47
 *  Initialise application. Returns zero on failure.
47
 *  Initialise application. Returns zero on failure.
48
 */
48
 */
49
int initapp(int argc, char **argv)
49
int initapp(int argc, char **argv)
50
{
50
{
51
	if (! app_initialised)
51
    if (! app_initialised)
52
	{
52
    {
53
		app_initialised = 1;
53
	app_initialised = 1;
54
		init_objects();
54
	init_objects();
55
		init_events();
55
	init_events();
56
		init_fonts();
56
	init_fonts();
57
		init_cursors();
57
	init_cursors();
58
		init_contexts();
58
	init_contexts();
59
		init_menus();
59
	init_menus();
60
	}
60
    }
61
	return (argc < 1) ? 1 : argc;
61
    return (argc < 1) ? 1 : argc;
62
}
62
}
63
 
63
 
64
/*
64
/*
65
 *  This function releases all GDI objects.
65
 *  This function releases all GDI objects.
66
 */
66
 */
67
PROTECTED
67
PROTECTED
68
void app_cleanup(void)
68
void app_cleanup(void)
69
{
69
{
70
	if (app_initialised) {
70
    if (app_initialised) {
71
		app_initialised = 0;
71
	app_initialised = 0;
72
		finish_contexts();
72
	finish_contexts();
73
		finish_objects();
73
	finish_objects();
74
		finish_events();
74
	finish_events();
75
	}
75
    }
76
}
76
}
77
 
77
 
78
/*
78
/*
79
 *  Standard quit application function.
79
 *  Standard quit application function.
80
 *  This function releases all GDI objects and terminates the program.
80
 *  This function releases all GDI objects and terminates the program.
81
 *  It can be called at any time from within a program, or at the end,
81
 *  It can be called at any time from within a program, or at the end,
82
 *  or else it will be called if all windows are closed.
82
 *  or else it will be called if all windows are closed.
83
 */
83
 */
84
void exitapp(void)
84
void exitapp(void)
85
{
85
{
86
	app_cleanup();
86
    app_cleanup();
87
	active_windows = 0;
87
    active_windows = 0;
88
	exit(0);
88
    exit(0);
89
}
89
}
90
 
90
 
91
/*
91
/*
92
 *  Run an application program:
92
 *  Run an application program:
93
 */
93
 */
94
int execapp(char *app)
94
int execapp(char *app)
95
{
95
{
96
	#ifdef __MSDOS__
96
#ifdef __MSDOS__
97
		if (WinExec(app, SW_SHOW) < 32)
97
    if (WinExec(app, SW_SHOW) < 32)
98
			return 0;
98
	return 0;
99
	#else
99
#else
100
		if (system(app) != 0)
100
    if (system(app) != 0)
101
			return 0;
101
	return 0;
102
	#endif
102
#endif
103
	return 1;
103
    return 1;
104
}
104
}
105
 
105
 
106
 
106
 
107
 
107
 
108
/*
108
/*
109
 *  Play error sound
109
 *  Play error sound
110
 */
110
 */
111
void gabeep(void)
111
void gabeep(void)
112
{
112
{
113
	MessageBeep(MB_ICONASTERISK);
113
    MessageBeep(MB_ICONASTERISK);
114
}
114
}
115
 
115
 
116
/*
116
/*
117
 *  Take a name like "PROG.EXE" and set app_name to be "Prog".
117
 *  Take a name like "PROG.EXE" and set app_name to be "Prog".
118
 */
118
 */
119
static void setappname(char *title)
119
static void setappname(char *title)
120
{
120
{
121
	int len;
121
    int len;
122
	char c;
122
    char c;
123
 
123
 
124
	if (title[0] == '\0')
124
    if (title[0] == '\0')
125
		return;
125
	return;
126
	for (len=1; (c=title[len]) != '\0'; len++)
126
    for (len=1; (c=title[len]) != '\0'; len++)
127
		title[len] = tolower(c);
127
	title[len] = tolower(c);
128
	if ((len-=4)<0)
128
    if ((len-=4)<0)
129
		len = 0;
129
	len = 0;
130
	if (! string_diff(title+len, ".exe"))
130
    if (! string_diff(title+len, ".exe"))
131
		title[len] = '\0';
131
	title[len] = '\0';
132
 
132
 
133
	app_name = new_string(title);
133
    app_name = new_string(title);
134
}
134
}
135
 
135
 
136
/*
136
/*
137
 *  Find out what the application is called.
137
 *  Find out what the application is called.
138
 */
138
 */
139
static void getappname(HANDLE Instance)
139
static void getappname(HANDLE Instance)
140
{
140
{
141
	char exename[MAX_PATH];
141
    char exename[MAX_PATH];
142
	char title[MAX_PATH];
142
    char title[MAX_PATH];
143
 
143
 
144
	/* find out executable name */
144
    /* find out executable name */
145
	GetModuleFileName(Instance, exename, sizeof(exename));
145
    GetModuleFileName(Instance, exename, sizeof(exename));
146
	GetFileTitle(exename, title, sizeof(title));
146
    GetFileTitle(exename, title, sizeof(title));
147
	setappname(title);
147
    setappname(title);
148
}
148
}
149
 
149
 
150
#if 0
150
#if 0
151
/*
151
/*
152
 *  Special function for making printf work on Windows systems.
152
 *  Special function for making printf work on Windows systems.
153
 *  This function is never called, it merely tricks the compiler into
153
 *  This function is never called, it merely tricks the compiler into
154
 *  including printf and scanf support.
154
 *  including printf and scanf support.
155
 */
155
 */
156
void app_init_printf(void)
156
void app_init_printf(void)
157
{
157
{
158
 	#ifdef __BORLANDC__
158
#ifdef __BORLANDC__
159
 		#if __BORLANDC__ <= 0x410
159
#if __BORLANDC__ <= 0x410
160
 		_InitEasyWin();
160
    _InitEasyWin();
161
 		#endif
161
#endif
162
 	#else
162
#else
163
 	printf(" ");
163
    printf(" ");
164
 	#endif
164
#endif
165
}
165
}
166
#endif
166
#endif
167
 
167
 
168
/*
168
/*
169
 *  The main Windows entry point is the WinMain function.
169
 *  The main Windows entry point is the WinMain function.
Line 171... Line 171...
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; is always NULL */
180
    /* prev_instance = PrevInstance; is always NULL */
181
 
181
 
182
	/*
182
    /*
183
	 *  Initialise the graphical interface.
183
     *  Initialise the graphical interface.
184
	 */
184
     */
185
	initapp(0, NULL);
185
    initapp(0, NULL);
186
	getappname(Instance);
186
    getappname(Instance);
187
}
187
}
188
 
188