/* Create a "SWT_Window_" + APP_NAME string with optional suffix. * Caller should free the memory when finished */ static char * createSWTWindowString(char * suffix, int semaphore) { #ifdef SOLARIS /* solaris requires semaphore names to start with '/' */ char * prefix = semaphore != 0 ? _T_ECLIPSE("/SWT_Window_") : _T_ECLIPSE("SWT_Window_"); #else char * prefix = _T_ECLIPSE("SWT_Window_"); #endif char * result = malloc((_tcslen(prefix) + _tcslen(getOfficialName()) + (suffix != NULL ? _tcslen(suffix) : 0) + 1) * sizeof(char)); if (suffix != NULL) _stprintf(result, _T_ECLIPSE("%s%s%s"), prefix, getOfficialName(), suffix); else _stprintf(result, _T_ECLIPSE("%s%s"), prefix, getOfficialName()); return result; }
static HWND findSWTMessageWindow() { HWND window = NULL; _TCHAR *windowTitle, *windowPrefix, *name; windowPrefix = _T("SWT_Window_"); name = getOfficialName(); windowTitle = malloc((_tcslen(windowPrefix) + _tcslen(name) + 1) * sizeof(_TCHAR)); _stprintf(windowTitle, _T_ECLIPSE("%s%s"), windowPrefix, name); window = FindWindow(NULL, windowTitle); free(windowTitle); return window; }
/* 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. */ gtk.gtk_set_locale(); if (!gtk.gtk_init_check(pArgc, &argv)) { return -1; } /*_gdk_set_program_class(getOfficialName());*/ gtkInitialized = TRUE; return 0; }
/* Create and Display the Splash Window */ int showSplash( const char* featureImage ) { GtkWidget *image; GdkPixbuf *pixbuf; if (splashHandle != 0) return 0; /* already showing splash */ if (featureImage == NULL) return -1; if (initialArgv == NULL) initialArgc = 0; if( initWindowSystem(&initialArgc, initialArgv, 1) != 0) return -1; shellHandle = gtk.gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk.gtk_window_set_decorated((GtkWindow*)(shellHandle), FALSE); gtk.g_signal_connect_data((gpointer)shellHandle, "destroy", (GtkSignalFunc)(gtk.gtk_widget_destroyed), &shellHandle, NULL, 0); pixbuf = gtk.gdk_pixbuf_new_from_file(featureImage, NULL); image = gtk.gtk_image_new_from_pixbuf(pixbuf); if (pixbuf) { gtk.g_object_unref(pixbuf); } gtk.gtk_container_add((GtkContainer*)(shellHandle), image); if (getOfficialName() != NULL) gtk.gtk_window_set_title((GtkWindow*)(shellHandle), getOfficialName()); gtk.gtk_window_set_position((GtkWindow*)(shellHandle), GTK_WIN_POS_CENTER); gtk.gtk_window_resize((GtkWindow*)(shellHandle), gtk.gdk_pixbuf_get_width(pixbuf), gtk.gdk_pixbuf_get_height(pixbuf)); gtk.gtk_widget_show_all((GtkWidget*)(shellHandle)); splashHandle = (long)shellHandle; dispatchMessages(); return 0; }
/* return > 0 if we successfully send a message to another eclipse instance */ int reuseWorkbench(_TCHAR** filePath, int timeout) { _TCHAR* mutexPrefix = _T("SWT_Mutex_"); _TCHAR* mutexName, *name; DWORD lock; HWND window = NULL; /* store for later */ openFilePath = filePath; openFileTimeout = timeout; name = getOfficialName(); mutexName = malloc((_tcslen(mutexPrefix) + _tcslen(name) + 1) * sizeof(_TCHAR)); _stprintf(mutexName, _T_ECLIPSE("%s%s"), mutexPrefix, name); mutex = CreateMutex(NULL, FALSE, mutexName); free(mutexName); if (mutex == NULL) return -1; //wait for timeout seconds lock = WaitForSingleObject(mutex, timeout * 1000); if (lock != WAIT_OBJECT_0) { /* failed to get the lock before timeout, We won't be reusing an existing eclipse. */ CloseHandle(mutex); return 0; } /* we have the mutex, look for the SWT window */ window = findSWTMessageWindow(); if (window != NULL) { sendOpenFileMessage(window); ReleaseMutex(mutex); CloseHandle(mutex); return 1; /* success! */ } /* no window, set a timer to look again later */ if (initWindowSystem(0, NULL, 0) == 0) SetTimer( topWindow, findWindowTimerId, findWindowTimeout, findWindowProc ); return 0; }
/* Create and Display the Splash Window */ int showSplash( const char* featureImage ) { GtkAdjustment* vadj, *hadj; int width, height; guint handlerId; GtkWidget* vboxHandle, * scrolledHandle, * handle; if (splashHandle != 0) return 0; /* already showing splash */ if (featureImage == NULL) return -1; if (initialArgv == NULL) initialArgc = 0; if( initWindowSystem(&initialArgc, initialArgv, 1) != 0) return -1; shellHandle = gtk.gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk.gtk_window_set_decorated((GtkWindow*)(shellHandle), FALSE); gtk.gtk_signal_connect((GtkObject*)shellHandle, "destroy", (GtkSignalFunc)(gtk.gtk_widget_destroyed), &shellHandle); vboxHandle = gtk.gtk_vbox_new(FALSE, 0); if(vboxHandle == 0) return -1; vadj = (GtkAdjustment*)gtk.gtk_adjustment_new(0, 0, 100, 1, 10, 10); hadj = (GtkAdjustment*)gtk.gtk_adjustment_new(0, 0, 100, 1, 10, 10); if (vadj == 0 || hadj == 0) return -1; scrolledHandle = gtk.gtk_scrolled_window_new(hadj, vadj); gtk.gtk_container_add((GtkContainer*)(vboxHandle), scrolledHandle); gtk.gtk_box_set_child_packing((GtkBox*)(vboxHandle), scrolledHandle, TRUE, TRUE, 0, GTK_PACK_END); gtk.gtk_scrolled_window_set_policy((GtkScrolledWindow*)(scrolledHandle), GTK_POLICY_NEVER, GTK_POLICY_NEVER); handle = gtk.gtk_fixed_new(); gtk.gtk_fixed_set_has_window((GtkFixed*)(handle), TRUE); ((GtkObject*)handle)->flags |= GTK_CAN_FOCUS; /*GTK_WIDGET_SET_FLAGS(handle, GTK_CAN_FOCUS);*/ /* avoid gtk_scrolled_window_add warning */ handlerId = gtk.g_log_set_handler("Gtk", G_LOG_LEVEL_WARNING, &log_handler, NULL); gtk.gtk_container_add((GtkContainer*)(scrolledHandle), handle); gtk.g_log_remove_handler("Gtk", handlerId); gtk.gtk_container_add((GtkContainer*)(shellHandle), vboxHandle); pixbuf = gtk.gdk_pixbuf_new_from_file(featureImage, NULL); image = gtk.gtk_image_new_from_pixbuf(pixbuf); gtk.gtk_signal_connect((GtkObject*)(image), "destroy", (GtkSignalFunc)(gtk.gtk_widget_destroyed), &image); gtk.gtk_container_add((GtkContainer*)(handle), image); width = gtk.gdk_pixbuf_get_width(pixbuf); height = gtk.gdk_pixbuf_get_height(pixbuf); gtk.gtk_window_set_position((GtkWindow*)(shellHandle), GTK_WIN_POS_CENTER); if (getOfficialName() != NULL) gtk.gtk_window_set_title((GtkWindow*)(shellHandle), getOfficialName()); gtk.gtk_window_resize((GtkWindow*)(shellHandle), width, height); gtk.gtk_widget_show_all((GtkWidget*)(shellHandle)); splashHandle = (long)shellHandle; dispatchMessages(); return 0; }