Exemple #1
0
static gboolean
ggu_tree_view_popup_menu (GtkWidget *widget)
{
  GtkTreeView      *view = GTK_TREE_VIEW (widget);
  GtkTreeSelection *selection;
  GtkTreeModel     *model;
  GtkTreeIter       iter;
  GtkWidget        *menu;
  gboolean          handled = FALSE;
  
  selection = gtk_tree_view_get_selection (view);
  if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
    GtkTreePath  *path;
    
    path = gtk_tree_model_get_path (model, &iter);
    gtk_tree_view_scroll_to_cell (view, path, NULL, FALSE, 0.0, 0.0);
    menu = create_popup_menu (GGU_TREE_VIEW (widget), path, &iter);
    gtk_tree_path_free (path);
  } else {
    menu = create_popup_menu (GGU_TREE_VIEW (widget), NULL, NULL);
  }
  if (menu) {
    gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
                    (GtkMenuPositionFunc) tree_view_popup_menu_position_func,
                    widget, 0, gtk_get_current_event_time ());
    handled = TRUE;
  }
  
  return handled;
}
Exemple #2
0
static gboolean
ggu_tree_view_button_press_event (GtkWidget      *widget,
                                  GdkEventButton *event)
{
  GtkTreeView  *view = GTK_TREE_VIEW (widget);
  gboolean      handled;
  
  /* run the default handler manually for it to set tup selection and stuff */
  handled = GTK_WIDGET_CLASS (ggu_tree_view_parent_class)->button_press_event (widget, event);
  if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
    GtkTreePath  *path;
    GtkWidget    *menu;
    
    if (gtk_tree_view_get_path_at_pos (view, (gint) event->x, (gint) event->y,
                                       &path, NULL, NULL, NULL)) {
      GtkTreeIter iter;
      
      gtk_tree_model_get_iter (gtk_tree_view_get_model (view), &iter, path);
      menu = create_popup_menu (GGU_TREE_VIEW (widget), path, &iter);
      gtk_tree_path_free (path);
    } else {
      menu = create_popup_menu (GGU_TREE_VIEW (widget), NULL, NULL);
    }
    
    if (menu) {
      gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, event->button,
                      event->time);
      handled = TRUE;
    }
  }
  
  return handled;
}
Exemple #3
0
GtkWidget *
picture_create_widget (GtkWidget * dlg)
{
  GtkWidget *sw;

  sw = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_NONE);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), options.hscroll_policy, options.vscroll_policy);

  viewport = gtk_viewport_new (gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (sw)),
                               gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (sw)));
  gtk_container_add (GTK_CONTAINER (sw), viewport);

  picture = gtk_image_new ();
  gtk_container_add (GTK_CONTAINER (viewport), picture);

  /* load picture */
  if (options.common_data.uri &&
      g_file_test (options.common_data.uri, G_FILE_TEST_EXISTS))
    load_picture (options.common_data.uri);
  else
    gtk_image_set_from_stock (GTK_IMAGE (picture), "gtk-missing-image", GTK_ICON_SIZE_DIALOG);

  if (loaded && !animated)
    {
      create_popup_menu ();
      g_signal_connect (G_OBJECT (viewport), "button-press-event", G_CALLBACK (button_handler), NULL);
      g_signal_connect (G_OBJECT (viewport), "key-press-event", G_CALLBACK (key_handler), NULL);
    }

  return sw;
}
Exemple #4
0
/**
@brief    The title menu is used for both the window menu and the dropdown list that appears at the top of the window.
@return   void
@todo     Does it assume that titles have already been created? 
**/
void 
create_title_menu(Display *display, struct Popup_menu *window_menu
, struct Themes *themes, struct Cursors *cursors) {

  window_menu->inner_width = DEFAULT_MENU_ITEM_WIDTH;        //TODO this must come from the theme
  window_menu->inner_height = themes->popup_menu[menu_item_mid].h;

  create_popup_menu(display, window_menu, themes, cursors);
}
Exemple #5
0
/**
@brief    This function only creates the frame and background for the workspace menu.
          When a workspace is created it must add itself to this menu.
          it should also check to see it it is bigger than the current width and enlarge it if required.
@return   void
**/
void 
create_workspaces_menu(Display *display, struct Workspace_list *workspaces
, struct Themes *themes, struct Cursors *cursors) {

  
  workspaces->workspace_menu.inner_width = DEFAULT_MENU_ITEM_WIDTH; //TODO this must come from the theme
  workspaces->workspace_menu.inner_height = themes->popup_menu[menu_item_mid].h;

  create_popup_menu(display, &workspaces->workspace_menu, themes, cursors);
}
Exemple #6
0
/**
@brief    Creates the mode menu which can be used by all windows in all workspaces.  The main even loop uses the windows and events to determine if a mode menu item was clicked or interacted with in some way.
@return   void
**/
void 
create_mode_menu(Display *display, struct Mode_menu *mode_menu
, struct Themes *themes, struct Cursors *cursors) {

  Screen* screen = DefaultScreenOfDisplay(display);
  int black = BlackPixelOfScreen(screen);

  mode_menu->menu.inner_width = DEFAULT_MENU_ITEM_WIDTH;
  mode_menu->menu.inner_height = themes->popup_menu[menu_item_mid].h * (hidden + 1);
  
  create_popup_menu(display, &mode_menu->menu, themes, cursors);

  //Create the menu items
  for(int i = 0; i <= hidden; i++) {

    mode_menu->items[i].item = XCreateSimpleWindow(display, mode_menu->menu.widgets[popup_menu_parent].widget
    , themes->popup_menu[popup_l_edge].w, themes->popup_menu[popup_t_edge].h + themes->popup_menu[menu_item_mid].h * i
    , mode_menu->menu.inner_width, themes->popup_menu[menu_item_mid].h, 0, black, black);

    XSelectInput(display, mode_menu->items[i].item,  ButtonReleaseMask | EnterWindowMask | LeaveWindowMask);
    for(int j = 0; j <= inactive; j++) {
      if(themes->popup_menu[i].state_p[j]) {
        char *label = NULL;
        char Floating[] = "Floating";
        char Tiling[] = "Tiling";
        char Hidden[] = "Hidden";
        char Desktop[] = "Desktop";

        switch(i) {
          case floating: label = Floating;
          break;
          case tiling: label = Tiling;
          break;
          case hidden: label = Hidden;
          break;
          case desktop: label = Desktop;
          break;
        }

        mode_menu->items[i].state[j] = XCreateSimpleWindow(display, mode_menu->items[i].item
        , 0, 0, mode_menu->menu.inner_width, themes->popup_menu[menu_item_mid].h, 0, black, black);

        create_text_background(display, mode_menu->items[i].state[j], label, &themes->font_theme[j]
        , themes->popup_menu[menu_item_mid].state_p[j]
        , themes->popup_menu[menu_item_mid].w, themes->popup_menu[menu_item_mid].h);
        XMapWindow(display, mode_menu->items[i].state[j]);
      }
//      else printf("Warning:  Skipping state pixmap\n");
    }
    XMapWindow(display, mode_menu->items[i].item);
  }

}
Exemple #7
0
/* delay updating popup menu until the selection has been set */
static gboolean on_button_release(G_GNUC_UNUSED GtkWidget *widget, GdkEventButton *event,
									G_GNUC_UNUSED gpointer user_data)
{
	if (event->button == 3)
	{
		static GtkWidget *popup_menu = NULL;

		if (popup_menu == NULL)
			popup_menu = create_popup_menu();

		update_popup_menu(popup_menu);

		gtk_menu_popup(GTK_MENU(popup_menu), NULL, NULL, NULL, NULL,
			       event->button, event->time);
	}
	return FALSE;
}
Exemple #8
0
static void
caja_emblem_sidebar_init (CajaEmblemSidebar *emblem_sidebar)
{
    GtkWidget *widget;

    emblem_sidebar->details = g_new0 (CajaEmblemSidebarDetails, 1);

    create_popup_menu (emblem_sidebar);

    widget = caja_emblem_sidebar_create_container (emblem_sidebar);
    caja_emblem_sidebar_populate (emblem_sidebar);

    g_signal_connect_object (caja_signaller_get_current (),
                             "emblems_changed",
                             G_CALLBACK (emblems_changed_callback), emblem_sidebar, 0);

    gtk_box_pack_start (GTK_BOX (emblem_sidebar), widget,
                        TRUE, TRUE, 0);
}
static void
nautilus_emblem_sidebar_init (NautilusEmblemSidebar *emblem_sidebar)
{
	GtkWidget *widget;
	
	emblem_sidebar->details = g_new0 (NautilusEmblemSidebarDetails, 1);

	emblem_sidebar->details->client = gconf_client_get_default ();

	create_popup_menu (emblem_sidebar);

	widget = nautilus_emblem_sidebar_create_container (emblem_sidebar);
	nautilus_emblem_sidebar_populate (emblem_sidebar);

	g_signal_connect_object (nautilus_signaller_get_current (),
				 "emblems_changed",
				 G_CALLBACK (emblems_changed_callback), emblem_sidebar, 0);
	
	gtk_box_pack_start (GTK_BOX (emblem_sidebar), widget,
			    TRUE, TRUE, 0);
}
Exemple #10
0
int main (int argc, 
          char *argv[])
{
  GtkWidget *window, *progress, *eventbox, *menu;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Accelerators");
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);
  gtk_widget_set_size_request (window, 250, -1);

  g_signal_connect (G_OBJECT (window), "destroy",
                    G_CALLBACK (gtk_main_quit), NULL);

  menu = gtk_menu_new ();
  eventbox = gtk_event_box_new ();
  progress = gtk_progress_bar_new ();
  gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progress), "Nothing Yet Happened");
  create_popup_menu (menu, window, progress);
  
  gtk_progress_bar_set_pulse_step (GTK_PROGRESS_BAR (progress), 0.05);   
  gtk_event_box_set_above_child (GTK_EVENT_BOX (eventbox), FALSE);
  
  g_signal_connect (G_OBJECT (eventbox), "button_press_event",
                    G_CALLBACK (button_press_event),
                    (gpointer) menu);
  
  gtk_container_add (GTK_CONTAINER (eventbox), progress);
  gtk_container_add (GTK_CONTAINER (window), eventbox);
  
  gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK);
  gtk_widget_realize (eventbox);

  gtk_widget_show_all (window);
  gtk_main ();
  return 0;
}
Exemple #11
0
/*
	run this function only once to create and customize gtk based opengl canvas
	all signal, socket connections are done here for opengl interractions
	params:gl config object, gtk container widget for opengl canvas
	return value:none
*/
void create_window(GdkGLConfig * glconfig, GtkWidget * vbox)
{
    gint major, minor;

    /*
     * Query OpenGL extension version.
     */

    gdk_gl_query_version(&major, &minor);
    g_print("\nOpenGL extension version - %d.%d\n", major, minor);

    /* Try double-buffered visual */

    if (IS_TEST_MODE_ON)	//printf some gl values, to test if your system has opengl stuff
	examine_gl_config_attrib(glconfig);
    /* Drawing area for drawing OpenGL scene. */
    view->drawing_area = gtk_drawing_area_new();
    gtk_widget_set_size_request(view->drawing_area, 300, 300);
    /* Set OpenGL-capability to the widget. */
    gtk_widget_set_gl_capability(view->drawing_area,
				 glconfig, NULL, TRUE, GDK_GL_RGBA_TYPE);

    gtk_widget_add_events(view->drawing_area,
//  GDK_BUTTON_MOTION_MASK      = 1 << 4,
			  GDK_BUTTON_MOTION_MASK |
			   GDK_POINTER_MOTION_MASK|
			  GDK_BUTTON_PRESS_MASK |
			  GDK_BUTTON_RELEASE_MASK |
			  GDK_VISIBILITY_NOTIFY_MASK);

    g_signal_connect_after(G_OBJECT(view->drawing_area), "realize",
			   G_CALLBACK(realize), NULL);
    g_signal_connect(G_OBJECT(view->drawing_area), "configure_event",
		     G_CALLBACK(configure_event), NULL);
    g_signal_connect(G_OBJECT(view->drawing_area), "expose_event",
		     G_CALLBACK(expose_event), NULL);

    g_signal_connect(G_OBJECT(view->drawing_area), "button_press_event",
		     G_CALLBACK(button_press_event), NULL);
    g_signal_connect(G_OBJECT(view->drawing_area), "button_release_event",
		     G_CALLBACK(button_release_event), NULL);
    g_signal_connect(G_OBJECT(view->drawing_area), "motion_notify_event",
		     G_CALLBACK(motion_notify_event), NULL);


    gtk_box_pack_start(GTK_BOX(vbox), view->drawing_area, TRUE, TRUE, 0);

    gtk_widget_show(view->drawing_area);

    /* Popup menu. */

#if 0
    menu = create_popup_menu(view->drawing_area);

    /* Signal handler */
    g_signal_connect_swapped(G_OBJECT(view->drawing_area),
			     "button_press_event",
			     G_CALLBACK(button_press_event_popup_menu),
			     menu);
#endif

}
Exemple #12
0
static gint
show_lwobject(const char *lwobject_name)
{
  GtkWidget *window, *frame, *glarea;
  mesh_info *info;
  lwObject *lwobject;

  /* read lightwave object */
  if (!lw_is_lwobject(lwobject_name))
    {
      g_print("%s is not a LightWave 3D object\n", lwobject_name);
      return FALSE;
    }
  lwobject = lw_object_read(lwobject_name);
  if (lwobject == NULL)
    {
      g_print("Can't read LightWave 3D object %s\n", lwobject_name);
      return FALSE;
    }
  lw_object_scale(lwobject, 10.0 / lw_object_radius(lwobject));


  /* create aspect frame */
  frame = gtk_aspect_frame_new(NULL, 0.5,0.5, VIEW_ASPECT, FALSE);

  /* create new OpenGL widget */
  glarea = gtk_drawing_area_new();
  if (glarea == NULL)
    {
      lw_object_free(lwobject);
      g_print("Can't create GtkDrawingArea widget\n");
      return FALSE;
    }

  /* Set OpenGL-capability to the widget. */
  gtk_widget_set_gl_capability(GTK_WIDGET (glarea),
                               glconfig,
                               NULL,
                               TRUE,
                               GDK_GL_RGBA_TYPE);

  /* set up events and signals for OpenGL widget */
  gtk_widget_set_events(glarea,
     			GDK_EXPOSURE_MASK|
     			GDK_BUTTON_PRESS_MASK|
     			GDK_BUTTON_RELEASE_MASK|
     			GDK_POINTER_MOTION_MASK|
     			GDK_POINTER_MOTION_HINT_MASK);

  g_signal_connect(G_OBJECT(glarea), "draw",
                   G_CALLBACK(draw), NULL);
  g_signal_connect(G_OBJECT(glarea), "motion_notify_event",
                   G_CALLBACK(motion_notify), NULL);
  g_signal_connect(G_OBJECT(glarea), "button_press_event",
                   G_CALLBACK(button_press), NULL);
  g_signal_connect(G_OBJECT(glarea), "button_release_event",
                   G_CALLBACK(button_release), NULL);
  g_signal_connect(G_OBJECT(glarea), "configure_event",
                   G_CALLBACK(configure), NULL);
  g_signal_connect(G_OBJECT (glarea), "map_event",
		   G_CALLBACK (map_event), NULL);
  g_signal_connect(G_OBJECT (glarea), "unmap_event",
		   G_CALLBACK (unmap_event), NULL);
  g_signal_connect(G_OBJECT (glarea), "visibility_notify_event",
		   G_CALLBACK (visibility_notify_event), NULL);
  g_signal_connect(G_OBJECT(glarea), "destroy",
                   G_CALLBACK(destroy), NULL);

  gtk_widget_set_size_request(glarea, 200,200/VIEW_ASPECT); /* minimum size */

  /* set up mesh info */
  info = (mesh_info*)g_malloc(sizeof(mesh_info));
  info->do_init = TRUE;
  info->lwobject = lwobject;
  info->beginx = 0;
  info->beginy = 0;
  info->dx = 0;
  info->dy = 0;
  info->quat[0] = 0;  info->quat[1] = 0;  info->quat[2] = 0;  info->quat[3] = 1;
  info->dquat[0] = 0; info->dquat[1] = 0; info->dquat[2] = 0; info->dquat[3] = 1;
  info->zoom   = 45;
  info->animate = FALSE;
  info->timeout_id = 0;
  trackball(info->quat , 0.0, 0.0, 0.0, 0.0);
  g_object_set_data(G_OBJECT(glarea), "mesh_info", info);


  /* create new top level window */
  window = gtk_window_new( GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(window), lwobject_name);
  gtk_container_set_border_width(GTK_CONTAINER(window), 10);
  gtk_container_set_reallocate_redraws(GTK_CONTAINER (window), TRUE);
  create_popup_menu(window); /* add popup menu to window */
  /* key_press_event handler for top-level window */
  g_signal_connect_swapped(G_OBJECT (window), "key_press_event",
                           G_CALLBACK (key_press_event), glarea);
  g_signal_connect(G_OBJECT(window), "destroy",
                   G_CALLBACK(window_destroy), NULL);
  window_count++;

  /* put glarea into window and show it all */
  gtk_container_add(GTK_CONTAINER(window), frame);
  gtk_container_add(GTK_CONTAINER(frame),glarea);
  gtk_widget_show(glarea);
  gtk_widget_show(frame);
  gtk_widget_show(window);

  return TRUE;
}
Exemple #13
0
/**
 * Program entry point. Initializes gtk+, calls the widget creating
 * functions and starts the main loop. Also connects 'popup-menu',
 * 'activate' and 'button-release-event' to the tray_icon.
 *
 * @param argc count of arguments
 * @param argv string array of arguments
 * @return 0 for success, otherwise error code
 */
int
main(int argc, char *argv[])
{
	GError *error = NULL;
	GOptionContext *context;
	want_debug = FALSE;

#ifdef ENABLE_NLS
	bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
	textdomain(GETTEXT_PACKAGE);
#endif

	DEBUG_PRINT("[Debugging Mode Build]\n");

	setlocale(LC_ALL, "");
	context = g_option_context_new(_("- A mixer for the system tray."));
	g_option_context_add_main_entries(context, args, GETTEXT_PACKAGE);
	g_option_context_add_group(context, gtk_get_option_group(TRUE));
	g_option_context_parse(context, &argc, &argv, &error);
	gtk_init(&argc, &argv);

	g_option_context_free(context);

	if (version) {
		printf(_("%s version: %s\n"), PACKAGE, VERSION);
		exit(0);
	}

	popup_window = NULL;

	add_pixmap_directory(PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");
	add_pixmap_directory("./data/pixmaps");

	prefs_ensure_save_dir();
	prefs_load();
	cards = NULL;		// so we don't try and free on first run
	alsa_init();
	init_libnotify();
	create_popup_window();
	create_popup_menu();
	add_filter();

	tray_icon = create_tray_icon();

	g_signal_connect(G_OBJECT(tray_icon), "popup-menu",
			 G_CALLBACK(popup_callback), popup_menu);
	g_signal_connect(G_OBJECT(tray_icon), "activate",
			 G_CALLBACK(tray_icon_on_click), NULL);
	g_signal_connect(G_OBJECT(tray_icon), "button-release-event",
			 G_CALLBACK(tray_icon_button), NULL);
	mute_check_popup_menu_handler =
		g_signal_connect(G_OBJECT(mute_check_popup_menu),
				"toggled", G_CALLBACK(on_mute_clicked), NULL);
	mute_check_popup_window_handler =
		g_signal_connect(G_OBJECT(mute_check_popup_window),
				"toggled", G_CALLBACK(on_mute_clicked), NULL);

	apply_prefs(0);

	gtk_main();
	uninit_libnotify();
	alsa_close();
	return 0;
}
Exemple #14
0
/***
 *** Creates the simple application window with one
 *** drawing area that has an OpenGL-capable visual.
 ***/
static GtkWidget *
create_window (GdkGLConfig *glconfig)
{
  GtkWidget *window;
  GtkWidget *drawing_area;
  GtkWidget *menu;

  /*
   * Top-level window.
   */

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), DEFAULT_TITLE);

  /* Get automatically redrawn if any of their children changed allocation. */
  gtk_container_set_reallocate_redraws (GTK_CONTAINER (window), TRUE);

  /* Connect signal handlers to the window */
  g_signal_connect (G_OBJECT (window), "delete_event",
		    G_CALLBACK (gtk_main_quit), NULL);

  /*
   * Drawing area to draw OpenGL scene.
   */

  drawing_area = gtk_drawing_area_new ();
  gtk_widget_set_size_request (drawing_area, DEFAULT_WIDTH, DEFAULT_HEIGHT);

  /* Set OpenGL-capability to the widget */
  gtk_widget_set_gl_capability (drawing_area,
				glconfig,
				NULL,
				TRUE,
				GDK_GL_RGBA_TYPE);

  gtk_widget_add_events (drawing_area,
			 GDK_BUTTON1_MOTION_MASK    |
			 GDK_BUTTON2_MOTION_MASK    |
			 GDK_BUTTON_PRESS_MASK      |
			 GDK_VISIBILITY_NOTIFY_MASK);

  /* Connect signal handlers to the drawing area */
  g_signal_connect_after (G_OBJECT (drawing_area), "realize",
                          G_CALLBACK (realize), NULL);
  g_signal_connect (G_OBJECT (drawing_area), "configure_event",
		    G_CALLBACK (configure_event), NULL);
  g_signal_connect (G_OBJECT (drawing_area), "draw",
		    G_CALLBACK (draw), NULL);

  g_signal_connect (G_OBJECT (drawing_area), "motion_notify_event",
		    G_CALLBACK (motion_notify_event), NULL);
  g_signal_connect (G_OBJECT (drawing_area), "button_press_event",
		    G_CALLBACK (button_press_event), NULL);
  g_signal_connect (G_OBJECT (drawing_area), "unrealize",
		    G_CALLBACK (unrealize), NULL);

  /* key_press_event handler for top-level window */
  g_signal_connect_swapped (G_OBJECT (window), "key_press_event",
			    G_CALLBACK (key_press_event), drawing_area);

  /* For timeout function. */
  g_signal_connect (G_OBJECT (drawing_area), "map_event",
		    G_CALLBACK (map_event), NULL);
  g_signal_connect (G_OBJECT (drawing_area), "unmap_event",
		    G_CALLBACK (unmap_event), NULL);
  g_signal_connect (G_OBJECT (drawing_area), "visibility_notify_event",
		    G_CALLBACK (visibility_notify_event), NULL);

  gtk_container_add (GTK_CONTAINER (window), drawing_area);
  gtk_widget_show (drawing_area);

  /*
   * Popup menu.
   */

  menu = create_popup_menu (window, drawing_area);

  g_signal_connect_swapped (G_OBJECT (drawing_area), "button_press_event",
			    G_CALLBACK (button_press_event_popup_menu), menu);

  return window;
}
Exemple #15
0
int
main(int   argc,
     char *argv[])
{
  GdkGLConfig *glconfig;
  gint major, minor;

  GtkWidget *window;
  GtkWidget *vbox;
  GtkWidget *drawing_area;
  GtkWidget *menu;
  GtkWidget *button;

  int i;
  gboolean arg_count = FALSE;

  /*
   * Init GTK.
   */

  gtk_init (&argc, &argv);

  /*
   * Init GtkGLExt.
   */

  gtk_gl_init (&argc, &argv);

  /*
   * Parse arguments.
   */

  for (i = 1; i < argc; i++)
    {
      if (arg_count)
	rot_count = atoi (argv[i]);

      if (strcmp (argv[i], "--help") == 0 ||
	  strcmp (argv[i], "-h") == 0)
	{
	  g_print ("Usage: %s [--count num] [--no-anim] [--help]\n", argv[0]);
	  exit (0);
	}

      if (strcmp (argv[i], "--count") == 0)
	arg_count = TRUE;

      if (strcmp (argv[i], "--no-anim") == 0)
	animate = FALSE;
    }

  /*
   * Query OpenGL extension version.
   */

  gdk_gl_query_version (&major, &minor);
  g_print ("\nOpenGL extension version - %d.%d\n",
           major, minor);

  /*
   * Configure OpenGL-capable visual.
   */

  /* Try double-buffered visual */
  glconfig = gdk_gl_config_new_by_mode (GDK_GL_MODE_RGB    |
					GDK_GL_MODE_DEPTH  |
					GDK_GL_MODE_DOUBLE);
  if (glconfig == NULL)
    {
      g_print ("*** Cannot find the double-buffered visual.\n");
      g_print ("*** Trying single-buffered visual.\n");

      /* Try single-buffered visual */
      glconfig = gdk_gl_config_new_by_mode (GDK_GL_MODE_RGB   |
					    GDK_GL_MODE_DEPTH);
      if (glconfig == NULL)
	{
	  g_print ("*** No appropriate OpenGL-capable visual found.\n");
	  exit (1);
	}
    }

  examine_gl_config_attrib (glconfig);

  /*
   * Top-level window.
   */

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "logo");

  /* Get automatically redrawn if any of their children changed allocation. */
  gtk_container_set_reallocate_redraws (GTK_CONTAINER (window), TRUE);

  g_signal_connect (G_OBJECT (window), "delete_event",
		    G_CALLBACK (gtk_main_quit), NULL);

  /*
   * VBox.
   */

  vbox = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (window), vbox);
  gtk_widget_show (vbox);

  /*
   * Drawing area for drawing OpenGL scene.
   */

  drawing_area = gtk_drawing_area_new ();
  gtk_widget_set_size_request (drawing_area, 300, 300);

  /* Set OpenGL-capability to the widget. */
  gtk_widget_set_gl_capability (drawing_area,
				glconfig,
				NULL,
				TRUE,
				GDK_GL_RGBA_TYPE);

  gtk_widget_add_events (drawing_area,
			 GDK_BUTTON1_MOTION_MASK    |
			 GDK_BUTTON2_MOTION_MASK    |
			 GDK_BUTTON_PRESS_MASK      |
			 GDK_VISIBILITY_NOTIFY_MASK);

  g_signal_connect_after (G_OBJECT (drawing_area), "realize",
                          G_CALLBACK (realize), NULL);
  g_signal_connect (G_OBJECT (drawing_area), "configure_event",
		    G_CALLBACK (configure_event), NULL);
  g_signal_connect (G_OBJECT (drawing_area), "expose_event",
		    G_CALLBACK (expose_event), NULL);

  g_signal_connect (G_OBJECT (drawing_area), "button_press_event",
		    G_CALLBACK (button_press_event), NULL);
  g_signal_connect (G_OBJECT (drawing_area), "motion_notify_event",
		    G_CALLBACK (motion_notify_event), NULL);

  g_signal_connect (G_OBJECT (drawing_area), "map_event",
		    G_CALLBACK (map_event), NULL);
  g_signal_connect (G_OBJECT (drawing_area), "unmap_event",
		    G_CALLBACK (unmap_event), NULL);
  g_signal_connect (G_OBJECT (drawing_area), "visibility_notify_event",
		    G_CALLBACK (visibility_notify_event), NULL);

  g_signal_connect_swapped (G_OBJECT (window), "key_press_event",
			    G_CALLBACK (key_press_event), drawing_area);

  gtk_box_pack_start (GTK_BOX (vbox), drawing_area, TRUE, TRUE, 0);

  gtk_widget_show (drawing_area);

  /*
   * Popup menu.
   */

  menu = create_popup_menu (drawing_area);

  /* Signal handler */
  g_signal_connect_swapped (G_OBJECT (drawing_area), "button_press_event",
                            G_CALLBACK (button_press_event_popup_menu), menu);

  /*
   * Simple quit button.
   */

  button = gtk_button_new_with_label ("Quit");

  g_signal_connect (G_OBJECT (button), "clicked",
                    G_CALLBACK (gtk_main_quit), NULL);

  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);

  gtk_widget_show (button);

  /*
   * Show window.
   */

  gtk_widget_show (window);

  /*
   * Main loop.
   */

  gtk_main ();

  return 0;
}
Exemple #16
0
static void
view_pixbuf (ViewerCbInfo * info, int xid, const char *color)
{
    GtkWidget *win;
    GdkColor bg_color;
    gint win_width, win_height;

    /* create toplevel window and set its title */

#ifdef ENABLE_XEMBED
    if (xid > 0) {
        GdkWindow *gdk_parent;

        win = gtk_plug_new (0);

        gdk_parent = gdk_window_foreign_new (xid);
        gdk_window_get_geometry (gdk_parent, NULL, NULL, &win_width, &win_height, NULL);

        /* so that button and key presses get registered */
        gtk_widget_add_events (win, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
    } else
#endif
    {
        char *title;

        win = gtk_window_new (GTK_WINDOW_TOPLEVEL);

        win_width = DEFAULT_WIDTH;
        win_height = DEFAULT_HEIGHT;

        if (info->id) {
            title = g_strdup_printf ("%s#%s — %s", info->base_uri, info->id, _("SVG Viewer"));
        } else {
            title = g_strdup_printf ("%s — %s", info->base_uri,  _("SVG Viewer"));
        }
        gtk_window_set_title (GTK_WINDOW (win), title);
        g_free (title);
    }

    populate_window (win, info, xid, win_width, win_height);

    rsvg_window_set_default_icon (GTK_WINDOW (win), info->pixbuf);

    /* exit when 'X' is clicked */
    g_signal_connect (G_OBJECT (win), "destroy", G_CALLBACK (quit_cb), NULL);
    g_signal_connect (G_OBJECT (win), "delete_event", G_CALLBACK (quit_cb), NULL);

    if (color && strcmp (color, "none") != 0) {
        if (gdk_color_parse (color, &bg_color)) {
            GtkWidget *parent_widget = gtk_widget_get_parent (info->image);

            if (gdk_colormap_alloc_color
                (gtk_widget_get_colormap (parent_widget), &bg_color, FALSE, TRUE))
                gtk_widget_modify_bg (parent_widget, GTK_STATE_NORMAL, &bg_color);
            else
                g_warning (_("Couldn't allocate color '%s'"), color);
        } else
            g_warning (_("Couldn't parse color '%s'"), color);
    }

    create_popup_menu (info);

    info->window = win;
    gtk_window_add_accel_group (GTK_WINDOW (win), info->accel_group);

    g_signal_connect (G_OBJECT (win), "button-press-event", G_CALLBACK (button_press_event), info);

    gtk_widget_show_all (win);

#ifdef ENABLE_XEMBED
    if (xid > 0) {
        XReparentWindow (GDK_WINDOW_XDISPLAY (win->window),
                         GDK_WINDOW_XID (win->window), xid, 0, 0);
        XMapWindow (GDK_WINDOW_XDISPLAY (win->window), GDK_WINDOW_XID (win->window));
    }
#endif
}