-void bmp_to_pixmap (const char* filename, GdkPixmap **pixmap, GdkBitmap **mask)
-{
- guint16 width, height;
- unsigned char *buf;
- GdkWindow *window = gdk_get_default_root_window();
- GdkColormap *colormap;
- GdkGC* gc = gdk_gc_new (window);
- int i, j;
- bool hasMask = false;
-
- *pixmap = *mask = NULL;
- buf = load_bitmap_file (filename, &width, &height);
- if (!buf)
- return;
-
- colormap = gdk_drawable_get_colormap (window);
- *pixmap = gdk_pixmap_new (window, width, height, -1);
-
- typedef struct
- {
- GdkColor c;
- unsigned char *p;
- } PAL;
-
- for (i = 0; i < height; i++)
- {
- for (j = 0; j < width; j++)
- {
- unsigned char *p = &buf[(i * width + j) * 3];
- PAL pe;
-
- pe.c.red = (gushort)(p[0] * 0xFF);
- pe.c.green = (gushort)(p[1] * 0xFF);
- pe.c.blue = (gushort)(p[2] * 0xFF);
- gdk_colormap_alloc_color(colormap, &pe.c, FALSE, TRUE);
- gdk_gc_set_foreground(gc, &pe.c);
- gdk_draw_point(*pixmap, gc, j, i);
-
- if (p[0] == 0xFF && p[1] == 0x00 && p[2] == 0xFF)
- hasMask = true;
- }
- }
-
- gdk_gc_unref (gc);
- *mask = gdk_pixmap_new (window, width, height, 1);
- gc = gdk_gc_new (*mask);
- if (hasMask)
- {
- for (i = 0; i < height; i++)
- {
- for (j = 0; j < width; j++)
- {
- GdkColor mask_pattern;
-
- // pink is transparent
- if ((buf[(i*width+j)*3] == 0xff) &&
- (buf[(i*width+j)*3+1] == 0x00) &&
- (buf[(i*width+j)*3+2] == 0xff))
- mask_pattern.pixel = 0;
- else
- mask_pattern.pixel = 1;
-
- gdk_gc_set_foreground (gc, &mask_pattern);
- // possible Win32 Gtk bug here
- //gdk_draw_point (*mask, gc, j, i);
- gdk_draw_line (*mask, gc, j, i, j + 1, i);
- }
- }
- }
- else
- {
- GdkColor mask_pattern;
- mask_pattern.pixel = 1;
- gdk_gc_set_foreground (gc, &mask_pattern);
- gdk_draw_rectangle (*mask, gc, 1, 0, 0, width, height);
- }
- gdk_gc_unref(gc);
- free (buf);
-}
-
-void load_pixmap (const char* filename, GtkWidget* widget, GdkPixmap **gdkpixmap, GdkBitmap **mask)
-{
- CString str;
-
- str = g_strBitmapsPath;
- str += filename;
-
- bmp_to_pixmap (str.GetBuffer (), gdkpixmap, mask);
- if (*gdkpixmap == NULL)
- {
- printf("gdkpixmap was null\n");
- gchar *dummy[] = { "1 1 1 1", " c None", " " };
- printf("calling gdk_pixmap_create_from_xpm_d\n");
- *gdkpixmap = gdk_pixmap_create_from_xpm_d (gdk_get_default_root_window(), mask, NULL, dummy);
- }
-}
-
-// this is the same as above but used by the plugins
-// GdkPixmap **gdkpixmap, GdkBitmap **mask
-bool WINAPI load_plugin_bitmap (const char* filename, void **gdkpixmap, void **mask)
-{
- CString str;
-
- str = g_strGameToolsPath;
- str += g_strPluginsDir;
- str += "bitmaps/";
- str += filename;
- bmp_to_pixmap (str.GetBuffer (), (GdkPixmap **)gdkpixmap, (GdkBitmap **)mask);
-
- if (*gdkpixmap == NULL)
- {
- // look in the core plugins
- str = g_strAppPath;
- str += g_strPluginsDir;
- str += "bitmaps/";
- str += filename;
- bmp_to_pixmap (str.GetBuffer (), (GdkPixmap **)gdkpixmap, (GdkBitmap **)mask);
-
- if (*gdkpixmap == NULL)
- {
-
- // look in core modules
- str = g_strAppPath;
- str += g_strModulesDir;
- str += "bitmaps/";
- str += filename;
- bmp_to_pixmap (str.GetBuffer (), (GdkPixmap **)gdkpixmap, (GdkBitmap **)mask);
-
- if (*gdkpixmap == NULL)
- {
- gchar *dummy[] = { "1 1 1 1", " c None", " " };
- *gdkpixmap = gdk_pixmap_create_from_xpm_d (gdk_get_default_root_window(), (GdkBitmap **)mask, NULL, dummy);
- return false;
- }
- }
- }
- return true;
-}
-
-// Load a xpm file and return a pixmap widget.
-GtkWidget* new_pixmap (GtkWidget* widget, const char* filename)
-{
- GdkPixmap *gdkpixmap;
- GdkBitmap *mask;
- GtkWidget *pixmap;
-
- load_pixmap (filename, widget, &gdkpixmap, &mask);
- pixmap = gtk_pixmap_new (gdkpixmap, mask);
-
- gdk_drawable_unref (gdkpixmap);
- gdk_drawable_unref (mask);
-
- return pixmap;
-}
-
-// =============================================================================
-// Menu stuff
-
-GtkWidget* menu_separator (GtkWidget *menu)
-{
- GtkWidget *menu_item = gtk_menu_item_new ();
- gtk_menu_append (GTK_MENU (menu), menu_item);
- gtk_widget_set_sensitive (menu_item, FALSE);
- gtk_widget_show (menu_item);
- return menu_item;
-}
-
-GtkWidget* menu_tearoff (GtkWidget *menu)
-{
- GtkWidget *menu_item = gtk_tearoff_menu_item_new ();
- gtk_menu_append (GTK_MENU (menu), menu_item);
-// gtk_widget_set_sensitive (menu_item, FALSE); -- controls whether menu is detachable
- gtk_widget_show (menu_item);
- return menu_item;
-}
-
-GtkWidget* create_sub_menu_with_mnemonic (GtkWidget *bar, const gchar *mnemonic)
-{
- GtkWidget *item, *sub_menu;
-
- item = gtk_menu_item_new_with_mnemonic (mnemonic);
- gtk_widget_show (item);
- gtk_container_add (GTK_CONTAINER (bar), item);
-
- sub_menu = gtk_menu_new ();
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), sub_menu);
-
- return sub_menu;
-}
-
-extern void AddMenuItem (GtkWidget* menu, unsigned int id);
-
-GtkWidget* create_menu_item_with_mnemonic (GtkWidget *menu, const gchar *mnemonic, GtkSignalFunc func, int id)
-{
- GtkWidget *item;
-
- item = gtk_menu_item_new_with_mnemonic (mnemonic);
-
- gtk_widget_show (item);
- gtk_container_add (GTK_CONTAINER (menu), item);
- gtk_signal_connect (GTK_OBJECT (item), "activate", GTK_SIGNAL_FUNC (func), GINT_TO_POINTER (id));
-
- AddMenuItem (item, id);
- return item;
-}
-
-GtkWidget* create_check_menu_item_with_mnemonic (GtkWidget *menu, const gchar *mnemonic, GtkSignalFunc func, int id, gboolean active)
-{
- GtkWidget *item;
-
- item = gtk_check_menu_item_new_with_mnemonic(mnemonic);
-
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), active);
- gtk_widget_show (item);
- gtk_container_add (GTK_CONTAINER (menu), item);
- gtk_signal_connect (GTK_OBJECT (item), "activate", GTK_SIGNAL_FUNC (func), GINT_TO_POINTER (id));
-
- AddMenuItem (item, id);
- return item;
-}
-
-GtkWidget* create_radio_menu_item_with_mnemonic (GtkWidget *menu, GtkWidget *last, const gchar *mnemonic, GtkSignalFunc func, int id, gboolean state)
-{
- GtkWidget *item;
- GSList *group = (GSList*)NULL;
-
- if (last != NULL)
- group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (last));
- item = gtk_radio_menu_item_new_with_mnemonic (group, mnemonic);
- gtk_check_menu_item_set_state (GTK_CHECK_MENU_ITEM (item), state);
-
- gtk_widget_show (item);
- gtk_container_add (GTK_CONTAINER (menu), item);
- gtk_signal_connect (GTK_OBJECT (item), "activate", GTK_SIGNAL_FUNC (func), GINT_TO_POINTER (id));
-
- AddMenuItem (item, id);
- return item;
-}
-
-GtkWidget* create_menu_in_menu_with_mnemonic (GtkWidget *menu, const gchar *mnemonic)
-{
- GtkWidget *item, *submenu;
-
- item = gtk_menu_item_new_with_mnemonic(mnemonic);
- gtk_widget_show (item);
- gtk_container_add (GTK_CONTAINER (menu), item);
-
- submenu = gtk_menu_new ();
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
-
- return submenu;
-}
-
-// =============================================================================
-// Message Boxes
-
-void dialog_button_callback( GtkWidget *widget, gpointer data ) {
- GtkWidget *parent;
- int *loop, *ret;
-
- parent = gtk_widget_get_toplevel( widget );
- loop = (int*)g_object_get_data( G_OBJECT( parent ), "loop" );
- ret = (int*)g_object_get_data( G_OBJECT( parent ), "ret" );
-
- *loop = 0;
- *ret = GPOINTER_TO_INT (data);
-}
-
-gint dialog_delete_callback (GtkWidget *widget, GdkEvent* event, gpointer data)
-{
- int *loop;
-
- gtk_widget_hide (widget);
- loop = (int*)g_object_get_data (G_OBJECT (widget), "loop");
- *loop = 0;
-
- return TRUE;
-}
-
-gint dialog_url_callback (GtkWidget *widget, GdkEvent* event, gpointer data)
-{
- OpenURL((const char *)g_object_get_data (G_OBJECT (widget), "URL"));
-
- return TRUE;
-}
-
-int WINAPI gtk_MessageBox (void *parent, const char* lpText, const char* lpCaption, guint32 uType, const char* URL)
-{
- GtkWidget *window, *w, *vbox, *hbox;
- GtkAccelGroup *accel;
- int mode = (uType & MB_TYPEMASK), ret, loop = 1;
-
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- gtk_signal_connect (GTK_OBJECT (window), "delete_event",
- GTK_SIGNAL_FUNC (dialog_delete_callback), NULL);
- gtk_signal_connect (GTK_OBJECT (window), "destroy",
- GTK_SIGNAL_FUNC (gtk_widget_destroy), NULL);
- gtk_window_set_title (GTK_WINDOW (window), lpCaption);
- gtk_container_border_width (GTK_CONTAINER (window), 10);
- g_object_set_data (G_OBJECT (window), "loop", &loop);
- g_object_set_data (G_OBJECT (window), "ret", &ret);
- gtk_widget_realize (window);
-
- gtk_window_set_policy(GTK_WINDOW (window),FALSE,FALSE,TRUE);
-
- if (parent != NULL)
- gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (parent));
-
- accel = gtk_accel_group_new ();
- gtk_window_add_accel_group (GTK_WINDOW (window), accel);
-
- vbox = gtk_vbox_new (FALSE, 10);
- gtk_container_add (GTK_CONTAINER (window), vbox);
- gtk_widget_show (vbox);
-
- w = gtk_label_new (lpText);
- gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 2);
- gtk_label_set_justify (GTK_LABEL (w), GTK_JUSTIFY_LEFT);
- gtk_widget_show (w);
-
- w = gtk_hseparator_new ();
- gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 2);
- gtk_widget_show (w);
-
- hbox = gtk_hbox_new (FALSE, 10);
- gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 2);
- gtk_widget_show (hbox);
-
- if (mode == MB_OK)
- {
- w = gtk_button_new_with_label (_("Ok"));
- gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
- gtk_signal_connect (GTK_OBJECT (w), "clicked",
- GTK_SIGNAL_FUNC (dialog_button_callback), GINT_TO_POINTER (IDOK));
- gtk_widget_add_accelerator (w, "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0);
- gtk_widget_add_accelerator (w, "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0);
- GTK_WIDGET_SET_FLAGS (w, GTK_CAN_DEFAULT);
- gtk_widget_grab_default (w);
- gtk_widget_show (w);
- ret = IDOK;
- }
- else if (mode == MB_OKCANCEL)
- {
- w = gtk_button_new_with_label (_("Ok"));
- gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
- gtk_signal_connect (GTK_OBJECT (w), "clicked",
- GTK_SIGNAL_FUNC (dialog_button_callback), GINT_TO_POINTER (IDOK));
- gtk_widget_add_accelerator (w, "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0);
- GTK_WIDGET_SET_FLAGS (w, GTK_CAN_DEFAULT);
- gtk_widget_grab_default (w);
- gtk_widget_show (w);
-
- w = gtk_button_new_with_label (_("Cancel"));
- gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
- gtk_signal_connect (GTK_OBJECT (w), "clicked",
- GTK_SIGNAL_FUNC (dialog_button_callback), GINT_TO_POINTER (IDCANCEL));
- gtk_widget_add_accelerator (w, "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0);
- gtk_widget_show (w);
- ret = IDCANCEL;
- }
- else if (mode == MB_YESNOCANCEL)
- {
- w = gtk_button_new_with_label (_("Yes"));
- gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
- gtk_signal_connect (GTK_OBJECT (w), "clicked",
- GTK_SIGNAL_FUNC (dialog_button_callback), GINT_TO_POINTER (IDYES));
- GTK_WIDGET_SET_FLAGS (w, GTK_CAN_DEFAULT);
- gtk_widget_grab_default (w);
- gtk_widget_show (w);
-
- w = gtk_button_new_with_label (_("No"));
- gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
- gtk_signal_connect (GTK_OBJECT (w), "clicked",
- GTK_SIGNAL_FUNC (dialog_button_callback), GINT_TO_POINTER (IDNO));
- gtk_widget_show (w);
-
- w = gtk_button_new_with_label (_("Cancel"));
- gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
- gtk_signal_connect (GTK_OBJECT (w), "clicked",
- GTK_SIGNAL_FUNC (dialog_button_callback), GINT_TO_POINTER (IDCANCEL));
- gtk_widget_show (w);
- ret = IDCANCEL;
- }
- else /* if (mode == MB_YESNO) */
- {
- w = gtk_button_new_with_label (_("Yes"));
- gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
- gtk_signal_connect (GTK_OBJECT (w), "clicked",
- GTK_SIGNAL_FUNC (dialog_button_callback), GINT_TO_POINTER (IDYES));
- GTK_WIDGET_SET_FLAGS (w, GTK_CAN_DEFAULT);
- gtk_widget_grab_default (w);
- gtk_widget_show (w);
-
- w = gtk_button_new_with_label (_("No"));
- gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
- gtk_signal_connect (GTK_OBJECT (w), "clicked",
- GTK_SIGNAL_FUNC (dialog_button_callback), GINT_TO_POINTER (IDNO));
- gtk_widget_show (w);
- ret = IDNO;
- }
-
- if (URL)
- {
- w = gtk_button_new_with_label (_("Go to URL"));
- gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
- gtk_signal_connect (GTK_OBJECT (w), "clicked",
- GTK_SIGNAL_FUNC (dialog_url_callback), NULL);
- g_object_set_data (G_OBJECT (w), "URL", (void *)URL);
- GTK_WIDGET_SET_FLAGS (w, GTK_CAN_DEFAULT);
- gtk_widget_grab_default (w);
- gtk_widget_show (w);
- }
-
-
- gtk_widget_show (window);
- gtk_grab_add (window);
-
- while (loop)
- gtk_main_iteration ();
-
- gtk_grab_remove (window);
- gtk_widget_destroy (window);
-
- return ret;