コード例 #1
0
ファイル: eog-application.c プロジェクト: daybologic/eog
static EogWindow *
eog_application_get_file_window (EogApplication *application, GFile *file)
{
	EogWindow *file_window = NULL;
	GList *windows;
	GList *l;

	g_return_val_if_fail (file != NULL, NULL);
	g_return_val_if_fail (EOG_IS_APPLICATION (application), NULL);

	windows = gtk_window_list_toplevels ();

	for (l = windows; l != NULL; l = l->next) {
		if (EOG_IS_WINDOW (l->data)) {
			EogWindow *window = EOG_WINDOW (l->data);

			if (!eog_window_is_empty (window)) {
				EogImage *image = eog_window_get_image (window);
				GFile *window_file;

				window_file = eog_image_get_file (image);
				if (g_file_equal (window_file, file)) {
					file_window = window;
					break;
				}
			}
		}
	}

	g_list_free (windows);

	return file_window;
}
コード例 #2
0
ファイル: testfocus.c プロジェクト: sam-m888/gtk
static gboolean
compare_focus (gpointer data)
{
  AtkObject *atk_focus;
  AtkObject *gtk_focus;
  GtkWidget *focus_widget;
  GList *list, *l;

  atk_focus = atk_get_focus_object ();

  focus_widget = NULL;
  list = gtk_window_list_toplevels ();
  for (l = list; l; l = l->next)
    {
      GtkWindow *w = l->data;
      if (gtk_window_is_active (w))
        {
          focus_widget = gtk_window_get_focus (w);
          break;
        }
    }
  g_list_free (list);

  if (GTK_IS_WIDGET (focus_widget))
    gtk_focus = gtk_widget_get_accessible (focus_widget);
  else
    gtk_focus = NULL;

  if (gtk_focus != atk_focus)
    g_print ("gtk focus: %s != atk focus: %s\n",
             get_name (gtk_focus), get_name (atk_focus));

  return G_SOURCE_CONTINUE;
}
コード例 #3
0
ファイル: util.c プロジェクト: ijuxda/transmission
void
gtr_widget_set_visible( GtkWidget * w, gboolean b )
{
    /* toggle the transient children, too */
    if( GTK_IS_WINDOW( w ) )
    {
        GList * l;
        GList * windows = gtk_window_list_toplevels( );
        GtkWindow * window = GTK_WINDOW( w );

        for( l=windows; l!=NULL; l=l->next )
            if( GTK_IS_WINDOW( l->data ) )
                if( gtk_window_get_transient_for( GTK_WINDOW( l->data ) ) == window )
                    gtr_widget_set_visible( GTK_WIDGET( l->data ), b );

        g_list_free( windows );
    }

#if GTK_CHECK_VERSION( 2,18,0 )
    gtk_widget_set_visible( w, b );
#else
    if( b )
        gtk_widget_show( w );
    else
        gtk_widget_hide( w );
#endif
}
コード例 #4
0
void
panel_multiscreen_reinit (void)
{
	GdkScreen *screen;
	GList     *toplevels, *l;

	if (monitors)
		g_free (monitors);

	if (geometries) {
		int j;

		for (j = 0; j < screens; j++)
			g_free (geometries[j]);
		g_free (geometries);
	}

	screen = gdk_screen_get_default ();
	g_signal_handlers_disconnect_by_func (screen, panel_multiscreen_queue_reinit, NULL);

	initialized = FALSE;
	panel_multiscreen_init ();

	toplevels = gtk_window_list_toplevels ();

	for (l = toplevels; l; l = l->next)
		gtk_widget_queue_resize (l->data);

	g_list_free (toplevels);
}
コード例 #5
0
ファイル: nocodec-ui-gtk.cpp プロジェクト: snorp/moon
void
GtkNoCodecsUI::AdaptToParentWindow ()
{
	// try to find a parent for our window
	// there must be a better way of doing this though :|
	GList *toplevels = gtk_window_list_toplevels ();
	GList *current = toplevels;
	GtkWindow *parent = NULL;

	while (current != NULL) {
		const char *title = gtk_window_get_title (GTK_WINDOW (current->data));
		if (title != NULL && strstr (title, "Mozilla Firefox") != NULL) {
			parent = GTK_WINDOW (current->data);
			break;
		}

		current = current->next;
	}
	g_list_free (toplevels);

	if (parent != NULL) {
		gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
		gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ON_PARENT);
	} else {
		// If no parent could be found, just center in the screen
		gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
	}
}
コード例 #6
0
ファイル: svte.c プロジェクト: mutantturkey/svte
/* event handler for closing windows
   close program when all windows are closed */
static void window_destroy(GtkWidget *widget){
  GList *list = gtk_window_list_toplevels();
  /* 3 is 1 for the window being destroyed and 1 for the remaining
     tooltip widget */
  if(g_list_length(list) < 3 ) {
    quit();
  }
}
コード例 #7
0
ファイル: gutachter-lookup.c プロジェクト: herzi/gutachter
/**
 * gutachter_lookup_n_windows:
 *
 * Find out how many windows there are.
 *
 * Returns: the number of alive #GtkWindow objects
 */
guint32
gutachter_lookup_n_windows (void)
{
  GList  * windows = gtk_window_list_toplevels ();
  guint32  result = g_list_length (windows);

  g_list_free (windows);
  return result;
}
コード例 #8
0
ファイル: mainframe.cpp プロジェクト: AresAndy/ufoai
static bool MainFrame_isActiveApp (void)
{
	GList* list = gtk_window_list_toplevels();
	for (GList* i = list; i != 0; i = g_list_next(i)) {
		if (gtk_window_is_active(GTK_WINDOW(i->data))) {
			return true;
		}
	}
	return false;
}
コード例 #9
0
ファイル: svte.c プロジェクト: skawouter/svte-tmp
/* function that closes the current window */
static void window_close(struct window *w) {
  gtk_widget_destroy(w->notebook);
  gtk_widget_destroy(w->win);
  g_free(w);

  GList *list = gtk_window_list_toplevels();
  g_warning("close called %d", g_list_length(list));
  g_warning("widget %s", gtk_widget_get_name(g_list_nth_data(list, 0)));
  g_warning("widget %s", gtk_widget_get_name(g_list_nth_data(list, 1)));
  if(g_list_length(list) < 2 ) {
    quit();
  }
}
コード例 #10
0
ファイル: gtkimagemenuitem.c プロジェクト: raja651/gtk
static void
gtk_image_menu_item_setting_changed (GtkSettings *settings)
{
    GList *list, *l;

    list = gtk_window_list_toplevels ();

    for (l = list; l; l = l->next)
        gtk_container_forall (GTK_CONTAINER (l->data),
                              traverse_container, NULL);

    g_list_free (list);
}
コード例 #11
0
ファイル: pk-gtk-module.c プロジェクト: zodman/PackageKit
static guint
guess_xid (void)
{
	guint xid = 0;
	GtkWindow *active = NULL;

	g_list_foreach (gtk_window_list_toplevels (),
			(GFunc) toplevels_foreach_cb, &active);

	if (active != NULL)
		xid = GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET(active)));

	return xid;
}
コード例 #12
0
void
hildon_desktop_ms_reinit (HildonDesktopMultiscreen *dms)
{
  GdkDisplay *display;
  GList *toplevels, *l;
  gint new_screens;
  gint i;

  if (dms->monitors)
    g_free (dms->monitors);

  if (dms->geometries)
  {
    gint i;

    for (i = 0; i < dms->screens; i++)
      g_free (dms->geometries[i]);

    g_free (dms->geometries);
  }

  display = gdk_display_get_default ();
	/* Don't use the screens variable since in the future, we might
	 * want to call this function when a screen appears/disappears. */
#ifndef ONE_SCREEN_MONITOR
  new_screens = gdk_display_get_n_screens (display);
#else
  new_screens = 1;
#endif
  for (i = 0; i < new_screens; i++)
  {
    GdkScreen *screen;

    screen = gdk_display_get_screen (display, i);
    g_signal_handlers_disconnect_by_func (screen,
				          hildon_desktop_ms_reinit,
					  dms);
  }

  hildon_desktop_ms_init (dms);

  toplevels = gtk_window_list_toplevels ();

  for (l = toplevels; l; l = l->next)
    gtk_widget_queue_resize (l->data);

  g_list_free (toplevels);
}
コード例 #13
0
ファイル: ev-application.c プロジェクト: avasha/atril
guint
ev_application_get_n_windows (EvApplication *application)
{
	GList *l, *toplevels;
	guint  retval = 0;

	toplevels = gtk_window_list_toplevels ();

	for (l = toplevels; l != NULL; l = l->next) {
		if (EV_IS_WINDOW (l->data))
			retval++;
	}

	g_list_free (toplevels);

	return retval;
}
コード例 #14
0
ファイル: ev-application.c プロジェクト: avasha/atril
gboolean
ev_application_has_window (EvApplication *application)
{
	GList    *l, *toplevels;
	gboolean  retval = FALSE;

	toplevels = gtk_window_list_toplevels ();

	for (l = toplevels; l != NULL && !retval; l = l->next) {
		if (EV_IS_WINDOW (l->data))
			retval = TRUE;
	}

	g_list_free (toplevels);

	return retval;
}
コード例 #15
0
    GtkMenu* getPopupMenu()
    {
        GOwnPtr<GList> toplevels(gtk_window_list_toplevels());
        for (GList* iter = toplevels.get(); iter; iter = g_list_next(iter)) {
            if (!GTK_IS_WINDOW(iter->data))
                continue;

            GtkWidget* child = gtk_bin_get_child(GTK_BIN(iter->data));
            if (!GTK_IS_MENU(child))
                continue;

            if (gtk_menu_get_attach_widget(GTK_MENU(child)) == GTK_WIDGET(m_webView))
                return GTK_MENU(child);
        }
        g_assert_not_reached();
        return 0;
    }
コード例 #16
0
ファイル: ev-application.c プロジェクト: avasha/atril
static GList *
ev_application_get_windows (EvApplication *application)
{
	GList *l, *toplevels;
	GList *windows = NULL;

	toplevels = gtk_window_list_toplevels ();

	for (l = toplevels; l != NULL; l = l->next) {
		if (EV_IS_WINDOW (l->data)) {
			windows = g_list_append (windows, l->data);
		}
	}

	g_list_free (toplevels);

	return windows;
}
コード例 #17
0
void
panel_multiscreen_reinit (void)
{
	GdkDisplay *display;
	GList      *toplevels, *l;
	int         new_screens;
	int         i;

	if (monitors)
		g_free (monitors);

	if (geometries) {
		int j;

		for (j = 0; j < screens; j++)
			g_free (geometries[j]);
		g_free (geometries);
	}

	display = gdk_display_get_default ();
	/* Don't use the screens variable since in the future, we might
	 * want to call this function when a screen appears/disappears. */
	new_screens = gdk_display_get_n_screens (display);

	for (i = 0; i < new_screens; i++) {
		GdkScreen *screen;

		screen = gdk_display_get_screen (display, i);
		g_signal_handlers_disconnect_by_func (screen,
						      panel_multiscreen_queue_reinit,
						      NULL);
	}

	initialized = FALSE;
	panel_multiscreen_init ();

	toplevels = gtk_window_list_toplevels ();

	for (l = toplevels; l; l = l->next)
		gtk_widget_queue_resize (l->data);

	g_list_free (toplevels);
}
コード例 #18
0
/*
 * There's a race condition that can freeze the UI if a dialog appears
 * between a HildonAppMenu and its parent window, see NB#100468
 */
static gboolean
hildon_app_menu_find_intruder                   (gpointer data)
{
    GtkWidget *widget = GTK_WIDGET (data);
    HildonAppMenuPrivate *priv = HILDON_APP_MENU_GET_PRIVATE (widget);

    priv->find_intruder_idle_id = 0;

    /* If there's a modal window between the menu and its parent window, hide the menu */
    if (priv->parent_window) {
        gboolean intruder_found = FALSE;
        GdkScreen *screen = gtk_widget_get_screen (widget);
        GList *stack = gdk_screen_get_window_stack (screen);
        GList *parent_pos = g_list_find (stack, GTK_WIDGET (priv->parent_window)->window);
        GList *toplevels = gtk_window_list_toplevels ();
        GList *i;

        for (i = toplevels; i != NULL && !intruder_found; i = i->next) {
            if (i->data != widget && i->data != priv->parent_window) {
                if (g_list_find (parent_pos, GTK_WIDGET (i->data)->window)) {
                    /* HildonBanners are not closed automatically when
                     * a new window appears, so we must close them by
                     * hand to make the AppMenu work as expected.
                     * Yes, this is a hack. See NB#111027 */
                    if (HILDON_IS_BANNER (i->data)) {
                        gtk_widget_hide (i->data);
                    } else if (GTK_IS_WINDOW (i->data)) {
                        intruder_found = gtk_window_get_modal (i->data);
                    }
                }
            }
        }

        g_list_foreach (stack, (GFunc) g_object_unref, NULL);
        g_list_free (stack);
        g_list_free (toplevels);

        if (intruder_found)
            gtk_widget_hide (widget);
    }

    return FALSE;
}
コード例 #19
0
ファイル: eog-application.c プロジェクト: daybologic/eog
static EogWindow *
eog_application_get_first_window (EogApplication *application)
{
	g_return_val_if_fail (EOG_IS_APPLICATION (application), NULL);

	GList *windows;
	GList *l;
	EogWindow *window = NULL;
	windows = gtk_window_list_toplevels ();
	for (l = windows; l != NULL; l = l->next) {
		if (EOG_IS_WINDOW (l->data)) {
			window = EOG_WINDOW (l->data);
			break;
		}
	}
	g_list_free (windows);

	return window;
}
コード例 #20
0
ファイル: eom-application.c プロジェクト: ZrN-kAyDqY/eom
/**
 * eom_application_get_windows:
 * @application: An #EomApplication.
 *
 * Gets the list of existing #EomApplication<!-- -->s. The windows
 * in this list are not individually referenced, you need to keep
 * your own references if you want to perform actions that may destroy
 * them.
 *
 * Returns: (element-type EomWindow) (transfer container): A new list of #EomWindow<!-- -->s.
 **/
GList *
eom_application_get_windows (EomApplication *application)
{
	GList *l, *toplevels;
	GList *windows = NULL;

	g_return_val_if_fail (EOM_IS_APPLICATION (application), NULL);

	toplevels = gtk_window_list_toplevels ();

	for (l = toplevels; l != NULL; l = l->next) {
		if (EOM_IS_WINDOW (l->data)) {
			windows = g_list_append (windows, l->data);
		}
	}

	g_list_free (toplevels);

	return windows;
}
コード例 #21
0
ファイル: window.c プロジェクト: Sidnioulz/SandboxGtk
static void
gtk_inspector_window_select_initially (GtkInspectorWindow *iw)
{
  GList *toplevels, *l;
  GtkWidget *widget;

  toplevels = gtk_window_list_toplevels ();
  widget = NULL;
  for (l = toplevels; l; l = l->next)
    {
      if (gtk_widget_get_mapped (GTK_WIDGET (l->data)) &&
          GTK_IS_WINDOW (l->data) &&
          !GTK_INSPECTOR_IS_WINDOW (l->data))
        {
          widget = l->data;
          break;
        }
    }
  g_list_free (toplevels);

  if (widget)
    gtk_inspector_widget_tree_scan (GTK_INSPECTOR_WIDGET_TREE (iw->widget_tree), widget);
}
コード例 #22
0
ファイル: actions.c プロジェクト: dot-Sean/telephony
void
sflphone_quit(gboolean force_quit, SFLPhoneClient *client)
{
    if (force_quit || calllist_get_size(current_calls_tab) == 0 || main_window_ask_quit(client)) {
        dbus_unregister(getpid());
        dbus_clean();
        account_list_free();
        calllist_clean(current_calls_tab);
        calllist_clean(contacts_tab);
        calllist_clean(history_tab);
        free_addressbook();

        // make sure all open dialogs get a response signal so that they can close
        GList* top_level_windows = gtk_window_list_toplevels();
        g_list_foreach(top_level_windows, (GFunc)send_response_to_dialogs, NULL);

#if GLIB_CHECK_VERSION(2,32,0)
        g_application_quit(G_APPLICATION(client));
#else
        g_application_release(G_APPLICATION(client));
#endif
    }
}
コード例 #23
0
ファイル: util.c プロジェクト: jordanl/transmission
void
gtr_widget_set_visible (GtkWidget * w, gboolean b)
{
  /* toggle the transient children, too */
  if (GTK_IS_WINDOW (w))
    {
      GList * l;
      GList * windows = gtk_window_list_toplevels ();
      GtkWindow * window = GTK_WINDOW (w);

      for (l=windows; l!=NULL; l=l->next)
        {
          if (!GTK_IS_WINDOW (l->data))
            continue;
          if (gtk_window_get_transient_for (GTK_WINDOW (l->data)) != window)
            continue;
          if (gtk_widget_get_visible (GTK_WIDGET (l->data)) == b)
            continue;

          if (b && g_object_get_data (G_OBJECT (l->data), GTR_CHILD_HIDDEN) != NULL)
            {
              g_object_steal_data (G_OBJECT (l->data), GTR_CHILD_HIDDEN);
              gtr_widget_set_visible (GTK_WIDGET (l->data), TRUE);
            }
          else if (!b)
            {
              g_object_set_data (G_OBJECT (l->data), GTR_CHILD_HIDDEN, GINT_TO_POINTER (1));
              gtr_widget_set_visible (GTK_WIDGET (l->data), FALSE);
            }
        }

      g_list_free (windows);
    }

  gtk_widget_set_visible (w, b);
}
コード例 #24
0
ファイル: reconcile-view.c プロジェクト: CAARNICL/gnucash
static gboolean
gnc_reconcile_view_tooltip_cb (GNCQueryView *qview, gint x, gint y,
	gboolean keyboard_mode, GtkTooltip *tooltip, gpointer *user_data)
{
    GtkTreeModel* model;
    GtkTreeIter iter;

    if (gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (qview), &x, &y, keyboard_mode, &model, NULL, &iter))
    {
        GtkTreeViewColumn *col;
        GList *cols;
        gint col_pos, col_width;
	gchar* desc_text = NULL;

        /* Are we in keyboard tooltip mode, CTRL+F1 */
        if (keyboard_mode == FALSE)
        {
            if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (qview), x, y, NULL, &col, NULL, NULL) == FALSE)
                return FALSE;
        }
        else
            gtk_tree_view_get_cursor (GTK_TREE_VIEW (qview), NULL, &col);

        cols = gtk_tree_view_get_columns (GTK_TREE_VIEW (qview));
        col_width = gtk_tree_view_column_get_width (col);
        col_pos = g_list_index (cols, col);
        g_list_free (cols);

        /* If column is not description, do not show tooltip */
        if (col_pos != 2)
            return FALSE;

        gtk_tree_model_get (model, &iter, 3, &desc_text, -1);

        if (desc_text)
        {
            PangoLayout* layout;
            gint text_width;
            gint root_x, root_y;
            gint cur_x, cur_y;

            layout = gtk_widget_create_pango_layout (GTK_WIDGET (qview), desc_text);
            pango_layout_get_pixel_size (layout, &text_width, NULL);
            g_object_unref (layout);

            /* If text_width + 10 <= column_width, do not show tooltip */
            if ((text_width + 10) <= col_width)
            {
                g_free (desc_text);
                return FALSE;
            }

            if (keyboard_mode == FALSE)
            {
                GdkScreen *screen;
                GtkWindow *tip_win = NULL;
                GdkWindow *parent_window, *temp_window;
                GList *win_list, *node;

                parent_window = gtk_widget_get_parent_window (GTK_WIDGET (qview));
                temp_window = gdk_window_get_pointer (parent_window, &cur_x, &cur_y, NULL);
                gdk_window_get_origin (parent_window, &root_x, &root_y);

                screen = gtk_widget_get_screen (GTK_WIDGET (qview));

                /* Get a list of toplevel windows */
                win_list = gtk_window_list_toplevels ();

                /* Look for the gtk-tooltip window, we do this as gtk_widget_get_tooltip_window
                   does not seem to work for the default tooltip window, custom yes */
                for (node = win_list;  node != NULL;  node = node->next)
                {
                    if (g_strcmp0 (gtk_widget_get_name (node->data), "gtk-tooltip") == 0)
                    tip_win = node->data;
                }
                g_list_free (win_list);

	        gtk_tooltip_set_text (tooltip, desc_text);

                if (GTK_IS_WINDOW (tip_win))
                {
                    GdkRectangle monitor;
                    GtkRequisition requisition;
                    gint monitor_num;
                    gint x, y;

                    gtk_widget_size_request (GTK_WIDGET (tip_win), &requisition);

                    x = root_x + cur_x + 10;
                    y = root_y + cur_y + 10;

                    monitor_num = gdk_screen_get_monitor_at_point (screen, x, y);
                    gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);

                    if (x + requisition.width > monitor.x + monitor.width)
                        x -= x - (monitor.x + monitor.width) + requisition.width;
                    else if (x < monitor.x)
                        x = monitor.x;

                    if (y + requisition.height > monitor.y + monitor.height)
                        y -= y - (monitor.y + monitor.height) + requisition.height;

                    gtk_window_move (tip_win, x, y);
                }
            }
	    gtk_tooltip_set_text (tooltip, desc_text);
            g_free (desc_text);
	    return TRUE;
        }
    }
    return FALSE;
}
コード例 #25
0
ファイル: winefish.c プロジェクト: BackupTheBerlios/winefish
void bluefish_exit_request() {

	GList *tmplist;
	
	gboolean tmpb;
	DEBUG_MSG("winefish_exit_request, started\n");
	/* if we have modified documents we have to do something, file_close_all_cb()
	does exactly want we want to do */
	tmplist = return_allwindows_documentlist();
	tmpb = (tmplist && test_docs_modified(tmplist));
	g_list_free(tmplist);
	tmplist = g_list_first(main_v->bfwinlist);
	while (tmplist) {
		/* if there is a project, we anyway want to save & close the project */
		if (BFWIN(tmplist->data)->project) {
			if (!project_save_and_close(BFWIN(tmplist->data))) {
				/* cancelled or error! */
				DEBUG_MSG("winefish_exit_request, project_save_and_close returned FALSE\n");
				return;
			}
		}
		if (tmpb) {
			file_close_all_cb(NULL, BFWIN(tmplist->data));
		}
		tmplist = g_list_next(tmplist);
	}
	/* if we still have modified documents we don't do a thing,
	 if we don't have them we can quit */
	if (tmpb) {
		tmplist = return_allwindows_documentlist();
		tmpb = (tmplist && test_docs_modified(tmplist));
		g_list_free(tmplist);
		if (tmpb) {
			return;
		}
	}
/*	gtk_widget_hide(main_v->main_window);*/
	
	tmplist = g_list_first(gtk_window_list_toplevels());
	gchar *role=NULL;
	while (tmplist) {
		/* BUG#38 */
		if (GTK_IS_WIDGET(tmplist->data)) {
			role = g_strdup(gtk_window_get_role ((GtkWindow*)tmplist->data));
			gtk_widget_hide(GTK_WIDGET(tmplist->data));
			if (role && strncmp(role,"html_dialog",11) ==0) {
				window_destroy(GTK_WIDGET(tmplist->data));
			}
		}
		/* g_print("type = %s, role=%s\n", GTK_OBJECT_TYPE_NAME((GtkObject*) tmplist->data), role); */
		tmplist = g_list_next(tmplist);
	}
	g_free(role);

	flush_queue();

	rcfile_save_all();
	{
		gchar *filename = g_strconcat(g_get_home_dir(), "/.winefish/dir_history", NULL);
		put_stringlist_limited(filename, main_v->recent_directories, main_v->props.max_dir_history);
		g_free(filename);
	}
	
	gtk_main_quit();
}
コード例 #26
0
ファイル: ml_gtk.c プロジェクト: CRogers/obc
CAMLprim value ml_gtk_window_list_toplevels(value unit)
{  return Val_GList(gtk_window_list_toplevels(), wrap_widget); }
コード例 #27
0
int Gtk2Gui_Dialog_Setup(GWEN_DIALOG *dlg, GtkWidget *parentWindow) {
  GTK2_GUI_DIALOG *xdlg;
  GWEN_WIDGET_TREE *wtree;
  GWEN_WIDGET *w;
  GtkWindow *gw;
  int rv;
  GList *tll;

  assert(dlg);
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GTK2_GUI_DIALOG, dlg);
  assert(xdlg);

  wtree=GWEN_Dialog_GetWidgets(dlg);
  if (wtree==NULL) {
    DBG_ERROR(GWEN_LOGDOMAIN, "No widget tree in dialog");
    return GWEN_ERROR_NOT_FOUND;
  }
  w=GWEN_Widget_Tree_GetFirst(wtree);
  if (w==NULL) {
    DBG_ERROR(GWEN_LOGDOMAIN, "No widgets in dialog");
    return GWEN_ERROR_NOT_FOUND;
  }

  rv=Gtk2Gui_Dialog_SetupTree(w);
  if (rv<0) {
    DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
    return rv;
  }

  gw=GTK_WINDOW(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL));
  gtk_window_set_type_hint(GTK_WINDOW(gw), GDK_WINDOW_TYPE_HINT_DIALOG);
  gtk_window_set_position (GTK_WINDOW (gw), GTK_WIN_POS_CENTER_ON_PARENT);
  /*gtk_window_set_keep_above(GTK_WINDOW(gw), TRUE);*/
  xdlg->mainWidget=GTK_WIDGET(gw);

  tll=gtk_window_list_toplevels();
  if (tll) {
    GList* element;
    GtkWindow *topLevel=NULL;

    for (element = tll; element; element = g_list_next(element)) {
      GtkWindow* win = GTK_WINDOW(element->data);
      if (gtk_window_is_active(win)) {
        topLevel=win;
        break;
      }
    }
    g_list_free(tll);

    if (topLevel) {
      DBG_NOTICE(GWEN_LOGDOMAIN, "Found active window [%s]",
                 gtk_window_get_title(topLevel));
      gtk_window_set_transient_for(gw, topLevel);
    }
    else {
      DBG_ERROR(GWEN_LOGDOMAIN, "No active window found...");
    }
  }

  return 0;
}
コード例 #28
0
ファイル: reconcile-view.c プロジェクト: Gnucash/gnucash
static gboolean
gnc_reconcile_view_tooltip_cb (GNCQueryView *qview, gint x, gint y,
    gboolean keyboard_mode, GtkTooltip *tooltip, gpointer *user_data)
{
    GtkTreeModel* model;
    GtkTreeIter iter;

    // If the Description is longer than can be display, show it in a tooltip
    if (gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (qview), &x, &y, keyboard_mode, &model, NULL, &iter))
    {
        GtkTreeViewColumn *col;
        GList *cols;
        gint col_pos, col_width;
        gchar* desc_text = NULL;

        /* Are we in keyboard tooltip mode, displays tooltip below/above treeview CTRL+F1 */
        if (keyboard_mode == FALSE)
        {
            if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (qview), x, y, NULL, &col, NULL, NULL) == FALSE)
                return FALSE;
        }
        else
            gtk_tree_view_get_cursor (GTK_TREE_VIEW (qview), NULL, &col);

        cols = gtk_tree_view_get_columns (GTK_TREE_VIEW (qview));
        col_width = gtk_tree_view_column_get_width (col);
        col_pos = g_list_index (cols, col);
        g_list_free (cols);

        /* If column is not description, do not show tooltip */
        if (col_pos != (REC_DESC - 1)) // allow for the pointer model column at 0
            return FALSE;

        gtk_tree_model_get (model, &iter, REC_DESC, &desc_text, -1);

        if (desc_text)
        {
            PangoLayout* layout;
            gint text_width;
            gint root_x, root_y;
            gint cur_x, cur_y;

            layout = gtk_widget_create_pango_layout (GTK_WIDGET (qview), desc_text);
            pango_layout_get_pixel_size (layout, &text_width, NULL);
            g_object_unref (layout);

            /* If text_width + 10 <= column_width, do not show tooltip */
            if ((text_width + 10) <= col_width)
            {
                g_free (desc_text);
                return FALSE;
            }

            if (keyboard_mode == FALSE)
            {
#if GTK_CHECK_VERSION(3,20,0)
                GdkSeat *seat;
#else
                GdkDeviceManager *device_manager;
#endif
                GdkDevice *pointer;
                GtkWindow *tip_win = NULL;
                GdkWindow *parent_window;
                GList *win_list, *node;

                parent_window = gtk_widget_get_parent_window (GTK_WIDGET (qview));

#if GTK_CHECK_VERSION(3,20,0)
                seat = gdk_display_get_default_seat (gdk_window_get_display (parent_window));
                pointer = gdk_seat_get_pointer (seat);
#else
                device_manager = gdk_display_get_device_manager (gdk_window_get_display (parent_window));
                pointer = gdk_device_manager_get_client_pointer (device_manager);
#endif
                gdk_window_get_device_position (parent_window, pointer, &cur_x, &cur_y, NULL);

                gdk_window_get_origin (parent_window, &root_x, &root_y);

                 /* Get a list of toplevel windows */
                win_list = gtk_window_list_toplevels ();

                /* Look for the gtk-tooltip window, we do this as gtk_widget_get_tooltip_window
                   does not seem to work for the default tooltip window, custom yes */
                for (node = win_list;  node != NULL;  node = node->next)
                {
                    if (g_strcmp0 (gtk_widget_get_name (node->data), "gtk-tooltip") == 0)
                    tip_win = node->data;
                }
                g_list_free (win_list);

                gtk_tooltip_set_text (tooltip, desc_text);

                if (GTK_IS_WINDOW (tip_win))
                {
#if GTK_CHECK_VERSION(3,22,0)
                    GdkMonitor *mon;
#else
                    GdkScreen *screen;
                    gint monitor_num;
#endif
                    GdkRectangle monitor;
                    GtkRequisition requisition;
                    gint x, y;

                    gtk_widget_get_preferred_size (GTK_WIDGET (tip_win), &requisition, NULL);

                    x = root_x + cur_x + 10;
                    y = root_y + cur_y + 10;

#if GTK_CHECK_VERSION(3,22,0)
                    mon = gdk_display_get_monitor_at_point (gdk_display_get_default(), x, y);
                    gdk_monitor_get_geometry (mon, &monitor);
#else
                    screen = gtk_widget_get_screen (GTK_WIDGET (qview));
                    monitor_num = gdk_screen_get_monitor_at_point (screen, x, y);
                    gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
#endif
                    if (x + requisition.width > monitor.x + monitor.width)
                        x -= x - (monitor.x + monitor.width) + requisition.width;
                    else if (x < monitor.x)
                        x = monitor.x;

                    if (y + requisition.height > monitor.y + monitor.height)
                        y -= y - (monitor.y + monitor.height) + requisition.height;

                    gtk_window_move (tip_win, x, y);
                }
            }
            gtk_tooltip_set_text (tooltip, desc_text);
            g_free (desc_text);
            return TRUE;
        }
    }
    return FALSE;
}
コード例 #29
0
ファイル: gutachter-lookup.c プロジェクト: herzi/gutachter
/**
 * gutachter_lookup_child:
 * @widget: the parent #GtkWidget or %NULL
 * @path: the path to the desired widget
 *
 * Lookup a child of @widget (or from the toplevel if @widget is %NULL).
 *
 * Returns: the child specified by @widget and @path or %NULL if not found.
 */
GtkWidget*
gutachter_lookup_child (GtkWidget  * widget,
                        gchar const* path)
{
  GtkWidget  * result = NULL;
  GList      * list;
  GList      * iterator;
  gchar const* lookup;
  gchar const* end;

  g_return_val_if_fail (path, NULL);
  if (!*path)
    {
      path = "urn:gtk:";
    }

  lookup = path;

  if (!g_str_has_prefix (lookup, "urn:"))
    {
      g_warning ("%s(%s): path is no URN: \"%s\" should start with \"urn:\"",
                 G_STRFUNC, G_STRLOC,
                 path);
      return NULL;
    }

  lookup += 4; /* path points to 32bit word boundary */

  if (!g_str_has_prefix (lookup, "gtk:"))
    {
      g_warning ("%s(%s): the URN's namespace doesn't match ours (\"gtk\"): %s",
                 G_STRFUNC, G_STRLOC,
                 path);
      return NULL;
    }

  lookup += 4; /* path points to 32bit and 64bit word boundary */

  if (widget)
    {
      result = widget;
    }
  else
    {
      if (!*lookup)
        {
          return NULL;
        }

      if (!g_str_has_prefix (lookup, "GtkWindow"))
        {
          g_warning ("the gtk namespace can only be used with GtkWindow functions");
          return NULL;
        }

      lookup += strlen ("GtkWindow");

      if (!g_str_has_prefix (lookup, "(\""))
        {
          g_warning ("GtkWindows can only be looked up by title right now (e.g. 'GtkWindow(\"window title\")'): %s",
                     path);
          return NULL;
        }

      lookup += 2;
      end = strstr (lookup, "\")");
      if (!end)
        {
          g_warning ("window title doesn't seem to be closed: %s", path);
          return NULL;
        }

      for (iterator = list = gtk_window_list_toplevels (); iterator; iterator = iterator->next)
        {
          gchar const* title = gtk_window_get_title (iterator->data);

          if (g_str_has_prefix (lookup, title) && *(title + (end - lookup)) == '\0')
            {
              result = iterator->data;
              break;
            }
        }
      g_list_free (list);

      if (!result)
        {
          /* no window found */
          return NULL;
        }

      lookup = end + 2; /* result holds the window now */

      if (*lookup == ':')
        {
          lookup++;
        }
    }

  while (*lookup != '\0')
    {
      gchar* type_name;
      GType  type;
      int    index;

      end = strstr (lookup, "[");
      if (!end)
        {
          g_warning ("the type starting at column %" G_GUINTPTR_FORMAT " doesn't have a lookup operator (\"[]\")",
                     lookup - path);
          return NULL;
        }

      type_name = g_strndup (lookup, end - lookup);
      type = g_type_from_name (type_name);
      if (!type)
        {
          g_warning ("couldn't lookup the type \"%s\". it is not registered. this "
                     "usually means that you have a typo in your string as the "
                     "creation of a widget would automatically register its type "
                     "(and its parent types)", type_name);
          g_free (type_name);
          return NULL;
        }
      g_free (type_name);

      lookup = end + 1;
      index = strtol (lookup, &type_name, 10); /* FIXME: watch for ERANGE in errno */
      end = type_name; /* use type_name because it is non-const */

      if (!end || *end != ']')
        {
          g_warning ("the index starting at column %" G_GUINTPTR_FORMAT " doesn't seem to be properly terminated: expected ']', got '%c': %s",
                     lookup - path, *end,
                     path);
          return NULL;
        }

      if (!GTK_IS_CONTAINER (result))
        {
          gchar* result_end = g_strrstr_len (path, lookup - path, ":");
          gchar* result_path = g_strndup (path, result_end - path);
          g_warning ("the widget specified by \"%s\" is a %s (which is not a GtkContainer)",
                     result_path,
                     G_OBJECT_TYPE_NAME (result));
          g_free (result_path);
          return NULL;
        }

      list = gtk_container_get_children (GTK_CONTAINER (result));
      iterator = g_list_nth (list, index);
      if (!iterator)
        {
          g_warning ("%s doesn't have a child with the index %d",
                     G_OBJECT_TYPE_NAME (result), index);
          g_list_free (list);
          return NULL;
        }
      result = iterator->data;
      g_list_free (list);

      lookup = end + 1;
      if (*lookup == '\0')
        {
          break;
        }
      else if (*lookup == ':')
        {
          lookup++;
          continue;
        }
      else
        {
          g_warning ("unexpected character after widget lookup (column %" G_GUINTPTR_FORMAT "): expected dereferencing (\":\") or end: '%c'",
                     lookup - path, *lookup);
          return NULL;
        }
    }

  return result;
}