static void
menu_position (GtkMenu  *menu,
               gint     *x,
               gint     *y,
               gboolean *push_in,
               gpointer  entry)
{
  GtkRequisition entry_request;
  GtkRequisition menu_request;
  GdkRectangle   geometry;
  GdkScreen     *screen;
  GtkWidget     *toplevel = gtk_widget_get_toplevel (entry);
  gint           monitor;
  gint           x0;
  gint           y0;

  gtk_widget_translate_coordinates (GTK_WIDGET (entry), toplevel, 0, 0, &x0, &y0);

  gtk_widget_size_request (GTK_WIDGET (entry), &entry_request);
  gtk_widget_size_request (GTK_WIDGET (menu), &menu_request);

  gdk_window_get_position (GTK_WIDGET (entry)->window, x, y);

  *x += x0 + gtk_container_get_border_width (GTK_CONTAINER (entry));
  *y += y0 + (entry_request.height - gtk_container_get_border_width (GTK_CONTAINER (entry)));

  /* verify the the menu is on-screen */
  screen = gtk_widget_get_screen (GTK_WIDGET (entry));
  if (G_LIKELY (screen != NULL))
    {
      monitor = gdk_screen_get_monitor_at_point (screen, *x, *y);
      gdk_screen_get_monitor_geometry (screen, monitor, &geometry);
      if (*y + menu_request.height > geometry.y + geometry.height)
        *y -= menu_request.height - entry_request.height;
    }

  *push_in = TRUE;
}
Ejemplo n.º 2
0
GdkPixmap *make_pixmap(GtkScrollbox *self, gchar *value)
{
        GdkWindow *rootwin;
        PangoLayout *pl;
        gint width, height, middle;
        GdkPixmap *pixmap;
        GtkRequisition widgsize = {0, }; 
        GtkWidget *widget = (GtkWidget *)self;
        

	/* If we can't draw yet, don't do anything to avoid screwing things */
	if (!GDK_IS_GC(widget->style->bg_gc[0]))
		return NULL;

        rootwin = gtk_widget_get_root_window(widget);

        pl = gtk_widget_create_pango_layout(widget, NULL);
        pango_layout_set_markup(pl, value, -1);

        pango_layout_get_pixel_size(pl, &width, &height);

        pixmap = gdk_pixmap_new(GDK_DRAWABLE(rootwin), width, height, -1);

        gdk_draw_rectangle(GDK_DRAWABLE(pixmap), 
                        widget->style->bg_gc[0],
                        TRUE, 0, 0, width, height);

        gdk_draw_layout(GDK_DRAWABLE(pixmap), widget->style->fg_gc[0], 0, 0, pl);

        g_object_unref(pl);

        gtk_widget_size_request(widget, &widgsize);

        if (width <= widgsize.width)
                width = widgsize.width;

        if (height <= widgsize.height)
                height = widgsize.height;
        else
                self->draw_maxoffset = -height;

        if (width != widgsize.width || height != widgsize.height)
                gtk_widget_set_size_request(widget, width, height);

        middle = width / 2;
        if (self->draw_maxmiddle < middle)
                self->draw_maxmiddle = middle;

        return pixmap;
}
Ejemplo n.º 3
0
static gboolean
use_scrolled_window (GtkSourceCompletionInfo *info,
                     GtkWidget               *widget)
{
	GtkRequisition req;
	gint mw;
	gint mh;
	
	mw = info->priv->max_width;
	mh = info->priv->max_height;
	gtk_widget_size_request (widget, &req);
	
	return (mw != -1 && mw < req.width) || (mh != -1 && mh < req.height);
}
Ejemplo n.º 4
0
static gboolean
avatar_image_expose_event (GtkWidget      *widget,
			   GdkEventExpose *event)
{
	GiggleAvatarImagePriv *priv = GET_PRIV (widget);
	GtkAllocation          allocation;
	GtkRequisition         requisition;
	GtkStyle              *style;
	float                  xalign, yalign;
	double                 x, y;
	int                    w, h;
	cairo_t               *cr;

	gtk_widget_size_request (widget, &requisition);
	gtk_widget_get_allocation (widget, &allocation);
	style = gtk_widget_get_style (widget);

	cr = gdk_cairo_create (event->window);
	gdk_cairo_region (cr, event->region);
	cairo_clip (cr);

	w = requisition.width;
	h = requisition.height;

	gtk_misc_get_alignment (GTK_MISC (widget), &xalign, &yalign);

	cairo_translate
		(cr, (int) ((allocation.width - w) * xalign),
		 (int) ((allocation.height - h) * yalign));

	rounded_rectangle (cr, 0.5, 0.5, w - 1, h - 1, MIN (w, h) * 0.2);
	gdk_cairo_set_source_color (cr, &style->base[GTK_STATE_NORMAL]);
	cairo_fill_preserve (cr);

	if (priv->pixbuf) {
		x = (w - gdk_pixbuf_get_width (priv->pixbuf)) * 0.5;
		y = (h - gdk_pixbuf_get_height (priv->pixbuf)) * 0.5;

		gdk_cairo_set_source_pixbuf (cr, priv->pixbuf, x, y);
		cairo_fill_preserve (cr);
	}

	gdk_cairo_set_source_color (cr, &style->text[GTK_STATE_NORMAL]);
	cairo_set_line_width (cr, 1);
	cairo_stroke (cr);

	cairo_destroy (cr);

	return TRUE;
}
Ejemplo n.º 5
0
Explorer* explorer_new(IterativeMap *map, Animation *animation) {
    Explorer *self = EXPLORER(g_object_new(explorer_get_type(), NULL));
    GtkWidget *editor, *window, *scroll;
    GtkRequisition win_req;

    self->animation = ANIMATION(g_object_ref(animation));
    self->map = ITERATIVE_MAP(g_object_ref(map));

    /* Create the parameter editor */
    editor = parameter_editor_new(PARAMETER_HOLDER(map));
    gtk_box_pack_start(GTK_BOX(glade_xml_get_widget(self->xml, "parameter_editor_box")),
		       editor, FALSE, FALSE, 0);
    gtk_widget_show_all(editor);

    /* Create the view */
    self->view = histogram_view_new(HISTOGRAM_IMAGER(map));
    gtk_container_add(GTK_CONTAINER(glade_xml_get_widget(self->xml, "drawing_area_viewport")), self->view);
    gtk_widget_show_all(self->view);

    /* Set the initial render time */
    on_render_time_changed(glade_xml_get_widget(self->xml, "render_time"), self);

    explorer_init_history(self);
    explorer_init_animation(self);
    explorer_init_tools(self);
    explorer_init_cluster(self);
    explorer_init_about(self);

    /* Start the iterative map rendering in the background, and get a callback every time a block
     * of calculations finish so we can update the GUI.
     */
    iterative_map_start_calculation(self->map);
    g_signal_connect(G_OBJECT(self->map), "calculation-finished",
		     G_CALLBACK(on_calculation_finished), self);

    /* Set the window's default size to include our default image size.
     * The cleanest way I know of to do this is to set the scrolled window's scrollbar policies
     * to 'never' and get the window's size requests, set them back to automatic, then set the
     * default size to that size request.
     */
    window = glade_xml_get_widget(self->xml, "explorer_window");
    scroll = glade_xml_get_widget(self->xml, "main_scrolledwindow");
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_NEVER, GTK_POLICY_NEVER);
    gtk_widget_size_request(window, &win_req);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    gtk_window_set_default_size(GTK_WINDOW(window), win_req.width, win_req.height);
    gtk_widget_show(window);

    return self;
}
static void
gdl_dock_item_grip_size_request (GtkWidget      *widget,
                                 GtkRequisition *requisition)
{
    GtkRequisition   child_requisition;
    GtkContainer    *container;
    GdlDockItemGrip *grip;
    gint             layout_height;

    g_return_if_fail (GDL_IS_DOCK_ITEM_GRIP (widget));
    g_return_if_fail (requisition != NULL);

    container = GTK_CONTAINER (widget);
    grip = GDL_DOCK_ITEM_GRIP (widget);
    
    requisition->width = container->border_width * 2 + ALIGN_BORDER;
    requisition->height = container->border_width * 2;

    ensure_title_and_icon_pixbuf (grip);
    pango_layout_get_pixel_size (grip->_priv->title_layout, NULL, &layout_height);

    gtk_widget_size_request (grip->_priv->close_button, &child_requisition);

    requisition->width += child_requisition.width;
    layout_height = MAX (layout_height, child_requisition.height);
    
    gtk_widget_size_request (grip->_priv->iconify_button, &child_requisition);

    requisition->width += child_requisition.width;
    layout_height = MAX (layout_height, child_requisition.height);
    
    requisition->height += layout_height;

    if (grip->_priv->icon_pixbuf) {
        requisition->width += gdk_pixbuf_get_width (grip->_priv->icon_pixbuf) + 1;
    }
}
Ejemplo n.º 7
0
static void
acw_selection_changed_lcb(GtkTreeSelection * selection, Tacwin * acw)
{
	GtkTreeModel *model;
	GtkTreeIter iter;
	BluefishTextView *master = BLUEFISH_TEXT_VIEW(acw->btv->master);
	DBG_AUTOCOMP("acw_selection_changed_lcb, in_fill=%d\n",acw->in_fill);
	if (acw->in_fill)
		return;

	if (!g_array_index(master->bflang->st->contexts, Tcontext, acw->contextnum).patternhash
		|| !main_v->props.show_autocomp_reference)
		return;

	if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
		gchar *key;
		gtk_tree_model_get(model, &iter, 1, &key, -1);
		if (key) {
			DBG_AUTOCOMP("lookup reference for %s\n",key);
			gint pattern_id =
				GPOINTER_TO_INT(g_hash_table_lookup
								(g_array_index
								 (master->bflang->st->contexts, Tcontext, acw->contextnum).patternhash, key));
			DBG_AUTOCOMP("got pattern_id %d for key %s\n",pattern_id, key);
			g_free(key);
			if (pattern_id && g_array_index(master->bflang->st->matches, Tpattern, pattern_id).reference) {
				GtkRequisition requisition;
				DBG_AUTOCOMP("acw_selection_changed_lcb, show %s\n",
							 g_array_index(master->bflang->st->matches, Tpattern, pattern_id).reference);
				gtk_label_set_markup(GTK_LABEL(acw->reflabel),
									 g_array_index(master->bflang->st->matches, Tpattern,
												   pattern_id).reference);
				gtk_widget_show(acw->reflabel);
#if GTK_CHECK_VERSION(3,0,0)
				gtk_widget_get_preferred_size(acw->reflabel, &requisition, NULL);
#else
				gtk_widget_size_request(acw->reflabel, &requisition);
#endif
				/*gtk_window_get_size(GTK_WINDOW(acw->win),&width,&height); */
				acw->w = acw->listwidth + requisition.width + 2;
				gtk_widget_set_size_request(acw->win, acw->w, (acw->h<350)?350:-1);
				return;
			}
		}
	}
	gtk_widget_hide(acw->reflabel);
	acw->w = acw->listwidth;
	gtk_widget_set_size_request(acw->win, acw->listwidth, -1);
}
Ejemplo n.º 8
0
Archivo: gitg-utils.c Proyecto: hb/gitg
void
gitg_utils_menu_position_under_tree_view (GtkMenu  *menu,
        gint     *x,
        gint     *y,
        gboolean *push_in,
        gpointer  user_data)
{
    GtkTreeView *tree = GTK_TREE_VIEW (user_data);
    GtkTreeModel *model;
    GtkTreeSelection *selection;
    GtkTreeIter iter;

    model = gtk_tree_view_get_model (tree);
    g_return_if_fail (model != NULL);

    selection = gtk_tree_view_get_selection (tree);
    g_return_if_fail (selection != NULL);

    if (gtk_tree_selection_get_selected (selection, NULL, &iter))
    {
        GtkTreePath *path;
        GdkRectangle rect;

        gdk_window_get_origin (GTK_WIDGET (tree)->window, x, y);

        path = gtk_tree_model_get_path (model, &iter);
        gtk_tree_view_get_cell_area (tree, path,
                                     gtk_tree_view_get_column (tree, 0), /* FIXME 0 for RTL ? */
                                     &rect);
        gtk_tree_path_free (path);

        *x += rect.x;
        *y += rect.y + rect.height;

        if (gtk_widget_get_direction (GTK_WIDGET (tree)) == GTK_TEXT_DIR_RTL)
        {
            GtkRequisition requisition;
            gtk_widget_size_request (GTK_WIDGET (menu), &requisition);
            *x += rect.width - requisition.width;
        }
    }
    else
    {
        /* no selection -> regular "under widget" positioning */
        gitg_utils_menu_position_under_widget (menu,
                                               x, y, push_in,
                                               tree);
    }
}
Ejemplo n.º 9
0
int TextWidth(const char *str)
{
    // Uses a dummy label widget to retrieve the requested width from str
    static GtkWidget *lab = NULL;
    
    if (!lab)
        lab = gtk_label_new(str);
    else
        gtk_label_set(GTK_LABEL(lab), str);
    
    GtkRequisition req;
    gtk_widget_size_request(lab, &req);
    
    return req.width;
}
Ejemplo n.º 10
0
int gSlider::getDefaultSize()
{
	GtkRequisition req;
	
#ifdef GTK3
	gtk_widget_get_preferred_size(widget, &req, NULL);
#else
	gtk_widget_size_request(widget, &req);
#endif
	
	if (width() < height())
		return req.width;
	else
		return req.height;
}
Ejemplo n.º 11
0
static gint
cpufreq_applet_get_max_unit_width (CPUFreqApplet *applet)
{
	GtkWidget     *label;
	GtkRequisition req;
	gint           w1, w2;

	if (applet->max_unit_width > 0)
		return applet->max_unit_width;

	label = gtk_label_new ("GHz");
	gtk_widget_size_request (label, &req);
	w1 = req.width;

	gtk_label_set_text (GTK_LABEL (label), "MHz");
	gtk_widget_size_request (label, &req);
	w2 = req.width;

	gtk_widget_destroy (label);

	applet->max_unit_width = MAX (w1, w2);

	return applet->max_unit_width;
}
Ejemplo n.º 12
0
static void spectool_channel_size_request (GtkWidget *widget, GtkRequisition *requisition) {
	SpectoolWidget *wwidget = SPECTOOL_WIDGET(widget);

	requisition->width = 0;
	requisition->height = 25;

	if (GTK_BIN(wwidget)->child && GTK_WIDGET_VISIBLE(GTK_BIN(wwidget)->child)) {
		GtkRequisition child_requisition;

		gtk_widget_size_request(GTK_BIN(wwidget)->child, &child_requisition);

		requisition->width += child_requisition.width;
		requisition->height += child_requisition.height;
	}
}
Ejemplo n.º 13
0
void notify_stack_add_window(NotifyStack* stack, GtkWindow* nw, gboolean new_notification)
{
	GtkRequisition  req;
	gint            x, y;

	gtk_widget_size_request(GTK_WIDGET(nw), &req);
	notify_stack_shift_notifications(stack, nw, NULL, req.width, req.height + NOTIFY_STACK_SPACING, &x, &y);
	theme_move_notification(nw, x, y);

	if (new_notification)
	{
		g_signal_connect_swapped(G_OBJECT(nw), "destroy", G_CALLBACK(notify_stack_remove_window), stack);
		stack->windows = g_list_prepend(stack->windows, nw);
	}
}
Ejemplo n.º 14
0
static void
gtk_vkb_button_size_request (GtkWidget *widget, GtkRequisition *requisition)
{
	GtkBin *bin = GTK_BIN(widget);

	requisition->width = 0;
	requisition->height = 0;

	if (bin->child && GTK_WIDGET_VISIBLE(bin->child)) {
		GtkRequisition child_requisition;
		gtk_widget_size_request(bin->child, &child_requisition);
		requisition->width += child_requisition.width;
		requisition->height += child_requisition.height;
	}
}
Ejemplo n.º 15
0
static gint
cpufreq_applet_get_max_unit_width (CPUFreqApplet *applet)
{
	GtkWidget     *label;
#if !GTK_CHECK_VERSION (3, 0, 0)
	GtkRequisition req;
#endif
	gint           w1, w2;

	if (applet->max_unit_width > 0)
		return applet->max_unit_width;

	label = gtk_label_new ("GHz");
#if GTK_CHECK_VERSION (3, 0, 0)
	gtk_widget_get_preferred_width (applet->label, &w1, NULL);
#else
	gtk_widget_size_request (label, &req);
	w1 = req.width;
#endif

	gtk_label_set_text (GTK_LABEL (label), "MHz");
#if GTK_CHECK_VERSION (3, 0, 0)
	gtk_widget_get_preferred_width (applet->label, &w2, NULL);
#else
	gtk_widget_size_request (label, &req);
	w2 = req.width;
#endif

	gtk_widget_destroy (label);
#if GTK_CHECK_VERSION (3, 0, 0)
	applet->max_unit_width = MAX (w1, w2)-1;
#else
	applet->max_unit_width = MAX (w1, w2);
#endif
	return applet->max_unit_width;
}
Ejemplo n.º 16
0
static void matenu_menu_bar_real_size_request (GtkWidget* base, GtkRequisition* req) {
	MatenuMenuBar * self;
	GtkRequisition _tmp0_ = {0};
	GtkRequisition r;
	self = (MatenuMenuBar*) base;
	r = (_tmp0_.width = 0, _tmp0_.height = 0, _tmp0_);
	GTK_WIDGET_CLASS (matenu_menu_bar_parent_class)->size_request ((GtkWidget*) GTK_MENU_BAR (self), req);
	gtk_widget_size_request ((GtkWidget*) self->priv->_overflown_arrow, &r);
	if (r.width > (*req).width) {
		(*req).width = r.width;
	}
	if (r.height > (*req).height) {
		(*req).height = r.height;
	}
}
/**
 * eel_gtk_widget_get_preferred_dimensions:
 * @gtk_widget: The source GtkWidget.
 *
 * Return value: The widget's preferred dimensions.  The preferred dimensions are
 *               computed by calling the widget's 'size_request' method and thus
 *               could potentially be expensive for complicated widgets.
 */
EelDimensions
eel_gtk_widget_get_preferred_dimensions (GtkWidget *gtk_widget)
{
	GtkRequisition requisition;
	EelDimensions preferred_dimensions;

	g_return_val_if_fail (GTK_IS_WIDGET (gtk_widget), eel_dimensions_empty);

	gtk_widget_size_request (gtk_widget, &requisition);

	preferred_dimensions.width = (int) requisition.width;
	preferred_dimensions.height = (int) requisition.height;

	return preferred_dimensions;
}
Ejemplo n.º 18
0
static void sp_button_size_request(GtkWidget *widget, GtkRequisition *requisition)
{
    GtkWidget *child = gtk_bin_get_child(GTK_BIN(widget));
    GtkStyle *style = gtk_widget_get_style(widget);

    if (child) {
        gtk_widget_size_request(GTK_WIDGET(child), requisition);
    } else {
        requisition->width = 0;
        requisition->height = 0;
    }

    requisition->width += 2 + 2 * MAX(2, style->xthickness);
    requisition->height += 2 + 2 * MAX(2, style->ythickness);
}
Ejemplo n.º 19
0
static void
constrain_list_size (GtkWidget      *widget,
                     GtkRequisition *requisition,
                     GtkWidget      *to_size)
{
        GtkRequisition req;
        int            max_height;

        /* Constrain height to be the tree height up to a max */
        max_height = (gdk_screen_get_height (gtk_widget_get_screen (widget))) / 4;

        gtk_widget_size_request (to_size, &req);

        requisition->height = MIN (req.height, max_height);
}
Ejemplo n.º 20
0
static void
gtk_combo_button_get_pos (GtkComboButton * combo_button, gint * x, gint * y, gint * height, gint * width)
{
  GtkBin *popwin;
  GtkWidget *widget;

  gint real_height, real_width;
  GtkRequisition child_requisition;
  gint avail_height, avail_width;
  gint min_height, min_width;
  gint work_width;
  gint work_height;

  widget = GTK_WIDGET(combo_button);
  popwin = GTK_BIN (combo_button->popwin);

  gdk_window_get_origin (combo_button->button->window, x, y);
  *x += combo_button->button->allocation.x;
  *y += combo_button->button->allocation.y;

  real_height = combo_button->button->allocation.height;
  real_width = combo_button->button->allocation.width + combo_button->arrow->allocation.width;

  *y += real_height;
  avail_height = gdk_screen_height () - *y;
  avail_width = gdk_screen_width() - *x;

  gtk_widget_size_request (combo_button->frame, &child_requisition);

  min_height = child_requisition.height;
  min_width = child_requisition.width;

  work_width = work_height = 0;

  if(work_height+child_requisition.height > avail_height)
    if(work_height + min_height > avail_height &&
       *y - real_height > avail_height)
      	      *y -= (work_height + child_requisition.height + real_height);

  if(work_width+child_requisition.width > avail_width)
    if(work_width + min_width > avail_width &&
       *x - real_width > avail_width)
      	      *x = *x + real_width - (work_width + child_requisition.width);

  *width = work_width + child_requisition.width;
  *height = work_height + child_requisition.height;
  
}
Ejemplo n.º 21
0
static gint
cpufreq_applet_get_max_label_width (CPUFreqApplet *applet)
{
	GList *available_freqs;
	gint   width = 0;

	if (applet->max_label_width > 0)
		return applet->max_label_width;

	if (!CPUFREQ_IS_MONITOR (applet->monitor))
		return 0;

	available_freqs = cpufreq_monitor_get_available_frequencies (applet->monitor);
	while (available_freqs) {
		GtkWidget     *label;
#if GTK_CHECK_VERSION (3, 0, 0)
		gint           label_width;
#else
		GtkRequisition req;
#endif
		const gchar   *text;
		gchar         *freq_text;
		gint           freq;

		text = (const gchar *) available_freqs->data;
		freq = atoi (text);

		freq_text = cpufreq_utils_get_frequency_label (freq);
		label = gtk_label_new (freq_text);
#if GTK_CHECK_VERSION (3, 0, 0)
		gtk_widget_get_preferred_width (applet->label, &label_width, NULL);
		width = MAX (width, label_width); 
#endif
#if !GTK_CHECK_VERSION (3, 0, 0)
		gtk_widget_size_request (label, &req);
		width = MAX (width, req.width);
#endif

		g_free (freq_text);
		gtk_widget_destroy (label);

		available_freqs = g_list_next (available_freqs);
	}

	applet->max_label_width = width;

	return width;
}
Ejemplo n.º 22
0
// Calculate the zoom ratio required to fit the whole image on the screen.
float UI_calcZoomToFitScreen(GtkWindow* window, GtkWidget* drawingArea, uint32_t imageWidth, uint32_t imageHeight)
{
    int windowWidth, windowHeight;
    int drawingWidth, drawingHeight;
    int reqWidth, reqHeight;
    uint32_t screenWidth, screenHeight;
	
    gtk_window_get_size(window, &windowWidth, &windowHeight);
    GtkRequisition size_req;
    gtk_widget_size_request (drawingArea, &size_req);
    drawingWidth = size_req.width;
    drawingHeight = size_req.height;
    gtk_widget_get_size_request(drawingArea, &reqWidth, &reqHeight);

    // Take borders and captions into consideration (GTK doesn't seem to
    // support this so we'll have to guess)
    windowWidth += 10;
    windowHeight += 10;

    // Take drawing area out of the equation, how much extra do we need for additional controls?
    // and then how much does that leave us for the image?
    uint32_t availableWidth = maxWindowWidth - (windowWidth - drawingWidth);
    uint32_t availableHeight = maxWindowHeight - (windowHeight - drawingHeight);

    float ratio;
    // Calculate zoom ratio
    if (imageWidth > availableWidth || imageHeight > availableHeight)
    {
        float wratio = (imageWidth <= availableWidth) ? 1
                       : (float (availableWidth) / float (imageWidth));
        float hratio = (imageHeight <= availableHeight) ? 1
                       : (float (availableHeight) / float (imageHeight));
        if (wratio < hratio)
            ratio = wratio;
        else
            ratio = hratio;
    }
    else
        ratio = 1;

    printf ("UI_calcZoomToFitScreen(): max %dx%d, win %dx%d, drawarea %dx%d (%dx%d), "
            "available %dx%d, image %dx%d, scale %.6f\n",
            maxWindowWidth, maxWindowHeight, windowWidth, windowHeight,
            drawingWidth, drawingHeight, reqWidth, reqHeight,
            availableWidth, availableHeight, imageWidth, imageHeight, ratio);

    return ratio;
}
Ejemplo n.º 23
0
static void
menu_position (GtkMenu             *menu,
	       gint                *x,
	       gint                *y,
	       gboolean            *push_in,
	       PlumaDocumentsPanel *panel)
{
	GtkTreePath *path;
	GdkRectangle rect;
	gint wx, wy;
	GtkAllocation allocation;
	GtkRequisition requisition;
	GtkWidget *w;

	w = panel->priv->treeview;

	gtk_widget_get_allocation(w, &allocation);

	path = get_current_path (panel);

	gtk_tree_view_get_cell_area (GTK_TREE_VIEW (w),
				     path,
				     NULL,
				     &rect);

	wx = rect.x;
	wy = rect.y;

	gdk_window_get_origin (gtk_widget_get_window (w), x, y);
	
	gtk_widget_size_request (GTK_WIDGET (menu), &requisition);

	if (gtk_widget_get_direction (w) == GTK_TEXT_DIR_RTL)
	{
		*x += allocation.x + allocation.width - requisition.width - 10;
	}
	else
	{
		*x += allocation.x + 10;
	}

	wy = MAX (*y + 5, *y + wy + 5);
	wy = MIN (wy, *y + allocation.height - requisition.height - 5);
	
	*y = wy;

	*push_in = TRUE;
}
Ejemplo n.º 24
0
static void
popup_button_position (PlannerPopupButton *button,
		       gint               *x,
		       gint               *y)
{
	PlannerPopupButtonPriv *priv;
	GtkWidget              *button_widget;
	GtkRequisition          popup_req;
	GdkScreen              *screen;
	gint                    monitor_num;
	GdkRectangle            monitor;

	priv = GET_PRIV (button);

	button_widget = GTK_WIDGET (button);

	gdk_window_get_origin (button_widget->window, x, y);

	if (! gtk_widget_get_has_window (button_widget)) {
		*x += button_widget->allocation.x;
		*y += button_widget->allocation.y;
	}

	/* The popup should be placed below the button, right-aligned to it. */
	*y += button_widget->allocation.height;
	*x += button_widget->allocation.width;

	gtk_widget_size_request (priv->popup_widget, &popup_req);

	*x -= popup_req.width;

	/* Don't popup outside the monitor edges. */
	screen = gtk_widget_get_screen (GTK_WIDGET (button));
	monitor_num = gdk_screen_get_monitor_at_window (
		screen, GTK_WIDGET (button)->window);
	gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);

	if (*x < monitor.x) {
		*x = monitor.x;
	}
	else if (*x + popup_req.width > monitor.x + monitor.width) {
		*x = monitor.x + monitor.width - popup_req.width;
	}

	if (*y + popup_req.height > monitor.y + monitor.height) {
		*y -= popup_req.height + button_widget->allocation.height;
	}
}
Ejemplo n.º 25
0
static void tab_completion_popup_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data)
{
	TabCompData *td = data;
	gint height;
	PangoLayout *layout;
	PangoRectangle strong_pos, weak_pos;
	gint length;
	gint xoffset, yoffset;
	GtkRequisition req;
	GdkScreen *screen;
	gint monitor_num;
	GdkRectangle monitor;
	GtkRequisition requisition;
	GtkAllocation allocation;

	gdk_window_get_origin(gtk_widget_get_window(GTK_WIDGET(td->entry)), x, y);

	screen = gtk_widget_get_screen(GTK_WIDGET(menu));
	monitor_num = gdk_screen_get_monitor_at_window(screen, gtk_widget_get_window(GTK_WIDGET(td->entry)));
	gdk_screen_get_monitor_geometry(screen, monitor_num, &monitor);

	gtk_widget_size_request(GTK_WIDGET(menu), &req);

	length = strlen(gtk_entry_get_text(GTK_ENTRY(td->entry)));
	gtk_entry_get_layout_offsets(GTK_ENTRY(td->entry), &xoffset, &yoffset);

	layout = gtk_entry_get_layout(GTK_ENTRY(td->entry));
	pango_layout_get_cursor_pos(layout, length, &strong_pos, &weak_pos);

	*x += strong_pos.x / PANGO_SCALE + xoffset;

	gtk_widget_get_requisition(td->entry, &requisition);
	gtk_widget_get_allocation(td->entry, &allocation);

	height = MIN(requisition.height, allocation.height);

	if (req.height > monitor.y + monitor.height - *y - height &&
	    *y - monitor.y >  monitor.y + monitor.height - *y)
		{
		height = MIN(*y - monitor.y, req.height);
		gtk_widget_set_size_request(GTK_WIDGET(menu), -1, height);
		*y -= height;
		}
	else
		{
		*y += height;
		}
}
Ejemplo n.º 26
0
static int
get_popup_height (GnomeCanvasItem *item,
                  int space_available,
                  int row_height,
                  gpointer user_data)
{
    GtkWidget *cal = GTK_WIDGET (GNC_DATE_PICKER (item)->calendar);
    GtkRequisition req;

    req.height = 0;
    req.width = 0;

    gtk_widget_size_request (cal, &req);

    return req.height;
}
Ejemplo n.º 27
0
static gint
cpufreq_applet_get_max_perc_width (CPUFreqApplet *applet)
{
	GtkWidget      *label;
	GtkRequisition req;

	if (applet->max_perc_width > 0)
		return applet->max_perc_width;

	label = gtk_label_new ("100%");
	gtk_widget_size_request (label, &req);
	applet->max_perc_width = req.width;
	gtk_widget_destroy (label);

	return applet->max_perc_width;
}
Ejemplo n.º 28
0
static void
gtk_mirror_bin_size_request (GtkWidget      *widget,
                              GtkRequisition *requisition)
{
  GtkMirrorBin *bin = GTK_MIRROR_BIN (widget);
  GtkRequisition child_requisition;

  child_requisition.width = 0;
  child_requisition.height = 0;

  if (bin->child && gtk_widget_get_visible (bin->child))
    gtk_widget_size_request (bin->child, &child_requisition);

  requisition->width = GTK_CONTAINER (widget)->border_width * 2 + child_requisition.width + 10;
  requisition->height = GTK_CONTAINER (widget)->border_width * 2 + child_requisition.height * 2 + 10;
}
Ejemplo n.º 29
0
gboolean
greeter_item_ulist_setup (void)
{
	GreeterItemInfo *info;

	info = greeter_lookup_id ("user-pw-entry");
	if (info && info->item &&
	    GNOME_IS_CANVAS_WIDGET (info->item) &&
	    GTK_IS_ENTRY (GNOME_CANVAS_WIDGET (info->item)->widget)) {
		pam_entry = GNOME_CANVAS_WIDGET (info->item)->widget;
	}

	info = greeter_lookup_id ("userlist");

	if (info && info->item &&
	    GNOME_IS_CANVAS_WIDGET (info->item)) {
		GtkWidget *sw = GNOME_CANVAS_WIDGET (info->item)->widget;

		if (GTK_IS_SCROLLED_WINDOW (sw) && 
		    GTK_IS_TREE_VIEW (GTK_BIN (sw)->child)) {
			GtkRequisition req;
			gdouble        height;

			user_list = GTK_BIN (sw)->child;

			force_no_tree_separators (user_list);

			greeter_generate_userlist (user_list, info);

			/* Reset size of the widget canvas item so it
			 * is the same size as the userlist.  This
			 * avoids the ugly white background displayed
			 * below the Face Browser when the list isn't
			 * as large as the rectangle defined in the
			 * MDM theme file.
			 */

			gtk_widget_size_request (user_list, &req);
			g_object_get (info->item, "height", &height, NULL);

			if (req.height < height)
				g_object_set (info->item, "height", (double)req.height, NULL);
		}
	}

	return TRUE;
}
Ejemplo n.º 30
0
/**
 * gimp_menu_position:
 * @menu: a #GtkMenu widget
 * @x: pointer to horizontal position
 * @y: pointer to vertical position
 *
 * Positions a #GtkMenu so that it pops up on screen.  This function
 * takes care of the preferred popup direction (taken from the widget
 * render direction) and it handles multiple monitors representing a
 * single #GdkScreen (Xinerama).
 *
 * You should call this function with @x and @y initialized to the
 * origin of the menu. This is typically the center of the widget the
 * menu is popped up from. gimp_menu_position() will then decide if
 * and how these initial values need to be changed.
 **/
void
gimp_menu_position (GtkMenu *menu,
                    gint    *x,
                    gint    *y)
{
  GtkWidget      *widget;
  GdkScreen      *screen;
  GtkRequisition  requisition;
  GdkRectangle    rect;
  gint            monitor;

  g_return_if_fail (GTK_IS_MENU (menu));
  g_return_if_fail (x != NULL);
  g_return_if_fail (y != NULL);

  widget = GTK_WIDGET (menu);

  screen = gtk_widget_get_screen (widget);

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

  gtk_menu_set_screen (menu, screen);

  gtk_widget_size_request (widget, &requisition);

  if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
    {
      *x -= requisition.width;
      if (*x < rect.x)
        *x += requisition.width;
    }
  else
    {
      if (*x + requisition.width > rect.x + rect.width)
        *x -= requisition.width;
    }

  if (*x < rect.x)
    *x = rect.x;

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

  if (*y < rect.y)
    *y = rect.y;
}