Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 06bed2a9d51406a95ccdb7709c91134a491c3c7f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*******************************************************************************
 * Copyright (c) 2006, 2009 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at 
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Andrew Niefer
 *******************************************************************************/
 
#include "eclipseCommon.h"
#include "eclipseOS.h"
#include "eclipseGtk.h"

#include <locale.h>
#include <dlfcn.h>
#include <stdio.h>
#include <string.h>

#define ECLIPSE_ICON  401

char   dirSeparator  = '/';
char   pathSeparator = ':';

/* Define local variables for the main window. */
static int          saveArgc   = 0;		/* arguments after they were parsed, for window system */
static char**       saveArgv   = 0;

gboolean     gtkInitialized = FALSE;

#ifdef SOLARIS
/* a call to this function appears inline in glib/gstring.h on Solaris,
   so provide a definition here and hook it up
   */
GString* g_string_insert_c (GString *string, gssize pos, gchar c) {
	/* see bug 264615, we can get here without having initialized the gtk pointers */
	if (gtk.not_initialized)
		loadGtk();
	return gtk.g_string_insert_c(string, pos, c);
}
#endif

/* Display a Message */
void displayMessage(char* title, char* message)
{
	GtkWidget* dialog;
	
    /* If GTK has not been initialized yet, do it now. */
    if (initWindowSystem( &saveArgc, saveArgv, 1 ) != 0) {
    	printf("%s:\n%s\n", title, message);
    	return;
    }

    if (strcmp( message, _T_ECLIPSE("GTK+ Version Check")) == 0) {
        return;
    }

  	dialog = gtk.gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT,
				   					GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
				   					"%s", message);
  	gtk.gtk_window_set_title((GtkWindow*)dialog, title);
  	gtk.gtk_dialog_run((GtkDialog*)dialog);
  	gtk.gtk_widget_destroy(dialog);
}

/* Initialize the Window System */
int initWindowSystem(int* pArgc, char* argv[], int showSplash)
{
	int defaultArgc = 1;
	char * defaultArgv [] = { "", 0 };
	
    if(gtkInitialized)
    	return 0;
    
    /* load the GTK libraries and initialize function pointers */
    if (loadGtk() != 0)
    	return -1;
    
    if (getOfficialName() != NULL) 
    	defaultArgv[0] = getOfficialName();
    
	if (argv == NULL) {
		/* gtk_init_check on Solaris 9 doesn't like NULL or empty argv */
		pArgc = &defaultArgc;
		argv = defaultArgv;
	}
	
    /* Save the arguments in case displayMessage() is called in the main launcher. */ 
    if (saveArgv == 0)
    {
    	saveArgc = *pArgc;
    	saveArgv =  argv;
    }  

	/* Initialize GTK. */
    if (gtk.gtk_set_locale) gtk.gtk_set_locale();
    if (gtk.gtk_init_with_args) {
        GError *error = NULL;
        if (!gtk.gtk_init_with_args(0, NULL, NULL, NULL, NULL, &error)) {
            if (error) {
                fprintf(stderr, "%s: %s\n", getOfficialName(), error->message);
                if (gtk.g_error_free) gtk.g_error_free(error);
            }
            return -1;
        }
    } else {
        if (!gtk.gtk_init_check(pArgc, &argv)) {
        	return -1;
        }
    }

	/*_gdk_set_program_class(getOfficialName());*/
	gtkInitialized = TRUE;
	return 0;
}

/* Load the specified shared library
 */
void * loadLibrary( char * library ){
	void * result= dlopen(library, RTLD_LAZY);
	if(result == 0) 
		printf("%s\n",dlerror());
	return result;
}

/* Unload the shared library
 */
void unloadLibrary( void * handle ){
	dlclose(handle);
}
 
/* Find the given symbol in the shared library
 */
void * findSymbol( void * handle, char * symbol ){
	return dlsym(handle, symbol);
}

Back to the top