/* Display a Message */ void displayMessage( _TCHAR* title, _TCHAR* message ) { if(!initialized) initWindowSystem(0, NULL, 0); System::String^ titleStr = gcnew System::String (title); System::String^ messageStr = gcnew System::String (message); System::Windows::MessageBox::Show (messageStr, titleStr, System::Windows::MessageBoxButton::OK); }
/* 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; } 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); }
int reuseWorkbench(_TCHAR** filePath, int timeout) { char *appName, *launcherName; int result = 0; if (initWindowSystem(&initialArgc, initialArgv, 1) != 0) return -1; openFileTimeout = timeout; openFilePath = filePath; //App name is defined in SWT as well. Values must be consistent. appName = createSWTWindowString(NULL, 0); appWindowAtom = gtk.XInternAtom(gtk_GDK_DISPLAY, appName, FALSE); free(appName); //check if app is already running. Just set property if it is. if (setAppWindowProperty() > 0) return 1; /* app is not running, create a launcher window to act as a mutex so we don't need to keep the semaphore locked */ launcherName = createSWTWindowString(_T_ECLIPSE("_Launcher"), 1); launcherWindowAtom = gtk.XInternAtom(gtk_GDK_DISPLAY, launcherName, FALSE); result = executeWithLock(launcherName, createLauncherWindow); free(launcherName); if (result == 1) { //The app is already being launched in another process. Set the property on that app window and exit while (openFileTimeout > 0) { if (setAppWindowProperty() > 0) return 1; //success else { openFileTimeout--; sleep(1); } } //timed out trying to set the app property result = 0; } return result; }
/* 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 ) { 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; }
/* Show the Splash Window * * Open the bitmap, insert into the splash window and display it. * */ int showSplash( const _TCHAR* featureImage ) { static int splashing = 0; HBITMAP hBitmap = 0; BITMAP bmp; HDC hDC; int depth; int x, y; int width, height; int dpiX, scaledWidth, scaledHeight; if(splashing) { /*splash screen is already showing, do nothing */ return 0; } if (featureImage == NULL) return -1; /* if Java was started first and is calling back to show the splash, we might not * have initialized the window system yet */ initWindowSystem(0, NULL, 1); /* Load the bitmap for the feature. */ hDC = GetDC( NULL); depth = GetDeviceCaps( hDC, BITSPIXEL ) * GetDeviceCaps( hDC, PLANES); /* fetch screen DPI and round it to 100% multiples, this implementation needs to be kept in sync with org.eclipse.swt.internal.DPIUtil#setDeviceZoom(int) */ dpiX = GetDeviceCaps ( hDC, LOGPIXELSX ); dpiX = ((int)((dpiX + 24) / 96 )) * 96; ReleaseDC(NULL, hDC); if (featureImage != NULL) hBitmap = LoadImage(NULL, featureImage, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); /* If the bitmap could not be found, return an error. */ if (hBitmap == 0) return ERROR_FILE_NOT_FOUND; GetObject(hBitmap, sizeof(BITMAP), &bmp); /* reload scaled up image when zoom > 100% */ if (dpiX > 96) { /* calculate scaled-up bounds */ scaledWidth = dpiX * bmp.bmWidth / 96; scaledHeight = dpiX * bmp.bmHeight / 96; hBitmap = LoadImage(NULL, featureImage, IMAGE_BITMAP, scaledWidth, scaledHeight, LR_LOADFROMFILE); /* If the bitmap could not be found, return an error. */ if (hBitmap == 0) return ERROR_FILE_NOT_FOUND; GetObject(hBitmap, sizeof(BITMAP), &bmp); } /* figure out position */ width = GetSystemMetrics (SM_CXSCREEN); height = GetSystemMetrics (SM_CYSCREEN); x = (width - bmp.bmWidth) / 2; y = (height - bmp.bmHeight) / 2; /* Centre the splash window and display it. */ SetWindowPos (topWindow, 0, x, y, bmp.bmWidth, bmp.bmHeight, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE); SendMessage( topWindow, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) hBitmap ); ShowWindow( topWindow, SW_SHOW ); BringWindowToTop( topWindow ); splashing = 1; /* Process messages */ dispatchMessages(); 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; }