The R Project SVN R

Rev

Rev 45017 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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