コード例 #1
0
ファイル: gtk3-nocsd.c プロジェクト: smcv/gtk3-nocsd
// This API exists since gtk+ 3.10
extern void gtk_window_set_titlebar (GtkWindow *window, GtkWidget *titlebar) {
    if(!is_compatible_gtk_version() || !are_csd_disabled()) {
        orig_gtk_window_set_titlebar(window, titlebar);
        return;
    }
    if (titlebar && is_gtk_version_larger_or_equal (3, 16, 1)) {
        /* We have to reimplement gtk_window_set_titlebar ourselves, since
         * those Gtk versions don't support turning CSD off anymore.
         * This mainly does the same things as the original function
         * (consisting of adding the title bar widget + connecting signals),
         * but it will not enable CSD and not set the client_decorated flag
         * in the window private space. (We wouldn't know which bit it is
         * anyway.) */
        gtk_window_private_info_t private_info = gtk_window_private_info ();
        char *priv = G_TYPE_INSTANCE_GET_PRIVATE (window, gtk_window_type, char);
        gboolean was_mapped = FALSE;
        GtkWidget *widget = GTK_WIDGET (window);
        GtkWidget **title_box_ptr = NULL;

        /* Something went wrong, so just stick with the original
         * implementation. */
        if (private_info.title_box_offset < 0 || !priv)
            goto orig_impl;

        title_box_ptr = (GtkWidget **) &priv[private_info.title_box_offset];

        if (!*title_box_ptr) {
            was_mapped = gtk_widget_get_mapped (widget);
            if (gtk_widget_get_realized (widget)) {
                g_warning ("gtk_window_set_titlebar() called on a realized window");
                gtk_widget_unrealize (widget);
            }
        }

        /* Remove any potential old title bar. We can't call
         * the static unset_titlebar() directly (not available),
         * so we call the full function; that shouldn't have
         * any side effects. */
        orig_gtk_window_set_titlebar (window, NULL);

        /* The solid-csd class is not removed when the titlebar
         * is unset in Gtk (it's probably a bug), so unset it
         * here explicitly, in case it's set. */
        gtk_style_context_remove_class (gtk_widget_get_style_context (widget), "solid-csd");

        /* We need to store the titlebar in priv->title_box,
         * which is where title_box_ptr points to. Then we
         * need to reparent the title bar and connect signals
         * if it's a GtkHeaderBar. Apart from CSD enablement,
         * this is what the original function boils down to.
         */
        *title_box_ptr = titlebar;
        gtk_widget_set_parent (*title_box_ptr, widget);
        if (GTK_IS_HEADER_BAR (titlebar)) {
            g_signal_connect (titlebar, "notify::title",
                        G_CALLBACK (private_info.on_titlebar_title_notify), window);
            private_info.on_titlebar_title_notify (GTK_HEADER_BAR (titlebar), NULL, window);
        }

        gtk_style_context_add_class (gtk_widget_get_style_context (titlebar),
                               GTK_STYLE_CLASS_TITLEBAR);

        if (was_mapped)
            gtk_widget_map (widget);

        return;
    }
コード例 #2
0
ファイル: panel-applet.c プロジェクト: lanoxx/gnome-panel
static void
panel_applet_size_allocate (GtkWidget     *widget,
			    GtkAllocation *allocation)
{
	PanelApplet   *applet;
	GtkAllocation  child_allocation;
	GtkAllocation  widget_allocation;
	GtkBin        *bin;
	GtkWidget     *child;
	GdkWindow     *window;
	int            border_width;
	int            focus_width = 0;

	applet = PANEL_APPLET (widget);
	bin    = GTK_BIN (widget);

	gtk_widget_get_allocation (widget, &widget_allocation);

	if (!panel_applet_can_focus (widget) && !applet->priv->has_handle) {
		GTK_WIDGET_CLASS (panel_applet_parent_class)->size_allocate (widget, allocation);
	} else {
		gtk_widget_set_allocation (widget, allocation);

		border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
		window = gtk_widget_get_window (widget);
		
		/*
		 * We are deliberately ignoring focus-padding here to
		 * save valuable panel real estate.
		 */
		gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);

		child_allocation.x      = allocation->x;
		child_allocation.y      = allocation->y;
		child_allocation.width  = allocation->width;
		child_allocation.height = allocation->height;

		if (applet->priv->has_handle) {
			applet->priv->handle_rect.x = 0;
			applet->priv->handle_rect.y = 0;

			switch (panel_applet_get_orient (applet)) {
				case PANEL_APPLET_ORIENT_UP:
				case PANEL_APPLET_ORIENT_DOWN:
					applet->priv->handle_rect.width  = HANDLE_SIZE;
					applet->priv->handle_rect.height = allocation->height;

					if (gtk_widget_get_direction (GTK_WIDGET (applet)) != GTK_TEXT_DIR_RTL) {
						applet->priv->handle_rect.x = 0;
						child_allocation.x = HANDLE_SIZE;
					} else {
						applet->priv->handle_rect.x = allocation->width - HANDLE_SIZE;
						child_allocation.x = 0;
					}

					child_allocation.y      = 0;
					child_allocation.width  = allocation->width - HANDLE_SIZE;
					child_allocation.height = allocation->height;
					break;
				case PANEL_APPLET_ORIENT_LEFT:
				case PANEL_APPLET_ORIENT_RIGHT:
					applet->priv->handle_rect.width  = allocation->width;
					applet->priv->handle_rect.height = HANDLE_SIZE;

					child_allocation.x      = 0;
					child_allocation.y      = HANDLE_SIZE;
					child_allocation.width  = allocation->width;
					child_allocation.height = allocation->height - HANDLE_SIZE;
					break;
				default:
					g_assert_not_reached ();
					break;
			}

			child_allocation.width  = MAX (1, child_allocation.width);
			child_allocation.height = MAX (1, child_allocation.height);
		}

		if (panel_applet_can_focus (widget)) {
			child_allocation.x += focus_width;
			child_allocation.y += focus_width;
		}
		
		child_allocation.width  = MAX (child_allocation.width  - border_width * 2, 0);
		child_allocation.height = MAX (child_allocation.height - border_width * 2, 0);
		
		if (gtk_widget_get_realized (widget)) {
			gdk_window_move_resize (window,
				allocation->x + border_width,
				allocation->y + border_width,
				MAX (allocation->width - border_width * 2, 0),
				MAX (allocation->height - border_width * 2, 0));
		}
		
		if (panel_applet_can_focus (widget)) {
			child_allocation.width  = MAX (child_allocation.width  - 2 * focus_width, 0);
			child_allocation.height = MAX (child_allocation.height - 2 * focus_width, 0);
		}

		child = gtk_bin_get_child (bin);
		if (child && gtk_widget_get_visible (child))
			gtk_widget_size_allocate (child, &child_allocation);
	}
}
コード例 #3
0
ファイル: glcanvas.cpp プロジェクト: Kaoswerk/newton-dynamics
bool wxGLCanvas::Create(wxWindow *parent,
                        wxWindowID id,
                        const wxPoint& pos,
                        const wxSize& size,
                        long style,
                        const wxString& name,
                        const int *attribList,
                        const wxPalette& palette)
{
#if wxUSE_PALETTE
    wxASSERT_MSG( !palette.IsOk(), wxT("palettes not supported") );
#endif // wxUSE_PALETTE
    wxUnusedVar(palette); // Unused when wxDEBUG_LEVEL==0

    m_exposed = false;
    m_noExpose = true;
    m_nativeSizeEvent = true;
#ifdef __WXGTK3__
    m_cairoPaintContext = NULL;
    m_backgroundStyle = wxBG_STYLE_PAINT;
#endif

    if ( !InitVisual(attribList) )
        return false;

    // watch for the "parent-set" signal on m_wxwindow so we can set colormap
    // before m_wxwindow is realized (which will occur before
    // wxWindow::Create() returns if parent is already visible)
    unsigned sig_id = g_signal_lookup("parent-set", GTK_TYPE_WIDGET);
    g_signal_add_emission_hook(sig_id, 0, parent_set_hook, this, NULL);

    wxWindow::Create( parent, id, pos, size, style, name );

    gtk_widget_set_double_buffered(m_wxwindow, false);

#if WXWIN_COMPATIBILITY_2_8
    g_signal_connect(m_wxwindow, "realize",       G_CALLBACK(gtk_glwindow_realized_callback), this);
#endif // WXWIN_COMPATIBILITY_2_8
#ifdef __WXGTK3__
    g_signal_connect(m_wxwindow, "draw", G_CALLBACK(draw), this);
#else
    g_signal_connect(m_wxwindow, "map",           G_CALLBACK(gtk_glwindow_map_callback),      this);
    g_signal_connect(m_wxwindow, "expose_event",  G_CALLBACK(gtk_glwindow_expose_callback),   this);
#endif
    g_signal_connect(m_widget,   "size_allocate", G_CALLBACK(gtk_glcanvas_size_callback),     this);

#if WXWIN_COMPATIBILITY_2_8
    // if our parent window is already visible, we had been realized before we
    // connected to the "realize" signal and hence our m_glContext hasn't been
    // initialized yet and we have to do it now
    if (gtk_widget_get_realized(m_wxwindow))
        gtk_glwindow_realized_callback( m_wxwindow, this );
#endif // WXWIN_COMPATIBILITY_2_8

#ifndef __WXGTK3__
    if (gtk_widget_get_mapped(m_wxwindow))
        gtk_glwindow_map_callback( m_wxwindow, this );
#endif

    return true;
}
コード例 #4
0
ファイル: ddbtabstrip.c プロジェクト: Tydus/deadbeef
static void
ddb_tabstrip_realize (GtkWidget *widget) {
    DdbTabStrip *darea = DDB_TABSTRIP (widget);
    GdkWindowAttr attributes;
    gint attributes_mask;

    if (!gtk_widget_get_has_window (widget))
    {
        GTK_WIDGET_CLASS (ddb_tabstrip_parent_class)->realize (widget);
    }
    else
    {
        gtk_widget_set_realized (widget, TRUE);

        attributes.window_type = GDK_WINDOW_CHILD;
        GtkAllocation a;
        gtk_widget_get_allocation (widget, &a);
        attributes.x = a.x;
        attributes.y = a.y;
        attributes.width = a.width;
        attributes.height = a.height;
        attributes.wclass = GDK_INPUT_OUTPUT;
        attributes.visual = gtk_widget_get_visual (widget);
#if !GTK_CHECK_VERSION(3,0,0)
        attributes.colormap = gtk_widget_get_colormap (widget);
#endif
        attributes.event_mask = gtk_widget_get_events (widget);
        attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK;

        attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
#if !GTK_CHECK_VERSION(3,0,0)
        attributes_mask |= GDK_WA_COLORMAP;
#endif

        gtk_widget_set_window(widget, gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask));
        gdk_window_set_user_data (gtk_widget_get_window(widget), darea);

        gtk_widget_set_style (widget, gtk_style_attach (gtk_widget_get_style (widget), gtk_widget_get_window(widget)));
        gtk_style_set_background (gtk_widget_get_style (widget), gtk_widget_get_window(widget), GTK_STATE_NORMAL);
    }

    ddb_tabstrip_send_configure (DDB_TABSTRIP (widget));
    GtkTargetEntry entry = {
        .target = "STRING",
        .flags = GTK_TARGET_SAME_APP,
        TARGET_SAMEWIDGET
    };
    gtk_drag_dest_set (widget, GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP, &entry, 1, GDK_ACTION_COPY | GDK_ACTION_MOVE);
    gtk_drag_dest_add_uri_targets (widget);
    gtk_drag_dest_set_track_motion (widget, TRUE);
}

static void
ddb_tabstrip_size_allocate (GtkWidget     *widget,
				GtkAllocation *allocation)
{
  g_return_if_fail (DDB_IS_TABSTRIP (widget));
  g_return_if_fail (allocation != NULL);

  gtk_widget_set_allocation (widget, allocation);

  if (gtk_widget_get_realized (widget))
    {
      if (gtk_widget_get_has_window (widget))
        gdk_window_move_resize (gtk_widget_get_window(widget),
                                allocation->x, allocation->y,
                                allocation->width, allocation->height);

      ddb_tabstrip_send_configure (DDB_TABSTRIP (widget));
    }
}
コード例 #5
0
/* serverside */
static void
on_message_received (const char *message,
		     gpointer    data)
{
	const PlumaEncoding *encoding = NULL;
	gchar **commands;
	gchar **params;
	gint workspace;
	gint viewport_x;
	gint viewport_y;
	gchar *display_name;
	gint screen_number;
	gint i;
	PlumaApp *app;
	PlumaWindow *window;
	GdkDisplay *display;
	GdkScreen *screen;

	g_return_if_fail (message != NULL);

	pluma_debug_message (DEBUG_APP, "Received message:\n%s\n", message);

	commands = g_strsplit (message, "\v", -1);

	/* header */
	params = g_strsplit (commands[0], "\t", 6);
	startup_timestamp = atoi (params[0]);
	display_name = params[1];
	screen_number = atoi (params[2]);
	workspace = atoi (params[3]);
	viewport_x = atoi (params[4]);
	viewport_y = atoi (params[5]);

	display = display_open_if_needed (display_name);
	if (display == NULL)
	{
		g_warning ("Could not open display %s\n", display_name);
		g_strfreev (params);
		goto out;
	}

	screen = gdk_display_get_screen (display, screen_number);

	g_strfreev (params);

	/* body */
	for (i = 1; commands[i] != NULL; i++)
	{
		params = g_strsplit (commands[i], "\t", -1);

		if (strcmp (params[0], "NEW-WINDOW") == 0)
		{
			new_window_option = TRUE;
		}
		else if (strcmp (params[0], "NEW-DOCUMENT") == 0)
		{
			new_document_option = TRUE;
		}
		else if (strcmp (params[0], "OPEN-URIS") == 0)
		{
			gint n_uris, j;
			gchar **uris;

			line_position = atoi (params[1]);

			if (params[2] != '\0')
				encoding = pluma_encoding_get_from_charset (params[2]);

			n_uris = atoi (params[3]);
			uris = g_strsplit (params[4], " ", n_uris);

			for (j = 0; j < n_uris; j++)
			{
				GFile *file;

				file = g_file_new_for_uri (uris[j]);
				file_list = g_slist_prepend (file_list, file);
			}

			file_list = g_slist_reverse (file_list);

			/* the list takes ownerhip of the strings,
			 * only free the array */
			g_free (uris);
		}
		else
		{
			g_warning ("Unexpected bacon command");
		}

		g_strfreev (params);
	}

	/* execute the commands */

	app = pluma_app_get_default ();

	if (new_window_option)
	{
		window = pluma_app_create_window (app, screen);
	}
	else
	{
		/* get a window in the current workspace (if exists) and raise it */
		window = _pluma_app_get_window_in_viewport (app,
							    screen,
							    workspace,
							    viewport_x,
							    viewport_y);
	}

	if (file_list != NULL)
	{
		_pluma_cmd_load_files_from_prompt (window,
						   file_list,
						   encoding,
						   line_position);

		if (new_document_option)
			pluma_window_create_tab (window, TRUE);
	}
	else
	{
		PlumaDocument *doc;
		doc = pluma_window_get_active_document (window);

		if (doc == NULL ||
		    !pluma_document_is_untouched (doc) ||
		    new_document_option)
			pluma_window_create_tab (window, TRUE);
	}

	/* set the proper interaction time on the window.
	 * Fall back to roundtripping to the X server when we
	 * don't have the timestamp, e.g. when launched from
	 * terminal. We also need to make sure that the window
	 * has been realized otherwise it will not work. lame.
	 */
	if (!gtk_widget_get_realized (GTK_WIDGET (window)))
		gtk_widget_realize (GTK_WIDGET (window));

	if (startup_timestamp <= 0)
		startup_timestamp = gdk_x11_get_server_time (gtk_widget_get_window (GTK_WIDGET (window)));

	gdk_x11_window_set_user_time (gtk_widget_get_window (GTK_WIDGET (window)),
				      startup_timestamp);

	gtk_window_present (GTK_WINDOW (window));

 out:
	g_strfreev (commands);

	free_command_line_data ();
}
コード例 #6
0
ファイル: toplevel.cpp プロジェクト: raydtang/wxWidgets
bool wxTopLevelWindowGTK::Show( bool show )
{
    wxCHECK_MSG(m_widget, false, "invalid frame");

#ifdef GDK_WINDOWING_X11
    bool deferShow = show && !m_isShown && m_deferShow;
    if (deferShow)
    {
        deferShow = m_deferShowAllowed &&
                    gs_requestFrameExtentsStatus != RFE_STATUS_BROKEN &&
                    !gtk_widget_get_realized(m_widget) &&
                    GDK_IS_X11_DISPLAY(gtk_widget_get_display(m_widget)) &&
                    g_signal_handler_find(m_widget,
                                          GSignalMatchType(G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA),
                                          g_signal_lookup("property_notify_event", GTK_TYPE_WIDGET),
                                          0, NULL, NULL, this);
        if (deferShow)
        {
            GdkScreen* screen = gtk_widget_get_screen(m_widget);
            GdkAtom atom = gdk_atom_intern("_NET_REQUEST_FRAME_EXTENTS", false);
            deferShow = gdk_x11_screen_supports_net_wm_hint(screen, atom) != 0;

            // If _NET_REQUEST_FRAME_EXTENTS not supported, don't allow changes
            // to m_decorSize, it breaks saving/restoring window size with
            // GetSize()/SetSize() because it makes window bigger between each
            // restore and save.
            m_updateDecorSize = deferShow;
        }

        m_deferShow = deferShow;
    }
    if (deferShow)
    {
        // Initial show. If WM supports _NET_REQUEST_FRAME_EXTENTS, defer
        // calling gtk_widget_show() until _NET_FRAME_EXTENTS property
        // notification is received, so correct frame extents are known.
        // This allows resizing m_widget to keep the overall size in sync with
        // what wxWidgets expects it to be without an obvious change in the
        // window size immediately after it becomes visible.

        // Realize m_widget, so m_widget->window can be used. Realizing normally
        // causes the widget tree to be size_allocated, which generates size
        // events in the wrong order. However, the size_allocates will not be
        // done if the allocation is not the default (1,1).
        GtkAllocation alloc;
        gtk_widget_get_allocation(m_widget, &alloc);
        const int alloc_width = alloc.width;
        if (alloc_width == 1)
        {
            alloc.width = 2;
            gtk_widget_set_allocation(m_widget, &alloc);
        }
        gtk_widget_realize(m_widget);
        if (alloc_width == 1)
        {
            alloc.width = 1;
            gtk_widget_set_allocation(m_widget, &alloc);
        }

        // send _NET_REQUEST_FRAME_EXTENTS
        XClientMessageEvent xevent;
        memset(&xevent, 0, sizeof(xevent));
        xevent.type = ClientMessage;
        GdkWindow* window = gtk_widget_get_window(m_widget);
        xevent.window = GDK_WINDOW_XID(window);
        xevent.message_type = gdk_x11_atom_to_xatom_for_display(
                                  gdk_window_get_display(window),
                                  gdk_atom_intern("_NET_REQUEST_FRAME_EXTENTS", false));
        xevent.format = 32;
        Display* display = GDK_DISPLAY_XDISPLAY(gdk_window_get_display(window));
        XSendEvent(display, DefaultRootWindow(display), false,
                   SubstructureNotifyMask | SubstructureRedirectMask,
                   (XEvent*)&xevent);

        if (gs_requestFrameExtentsStatus == RFE_STATUS_UNKNOWN)
        {
            // if WM does not respond to request within 1 second,
            // we assume support for _NET_REQUEST_FRAME_EXTENTS is not working
            m_netFrameExtentsTimerId =
                g_timeout_add(1000, request_frame_extents_timeout, this);
        }

        // defer calling gtk_widget_show()
        m_isShown = true;
        return true;
    }
#endif // GDK_WINDOWING_X11

    if (show && !gtk_widget_get_realized(m_widget))
    {
        // size_allocate signals occur in reverse order (bottom to top).
        // Things work better if the initial wxSizeEvents are sent (from the
        // top down), before the initial size_allocate signals occur.
        wxSizeEvent event(GetSize(), GetId());
        event.SetEventObject(this);
        HandleWindowEvent(event);

#ifdef __WXGTK3__
        GTKSizeRevalidate();
#endif
    }

    bool change = base_type::Show(show);

    if (change && !show)
    {
        // make sure window has a non-default position, so when it is shown
        // again, it won't be repositioned by WM as if it were a new window
        // Note that this must be done _after_ the window is hidden.
        gtk_window_move((GtkWindow*)m_widget, m_x, m_y);
    }

    return change;
}
コード例 #7
0
ファイル: applet.c プロジェクト: alexandervdm/mate-applets
static gboolean accessx_status_applet_fill(MatePanelApplet* applet)
{
	AccessxStatusApplet* sapplet;
	AtkObject* atk_object;
	GtkActionGroup* action_group;
	gchar* ui_path;
	gboolean was_realized = FALSE;

	sapplet = create_applet(applet);

	if (!gtk_widget_get_realized(sapplet->box))
	{
		g_signal_connect_after(G_OBJECT(sapplet->box), "realize", G_CALLBACK(accessx_status_applet_realize), sapplet);
	}
	else
	{
		accessx_status_applet_initialize(sapplet);
		was_realized = TRUE;
	}

	g_object_connect(sapplet->applet,
		"signal::destroy", accessx_status_applet_destroy, sapplet,
		"signal::change_orient", accessx_status_applet_reorient, sapplet,
		"signal::change_size", accessx_status_applet_resize, sapplet,
#if !GTK_CHECK_VERSION (3, 0, 0)
		"signal::change_background", accessx_status_applet_background, sapplet,
#endif
		NULL);

	g_signal_connect(sapplet->applet, "button_press_event", G_CALLBACK(button_press_cb), sapplet);
	g_signal_connect(sapplet->applet, "key_press_event", G_CALLBACK(key_press_cb), sapplet);

	action_group = gtk_action_group_new("Accessx Applet Actions");
	gtk_action_group_set_translation_domain(action_group, GETTEXT_PACKAGE);
	gtk_action_group_add_actions(action_group, accessx_status_applet_menu_actions, G_N_ELEMENTS(accessx_status_applet_menu_actions), sapplet);
	ui_path = g_build_filename(ACCESSX_MENU_UI_DIR, "accessx-status-applet-menu.xml", NULL);
	mate_panel_applet_setup_menu_from_file(sapplet->applet, ui_path, action_group);
	g_free(ui_path);

	if (mate_panel_applet_get_locked_down(sapplet->applet))
	{
		GtkAction* action = gtk_action_group_get_action(action_group, "Dialog");
		gtk_action_set_visible(action, FALSE);
	}

	g_object_unref(action_group);

	gtk_widget_set_tooltip_text(GTK_WIDGET(sapplet->applet), _("Keyboard Accessibility Status"));

	atk_object = gtk_widget_get_accessible(GTK_WIDGET(sapplet->applet));
	atk_object_set_name(atk_object, _("AccessX Status"));
	atk_object_set_description(atk_object, _("Displays current state of keyboard accessibility features"));
	gtk_widget_show_all(GTK_WIDGET(sapplet->applet));

	if (was_realized)
	{
		accessx_status_applet_reset(sapplet);
	}

	mate_panel_applet_set_background_widget (sapplet->applet, GTK_WIDGET (sapplet->applet));

	return TRUE;
}
コード例 #8
0
static void
greeter_menu_bar_size_allocate(GtkWidget* widget, GtkAllocation* allocation)
{
    GList* item;
    GList* shell_children;
    GList* expand_nums = NULL;
    guint visible_count = 0, expand_count = 0;

	g_return_if_fail(allocation != NULL);
	g_return_if_fail(GREETER_IS_MENU_BAR(widget));

    gtk_widget_set_allocation(widget, allocation);

    GtkPackDirection pack_direction = gtk_menu_bar_get_pack_direction(GTK_MENU_BAR(widget));
    g_return_if_fail(pack_direction == GTK_PACK_DIRECTION_LTR || pack_direction == GTK_PACK_DIRECTION_RTL);

    shell_children = gtk_container_get_children(GTK_CONTAINER(widget));

    for(item = shell_children; item; item = g_list_next(item))
        if(gtk_widget_get_visible(item->data))
        {
            if(gtk_widget_compute_expand(item->data, GTK_ORIENTATION_HORIZONTAL))
            {
                expand_nums = g_list_prepend(expand_nums, GINT_TO_POINTER(visible_count));
                expand_count++;
            }
            visible_count++;
        }

    if(gtk_widget_get_realized(widget))
        gdk_window_move_resize(gtk_widget_get_window(widget),
                               allocation->x, allocation->y,
                               allocation->width, allocation->height);

    if(visible_count > 0)
    {
        GtkAllocation remaining_space;
        GtkStyleContext* context = gtk_widget_get_style_context(widget);
        GtkStateFlags flags = gtk_widget_get_state_flags(widget);
        GtkRequestedSize* requested_sizes = g_newa(GtkRequestedSize, visible_count);
        guint border_width = gtk_container_get_border_width(GTK_CONTAINER(widget));
        GtkShadowType shadow_type = GTK_SHADOW_OUT;
        GtkBorder border;
        gint toggle_size;

        gtk_style_context_get_padding(context, flags, &border);
        gtk_widget_style_get(widget, "shadow-type", &shadow_type, NULL);

        remaining_space.x = (border_width + border.left);
        remaining_space.y = (border_width + border.top);
        remaining_space.width = allocation->width -
                                2 * border_width - border.left - border.right;
        remaining_space.height = allocation->height -
                                 2 * border_width - border.top - border.bottom;

        if (shadow_type != GTK_SHADOW_NONE)
        {
            gtk_style_context_get_border(context, flags, &border);

            remaining_space.x += border.left;
            remaining_space.y += border.top;
            remaining_space.width -= border.left + border.right;
            remaining_space.height -= border.top + border.bottom;
        }

        GtkRequestedSize* request = requested_sizes;
        int size = remaining_space.width;
        gboolean ltr = (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_LTR) == (pack_direction == GTK_PACK_DIRECTION_LTR);

        for(item = shell_children; item; item = g_list_next(item))
        {
            if (!gtk_widget_get_visible(item->data))
                continue;

            request->data = item->data;
            gtk_widget_get_preferred_width_for_height(item->data, remaining_space.height,
                    &request->minimum_size,
                    &request->natural_size);
            gtk_menu_item_toggle_size_request(GTK_MENU_ITEM(item->data),
                                              &toggle_size);
            request->minimum_size += toggle_size;
            request->natural_size += toggle_size;

            gtk_menu_item_toggle_size_allocate(GTK_MENU_ITEM(item->data), toggle_size);

            size -= request->minimum_size;
            request++;
        }

        size = gtk_distribute_natural_allocation(size, visible_count, requested_sizes);

        /* Distribution extra space for widgets with expand=True */
        if(size > 0 && expand_nums)
        {
            expand_nums = g_list_sort_with_data(expand_nums, (GCompareDataFunc)sort_minimal_size,
                                                requested_sizes);
            GList* first_item = expand_nums;
            gint needed_size = -1;
            gint max_size = requested_sizes[GPOINTER_TO_INT(first_item->data)].natural_size;
            gint total_needed_size = 0;


            /* Free space that all widgets need to have the same (max_size) width
             * [___max_width___][widget         ][widget____     ]
             * total_needed_size := [] + [         ] + [     ]
             * total_needed_size = [              ]
             */
            for(item = g_list_next(expand_nums); item; item = g_list_next(item))
                total_needed_size += max_size - requested_sizes[GPOINTER_TO_INT(item->data)].natural_size;

            while(first_item)
            {
                if(size >= total_needed_size)
                {
                    /* total_needed_size is enough for all remaining widgets */
                    needed_size = max_size + (size - total_needed_size)/expand_count;
                    break;
                }
                /* Removing current maximal widget from list */
                total_needed_size -= max_size - requested_sizes[GPOINTER_TO_INT(item->data)].natural_size;
                first_item = g_list_next(first_item);
                if(first_item)
                    max_size = requested_sizes[GPOINTER_TO_INT(first_item->data)].natural_size;
            }

            for(item = first_item; item; item = g_list_next(item))
            {
                request = &requested_sizes[GPOINTER_TO_INT(item->data)];
                gint dsize = needed_size - request->natural_size;
                if(size < dsize)
                    dsize = size;
                size -= dsize;
                request->natural_size += dsize;
            }
        }
        
        gint i;
        for(i = 0; i < visible_count; i++)
        {
            GtkAllocation child_allocation = remaining_space;
            request = &requested_sizes[i];

            child_allocation.width = request->natural_size;
            remaining_space.width -= request->natural_size;
            if (ltr)
                remaining_space.x += request->natural_size;
            else
                child_allocation.x += remaining_space.width;
            gtk_widget_size_allocate(request->data, &child_allocation);
        }
        g_list_free(expand_nums);
    }
    g_list_free(shell_children);
}
コード例 #9
0
ファイル: widget-overlay.c プロジェクト: arthurnn/libgda
static void
widget_overlay_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
{
	WidgetOverlay *ovl = WIDGET_OVERLAY (widget);
	gint border_width;
	gint w, h;

	gtk_widget_set_allocation (widget, allocation);

	border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));

	w = allocation->width - border_width * 2;
	h = allocation->height - border_width * 2;

	if (gtk_widget_get_realized (widget)) {
		GdkWindow *win;
		win = gtk_widget_get_window (widget);
		gdk_window_move_resize (win,
					allocation->x + border_width,
					allocation->y + border_width,
					w, h);
	}

	GList *list;
	for (list = ovl->priv->children; list; list = list->next) {
		ChildData *cd = (ChildData*) list->data;
		if (gtk_widget_get_visible (cd->child)){
			GtkRequisition child_requisition;
			GtkAllocation child_allocation;
			
			gtk_widget_get_preferred_size (cd->child, &child_requisition, NULL);
			child_allocation.x = 0;
			child_allocation.y = 0;
			child_allocation.height = child_requisition.height;
			child_allocation.width = child_requisition.width;
			
			if (cd->halign == WIDGET_OVERLAY_ALIGN_FILL)
				child_allocation.width = w / cd->scale;
			if ((cd->valign == WIDGET_OVERLAY_ALIGN_FILL) ||
			    (cd == ovl->priv->scale_child))
				child_allocation.height = h / cd->scale;

			if (cd->is_tooltip) {
				cd->scale = 1.;
				if ((allocation->width > 0) && (allocation->height > 0)) {
					if (child_allocation.width > allocation->width)
						cd->scale = (gdouble) allocation->width /
							(gdouble) child_allocation.width;
					if (child_allocation.height > allocation->height) {
						if (cd->scale > ((gdouble) allocation->height /
								 (gdouble) child_allocation.height))
							cd->scale = (gdouble) allocation->height /
								(gdouble) child_allocation.height;
					}
				}
			}

			if (gtk_widget_get_realized (widget))
				gdk_window_move_resize (cd->offscreen_window,
							child_allocation.x,
							child_allocation.y,
							child_allocation.width,
							child_allocation.height);
			
			child_allocation.x = child_allocation.y = 0;

			gtk_widget_size_allocate (cd->child, &child_allocation);
		}
	}
}
コード例 #10
0
ファイル: icon-grid.c プロジェクト: setzer22/lxpanel
/* Establish the widget placement of an icon grid. */
static void panel_icon_grid_size_allocate(GtkWidget *widget,
                                          GtkAllocation *allocation)
{
    PanelIconGrid *ig = PANEL_ICON_GRID(widget);
    GtkRequisition req;
    GtkAllocation child_allocation;
    int child_width;
    int child_height;
    GtkTextDirection direction;
    guint border;
    int x_delta;
    guint next_coord;
    guint x, y;
    GList *ige;
    GtkWidget *child;

    /* Apply given allocation */
    gtk_widget_set_allocation(widget, allocation);
    border = gtk_container_get_border_width(GTK_CONTAINER(widget));
    child_allocation.width = MAX(allocation->width - border * 2, 0);
    child_allocation.height = MAX(allocation->height - border * 2, 0);
    if (gtk_widget_get_realized(widget))
    {
        if (!gtk_widget_get_has_window(widget))
        {
            child_allocation.x = allocation->x + border;
            child_allocation.y = allocation->y + border;
        }
        else
        {
            child_allocation.x = 0;
            child_allocation.y = 0;
        }
        if (ig->event_window != NULL)
            gdk_window_move_resize(ig->event_window,
                                   child_allocation.x,
                                   child_allocation.y,
                                   child_allocation.width,
                                   child_allocation.height);
        if (gtk_widget_get_has_window(widget))
            gdk_window_move_resize(gtk_widget_get_window(widget),
                                   allocation->x + border,
                                   allocation->y + border,
                                   child_allocation.width,
                                   child_allocation.height);
    }

    /* Get and save the desired container geometry. */
    if (ig->orientation == GTK_ORIENTATION_HORIZONTAL && allocation->height > 1)
        ig->target_dimension = allocation->height;
    else if (ig->orientation == GTK_ORIENTATION_VERTICAL && allocation->width > 1)
        ig->target_dimension = allocation->width;
    child_width = ig->child_width;
    child_height = ig->child_height;

    /* FIXME: is there any sense to recheck rows and columns again?
       GTK+ should have it done right before this call. */

    /* Get the constrained child geometry if the allocated geometry is insufficient.
     * All children are still the same size and share equally in the deficit. */
    if ((ig->columns != 0) && (ig->rows != 0) && (child_allocation.width > 0))
    {
        if (ig->constrain_width &&
            (x_delta = (child_allocation.width + ig->spacing) / ig->columns - ig->spacing) < child_width)
            child_width = MAX(2, x_delta);
        /* fill vertical space evenly in horisontal orientation */
        if (ig->orientation == GTK_ORIENTATION_HORIZONTAL &&
            (x_delta = (child_allocation.height + ig->spacing) / ig->rows - ig->spacing) > child_height)
            child_height = MAX(2, x_delta);
    }

    /* Initialize parameters to control repositioning each visible child. */
    direction = gtk_widget_get_direction(widget);
    x = (direction == GTK_TEXT_DIR_RTL) ? allocation->width - border : border;
    y = border;
    x_delta = 0;
    next_coord = border;

    /* Reposition each visible child. */
    for (ige = ig->children; ige != NULL; ige = ige->next)
    {
        child = ige->data;
        if (gtk_widget_get_visible(child))
        {
            /* Do necessary operations on the child. */
            gtk_widget_get_child_requisition(child, &req);
            icon_grid_element_check_requisition(ig, &req);
            child_allocation.width = MIN(req.width, child_width);
            child_allocation.height = MIN(req.height, child_height);

            /* Check this grid position */
            if (ig->orientation == GTK_ORIENTATION_HORIZONTAL)
            {
                y = next_coord;
                if (y + child_height > allocation->height - border && y > border)
                {
                    y = border;
                    if (direction == GTK_TEXT_DIR_RTL)
                        x -= (x_delta + ig->spacing);
                    else
                        x += (x_delta + ig->spacing);
                    x_delta = 0;
                    // FIXME: if fill_width and rows = 1 then allocate whole column
                }
                next_coord = y + child_height + ig->spacing;
                x_delta = MAX(x_delta, child_allocation.width);
            }
            else
            {
                // FIXME: if fill_width then use aspect to check delta
                if (direction == GTK_TEXT_DIR_RTL)
                {
                    next_coord = x - child_allocation.width;
                    if (x < allocation->width - border)
                    {
                        next_coord -= ig->spacing;
                        if (next_coord < border)
                        {
                            next_coord = allocation->width - border;
                            y += child_height + ig->spacing;
                        }
                    }
                    x = next_coord;
                }
                else
                {
                    x = next_coord;
                    if (x + child_allocation.width > allocation->width - border && x > border)
                    {
                        x = border;
                        y += child_height + ig->spacing;
                    }
                    next_coord = x + child_allocation.width + ig->spacing;
                }
            }
            child_allocation.x = x;
            if (req.height < child_height - 1)
                y += (child_height - req.height) / 2;
            child_allocation.y = y;

            if (!gtk_widget_get_has_window (widget))
            {
                child_allocation.x += allocation->x;
                child_allocation.y += allocation->y;
            }
            // FIXME: if fill_width and rows > 1 then delay allocation
            gtk_widget_size_allocate(child, &child_allocation);
        }
    }
}
コード例 #11
0
/**
 * gimp_button_menu_position:
 * @button: a button widget to popup the menu from
 * @menu: the menu to position
 * @position: the preferred popup direction for the menu (left or right)
 * @x: return location for x coordinate
 * @y: return location for y coordinate
 *
 * Utility function to position a menu that pops up from a button.
 **/
void
gimp_button_menu_position (GtkWidget       *button,
                           GtkMenu         *menu,
                           GtkPositionType  position,
                           gint            *x,
                           gint            *y)
{
  GdkScreen      *screen;
  GtkAllocation   button_allocation;
  GtkRequisition  menu_requisition;
  GdkRectangle    rect;
  gint            monitor;

  g_return_if_fail (GTK_IS_WIDGET (button));
  g_return_if_fail (gtk_widget_get_realized (button));
  g_return_if_fail (GTK_IS_MENU (menu));
  g_return_if_fail (x != NULL);
  g_return_if_fail (y != NULL);

  gtk_widget_get_allocation (button, &button_allocation);

  if (gtk_widget_get_direction (button) == GTK_TEXT_DIR_RTL)
    {
      switch (position)
        {
        case GTK_POS_LEFT:   position = GTK_POS_RIGHT;  break;
        case GTK_POS_RIGHT:  position = GTK_POS_LEFT;   break;
        default:
          break;
        }
    }

  *x = 0;
  *y = 0;

  if (! gtk_widget_get_has_window (button))
    {
      *x += button_allocation.x;
      *y += button_allocation.y;
    }

  gdk_window_get_root_coords (gtk_widget_get_window (button), *x, *y, x, y);

  gtk_widget_size_request (GTK_WIDGET (menu), &menu_requisition);

  screen = gtk_widget_get_screen (button);

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

  gtk_menu_set_screen (menu, screen);

  switch (position)
    {
    case GTK_POS_LEFT:
      *x -= menu_requisition.width;
      if (*x < rect.x)
        *x += menu_requisition.width + button_allocation.width;
      break;

    case GTK_POS_RIGHT:
      *x += button_allocation.width;
      if (*x + menu_requisition.width > rect.x + rect.width)
        *x -= button_allocation.width + menu_requisition.width;
      break;

    default:
      g_warning ("%s: unhandled position (%d)", G_STRFUNC, position);
      break;
    }

  *y += button_allocation.height / 2;

  if (*y + menu_requisition.height > rect.y + rect.height)
    *y -= menu_requisition.height;

  if (*y < rect.y)
    *y = rect.y;
}
コード例 #12
0
ファイル: widget-tree.c プロジェクト: jwendell/gtkparasite
static void
append_widget(GtkTreeStore *model,
              GtkWidget *widget,
              GtkTreeIter *parent_iter)
{
    GtkTreeIter iter;
    const char *class_name = G_OBJECT_CLASS_NAME(GTK_WIDGET_GET_CLASS(widget));
    const char *name;
    char *row_color = NULL;
    char *window_info;
    char *address;
    gboolean realized;
    gboolean mapped;
    gboolean visible;
    GList *l;

    name = gtk_widget_get_name(widget);
    if (name == NULL || strcmp(name, class_name) == 0) {
        if (GTK_IS_LABEL(widget))
        {
            name = gtk_label_get_text(GTK_LABEL(widget));
        }
        else if (GTK_IS_BUTTON(widget))
        {
            name = gtk_button_get_label(GTK_BUTTON(widget));
        }
        else if (GTK_IS_WINDOW(widget))
        {
            name = gtk_window_get_title(GTK_WINDOW(widget));
        }
        else
        {
            name = "";
        }
    }

    if (gtk_widget_get_window(widget))
    {
#if HAVE_X11
	window_info = g_strdup_printf("%p (XID 0x%x)", widget->window,
	                              (int)GDK_WINDOW_XID(widget->window));
#else
	window_info = g_strdup("");
#endif
    }
    else
    {
        window_info = g_strdup("");
    }

    address = g_strdup_printf("%p", widget);

    realized = gtk_widget_get_realized(widget);
    mapped = gtk_widget_get_mapped(widget);
    visible = gtk_widget_get_visible(widget);

    if (!realized || !mapped || !visible)
    {
        GtkStyle* style = gtk_widget_get_style(GTK_WIDGET(widget));
        GdkColor color = style->fg[GTK_STATE_INSENSITIVE];

        row_color = gdk_color_to_string(&color);
    }

    gtk_tree_store_append(model, &iter, parent_iter);
    gtk_tree_store_set(model, &iter,
                       WIDGET, widget,
                       WIDGET_TYPE, class_name,
                       WIDGET_NAME, name,
                       WIDGET_REALIZED, realized,
                       WIDGET_MAPPED, mapped,
                       WIDGET_VISIBLE, visible,
                       WIDGET_WINDOW, window_info,
                       WIDGET_ADDRESS, address,
                       ROW_COLOR, row_color,
                       -1);

    g_free(window_info);
    g_free(address);
    g_free(row_color);

    if (GTK_IS_CONTAINER(widget))
    {
        GList* children = NULL;

        /* Pick up all children, including those that are internal. */
        gtk_container_forall(GTK_CONTAINER(widget),
                             on_container_forall, &children);

        for (l = children; l != NULL; l = l->next)
        {
            append_widget(model, GTK_WIDGET(l->data), &iter);
        }

        g_list_free(children);
    }
}
コード例 #13
0
static void
gtk_notification_size_allocate (GtkWidget *widget,
                                GtkAllocation *allocation)
{
  GtkNotification *notification = GTK_NOTIFICATION (widget);
  GtkNotificationPrivate *priv = notification->priv;
  GtkBin *bin = GTK_BIN (widget);
  GtkAllocation child_allocation;
  GtkBorder padding;
  GtkRequisition button_req;
  GtkWidget *child;

  gtk_widget_set_allocation (widget, allocation);

  /* If somehow the notification changes while not hidden
     and we're not animating, immediately follow the resize */
  if (priv->animate_y > 0 &&
      !priv->animate_timeout)
    priv->animate_y = allocation->height;

  get_padding_and_border (notification, &padding);

  if (gtk_widget_get_realized (widget))
    {
      gdk_window_move_resize (gtk_widget_get_window (widget),
                              allocation->x,
                              allocation->y,
                              allocation->width,
                              allocation->height);
      gdk_window_move_resize (priv->bin_window,
                              0,
                              -allocation->height + priv->animate_y,
                              allocation->width,
                              allocation->height);
    }

  child_allocation.x = SHADOW_OFFSET_X + padding.left;
  child_allocation.y = padding.top;

  if (priv->show_close_button)
    gtk_widget_get_preferred_size (priv->close_button, &button_req, NULL);
  else
    button_req.width = button_req.height = 0;

  child_allocation.height = MAX (1, allocation->height - SHADOW_OFFSET_Y - padding.top - padding.bottom);
  child_allocation.width = MAX (1, (allocation->width - button_req.width -
                                    2 * SHADOW_OFFSET_X - padding.left - padding.right));

  child = gtk_bin_get_child (bin);
  if (child && gtk_widget_get_visible (child))
    gtk_widget_size_allocate (child, &child_allocation);

  if (priv->show_close_button)
    {
      child_allocation.x += child_allocation.width;
      child_allocation.width = button_req.width;
      child_allocation.y += (child_allocation.height - button_req.height) / 2;
      child_allocation.height = button_req.height;

      gtk_widget_size_allocate (priv->close_button, &child_allocation);
    }
}
コード例 #14
0
static void
attachment_paned_notify_cb (EAttachmentPaned *paned,
                            GParamSpec *pspec,
                            GtkExpander *expander)
{
	GtkAllocation toplevel_allocation;
	GtkWidget *toplevel;
	GtkWidget *child;
	GtkLabel *label;
	const gchar *text;

	label = GTK_LABEL (paned->priv->show_hide_label);

	/* Update the expander label and set the right bottom margin around the handle. */
	if (gtk_expander_get_expanded (expander)) {
		gint bottom, value;

		text = _("Hide Attachment _Bar");

		bottom = gtk_widget_get_margin_bottom (paned->priv->controls_container);
		value = bottom - paned->priv->vpaned_handle_size;

		gtk_widget_set_margin_bottom (
			paned->priv->controls_container, (value < 0) ? 0 : value);
	} else {
		gtk_widget_set_margin_bottom (paned->priv->controls_container, 6);
		text = _("Show Attachment _Bar");
	}

	gtk_label_set_text_with_mnemonic (label, text);

	/* Resize the top-level window if required conditions are met.
	 * This is based on gtk_expander_resize_toplevel(), but adapted
	 * to the fact our GtkExpander has no direct child widget. */

	if (!e_attachment_paned_get_resize_toplevel (paned))
		return;

	if (!gtk_widget_get_realized (GTK_WIDGET (paned)))
		return;

	child = gtk_paned_get_child2 (GTK_PANED (paned));
	toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));

	if (toplevel == NULL)
		return;

	if (!gtk_widget_get_realized (GTK_WIDGET (toplevel)))
		return;

	gtk_widget_get_allocation (toplevel, &toplevel_allocation);

	if (gtk_expander_get_expanded (expander)) {
		GtkRequisition child_requisition;

		gtk_widget_get_preferred_size (
			child, &child_requisition, NULL);

		toplevel_allocation.height += child_requisition.height;
	} else {
		GtkAllocation child_allocation;

		gtk_widget_get_allocation (child, &child_allocation);

		toplevel_allocation.height -= child_allocation.height;
	}

	gtk_window_resize (
		GTK_WINDOW (toplevel),
		toplevel_allocation.width,
		toplevel_allocation.height);
}
コード例 #15
0
ファイル: widget-tree.c プロジェクト: jjardon/gtkparasite
static void
append_widget(GtkTreeStore *model,
              GtkWidget *widget,
              GtkTreeIter *parent_iter)
{
    GtkTreeIter iter;
    const char *class_name = G_OBJECT_CLASS_NAME(GTK_WIDGET_GET_CLASS(widget));
    const char *name;
    const char *row_color;
    GdkWindow *window;
    char *window_info;
    char *address;
    gboolean realized;
    gboolean mapped;
    gboolean visible;
    GList *l;

    name = gtk_widget_get_name(widget);
    if (name == NULL || strcmp(name, class_name) == 0) {
        if (GTK_IS_LABEL(widget))
        {
            name = gtk_label_get_text(GTK_LABEL(widget));
        }
        else if (GTK_IS_BUTTON(widget))
        {
            name = gtk_button_get_label(GTK_BUTTON(widget));
        }
        else if (GTK_IS_WINDOW(widget))
        {
            name = gtk_window_get_title(GTK_WINDOW(widget));
        }
        else
        {
            name = "";
        }
    }

    window = gtk_widget_get_window (widget);
    if (window_info)
    {
#if HAVE_X11
	window_info = g_strdup_printf("%p (XID 0x%x)", window,
	                              (int)GDK_WINDOW_XID(window));
#else
	window_info = g_strdup("");
#endif
    }
    else
    {
        window_info = g_strdup("");
    }

    address = g_strdup_printf("%p", widget);

    realized = gtk_widget_get_realized (widget);
    mapped = gtk_widget_get_mapped (widget);
    visible = gtk_widget_get_visible (widget);

    row_color = (realized && mapped && visible) ? "black" : "grey";

    gtk_tree_store_append(model, &iter, parent_iter);
    gtk_tree_store_set(model, &iter,
                       WIDGET, widget,
                       WIDGET_TYPE, class_name,
                       WIDGET_NAME, name,
                       WIDGET_REALIZED, realized,
                       WIDGET_MAPPED, mapped,
                       WIDGET_VISIBLE, visible,
                       WIDGET_WINDOW, window_info,
                       WIDGET_ADDRESS, address,
                       ROW_COLOR, row_color,
                       -1);

    g_free(window_info);
    g_free(address);

    if (GTK_IS_CONTAINER(widget))
    {
        for (l = gtk_container_get_children(GTK_CONTAINER(widget));
             l != NULL;
             l = l->next)
        {
            append_widget(model, GTK_WIDGET(l->data), &iter);
        }
    }
}
コード例 #16
0
gboolean
pointer_update (GtkWidget* window)
{
	gint       pointer_rel_x;
	gint       pointer_rel_y;
	gint       pointer_abs_x;
	gint       pointer_abs_y;
	gint       win_x;
	gint       win_y;
	gint       width;
	gint       height;
	gboolean   old_mouse_over;
	gfloat     old_distance = 0;

	if (!GTK_IS_WINDOW (window))
		return FALSE;

	old_mouse_over = g_mouse_over;

	if (gtk_widget_get_realized (window))
	{
		gint distance_x = 0;
		gint distance_y = 0;

		gtk_widget_get_pointer (window, &pointer_rel_x, &pointer_rel_y);
		gtk_window_get_position (GTK_WINDOW (window), &win_x, &win_y);
		pointer_abs_x = win_x + pointer_rel_x;
		pointer_abs_y = win_y + pointer_rel_y;
		gtk_window_get_size (GTK_WINDOW (window), &width, &height);
		if (pointer_abs_x >= win_x &&
		    pointer_abs_x <= win_x + width &&
		    pointer_abs_y >= win_y &&
		    pointer_abs_y <= win_y + height)
			g_mouse_over = TRUE;
		else
			g_mouse_over = FALSE;

		if (pointer_abs_x >= win_x &&
		    pointer_abs_x <= win_x + width)
			distance_x = 0;
		else
		{
			if (pointer_abs_x < win_x)
				distance_x = abs (pointer_rel_x);

			if (pointer_abs_x > win_x + width)
				distance_x = abs (pointer_rel_x - width);
		}

		if (pointer_abs_y >= win_y &&
		    pointer_abs_y <= win_y + height)
			distance_y = 0;
		else
		{
			if (pointer_abs_y < win_y)
				distance_y = abs (pointer_rel_y);

			if (pointer_abs_y > win_y + height)
				distance_y = abs (pointer_rel_y - height);
		}

		old_distance = g_distance;
		g_distance = sqrt (distance_x * distance_x +
				       distance_y * distance_y) /
				       (double) 40;
	}

	if (old_mouse_over != g_mouse_over)
		set_bg_blur (window, !g_mouse_over);

	if (old_distance != g_distance)
		gtk_widget_queue_draw (window);

	return TRUE;
}
コード例 #17
0
static void
dlg_ask_password__common (FrWindow       *window,
			  FrPasswordType  pwd_type)
{
	DialogData *data;
	GtkWidget  *label;
	char       *text;
	char       *name = NULL;

	data = g_new0 (DialogData, 1);

	data->builder = _gtk_builder_new_from_file ("batch-password.ui");
	if (data->builder == NULL) {
		g_free (data);
		return;
	}

	data->window = window;
	data->pwd_type = pwd_type;

	/* Get the widgets. */

	data->dialog = _gtk_builder_get_widget (data->builder, "password_dialog");
	data->pw_password_entry = _gtk_builder_get_widget (data->builder, "pw_password_entry");

	label = _gtk_builder_get_widget (data->builder, "pw_password_label");

	/* Set widgets data. */

	if (data->pwd_type == FR_PASSWORD_TYPE_MAIN)
		name = g_uri_display_basename (fr_window_get_archive_uri (window));
	else if (data->pwd_type == FR_PASSWORD_TYPE_PASTE_FROM)
		name = g_uri_display_basename (fr_window_get_paste_archive_uri (window));
        g_assert (name != NULL);
	text = g_strdup_printf (_("Enter the password for the archive '%s'."), name);
	gtk_label_set_label (GTK_LABEL (label), text);
	g_free (text);
	
	if (fr_window_get_password (window) != NULL)
		_gtk_entry_set_locale_text (GTK_ENTRY (data->pw_password_entry),
					    fr_window_get_password (window));

	/* Set the signals handlers. */

	g_signal_connect (G_OBJECT (data->dialog),
			  "destroy",
			  G_CALLBACK (destroy_cb),
			  data);

	g_signal_connect (G_OBJECT (data->dialog),
			  "response",
			  G_CALLBACK (ask_password__response_cb),
			  data);

	/* Run dialog. */

	gtk_widget_grab_focus (data->pw_password_entry);
	if (gtk_widget_get_realized (GTK_WIDGET (window))) {
		gtk_window_set_transient_for (GTK_WINDOW (data->dialog),
					      GTK_WINDOW (window));
		gtk_window_set_modal (GTK_WINDOW (data->dialog), TRUE);
	}
	else 
		gtk_window_set_title (GTK_WINDOW (data->dialog), name);
	g_free (name);
	
	gtk_widget_show (data->dialog);
}
コード例 #18
0
static void
gcal_month_view_size_allocate (GtkWidget     *widget,
                               GtkAllocation *allocation)
{
  GcalMonthViewPrivate *priv;
  gint i;
  GList *l;

  GtkStyleContext *context;
  GtkStateFlags state;
  GtkBorder padding;
  PangoLayout *layout;
  gint font_height;
  gdouble added_height;

  priv = GCAL_MONTH_VIEW (widget)->priv;

  gtk_widget_set_allocation (widget, allocation);
  if (gtk_widget_get_realized (widget))
    {
      gdk_window_move_resize (priv->event_window,
                              allocation->x,
                              allocation->y,
                              allocation->width,
                              allocation->height);
    }

  context = gtk_widget_get_style_context (widget);
  state = gtk_widget_get_state_flags (widget);
  gtk_style_context_get_padding (context, state, &padding);

  layout = pango_layout_new (gtk_widget_get_pango_context (widget));
  pango_layout_set_font_description (layout,
                                     gtk_style_context_get_font (context,
                                                                 state));
  pango_layout_get_pixel_size (layout, NULL, &font_height);

  /* init values */
  priv->header_font_size = 12;
  priv->horizontal_step =
    (allocation->width - (allocation->x + padding.left + padding.right)) / 7;
  priv->vertical_step =
    (allocation->height - (allocation->y + padding.top + padding.bottom + priv->header_font_size)) / 5;

  for (i = 0; i < 35; i++)
    {
      if (priv->days[i] == NULL)
        continue;
      added_height = 0;
      for (l = priv->days[i]; l != NULL; l = l->next)
        {
          gint pos_x;
          gint pos_y;
          gint min_height;
          gint natural_height;
          GtkAllocation child_allocation;

          pos_x = ( i % 7 ) * priv->horizontal_step;
          pos_y = ( i / 7 ) * priv->vertical_step;

          gtk_widget_get_preferred_height (GTK_WIDGET (l->data),
                                           &min_height,
                                           &natural_height);
          child_allocation.x = pos_x + allocation->x + padding.top;
          child_allocation.y = pos_y + font_height + allocation->y
            + priv->header_font_size + padding.left;
          child_allocation.width = priv->horizontal_step;
          child_allocation.height = MIN (natural_height, priv->vertical_step);
          if (added_height + font_height + child_allocation.height
              > priv->vertical_step)
            {
              gtk_widget_hide (GTK_WIDGET (l->data));
            }
          else
            {
              gtk_widget_show (GTK_WIDGET (l->data));
              child_allocation.y = child_allocation.y + added_height;
              gtk_widget_size_allocate (GTK_WIDGET (l->data), &child_allocation);
              added_height += child_allocation.height;
            }
        }
    }
}
コード例 #19
0
static void
label_window_composited_changed_cb (GtkWidget *widget, CcRRLabeler *labeler)
{
	if (gtk_widget_get_realized (widget))
		maybe_update_shape (widget);
}
コード例 #20
0
gboolean
rb_missing_plugins_install (const char **details, gboolean ignore_blacklist, GClosure *closure)
{
	RBPluginInstallContext *ctx;
	GstInstallPluginsContext *install_ctx;
	GstInstallPluginsReturn status;
	int i, num;

	num = g_strv_length ((char **)details);
	g_return_val_if_fail (num > 0, FALSE);

	ctx = g_new0 (RBPluginInstallContext, 1);
	ctx->closure = g_closure_ref (closure);
	ctx->details = g_strdupv ((char **)details);

	num = g_strv_length (ctx->details);
	for (i = 0; i < num; ++i) {
		if (ignore_blacklist == FALSE && rb_plugin_install_plugin_is_blacklisted (ctx->details[i])) {
			g_message ("Missing plugin: %s (ignoring)", ctx->details[i]);
			g_free (ctx->details[i]);
			ctx->details[i] = ctx->details[num-1];
			ctx->details[num-1] = NULL;
			--num;
			--i;
		} else {
			g_message ("Missing plugin: %s", ctx->details[i]);
		}
	}

	if (num == 0) {
		g_message ("All missing plugins are blacklisted, doing nothing");
		rb_plugin_install_context_free (ctx);
		return FALSE;
	}

	install_ctx = gst_install_plugins_context_new ();

	if (parent_window != NULL && gtk_widget_get_realized (GTK_WIDGET (parent_window))) {
#ifdef GDK_WINDOWING_X11
		gulong xid = 0;
		xid = gdk_x11_window_get_xid (gtk_widget_get_window (GTK_WIDGET (parent_window)));
		gst_install_plugins_context_set_xid (install_ctx, xid);
#endif
	}

	status = gst_install_plugins_async (ctx->details, install_ctx,
	                                    on_plugin_installation_done,
	                                    ctx);

	gst_install_plugins_context_free (install_ctx);

	rb_debug ("gst_install_plugins_async() result = %d", status);

	if (status != GST_INSTALL_PLUGINS_STARTED_OK) {
		if (status == GST_INSTALL_PLUGINS_HELPER_MISSING) {
			g_message ("Automatic missing codec installation not supported "
			           "(helper script missing)");
		} else {
			g_warning ("Failed to start codec installation: %s",
			           gst_install_plugins_return_get_name (status));
		}
		rb_plugin_install_context_free (ctx);
		return FALSE;
	}

	return TRUE;
}
コード例 #21
0
ファイル: canvas.cpp プロジェクト: Cydrak/dasShiny
void pCanvas::update() {
  memcpy(cairo_image_surface_get_data(surface), canvas.state.data, canvas.state.width * canvas.state.height * sizeof(uint32_t));
  if(gtk_widget_get_realized(gtkWidget) == false) return;
  gdk_window_invalidate_rect(gtk_widget_get_window(gtkWidget), nullptr, true);
}
コード例 #22
0
ファイル: gimpview.c プロジェクト: Hboybowen/gimp
static void
gimp_view_size_allocate (GtkWidget     *widget,
                         GtkAllocation *allocation)
{
    GimpView *view = GIMP_VIEW (widget);
    gint      width;
    gint      height;

    if (view->expand)
    {
        width  = MIN (GIMP_VIEWABLE_MAX_PREVIEW_SIZE,
                      allocation->width - 2 * view->renderer->border_width);
        height = MIN (GIMP_VIEWABLE_MAX_PREVIEW_SIZE,
                      allocation->height - 2 * view->renderer->border_width);

        if (view->renderer->width  != width ||
                view->renderer->height != height)
        {
            gint border_width = view->renderer->border_width;

            if (view->renderer->size != -1 && view->renderer->viewable)
            {
                gint view_width;
                gint view_height;
                gint scaled_width;
                gint scaled_height;

                gimp_viewable_get_preview_size (view->renderer->viewable,
                                                GIMP_VIEWABLE_MAX_PREVIEW_SIZE,
                                                view->renderer->is_popup,
                                                view->renderer->dot_for_dot,
                                                &view_width,
                                                &view_height);

                gimp_viewable_calc_preview_size (view_width, view_height,
                                                 width, height,
                                                 TRUE, 1.0, 1.0,
                                                 &scaled_width, &scaled_height,
                                                 NULL);

                if (scaled_width > width)
                {
                    scaled_height = scaled_height * width / scaled_width;
                    scaled_width  = scaled_width  * width / scaled_width;
                }
                else if (scaled_height > height)
                {
                    scaled_width  = scaled_width  * height / scaled_height;
                    scaled_height = scaled_height * height / scaled_height;
                }

                gimp_view_renderer_set_size (view->renderer,
                                             MAX (scaled_width, scaled_height),
                                             border_width);
            }
            else
            {
                gimp_view_renderer_set_size_full (view->renderer,
                                                  width, height,
                                                  border_width);
            }

            gimp_view_renderer_remove_idle (view->renderer);
        }
    }

    width  = (view->renderer->width +
              2 * view->renderer->border_width);
    height = (view->renderer->height +
              2 * view->renderer->border_width);

    if (allocation->width > width)
        allocation->x += (allocation->width - width) / 2;

    if (allocation->height > height)
        allocation->y += (allocation->height - height) / 2;

    allocation->width  = width;
    allocation->height = height;

    gtk_widget_set_allocation (widget, allocation);

    if (gtk_widget_get_realized (widget))
        gdk_window_move_resize (view->event_window,
                                allocation->x,
                                allocation->y,
                                allocation->width,
                                allocation->height);
}
コード例 #23
0
ファイル: sheet.c プロジェクト: manasdas17/oregano-1
/*
 * position within the sheet in pixel coordinates
 * coordinates are clamped to grid if grid is enabled
 * see snap_to_grid
 * zero point : top left corner of the window (not widget!)
 * x : horizontal, left to right
 * y : vertical, top to bottom
 * returns wether the position could be detected properly
 */
gboolean
sheet_get_pointer_pixel (Sheet *sheet, gdouble *x, gdouble *y)
{
	GtkAdjustment *hadj = NULL, *vadj = NULL;
	gdouble x1, y1;
	gint _x, _y;
	GdkDeviceManager *device_manager;
	GdkDevice *device_pointer;
	GdkRectangle allocation;
	GdkDisplay *display;
	GdkWindow *window;

	// deprecated gtk_widget_get_pointer (GTK_WIDGET (sheet), &_x, &_y);
	// replaced by a code copied from evince

	if (G_UNLIKELY (!sheet || !gtk_widget_get_realized (GTK_WIDGET (sheet)))) {
		NG_DEBUG ("Widget is not realized.");
		return FALSE;
	}

	display = gtk_widget_get_display (GTK_WIDGET (sheet));
	device_manager = gdk_display_get_device_manager (display);
	// gdk_device_manager_get_client_pointer
	// shall not be used within events
	device_pointer = gdk_device_manager_get_client_pointer (device_manager);
	window = gtk_widget_get_window (GTK_WIDGET (sheet));

	if (!window) {
		NG_DEBUG ("Window is not realized.");
		return FALSE;
	}
	// even though above is all defined the below will always return NUL for
	// unknown reason and _x and _y are populated as expected
	gdk_window_get_device_position (
	                window,
					device_pointer,
					&_x, &_y, NULL);
#if 0
	if (!window) { //fails always
		NG_DEBUG ("Window does not seem to be realized yet?");
		return FALSE;
	}
#else
	NG_DEBUG ("\n%p %p %p %p %i %i\n\n",display, device_manager, device_pointer, window, _x, _y);
#endif


	gtk_widget_get_allocation (GTK_WIDGET (sheet), &allocation);

	_x -= allocation.x;
	_y -= allocation.y;

	x1 = (gdouble) _x;
	y1 = (gdouble) _y;

	if (!sheet_get_adjustments (sheet, &hadj, &vadj))
	      return FALSE;

	x1 += gtk_adjustment_get_value (hadj);
	y1 += gtk_adjustment_get_value (vadj);

	*x = x1;
	*y = y1;
	return TRUE;
}
コード例 #24
0
ファイル: gimpview.c プロジェクト: Hboybowen/gimp
static gboolean
gimp_view_button_press_event (GtkWidget      *widget,
                              GdkEventButton *bevent)
{
    GimpView *view = GIMP_VIEW (widget);

#ifdef DEBUG_MEMSIZE
    if (bevent->type == GDK_BUTTON_PRESS && bevent->button == 2)
    {
        gimp_debug_memsize = TRUE;

        gimp_object_get_memsize (GIMP_OBJECT (view->viewable), NULL);

        gimp_debug_memsize = FALSE;
    }
#endif /* DEBUG_MEMSIZE */

    if (! view->clickable &&
            ! view->show_popup)
        return FALSE;

    if (! gtk_widget_get_realized (widget))
        return FALSE;

    if (bevent->type == GDK_BUTTON_PRESS)
    {
        if (gdk_event_triggers_context_menu ((GdkEvent *) bevent))
        {
            view->press_state = 0;

            g_signal_emit (widget, view_signals[CONTEXT], 0);
        }
        else if (bevent->button == 1)
        {
            gtk_grab_add (widget);

            view->has_grab    = TRUE;
            view->press_state = bevent->state;

            if (view->show_popup && view->viewable)
            {
                gimp_view_popup_show (widget, bevent,
                                      view->renderer->context,
                                      view->viewable,
                                      view->renderer->width,
                                      view->renderer->height,
                                      view->renderer->dot_for_dot);
            }
        }
        else
        {
            view->press_state = 0;

            if (bevent->button == 2)
                gimp_view_popup_show (widget, bevent,
                                      view->renderer->context,
                                      view->viewable,
                                      view->renderer->width,
                                      view->renderer->height,
                                      view->renderer->dot_for_dot);

            return FALSE;
        }
    }
    else if (bevent->type == GDK_2BUTTON_PRESS)
    {
        if (bevent->button == 1)
            g_signal_emit (widget, view_signals[DOUBLE_CLICKED], 0);
    }

    return view->eat_button_events ? TRUE : FALSE;
}
コード例 #25
0
ファイル: window_gtk.cpp プロジェクト: 112000/opencv
static void
cvImageWidget_size_allocate (GtkWidget     *widget,
                        GtkAllocation *allocation)
{
  CvImageWidget *image_widget;

  //printf("cvImageWidget_size_allocate\n");
  g_return_if_fail (widget != NULL);
  g_return_if_fail (CV_IS_IMAGE_WIDGET (widget));
  g_return_if_fail (allocation != NULL);

#if defined (GTK_VERSION3)
  gtk_widget_set_allocation(widget, allocation);
#else
  widget->allocation = *allocation;
#endif //GTK_VERSION3
  image_widget = CV_IMAGE_WIDGET (widget);


  if( (image_widget->flags & CV_WINDOW_AUTOSIZE)==0 && image_widget->original_image ){
      // (re) allocated scaled image
      if( image_widget->flags & CV_WINDOW_NO_IMAGE ){
          cvImageWidget_set_size( widget, image_widget->original_image->cols,
                                          image_widget->original_image->rows);
      }
      else{
          cvImageWidget_set_size( widget, allocation->width, allocation->height );
      }
      cvResize( image_widget->original_image, image_widget->scaled_image, CV_INTER_AREA );
  }

  if (gtk_widget_get_realized (widget))
    {
      image_widget = CV_IMAGE_WIDGET (widget);

      if( image_widget->original_image &&
              ((image_widget->flags & CV_WINDOW_AUTOSIZE) ||
               (image_widget->flags & CV_WINDOW_NO_IMAGE)) )
      {
#if defined (GTK_VERSION3)
          allocation->width = image_widget->original_image->cols;
          allocation->height = image_widget->original_image->rows;
          gtk_widget_set_allocation(widget, allocation);
#else
          widget->allocation.width = image_widget->original_image->cols;
          widget->allocation.height = image_widget->original_image->rows;
#endif //GTK_VERSION3
          gdk_window_move_resize( gtk_widget_get_window(widget),
              allocation->x, allocation->y,
              image_widget->original_image->cols, image_widget->original_image->rows );
          if(image_widget->flags & CV_WINDOW_NO_IMAGE){
              image_widget->flags &= ~CV_WINDOW_NO_IMAGE;
              gtk_widget_queue_resize( GTK_WIDGET(widget) );
          }
      }
      else{
          gdk_window_move_resize (gtk_widget_get_window(widget),
                  allocation->x, allocation->y,
                  allocation->width, allocation->height );
      }
    }
}
コード例 #26
0
static void
emoticon_tool_button_popup (EEmoticonToolButton *button)
{
	GtkToggleToolButton *tool_button;
	GdkWindow *window;
	gboolean grab_status;
	GdkDevice *device, *mouse, *keyboard;
	guint32 activate_time;

	device = gtk_get_current_event_device ();
	g_return_if_fail (device != NULL);

	if (!gtk_widget_get_realized (GTK_WIDGET (button)))
		return;

	if (button->priv->popup_shown)
		return;

	activate_time = gtk_get_current_event_time ();
	if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) {
		keyboard = device;
		mouse = gdk_device_get_associated_device (device);
	} else {
		keyboard = gdk_device_get_associated_device (device);
		mouse = device;
	}

	/* Position the window over the button. */
	emoticon_tool_button_reposition_window (button);

	/* Show the pop-up. */
	gtk_widget_show (button->priv->window);
	gtk_widget_grab_focus (button->priv->window);

	/* Activate the tool button. */
	tool_button = GTK_TOGGLE_TOOL_BUTTON (button);
	gtk_toggle_tool_button_set_active (tool_button, TRUE);

	/* Try to grab the pointer and keyboard. */
	window = gtk_widget_get_window (button->priv->window);
	grab_status = !keyboard ||
		gdk_device_grab (
			keyboard, window,
			GDK_OWNERSHIP_WINDOW, TRUE,
			GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
			NULL, activate_time) == GDK_GRAB_SUCCESS;
	if (grab_status) {
		grab_status = !mouse ||
			gdk_device_grab (mouse, window,
				GDK_OWNERSHIP_WINDOW, TRUE,
				GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK,
				NULL, activate_time) == GDK_GRAB_SUCCESS;
		if (!grab_status && keyboard)
			gdk_device_ungrab (keyboard, activate_time);
	}

	if (grab_status) {
		gtk_device_grab_add (button->priv->window, mouse, TRUE);
		button->priv->grab_keyboard = keyboard;
		button->priv->grab_mouse = mouse;
	} else {
		gtk_widget_hide (button->priv->window);
	}
}
コード例 #27
0
void budgie_popover_present(BudgiePopover *self,
                            GtkWidget *parent,
                            GdkEventButton *event)
{
        GtkWidget *real_parent;
        GdkWindow *parent_window;
        gint x, y, tx, ty, rx, margin;
        GdkScreen *screen;
        GtkAllocation alloc, our_alloc;
        GdkDeviceManager *manager;
        gint32 time;

        if (event) {
                x = event->x;
                y = event->y;
        }

        if (gtk_widget_get_visible(GTK_WIDGET(self))) {
                budgie_popover_hide(self);
                return;
        }
        if (!gtk_widget_get_realized(GTK_WIDGET(self)))
                gtk_widget_realize(GTK_WIDGET(self));

        /* Get position of parent widget on screen */
        real_parent = gtk_widget_get_toplevel(parent);
        parent_window = gtk_widget_get_window(real_parent);
        gdk_window_get_position(parent_window, &x, &y);
        gtk_widget_translate_coordinates(parent, real_parent, x, y, &tx, &ty);

        gtk_widget_get_allocation(parent, &alloc);
        gtk_widget_get_allocation(GTK_WIDGET(self), &our_alloc);
        screen = gtk_widget_get_screen(GTK_WIDGET(self));

        /* Ensure we're in a sensible position (under/over) */
        if (ty + our_alloc.height + 11 < gdk_screen_get_height(screen)) {
                self->top = TRUE;
                ty = y+alloc.y+alloc.height;
        } else {
                ty = (y+alloc.y)-our_alloc.height;
                self->top = FALSE;
        }

        /* Ensure widg_x is within bounds */
        if (event) {
                /* Point tip to mouse x,y */
                rx = event->x;
        } else {
                /* Center the tip when there is no event */
                rx = alloc.x + (alloc.width/2);
        }
        /* ensure margin is accounted for */
        g_object_get(parent, "margin", &margin, NULL);
        tx -= margin;
        rx -= margin;
        if (rx >= our_alloc.width)
                rx = our_alloc.width - 18;
        if (rx <= 18)
                rx = 18;
        self->widg_x = rx;


        gtk_window_move(GTK_WINDOW(self), tx-11, ty);
        gtk_widget_show_all(GTK_WIDGET(self));
        if (event) {
                self->pointer = event->device;
                time = event->time;
        } else {
                manager = gdk_display_get_device_manager(gdk_screen_get_display(screen));
                self->pointer = gdk_device_manager_get_client_pointer(manager);
                time = GDK_CURRENT_TIME;
        }
        self->parent_widget = real_parent;
        self->con_id = g_signal_connect(real_parent, "button-press-event", G_CALLBACK(button_press), self);
        self->con_id = 0;
        /* TODO: Handle keyboard grab too */
        popup_grab_on_window(gtk_widget_get_window(GTK_WIDGET(real_parent)),
                NULL, self->pointer, time);
}
コード例 #28
0
static void pizza_size_allocate(GtkWidget* widget, GtkAllocation* alloc)
{
    wxPizza* pizza = WX_PIZZA(widget);
    GtkBorder border;
    pizza->get_border(border);
    int w = alloc->width - border.left - border.right;
    if (w < 0) w = 0;

    if (gtk_widget_get_realized(widget))
    {
        int h = alloc->height - border.top - border.bottom;
        if (h < 0) h = 0;
        const int x = alloc->x + border.left;
        const int y = alloc->y + border.top;

        GdkWindow* window = gtk_widget_get_window(widget);
        int old_x, old_y;
        gdk_window_get_position(window, &old_x, &old_y);

        if (x != old_x || y != old_y ||
            w != gdk_window_get_width(window) || h != gdk_window_get_height(window))
        {
            gdk_window_move_resize(window, x, y, w, h);

            if (border.left + border.right + border.top + border.bottom)
            {
                // old and new border areas need to be invalidated,
                // otherwise they will not be erased/redrawn properly
                GtkAllocation old_alloc;
                gtk_widget_get_allocation(widget, &old_alloc);
                GdkWindow* parent = gtk_widget_get_parent_window(widget);
                gdk_window_invalidate_rect(parent, &old_alloc, false);
                gdk_window_invalidate_rect(parent, alloc, false);
            }
        }
    }

    gtk_widget_set_allocation(widget, alloc);

    // adjust child positions
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
    for (const GList* p = pizza->m_children; p; p = p->next)
    {
        const wxPizzaChild* child = static_cast<wxPizzaChild*>(p->data);
        if (gtk_widget_get_visible(child->widget))
        {
            GtkAllocation child_alloc;
            // note that child positions do not take border into
            // account, they need to be relative to widget->window,
            // which has already been adjusted
            child_alloc.x = child->x - pizza->m_scroll_x;
            child_alloc.y = child->y - pizza->m_scroll_y;
            child_alloc.width  = child->width;
            child_alloc.height = child->height;
            if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
                child_alloc.x = w - child_alloc.x - child_alloc.width;
            gtk_widget_size_allocate(child->widget, &child_alloc);
        }
    }
}
コード例 #29
0
ファイル: gtk-reftest.c プロジェクト: RavikumarTulugu/antkorp
static cairo_surface_t *
snapshot_widget (GtkWidget *widget, SnapshotMode mode)
{
    cairo_surface_t *surface;
    cairo_pattern_t *bg;
    GMainLoop *loop;
    cairo_t *cr;

    g_assert (gtk_widget_get_realized (widget));

    surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget),
              CAIRO_CONTENT_COLOR,
              gtk_widget_get_allocated_width (widget),
              gtk_widget_get_allocated_height (widget));

    loop = g_main_loop_new (NULL, FALSE);
    /* We wait until the widget is drawn for the first time.
     * We can not wait for a GtkWidget::draw event, because that might not
     * happen if the window is fully obscured by windowed child widgets.
     * Alternatively, we could wait for an expose event on widget's window.
     * Both of these are rather hairy, not sure what's best. */
    gdk_event_handler_set (check_for_draw, loop, NULL);
    g_main_loop_run (loop);

    cr = cairo_create (surface);

    switch (mode)
    {
    case SNAPSHOT_WINDOW:
    {
        GdkWindow *window = gtk_widget_get_window (widget);
        if (gdk_window_get_window_type (window) == GDK_WINDOW_TOPLEVEL ||
                gdk_window_get_window_type (window) == GDK_WINDOW_FOREIGN)
        {
            /* give the WM/server some time to sync. They need it.
             * Also, do use popups instead of toplevls in your tests
             * whenever you can. */
            gdk_display_sync (gdk_window_get_display (window));
            g_timeout_add (500, quit_when_idle, loop);
            g_main_loop_run (loop);
        }
        gdk_cairo_set_source_window (cr, window, 0, 0);
        cairo_paint (cr);
    }
    break;
    case SNAPSHOT_DRAW:
        bg = gdk_window_get_background_pattern (gtk_widget_get_window (widget));
        if (bg)
        {
            cairo_set_source (cr, bg);
            cairo_paint (cr);
        }
        gtk_widget_draw (widget, cr);
        break;
    default:
        g_assert_not_reached();
        break;
    }

    cairo_destroy (cr);
    g_main_loop_unref (loop);
    gtk_widget_destroy (widget);

    return surface;
}
コード例 #30
0
static void
gdu_format_volume_dialog_show_internal (UDisksClient *client,
                                        GtkWindow    *parent_window,
                                        gint          parent_xid,
                                        UDisksObject *object)
{
  GduApplication *app = GDU_APPLICATION (g_application_get_default ());
  FormatVolumeData *data;
  gint response;

  data = g_new0 (FormatVolumeData, 1);
  data->parent_window = (parent_window != NULL) ? g_object_ref (parent_window) : NULL;
  data->object = g_object_ref (object);
  data->block = udisks_object_get_block (object);
  g_assert (data->block != NULL);
  data->drive = udisks_client_get_drive_for_block (client, data->block);

  data->dialog = GTK_WIDGET (gdu_application_new_widget (app,
                                                         "format-volume-dialog.ui",
                                                         "format-volume-dialog",
                                                         &data->builder));

  data->contents_box = GTK_WIDGET (gtk_builder_get_object (data->builder, "contents-box"));
  data->create_filesystem_widget = gdu_create_filesystem_widget_new (app,
                                                                     data->drive,
                                                                     NULL); /* additional_fstypes */
  gtk_box_pack_start (GTK_BOX (data->contents_box),
                      data->create_filesystem_widget,
                      TRUE, TRUE, 0);
  g_signal_connect (data->create_filesystem_widget, "notify::has-info",
                    G_CALLBACK (format_volume_property_changed), data);

  if (parent_window != NULL)
    {
      gtk_window_set_transient_for (GTK_WINDOW (data->dialog), parent_window);
    }
  else if (parent_xid != -1)
    {
      GdkWindow *foreign_window = gdk_x11_window_foreign_new_for_display (gdk_display_get_default (), parent_xid);
      if (!gtk_widget_get_realized (data->dialog))
          gtk_widget_realize (data->dialog);
      gdk_window_set_transient_for (gtk_widget_get_window (data->dialog), foreign_window);
    }

  gtk_dialog_set_default_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK);

  format_volume_update (data);

  gtk_widget_show_all (data->dialog);
  gtk_widget_grab_focus (gdu_create_filesystem_widget_get_name_entry (GDU_CREATE_FILESYSTEM_WIDGET (data->create_filesystem_widget)));

  response = gtk_dialog_run (GTK_DIALOG (data->dialog));
  if (response == GTK_RESPONSE_OK)
    {
      const gchar *primary_message;
      const gchar *erase_type;
      GString *str;
      GList *objects = NULL;

      gtk_widget_hide (data->dialog);

      erase_type = gdu_create_filesystem_widget_get_erase (GDU_CREATE_FILESYSTEM_WIDGET (data->create_filesystem_widget));

      primary_message = _("Are you sure you want to format the volume?");
      if (erase_type == NULL || g_strcmp0 (erase_type, "") == 0)
        {
          /* Translators: warning used for quick format of the volume*/
          str = g_string_new (_("All data on the volume will be lost but may still be recoverable by data recovery services"));
          g_string_append (str, "\n\n");
          g_string_append (str, _("<b>Tip</b>: If you are planning to recycle, sell or give away your old computer or disk, you should use a more thorough erase type to keep your private information from falling into the wrong hands"));
        }
      else
        {
          /* Translators: warning used when overwriting data of the volume */
          str = g_string_new (_("All data on the volume will be overwritten and will likely not be recoverable by data recovery services"));
        }

      objects = g_list_append (NULL, object);
      if (!gdu_utils_show_confirmation (GTK_WINDOW (data->parent_window),
                                        primary_message,
                                        str->str,
                                        _("_Format"),
                                        NULL, NULL,
                                        client, objects))
        {
          g_list_free (objects);
          g_string_free (str, TRUE);
          goto out;
        }

      g_list_free (objects);
      g_string_free (str, TRUE);

      /* ensure the volume is unused (e.g. unmounted) before formatting it... */
      gdu_utils_ensure_unused (client,
                               GTK_WINDOW (data->parent_window),
                               data->object,
                               (GAsyncReadyCallback) ensure_unused_cb,
                               NULL, /* GCancellable */
                               data);
      return;
    }
 out:
  format_volume_data_free (data);
}